diff --git a/Common/src/main/java/at/petrak/hexcasting/api/PatternRegistry.kt b/Common/src/main/java/at/petrak/hexcasting/api/PatternRegistry.kt index b1ba09b1..cddcafc8 100644 --- a/Common/src/main/java/at/petrak/hexcasting/api/PatternRegistry.kt +++ b/Common/src/main/java/at/petrak/hexcasting/api/PatternRegistry.kt @@ -212,6 +212,7 @@ object PatternRegistry { private const val TAG_OP_ID = "op_id" private const val TAG_START_DIR = "start_dir" + @JvmStatic fun getPatternCountInfo(): String = "Loaded ${regularPatternLookup.size} regular patterns, " + "${perWorldPatternLookup.size} per-world patterns, and " + "${specialHandlers.size} special handlers." diff --git a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgCastParticleAck.java b/Common/src/main/java/at/petrak/hexcasting/common/network/MsgCastParticleAck.java index 9e94a063..174e1822 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgCastParticleAck.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/network/MsgCastParticleAck.java @@ -18,7 +18,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc; * Sent server->client to spray particles everywhere. */ public record MsgCastParticleAck(ParticleSpray spray, FrozenColorizer colorizer) implements IMessage { - public static final ResourceLocation ID = modLoc("cPrtl"); + public static final ResourceLocation ID = modLoc("cprtcl"); @Override public ResourceLocation getFabricId() { diff --git a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgNewSpellPatternAck.java b/Common/src/main/java/at/petrak/hexcasting/common/network/MsgNewSpellPatternAck.java index a0ab3366..72c48fea 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgNewSpellPatternAck.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/network/MsgNewSpellPatternAck.java @@ -17,7 +17,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc; * Sent server->client when the player finishes casting a spell. */ public record MsgNewSpellPatternAck(ControllerInfo info) implements IMessage { - public static final ResourceLocation ID = modLoc("patSC"); + public static final ResourceLocation ID = modLoc("pat_sc"); @Override public ResourceLocation getFabricId() { diff --git a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgNewSpellPatternSyn.java b/Common/src/main/java/at/petrak/hexcasting/common/network/MsgNewSpellPatternSyn.java index 3d19e8d7..62662cb7 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgNewSpellPatternSyn.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/network/MsgNewSpellPatternSyn.java @@ -28,7 +28,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc; public record MsgNewSpellPatternSyn(InteractionHand handUsed, HexPattern pattern, List resolvedPatterns) implements IMessage { - public static final ResourceLocation ID = modLoc("patCS"); + public static final ResourceLocation ID = modLoc("pat_cs"); @Override public ResourceLocation getFabricId() { diff --git a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgOpenSpellGuiAck.java b/Common/src/main/java/at/petrak/hexcasting/common/network/MsgOpenSpellGuiAck.java index 5a036075..349f6c2b 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/network/MsgOpenSpellGuiAck.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/network/MsgOpenSpellGuiAck.java @@ -19,7 +19,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc; */ public record MsgOpenSpellGuiAck(InteractionHand hand, List patterns, List components) implements IMessage { - public static final ResourceLocation ID = modLoc("cGui"); + public static final ResourceLocation ID = modLoc("cgui"); @Override public ResourceLocation getFabricId() { diff --git a/Fabric/src/main/java/at/petrak/hexcasting/FabricHexClientInitializer.kt b/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexClientInitializer.kt similarity index 96% rename from Fabric/src/main/java/at/petrak/hexcasting/FabricHexClientInitializer.kt rename to Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexClientInitializer.kt index f9737274..54f73dca 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/FabricHexClientInitializer.kt +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexClientInitializer.kt @@ -1,3 +1,5 @@ +package at.petrak.hexcasting.fabric + import at.petrak.hexcasting.client.ClientTickCounter import at.petrak.hexcasting.client.HexAdditionalRenderers import at.petrak.hexcasting.client.RegisterClientStuff diff --git a/Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt b/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexInitializer.kt similarity index 98% rename from Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt rename to Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexInitializer.kt index 22d61e1f..9e93018c 100644 --- a/Fabric/src/main/java/at/petrak/hexcasting/FabricHexInitializer.kt +++ b/Fabric/src/main/java/at/petrak/hexcasting/fabric/FabricHexInitializer.kt @@ -1,3 +1,5 @@ +package at.petrak.hexcasting.fabric + import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers import at.petrak.hexcasting.api.mod.HexStatistics import at.petrak.hexcasting.common.blocks.behavior.HexComposting @@ -8,7 +10,6 @@ import at.petrak.hexcasting.common.entities.HexEntities import at.petrak.hexcasting.common.lib.* import at.petrak.hexcasting.common.misc.Brainsweeping import at.petrak.hexcasting.common.recipe.HexRecipeSerializers -import at.petrak.hexcasting.fabric.FabricHexConfig import at.petrak.hexcasting.fabric.event.VillagerConversionCallback import at.petrak.hexcasting.fabric.network.FabricPacketHandler import net.fabricmc.api.ModInitializer diff --git a/Fabric/src/main/resources/fabric.mod.json b/Fabric/src/main/resources/fabric.mod.json index 7c0f5e3f..aabb7970 100644 --- a/Fabric/src/main/resources/fabric.mod.json +++ b/Fabric/src/main/resources/fabric.mod.json @@ -19,10 +19,10 @@ "environment": "*", "entrypoints": { "main": [ - {"adapter": "kotlin", "value": "at.petrak.hexcasting.FabricHexInitializer"} + {"adapter": "kotlin", "value": "at.petrak.hexcasting.fabric.FabricHexInitializer"} ], "client": [ - {"adapter": "kotlin", "value": "at.petrak.hexcasting.FabricHexInitializer"} + {"adapter": "kotlin", "value": "at.petrak.hexcasting.fabric.FabricHexClientInitializer"} ], "cardinal-components": [ "at.petrak.hexcasting.fabric.cc.HexCardinalComponents" diff --git a/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt b/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt deleted file mode 100644 index b95a2e21..00000000 --- a/Forge/src/main/java/at/petrak/hexcasting/ForgeHexInitializer.kt +++ /dev/null @@ -1,169 +0,0 @@ -package at.petrak.hexcasting - -import at.petrak.hexcasting.api.HexAPI -import at.petrak.hexcasting.api.PatternRegistry -import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers -import at.petrak.hexcasting.api.mod.HexConfig -import at.petrak.hexcasting.api.mod.HexStatistics -import at.petrak.hexcasting.common.blocks.behavior.HexComposting -import at.petrak.hexcasting.common.blocks.behavior.HexStrippables -import at.petrak.hexcasting.common.casting.RegisterPatterns -import at.petrak.hexcasting.common.casting.operators.spells.great.OpFlight -import at.petrak.hexcasting.common.command.PatternResLocArgument -import at.petrak.hexcasting.common.entities.HexEntities -import at.petrak.hexcasting.common.lib.* -import at.petrak.hexcasting.common.misc.Brainsweeping -import at.petrak.hexcasting.common.recipe.HexRecipeSerializers -import at.petrak.hexcasting.forge.ForgeHexConfig -import at.petrak.hexcasting.forge.ForgeOnlyEvents -import at.petrak.hexcasting.forge.cap.CapSyncers -import at.petrak.hexcasting.forge.datagen.HexDataGenerators -import at.petrak.hexcasting.forge.datagen.lootmods.HexLootModifiers -import at.petrak.hexcasting.forge.network.ForgePacketHandler -import net.minecraft.commands.synchronization.ArgumentTypes -import net.minecraft.commands.synchronization.EmptyArgumentSerializer -import net.minecraft.resources.ResourceLocation -import net.minecraft.world.item.Item -import net.minecraftforge.common.ForgeConfigSpec -import net.minecraftforge.event.RegisterCommandsEvent -import net.minecraftforge.event.RegistryEvent -import net.minecraftforge.event.entity.living.LivingConversionEvent -import net.minecraftforge.event.entity.living.LivingEvent -import net.minecraftforge.event.entity.player.PlayerInteractEvent.EntityInteract -import net.minecraftforge.fml.ModLoadingContext -import net.minecraftforge.fml.common.Mod -import net.minecraftforge.fml.config.ModConfig -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent -import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent -import net.minecraftforge.registries.ForgeRegistries -import net.minecraftforge.registries.IForgeRegistry -import net.minecraftforge.registries.IForgeRegistryEntry -import org.apache.logging.log4j.Logger -import java.util.function.BiConsumer -import java.util.function.Consumer - - -@Mod(HexAPI.MOD_ID) -object ForgeHexInitializer { - init { - initConfig() - - initRegistry() - initListeners() - - ArgumentTypes.register( - "hexcasting:pattern", - PatternResLocArgument::class.java, - EmptyArgumentSerializer { PatternResLocArgument.id() } - ) - HexAdvancementTriggers.registerTriggers() - } - - fun initConfig() { - val config = ForgeConfigSpec.Builder() - .configure { builder: ForgeConfigSpec.Builder? -> ForgeHexConfig(builder) } - val serverConfig = ForgeConfigSpec.Builder() - .configure { builder: ForgeConfigSpec.Builder? -> ForgeHexConfig.Server(builder) } - val clientConfig = ForgeConfigSpec.Builder() - .configure { builder: ForgeConfigSpec.Builder? -> ForgeHexConfig.Client(builder) } - HexConfig.setCommon(config.left) - HexConfig.setClient(clientConfig.left) - HexConfig.setServer(serverConfig.left) - ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, config.right) - ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, serverConfig.right) - ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, clientConfig.right) - } - - fun initRegistry() { - bind(ForgeRegistries.SOUND_EVENTS, HexSounds::registerSounds) - bind(ForgeRegistries.BLOCKS, HexBlocks::registerBlocks) - bind(ForgeRegistries.ITEMS, HexBlocks::registerBlockItems) - bind(ForgeRegistries.BLOCK_ENTITIES, HexBlockEntities::registerTiles) - bind(ForgeRegistries.ITEMS, HexItems::registerItems) - - bind(ForgeRegistries.RECIPE_SERIALIZERS, HexRecipeSerializers::registerSerializers) - - bind(ForgeRegistries.ENTITIES, HexEntities::registerEntities) - - bind(ForgeRegistries.PARTICLE_TYPES, HexParticles::registerParticles) - - val modBus = thedarkcolour.kotlinforforge.forge.MOD_BUS - HexLootModifiers.LOOT_MODS.register(modBus) - } - - fun initListeners() { - // mod lifecycle - val modBus = thedarkcolour.kotlinforforge.forge.MOD_BUS - // game events - val evBus = thedarkcolour.kotlinforforge.forge.FORGE_BUS - - modBus.addListener(ForgeHexClientInitializer::clientInit) - - modBus.addListener { evt: FMLCommonSetupEvent -> - evt.enqueueWork { - ForgePacketHandler.init() - HexComposting.setup() - HexStrippables.init() - } - } - - // We have to do these at some point when the registries are still open - modBus.addGenericListener(Item::class.java) { _: RegistryEvent -> - HexRecipeSerializers.registerTypes() - HexStatistics.register() - } - - modBus.addListener { _: FMLLoadCompleteEvent -> - RegisterPatterns.registerPatterns() - getLogger().info( - PatternRegistry.getPatternCountInfo() - ) - } - - evBus.addListener { evt: EntityInteract -> - val res = Brainsweeping.tradeWithVillager( - evt.player, evt.world, evt.hand, evt.target, - null - ) - if (res.consumesAction()) { - evt.isCanceled = true - evt.cancellationResult = res - } - } - evBus.addListener { evt: LivingConversionEvent.Post -> - Brainsweeping.copyBrainsweepFromVillager( - evt.entityLiving, evt.outcome - ) - } - - evBus.addListener { evt: LivingEvent.LivingUpdateEvent -> - OpFlight.tickDownFlight(evt.entityLiving) - } - - evBus.addListener { evt: RegisterCommandsEvent -> - HexCommands.register(evt.dispatcher) - } - - modBus.register(HexDataGenerators::class.java) - evBus.register(CapSyncers::class.java) - evBus.register(ForgeOnlyEvents::class.java) - } - - private fun > bind( - registry: IForgeRegistry, - source: Consumer> - ) { - thedarkcolour.kotlinforforge.forge.MOD_BUS.addGenericListener( - registry.registrySuperType - ) { event: RegistryEvent.Register -> - val forgeRegistry = event.registry - source.accept { t, rl -> - t.registryName = rl - forgeRegistry.register(t) - } - } - } - - @JvmStatic - fun getLogger(): Logger = HexAPI.LOGGER -} diff --git a/Forge/src/main/java/at/petrak/hexcasting/ForgeHexClientInitializer.java b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexClientInitializer.java similarity index 72% rename from Forge/src/main/java/at/petrak/hexcasting/ForgeHexClientInitializer.java rename to Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexClientInitializer.java index a3515808..619779ae 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/ForgeHexClientInitializer.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexClientInitializer.java @@ -1,4 +1,4 @@ -package at.petrak.hexcasting; +package at.petrak.hexcasting.forge; import at.petrak.hexcasting.client.ClientTickCounter; import at.petrak.hexcasting.client.HexAdditionalRenderers; @@ -10,23 +10,15 @@ import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; // This is Java because I can't kotlin-fu some of the consumers public class ForgeHexClientInitializer { @SubscribeEvent public static void clientInit(FMLClientSetupEvent evt) { - RegisterClientStuff.init(); + evt.enqueueWork(RegisterClientStuff::init); - var modBus = FMLJavaModLoadingContext.get().getModEventBus(); var evBus = MinecraftForge.EVENT_BUS; - modBus.addListener(EventPriority.LOWEST, (ParticleFactoryRegisterEvent e) -> - RegisterClientStuff.registerParticles()); - - modBus.addListener((EntityRenderersEvent.RegisterRenderers e) -> - RegisterClientStuff.registerBlockEntityRenderers(e::registerBlockEntityRenderer)); - evBus.addListener((RenderLevelLastEvent e) -> HexAdditionalRenderers.overlayLevel(e.getPoseStack(), e.getPartialTick())); @@ -40,4 +32,14 @@ public class ForgeHexClientInitializer { e.setCanceled(cancel); }); } + + @SubscribeEvent(priority = EventPriority.LOWEST) + public static void registerParticles(ParticleFactoryRegisterEvent evt) { + RegisterClientStuff.registerParticles(); + } + + @SubscribeEvent + public static void registerRenderers(EntityRenderersEvent.RegisterRenderers evt) { + RegisterClientStuff.registerBlockEntityRenderers(evt::registerBlockEntityRenderer); + } } diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexInitializer.java b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexInitializer.java new file mode 100644 index 00000000..9ee7707c --- /dev/null +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeHexInitializer.java @@ -0,0 +1,188 @@ +package at.petrak.hexcasting.forge; + +import at.petrak.hexcasting.api.HexAPI; +import at.petrak.hexcasting.api.PatternRegistry; +import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers; +import at.petrak.hexcasting.api.mod.HexConfig; +import at.petrak.hexcasting.api.mod.HexStatistics; +import at.petrak.hexcasting.common.blocks.behavior.HexComposting; +import at.petrak.hexcasting.common.blocks.behavior.HexStrippables; +import at.petrak.hexcasting.common.casting.RegisterPatterns; +import at.petrak.hexcasting.common.casting.operators.spells.great.OpFlight; +import at.petrak.hexcasting.common.command.PatternResLocArgument; +import at.petrak.hexcasting.common.entities.HexEntities; +import at.petrak.hexcasting.common.lib.*; +import at.petrak.hexcasting.common.misc.Brainsweeping; +import at.petrak.hexcasting.common.recipe.HexRecipeSerializers; +import at.petrak.hexcasting.forge.cap.CapSyncers; +import at.petrak.hexcasting.forge.cap.ForgeCapabilityHandler; +import at.petrak.hexcasting.forge.datagen.HexDataGenerators; +import at.petrak.hexcasting.forge.datagen.lootmods.HexLootModifiers; +import at.petrak.hexcasting.forge.network.ForgePacketHandler; +import at.petrak.hexcasting.forge.network.MsgBrainsweepAck; +import at.petrak.hexcasting.xplat.IXplatAbstractions; +import net.minecraft.commands.synchronization.ArgumentTypes; +import net.minecraft.commands.synchronization.EmptyArgumentSerializer; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.ToolActions; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.event.entity.living.LivingConversionEvent; +import net.minecraftforge.event.entity.living.LivingEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.event.world.BlockEvent; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.config.ModConfig; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; +import net.minecraftforge.network.PacketDistributor; +import net.minecraftforge.registries.ForgeRegistries; +import net.minecraftforge.registries.IForgeRegistry; +import net.minecraftforge.registries.IForgeRegistryEntry; +import thedarkcolour.kotlinforforge.KotlinModLoadingContext; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +@Mod(HexAPI.MOD_ID) +public class ForgeHexInitializer { + public ForgeHexInitializer() { + initConfig(); + initRegistry(); + initListeners(); + + } + + private static void initConfig() { + var config = new ForgeConfigSpec.Builder().configure(ForgeHexConfig::new); + var clientConfig = new ForgeConfigSpec.Builder().configure(ForgeHexConfig.Client::new); + var serverConfig = new ForgeConfigSpec.Builder().configure(ForgeHexConfig.Server::new); + HexConfig.setCommon(config.getLeft()); + HexConfig.setClient(clientConfig.getLeft()); + HexConfig.setServer(serverConfig.getLeft()); + var mlc = ModLoadingContext.get(); + mlc.registerConfig(ModConfig.Type.COMMON, config.getRight()); + mlc.registerConfig(ModConfig.Type.CLIENT, clientConfig.getRight()); + mlc.registerConfig(ModConfig.Type.SERVER, serverConfig.getRight()); + } + + private static void initRegistry() { + bind(ForgeRegistries.SOUND_EVENTS, HexSounds::registerSounds); + bind(ForgeRegistries.BLOCKS, HexBlocks::registerBlocks); + bind(ForgeRegistries.ITEMS, HexBlocks::registerBlockItems); + bind(ForgeRegistries.BLOCK_ENTITIES, HexBlockEntities::registerTiles); + bind(ForgeRegistries.ITEMS, HexItems::registerItems); + + bind(ForgeRegistries.RECIPE_SERIALIZERS, HexRecipeSerializers::registerSerializers); + + bind(ForgeRegistries.ENTITIES, HexEntities::registerEntities); + + bind(ForgeRegistries.PARTICLE_TYPES, HexParticles::registerParticles); + + HexLootModifiers.LOOT_MODS.register(getModEventBus()); + + ArgumentTypes.register(HexAPI.MOD_ID + ":pattern", PatternResLocArgument.class, + new EmptyArgumentSerializer<>(PatternResLocArgument::id)); + HexAdvancementTriggers.registerTriggers(); + } + + // https://github.com/VazkiiMods/Botania/blob/1.18.x/Forge/src/main/java/vazkii/botania/forge/ForgeCommonInitializer.java + private static > void bind(IForgeRegistry registry, + Consumer> source) { + getModEventBus().addGenericListener(registry.getRegistrySuperType(), + (RegistryEvent.Register event) -> { + IForgeRegistry forgeRegistry = event.getRegistry(); + source.accept((t, rl) -> { + t.setRegistryName(rl); + forgeRegistry.register(t); + }); + }); + } + + private static void initListeners() { + var modBus = getModEventBus(); + var evBus = MinecraftForge.EVENT_BUS; + + modBus.register(ForgeHexClientInitializer.class); + + modBus.addListener((FMLCommonSetupEvent evt) -> + evt.enqueueWork(() -> { + ForgePacketHandler.init(); + HexComposting.setup(); + HexStrippables.init(); + RegisterPatterns.registerPatterns(); + })); + + // We have to do these at some point when the registries are still open + modBus.addGenericListener(Item.class, (RegistryEvent evt) -> { + HexRecipeSerializers.registerTypes(); + HexStatistics.register(); + }); + + modBus.addListener((FMLLoadCompleteEvent evt) -> + HexAPI.LOGGER.info(PatternRegistry.getPatternCountInfo())); + + evBus.addListener((PlayerInteractEvent.EntityInteract evt) -> { + var res = Brainsweeping.tradeWithVillager( + evt.getPlayer(), evt.getWorld(), evt.getHand(), evt.getTarget(), null); + if (res.consumesAction()) { + evt.setCanceled(true); + evt.setCancellationResult(res); + } + }); + evBus.addListener((LivingConversionEvent.Post evt) -> + Brainsweeping.copyBrainsweepFromVillager(evt.getEntityLiving(), evt.getOutcome())); + + evBus.addListener((LivingEvent.LivingUpdateEvent evt) -> + OpFlight.INSTANCE.tickDownFlight(evt.getEntityLiving())); + + evBus.addListener((RegisterCommandsEvent evt) -> HexCommands.register(evt.getDispatcher())); + + // === Events implemented in other ways on Fabric + + // On Fabric this should be auto-synced + evBus.addListener((PlayerEvent.StartTracking evt) -> { + Entity target = evt.getTarget(); + if (evt.getPlayer() instanceof ServerPlayer serverPlayer && + target instanceof Mob mob && IXplatAbstractions.INSTANCE.isBrainswept(mob)) { + ForgePacketHandler.getNetwork() + .send(PacketDistributor.PLAYER.with(() -> serverPlayer), MsgBrainsweepAck.of(mob)); + } + }); + + // Implemented with a mixin on Farbc + evBus.addListener((BlockEvent.BlockToolModificationEvent evt) -> { + if (!evt.isSimulated() && evt.getToolAction() == ToolActions.AXE_STRIP) { + BlockState bs = evt.getState(); + var output = HexStrippables.STRIPPABLES.get(bs.getBlock()); + if (output != null) { + evt.setFinalState(output.withPropertiesOf(bs)); + } + } + }); + + // Caps are cardinal components on farbc + modBus.addListener(ForgeCapabilityHandler::registerCaps); + evBus.addGenericListener(ItemStack.class, ForgeCapabilityHandler::attachItemCaps); + + modBus.register(HexDataGenerators.class); + modBus.register(ForgeCapabilityHandler.class); + evBus.register(CapSyncers.class); + } + + // aaaauughhg + private static IEventBus getModEventBus() { + return KotlinModLoadingContext.Companion.get().getKEventBus(); + } +} diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeOnlyEvents.java b/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeOnlyEvents.java deleted file mode 100644 index f545738d..00000000 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/ForgeOnlyEvents.java +++ /dev/null @@ -1,41 +0,0 @@ -package at.petrak.hexcasting.forge; - -import at.petrak.hexcasting.common.blocks.behavior.HexStrippables; -import at.petrak.hexcasting.forge.network.ForgePacketHandler; -import at.petrak.hexcasting.forge.network.MsgBrainsweepAck; -import at.petrak.hexcasting.xplat.IXplatAbstractions; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.Mob; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraftforge.common.ToolActions; -import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.event.world.BlockEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.network.PacketDistributor; - -// Events we don't need on fabric for whatever reasons -public class ForgeOnlyEvents { - // On Fabric this should be auto-synced - @SubscribeEvent - public static void startTracking(PlayerEvent.StartTracking evt) { - Entity target = evt.getTarget(); - if (evt.getPlayer() instanceof ServerPlayer serverPlayer && - target instanceof Mob mob && IXplatAbstractions.INSTANCE.isBrainswept(mob)) { - ForgePacketHandler.getNetwork() - .send(PacketDistributor.PLAYER.with(() -> serverPlayer), MsgBrainsweepAck.of(mob)); - } - } - - // Implemented with a mixin - @SubscribeEvent - public static void stripBlock(BlockEvent.BlockToolModificationEvent evt) { - if (!evt.isSimulated() && evt.getToolAction() == ToolActions.AXE_STRIP) { - BlockState bs = evt.getState(); - var output = HexStrippables.STRIPPABLES.get(bs.getBlock()); - if (output != null) { - evt.setFinalState(output.withPropertiesOf(bs)); - } - } - } -} diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/ForgeCapabilityHandler.java b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/ForgeCapabilityHandler.java index 40ca5a82..f97e82d2 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/cap/ForgeCapabilityHandler.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/cap/ForgeCapabilityHandler.java @@ -25,7 +25,6 @@ import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.NonNullSupplier; import net.minecraftforge.event.AttachCapabilitiesEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -35,7 +34,6 @@ import java.util.function.Function; import java.util.function.Supplier; public class ForgeCapabilityHandler { - private static final ResourceLocation DATA_HOLDER_CAPABILITY = new ResourceLocation("hexcasting", "data_holder"); private static final ResourceLocation DATA_ITEM_CAPABILITY = new ResourceLocation("hexcasting", "data_item"); private static final ResourceLocation MANA_HOLDER_CAPABILITY = new ResourceLocation("hexcasting", "mana_holder"); @@ -43,7 +41,6 @@ public class ForgeCapabilityHandler { private static final ResourceLocation SPELL_HOLDER_CAPABILITY = new ResourceLocation("hexcasting", "spell_item"); private static final ResourceLocation COLORIZER_CAPABILITY = new ResourceLocation("hexcasting", "colorizer"); - @SubscribeEvent public static void registerCaps(RegisterCapabilitiesEvent evt) { evt.register(ManaHolder.class); evt.register(DataHolder.class); @@ -51,8 +48,7 @@ public class ForgeCapabilityHandler { evt.register(Colorizer.class); } - @SubscribeEvent - public static void attachCaps(AttachCapabilitiesEvent evt) { + public static void attachItemCaps(AttachCapabilitiesEvent evt) { ItemStack stack = evt.getObject(); if (stack.getItem() instanceof ManaHolderItem holder) { evt.addCapability(MANA_HOLDER_CAPABILITY, provide(HexCapabilities.MANA, @@ -71,8 +67,8 @@ public class ForgeCapabilityHandler { if (stack.getItem() instanceof DataHolderItem holder) { evt.addCapability(DATA_HOLDER_CAPABILITY, provide(HexCapabilities.DATUM, () -> new ItemBasedDataHolder(holder, stack))); - } else if (stack.is(Items.PUMPKIN_PIE)) // haha yes - { + } else if (stack.is(Items.PUMPKIN_PIE)) { + // haha yes evt.addCapability(DATA_ITEM_CAPABILITY, provide(HexCapabilities.DATUM, () -> new StaticDatumHolder((s) -> SpellDatum.make(Math.PI * s.getCount()), stack))); }