FORGE WORKS
This commit is contained in:
parent
ad18f9ec9e
commit
816c86cdc3
13 changed files with 214 additions and 234 deletions
|
@ -212,6 +212,7 @@ object PatternRegistry {
|
||||||
private const val TAG_OP_ID = "op_id"
|
private const val TAG_OP_ID = "op_id"
|
||||||
private const val TAG_START_DIR = "start_dir"
|
private const val TAG_START_DIR = "start_dir"
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
fun getPatternCountInfo(): String = "Loaded ${regularPatternLookup.size} regular patterns, " +
|
fun getPatternCountInfo(): String = "Loaded ${regularPatternLookup.size} regular patterns, " +
|
||||||
"${perWorldPatternLookup.size} per-world patterns, and " +
|
"${perWorldPatternLookup.size} per-world patterns, and " +
|
||||||
"${specialHandlers.size} special handlers."
|
"${specialHandlers.size} special handlers."
|
||||||
|
|
|
@ -18,7 +18,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
* Sent server->client to spray particles everywhere.
|
* Sent server->client to spray particles everywhere.
|
||||||
*/
|
*/
|
||||||
public record MsgCastParticleAck(ParticleSpray spray, FrozenColorizer colorizer) implements IMessage {
|
public record MsgCastParticleAck(ParticleSpray spray, FrozenColorizer colorizer) implements IMessage {
|
||||||
public static final ResourceLocation ID = modLoc("cPrtl");
|
public static final ResourceLocation ID = modLoc("cprtcl");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getFabricId() {
|
public ResourceLocation getFabricId() {
|
||||||
|
|
|
@ -17,7 +17,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
* Sent server->client when the player finishes casting a spell.
|
* Sent server->client when the player finishes casting a spell.
|
||||||
*/
|
*/
|
||||||
public record MsgNewSpellPatternAck(ControllerInfo info) implements IMessage {
|
public record MsgNewSpellPatternAck(ControllerInfo info) implements IMessage {
|
||||||
public static final ResourceLocation ID = modLoc("patSC");
|
public static final ResourceLocation ID = modLoc("pat_sc");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getFabricId() {
|
public ResourceLocation getFabricId() {
|
||||||
|
|
|
@ -28,7 +28,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
public record MsgNewSpellPatternSyn(InteractionHand handUsed, HexPattern pattern,
|
public record MsgNewSpellPatternSyn(InteractionHand handUsed, HexPattern pattern,
|
||||||
List<ResolvedPattern> resolvedPatterns)
|
List<ResolvedPattern> resolvedPatterns)
|
||||||
implements IMessage {
|
implements IMessage {
|
||||||
public static final ResourceLocation ID = modLoc("patCS");
|
public static final ResourceLocation ID = modLoc("pat_cs");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getFabricId() {
|
public ResourceLocation getFabricId() {
|
||||||
|
|
|
@ -19,7 +19,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
||||||
*/
|
*/
|
||||||
public record MsgOpenSpellGuiAck(InteractionHand hand, List<ResolvedPattern> patterns, List<Component> components)
|
public record MsgOpenSpellGuiAck(InteractionHand hand, List<ResolvedPattern> patterns, List<Component> components)
|
||||||
implements IMessage {
|
implements IMessage {
|
||||||
public static final ResourceLocation ID = modLoc("cGui");
|
public static final ResourceLocation ID = modLoc("cgui");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation getFabricId() {
|
public ResourceLocation getFabricId() {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
package at.petrak.hexcasting.fabric
|
||||||
|
|
||||||
import at.petrak.hexcasting.client.ClientTickCounter
|
import at.petrak.hexcasting.client.ClientTickCounter
|
||||||
import at.petrak.hexcasting.client.HexAdditionalRenderers
|
import at.petrak.hexcasting.client.HexAdditionalRenderers
|
||||||
import at.petrak.hexcasting.client.RegisterClientStuff
|
import at.petrak.hexcasting.client.RegisterClientStuff
|
|
@ -1,3 +1,5 @@
|
||||||
|
package at.petrak.hexcasting.fabric
|
||||||
|
|
||||||
import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers
|
import at.petrak.hexcasting.api.advancements.HexAdvancementTriggers
|
||||||
import at.petrak.hexcasting.api.mod.HexStatistics
|
import at.petrak.hexcasting.api.mod.HexStatistics
|
||||||
import at.petrak.hexcasting.common.blocks.behavior.HexComposting
|
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.lib.*
|
||||||
import at.petrak.hexcasting.common.misc.Brainsweeping
|
import at.petrak.hexcasting.common.misc.Brainsweeping
|
||||||
import at.petrak.hexcasting.common.recipe.HexRecipeSerializers
|
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.event.VillagerConversionCallback
|
||||||
import at.petrak.hexcasting.fabric.network.FabricPacketHandler
|
import at.petrak.hexcasting.fabric.network.FabricPacketHandler
|
||||||
import net.fabricmc.api.ModInitializer
|
import net.fabricmc.api.ModInitializer
|
|
@ -19,10 +19,10 @@
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"main": [
|
"main": [
|
||||||
{"adapter": "kotlin", "value": "at.petrak.hexcasting.FabricHexInitializer"}
|
{"adapter": "kotlin", "value": "at.petrak.hexcasting.fabric.FabricHexInitializer"}
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
{"adapter": "kotlin", "value": "at.petrak.hexcasting.FabricHexInitializer"}
|
{"adapter": "kotlin", "value": "at.petrak.hexcasting.fabric.FabricHexClientInitializer"}
|
||||||
],
|
],
|
||||||
"cardinal-components": [
|
"cardinal-components": [
|
||||||
"at.petrak.hexcasting.fabric.cc.HexCardinalComponents"
|
"at.petrak.hexcasting.fabric.cc.HexCardinalComponents"
|
||||||
|
|
|
@ -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<Item> ->
|
|
||||||
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 <T : IForgeRegistryEntry<T>> bind(
|
|
||||||
registry: IForgeRegistry<T>,
|
|
||||||
source: Consumer<BiConsumer<T, ResourceLocation>>
|
|
||||||
) {
|
|
||||||
thedarkcolour.kotlinforforge.forge.MOD_BUS.addGenericListener(
|
|
||||||
registry.registrySuperType
|
|
||||||
) { event: RegistryEvent.Register<T> ->
|
|
||||||
val forgeRegistry = event.registry
|
|
||||||
source.accept { t, rl ->
|
|
||||||
t.registryName = rl
|
|
||||||
forgeRegistry.register(t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun getLogger(): Logger = HexAPI.LOGGER
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
package at.petrak.hexcasting;
|
package at.petrak.hexcasting.forge;
|
||||||
|
|
||||||
import at.petrak.hexcasting.client.ClientTickCounter;
|
import at.petrak.hexcasting.client.ClientTickCounter;
|
||||||
import at.petrak.hexcasting.client.HexAdditionalRenderers;
|
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.EventPriority;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
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
|
// This is Java because I can't kotlin-fu some of the consumers
|
||||||
public class ForgeHexClientInitializer {
|
public class ForgeHexClientInitializer {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void clientInit(FMLClientSetupEvent evt) {
|
public static void clientInit(FMLClientSetupEvent evt) {
|
||||||
RegisterClientStuff.init();
|
evt.enqueueWork(RegisterClientStuff::init);
|
||||||
|
|
||||||
var modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
|
||||||
var evBus = MinecraftForge.EVENT_BUS;
|
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) ->
|
evBus.addListener((RenderLevelLastEvent e) ->
|
||||||
HexAdditionalRenderers.overlayLevel(e.getPoseStack(), e.getPartialTick()));
|
HexAdditionalRenderers.overlayLevel(e.getPoseStack(), e.getPartialTick()));
|
||||||
|
|
||||||
|
@ -40,4 +32,14 @@ public class ForgeHexClientInitializer {
|
||||||
e.setCanceled(cancel);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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 <T extends IForgeRegistryEntry<T>> void bind(IForgeRegistry<T> registry,
|
||||||
|
Consumer<BiConsumer<T, ResourceLocation>> source) {
|
||||||
|
getModEventBus().addGenericListener(registry.getRegistrySuperType(),
|
||||||
|
(RegistryEvent.Register<T> event) -> {
|
||||||
|
IForgeRegistry<T> 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<Item> 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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -25,7 +25,6 @@ import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
import net.minecraftforge.common.util.NonNullSupplier;
|
import net.minecraftforge.common.util.NonNullSupplier;
|
||||||
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@ -35,7 +34,6 @@ import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ForgeCapabilityHandler {
|
public class ForgeCapabilityHandler {
|
||||||
|
|
||||||
private static final ResourceLocation DATA_HOLDER_CAPABILITY = new ResourceLocation("hexcasting", "data_holder");
|
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 DATA_ITEM_CAPABILITY = new ResourceLocation("hexcasting", "data_item");
|
||||||
private static final ResourceLocation MANA_HOLDER_CAPABILITY = new ResourceLocation("hexcasting", "mana_holder");
|
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 SPELL_HOLDER_CAPABILITY = new ResourceLocation("hexcasting", "spell_item");
|
||||||
private static final ResourceLocation COLORIZER_CAPABILITY = new ResourceLocation("hexcasting", "colorizer");
|
private static final ResourceLocation COLORIZER_CAPABILITY = new ResourceLocation("hexcasting", "colorizer");
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void registerCaps(RegisterCapabilitiesEvent evt) {
|
public static void registerCaps(RegisterCapabilitiesEvent evt) {
|
||||||
evt.register(ManaHolder.class);
|
evt.register(ManaHolder.class);
|
||||||
evt.register(DataHolder.class);
|
evt.register(DataHolder.class);
|
||||||
|
@ -51,8 +48,7 @@ public class ForgeCapabilityHandler {
|
||||||
evt.register(Colorizer.class);
|
evt.register(Colorizer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
public static void attachItemCaps(AttachCapabilitiesEvent<ItemStack> evt) {
|
||||||
public static void attachCaps(AttachCapabilitiesEvent<ItemStack> evt) {
|
|
||||||
ItemStack stack = evt.getObject();
|
ItemStack stack = evt.getObject();
|
||||||
if (stack.getItem() instanceof ManaHolderItem holder) {
|
if (stack.getItem() instanceof ManaHolderItem holder) {
|
||||||
evt.addCapability(MANA_HOLDER_CAPABILITY, provide(HexCapabilities.MANA,
|
evt.addCapability(MANA_HOLDER_CAPABILITY, provide(HexCapabilities.MANA,
|
||||||
|
@ -71,8 +67,8 @@ public class ForgeCapabilityHandler {
|
||||||
if (stack.getItem() instanceof DataHolderItem holder) {
|
if (stack.getItem() instanceof DataHolderItem holder) {
|
||||||
evt.addCapability(DATA_HOLDER_CAPABILITY, provide(HexCapabilities.DATUM,
|
evt.addCapability(DATA_HOLDER_CAPABILITY, provide(HexCapabilities.DATUM,
|
||||||
() -> new ItemBasedDataHolder(holder, stack)));
|
() -> 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,
|
evt.addCapability(DATA_ITEM_CAPABILITY, provide(HexCapabilities.DATUM,
|
||||||
() -> new StaticDatumHolder((s) -> SpellDatum.make(Math.PI * s.getCount()), stack)));
|
() -> new StaticDatumHolder((s) -> SpellDatum.make(Math.PI * s.getCount()), stack)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue