From 572490e880b10491c44f8522bd723f441e71ebac Mon Sep 17 00:00:00 2001 From: Xalcon Date: Wed, 16 Oct 2024 20:24:23 +0200 Subject: [PATCH] pass all parameters to original function #243 also registers the missing torchmaster command --- CHANGELOG.md | 4 ++ .../commands/CommandTorchmaster.java | 42 ++++++++++++++++++- .../xalcon/torchmaster/TorchmasterFabric.java | 4 ++ .../torchmaster/mixin/VillageSiegeMixin.java | 2 +- gradle.properties | 2 +- .../torchmaster/TorchmasterNeoforge.java | 8 +++- 6 files changed, 58 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1504c4..78cfdde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/common/src/main/java/net/xalcon/torchmaster/commands/CommandTorchmaster.java b/common/src/main/java/net/xalcon/torchmaster/commands/CommandTorchmaster.java index 2f9e964..3b536e8 100644 --- a/common/src/main/java/net/xalcon/torchmaster/commands/CommandTorchmaster.java +++ b/common/src/main/java/net/xalcon/torchmaster/commands/CommandTorchmaster.java @@ -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 @@ -70,7 +75,42 @@ public int execute(CommandContext 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 ctx) + { + var level = ctx.getSource().getLevel(); + try + { + var field = ServerLevel.class.getDeclaredField("customSpawners"); + field.setAccessible(true); + var customSpawnersList = (List)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; diff --git a/fabric/src/main/java/net/xalcon/torchmaster/TorchmasterFabric.java b/fabric/src/main/java/net/xalcon/torchmaster/TorchmasterFabric.java index 4e1e03c..6a21b44 100644 --- a/fabric/src/main/java/net/xalcon/torchmaster/TorchmasterFabric.java +++ b/fabric/src/main/java/net/xalcon/torchmaster/TorchmasterFabric.java @@ -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(); @@ -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)); } diff --git a/fabric/src/main/java/net/xalcon/torchmaster/mixin/VillageSiegeMixin.java b/fabric/src/main/java/net/xalcon/torchmaster/mixin/VillageSiegeMixin.java index e58b819..c1190bf 100644 --- a/fabric/src/main/java/net/xalcon/torchmaster/mixin/VillageSiegeMixin.java +++ b/fabric/src/main/java/net/xalcon/torchmaster/mixin/VillageSiegeMixin.java @@ -31,7 +31,7 @@ public abstract class VillageSiegeMixin ) private Vec3 torchmaster_tryToSetupSiege_findRandomSpawnPos(VillageSiege siege, ServerLevel level, BlockPos pos, Operation original) { - var result = original.call(level, pos); + var result = original.call(siege, level, pos); if(result != null) { var container = new EventResultContainer(EventResult.DEFAULT); diff --git a/gradle.properties b/gradle.properties index ebe88c2..75a0c4b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/neoforge/src/main/java/net/xalcon/torchmaster/TorchmasterNeoforge.java b/neoforge/src/main/java/net/xalcon/torchmaster/TorchmasterNeoforge.java index 992bc42..7dc33dd 100644 --- a/neoforge/src/main/java/net/xalcon/torchmaster/TorchmasterNeoforge.java +++ b/neoforge/src/main/java/net/xalcon/torchmaster/TorchmasterNeoforge.java @@ -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 @@ -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"); @@ -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()); + } } \ No newline at end of file