Skip to content

Commit

Permalink
pass all parameters to original function #243
Browse files Browse the repository at this point in the history
also registers the missing torchmaster command
  • Loading branch information
Xalcon committed Oct 16, 2024
1 parent 931319f commit 572490e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v21.1.4
- Fix crash during setup of a village siege on fabric
- Add missing torchmaster command from previous versions

## v21.1.3
- Fix spam related to config auto fixing on neoforge

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.ai.village.VillageSiege;
import net.minecraft.world.level.CustomSpawner;
import net.xalcon.torchmaster.Constants;
import net.xalcon.torchmaster.Torchmaster;
import net.xalcon.torchmaster.logic.entityblocking.TorchInfo;

import java.util.List;

public class CommandTorchmaster
{
public enum SubCommands
Expand Down Expand Up @@ -70,7 +75,42 @@ public int execute(CommandContext<CommandSourceStack> ctx)
source.sendSuccess(() -> Component.translatable(Constants.MOD_ID + ".command.entity_dump.completed"), false);
return 0;
}
};
},
TRY_SETUP_SIEGE("try_setup_siege")
{
@Override
public int execute(CommandContext<CommandSourceStack> ctx)
{
var level = ctx.getSource().getLevel();
try
{
var field = ServerLevel.class.getDeclaredField("customSpawners");
field.setAccessible(true);
var customSpawnersList = (List<CustomSpawner>)field.get(level);
for(var customSpawner : customSpawnersList)
{
if(customSpawner instanceof VillageSiege siege)
{
var siegeStateField = VillageSiege.class.getDeclaredField("siegeState");
siegeStateField.setAccessible(true);
siegeStateField.set(siege, siegeStateField.getType().getEnumConstants()[1]);

var hasSetupSiegeField = VillageSiege.class.getDeclaredField("hasSetupSiege");
hasSetupSiegeField.setAccessible(true);
hasSetupSiegeField.setBoolean(siege, false);

ctx.getSource().sendSystemMessage(Component.literal("Attempting village siege"));
}
}
}
catch(Exception ex)
{
ctx.getSource().sendSystemMessage(Component.literal("Exception during siege setup"));
Torchmaster.LOG.error("Error while setting up siege", ex);
}
return 0;
}
};

private final String translationKey;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
import net.minecraft.client.renderer.RenderType;
import net.xalcon.torchmaster.commands.CommandTorchmaster;

public class TorchmasterFabric implements ModInitializer {
public static final net.xalcon.torchmaster.TorchmasterConfig CONFIG = net.xalcon.torchmaster.TorchmasterConfig.createAndLoad();
Expand All @@ -24,6 +26,8 @@ public void onInitialize() {
Torchmaster.onWorldLoaded();
});
// BlockRenderLayerMap.INSTANCE.putBlock(ModRegistry.blockDreadLamp.get(), RenderType.cutout());

CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> CommandTorchmaster.register(dispatcher));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public abstract class VillageSiegeMixin
)
private Vec3 torchmaster_tryToSetupSiege_findRandomSpawnPos(VillageSiege siege, ServerLevel level, BlockPos pos, Operation<Vec3> original)
{
var result = original.call(level, pos);
var result = original.call(siege, level, pos);
if(result != null)
{
var container = new EventResultContainer(EventResult.DEFAULT);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Every field you add must be added to the root build.gradle expandProps map.

# Project
version=21.1.3-beta
version=21.1.4-beta
group=net.xalcon.torchmaster
java_version=21

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.neoforged.fml.javafmlmod.FMLJavaModLanguageProvider;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
import net.neoforged.neoforge.event.level.LevelEvent;
import net.xalcon.torchmaster.commands.CommandTorchmaster;

@Mod(Constants.MOD_ID)
public class TorchmasterNeoforge
Expand All @@ -25,6 +27,7 @@ public TorchmasterNeoforge(ModContainer container, IEventBus eventBus) {
// project.
eventBus.addListener(this::doClientStuff);
NeoForge.EVENT_BUS.addListener(TorchmasterNeoforge::loadComplete);
NeoForge.EVENT_BUS.addListener(TorchmasterNeoforge::onRegisterCommands);

container.registerConfig(ModConfig.Type.COMMON, TorchmasterNeoforgeConfig.spec, "torchmaster.toml");

Expand All @@ -43,5 +46,8 @@ private void doClientStuff(final FMLClientSetupEvent event) {
// ItemBlockRenderTypes.setRenderLayer(ModRegistry.blockDreadLamp.get(), RenderType.cutout());
}


private static void onRegisterCommands(RegisterCommandsEvent event)
{
CommandTorchmaster.register(event.getDispatcher());
}
}

0 comments on commit 572490e

Please sign in to comment.