From 84c7b0d61a6e26320750501f3e995fb588d83b90 Mon Sep 17 00:00:00 2001 From: Mrbysco Date: Wed, 16 Oct 2024 22:40:19 +0200 Subject: [PATCH] Move Entity registration code to InitEntities Move BiomeModifier and Condition registration code to ActuallyBiomeModifiers --- .../mod/ActuallyAdditions.java | 25 +++------------ .../mod/ActuallyAdditionsClient.java | 3 +- .../mod/entity/InitEntities.java | 20 ++++++------ .../mod/gen/ActuallyBiomeModifiers.java | 31 ++++++++++++++++++- .../BoolConfigFeatureBiomeModifier.java | 3 +- .../actuallyadditions/mod/items/Worm.java | 3 +- 6 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index 6eec6fabe..0345edc9e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -26,6 +26,7 @@ import de.ellpeck.actuallyadditions.mod.entity.EntityWorm; import de.ellpeck.actuallyadditions.mod.entity.InitEntities; import de.ellpeck.actuallyadditions.mod.event.CommonEvents; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; +import de.ellpeck.actuallyadditions.mod.gen.ActuallyBiomeModifiers; import de.ellpeck.actuallyadditions.mod.gen.ActuallyVillages; import de.ellpeck.actuallyadditions.mod.gen.modifier.BoolConfigFeatureBiomeModifier; import de.ellpeck.actuallyadditions.mod.gen.village.ActuallyPOITypes; @@ -89,22 +90,6 @@ public class ActuallyAdditions { public static final Logger LOGGER = LoggerFactory.getLogger(MODID); - private static final DeferredRegister> ENTITIES = DeferredRegister.create(BuiltInRegistries.ENTITY_TYPE, MODID); - public static final Supplier> ENTITY_WORM = ENTITIES.register("worm", () -> EntityType.Builder.of(EntityWorm::new, MobCategory.MISC).build(MODID + ":worm")); - - private static final DeferredRegister> CONDITION_CODECS = DeferredRegister.create(NeoForgeRegistries.Keys.CONDITION_CODECS, MODID); - public static final DeferredHolder, MapCodec> BOOL_CONFIG_CONDITION = CONDITION_CODECS.register("bool_config_condition", () -> BoolConfigCondition.CODEC); - - public static final DeferredRegister> BIOME_MODIFIER_SERIALIZERS = DeferredRegister.create(NeoForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, MODID); - public static final Supplier> BOOL_CONFIG_MODIFIER = BIOME_MODIFIER_SERIALIZERS.register("bool_config_feature_modifier", () -> - RecordCodecBuilder.mapCodec(builder -> builder.group( - Biome.LIST_CODEC.fieldOf("biomes").forGetter(BoolConfigFeatureBiomeModifier::biomes), - PlacedFeature.LIST_CODEC.fieldOf("features").forGetter(BoolConfigFeatureBiomeModifier::features), - GenerationStep.Decoration.CODEC.fieldOf("step").forGetter(BoolConfigFeatureBiomeModifier::step), - Codec.STRING.fieldOf("boolConfig").forGetter(BoolConfigFeatureBiomeModifier::boolConfig) - ).apply(builder, BoolConfigFeatureBiomeModifier::new)) - ); - public static boolean commonCapsLoaded; public ActuallyAdditions(IEventBus eventBus, ModContainer container, Dist dist) { @@ -121,9 +106,9 @@ public class ActuallyAdditions { ActuallyLootModifiers.init(eventBus); ActuallyContainers.CONTAINERS.register(eventBus); ArmorMaterials.init(eventBus); - ENTITIES.register(eventBus); - CONDITION_CODECS.register(eventBus); - BIOME_MODIFIER_SERIALIZERS.register(eventBus); + InitEntities.init(eventBus); + InitFluids.init(eventBus); + ActuallyBiomeModifiers.init(eventBus); eventBus.addListener(this::onConfigReload); ActuallyParticles.init(eventBus); ActuallyTags.init(); @@ -136,7 +121,6 @@ public class ActuallyAdditions { NeoForge.EVENT_BUS.addListener(ActuallyAdditions::reloadEvent); NeoForge.EVENT_BUS.addListener(Worm::onHoe); NeoForge.EVENT_BUS.addListener(ActuallyVillages::modifyVillageStructures); - InitFluids.init(eventBus); eventBus.addListener(PacketHandler::register); eventBus.addListener(this::setup); @@ -164,7 +148,6 @@ public class ActuallyAdditions { commonCapsLoaded = false; // Loader.isModLoaded("commoncapabilities"); new UpdateChecker(); - InitEntities.init(); // todo: [port] replace } private void onConfigReload(ModConfigEvent event) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java index 28cb4800f..f34d663ed 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditionsClient.java @@ -16,6 +16,7 @@ import de.ellpeck.actuallyadditions.mod.blocks.render.RenderBatteryBox; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderDisplayStand; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderEmpowerer; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderLaserRelay; +import de.ellpeck.actuallyadditions.mod.entity.InitEntities; import de.ellpeck.actuallyadditions.mod.entity.RenderWorm; import de.ellpeck.actuallyadditions.mod.event.ClientEvents; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; @@ -142,7 +143,7 @@ public class ActuallyAdditionsClient { event.registerBlockEntityRenderer(ActuallyBlocks.LASER_RELAY_ITEM_ADVANCED.getTileEntityType(), RenderLaserRelay::new); event.registerBlockEntityRenderer(ActuallyBlocks.LASER_RELAY_FLUIDS.getTileEntityType(), RenderLaserRelay::new); - event.registerEntityRenderer(ActuallyAdditions.ENTITY_WORM.get(), RenderWorm::new); + event.registerEntityRenderer(InitEntities.ENTITY_WORM.get(), RenderWorm::new); } public static void registerParticleFactories(RegisterParticleProvidersEvent event) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/entity/InitEntities.java b/src/main/java/de/ellpeck/actuallyadditions/mod/entity/InitEntities.java index 42bff110d..a8579c996 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/entity/InitEntities.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/entity/InitEntities.java @@ -11,19 +11,19 @@ package de.ellpeck.actuallyadditions.mod.entity; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.MobCategory; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredRegister; +import java.util.function.Supplier; public final class InitEntities { + private static final DeferredRegister> ENTITIES = DeferredRegister.create(BuiltInRegistries.ENTITY_TYPE, ActuallyAdditions.MODID); + public static final Supplier> ENTITY_WORM = ENTITIES.register("worm", () -> EntityType.Builder.of(EntityWorm::new, MobCategory.MISC).build(ActuallyAdditions.MODID + ":worm")); - public static void init() { - ActuallyAdditions.LOGGER.info("Initializing Entities..."); - - //EntityRegistry.registerModEntity(ActuallyAdditions.modLoc("worm"), EntityWorm.class, ActuallyAdditions.MODID + ".worm", 0, ActuallyAdditions.INSTANCE, 64, 1, false); + public static void init(IEventBus bus) { + ENTITIES.register(bus); } - - - public static void initClient() { - //RenderingRegistry.registerEntityRenderingHandler(EntityWorm.class, RenderWorm::new); - } - } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/ActuallyBiomeModifiers.java b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/ActuallyBiomeModifiers.java index a848823fd..e2d49f8fc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/ActuallyBiomeModifiers.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/ActuallyBiomeModifiers.java @@ -1,6 +1,10 @@ package de.ellpeck.actuallyadditions.mod.gen; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import de.ellpeck.actuallyadditions.mod.config.conditions.BoolConfigCondition; import de.ellpeck.actuallyadditions.mod.gen.modifier.BoolConfigFeatureBiomeModifier; import net.minecraft.core.HolderGetter; import net.minecraft.core.HolderSet; @@ -11,10 +15,35 @@ import net.minecraft.tags.BiomeTags; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.common.conditions.ICondition; import net.neoforged.neoforge.common.world.BiomeModifier; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; import net.neoforged.neoforge.registries.NeoForgeRegistries; -public class ActuallyBiomeModifiers { +import java.util.function.Supplier; + +public final class ActuallyBiomeModifiers { + private static final DeferredRegister> CONDITION_CODECS = DeferredRegister.create(NeoForgeRegistries.Keys.CONDITION_CODECS, ActuallyAdditions.MODID); + public static final DeferredHolder, MapCodec> BOOL_CONFIG_CONDITION = CONDITION_CODECS.register("bool_config_condition", () -> BoolConfigCondition.CODEC); + + public static final DeferredRegister> BIOME_MODIFIER_SERIALIZERS = DeferredRegister.create(NeoForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, ActuallyAdditions.MODID); + public static final Supplier> BOOL_CONFIG_MODIFIER = BIOME_MODIFIER_SERIALIZERS.register("bool_config_feature_modifier", () -> + RecordCodecBuilder.mapCodec(builder -> builder.group( + Biome.LIST_CODEC.fieldOf("biomes").forGetter(BoolConfigFeatureBiomeModifier::biomes), + PlacedFeature.LIST_CODEC.fieldOf("features").forGetter(BoolConfigFeatureBiomeModifier::features), + GenerationStep.Decoration.CODEC.fieldOf("step").forGetter(BoolConfigFeatureBiomeModifier::step), + Codec.STRING.fieldOf("boolConfig").forGetter(BoolConfigFeatureBiomeModifier::boolConfig) + ).apply(builder, BoolConfigFeatureBiomeModifier::new)) + ); + + public static void init(IEventBus bus) { + CONDITION_CODECS.register(bus); + BIOME_MODIFIER_SERIALIZERS.register(bus); + } + + protected static final ResourceKey ADD_BLACK_QUARTZ_ORE_MODIFIER = ResourceKey.create(NeoForgeRegistries.Keys.BIOME_MODIFIERS, ActuallyAdditions.modLoc("add_black_quartz")); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/modifier/BoolConfigFeatureBiomeModifier.java b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/modifier/BoolConfigFeatureBiomeModifier.java index b8025da2e..0472c393a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/modifier/BoolConfigFeatureBiomeModifier.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/modifier/BoolConfigFeatureBiomeModifier.java @@ -3,6 +3,7 @@ package de.ellpeck.actuallyadditions.mod.gen.modifier; import com.mojang.serialization.MapCodec; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.config.CommonConfig; +import de.ellpeck.actuallyadditions.mod.gen.ActuallyBiomeModifiers; import net.minecraft.core.Holder; import net.minecraft.core.HolderSet; import net.minecraft.world.level.biome.Biome; @@ -34,6 +35,6 @@ public record BoolConfigFeatureBiomeModifier(HolderSet biomes, HolderSet< @Override public MapCodec codec() { - return ActuallyAdditions.BOOL_CONFIG_MODIFIER.get(); + return ActuallyBiomeModifiers.BOOL_CONFIG_MODIFIER.get(); } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/Worm.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/Worm.java index 169855a28..e71410ca5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/Worm.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/Worm.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.items; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.config.CommonConfig; import de.ellpeck.actuallyadditions.mod.entity.EntityWorm; +import de.ellpeck.actuallyadditions.mod.entity.InitEntities; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionResult; @@ -48,7 +49,7 @@ public class Worm extends ItemBase { if (!worms.isEmpty()) return super.useOn(context); - EntityWorm worm = new EntityWorm(ActuallyAdditions.ENTITY_WORM.get(), level); + EntityWorm worm = new EntityWorm(InitEntities.ENTITY_WORM.get(), level); worm.setPos(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); worm.setCustomName(stack.getHoverName()); level.addFreshEntity(worm);