From 4ff8137aae9e5f80c43eca3c3993bc8acd42bd5b Mon Sep 17 00:00:00 2001 From: "Joseph T. McQuigg" Date: Thu, 19 Dec 2024 22:02:18 -0500 Subject: [PATCH] Remove Consumer Use for EntityAttributeCreation, USe SpawnPlacementRegisterEvent on Forge Signed-off-by: Joseph T. McQuigg --- CHANGELOG.md | 1 + .../potionstudios/biomeswevegone/BiomesWeveGone.java | 1 - .../biomeswevegone/world/entity/BWGEntities.java | 10 +++++++--- .../biomeswevegone/world/entity/manowar/ManOWar.java | 6 ++---- .../biomeswevegone/fabric/BiomesWeveGoneFabric.java | 2 ++ .../biomeswevegone/forge/BiomesWeveGoneForge.java | 6 +++--- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29e36f6c1..4cfea9c92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Move Config Classes to Config Package - Correct BWG Pitcher Plant Item Models - Slight Change to FruitBlockProcessor#finalizeProcessing to be more Efficient +- Use SpawnPlacementRegisterEvent on Forge to Register Entity Spawn Placements # 1.4.4 - Add Russian Translations (ru_ru) (Credits: j-tap) diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/BiomesWeveGone.java b/Common/src/main/java/net/potionstudios/biomeswevegone/BiomesWeveGone.java index 013abf94a..2d7bb60be 100644 --- a/Common/src/main/java/net/potionstudios/biomeswevegone/BiomesWeveGone.java +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/BiomesWeveGone.java @@ -72,7 +72,6 @@ public static void init() { * Ran later in the initialization process to setup common things. */ public static void commonSetup() { - BWGEntities.registerSpawnPlacements(); BWGVillagerType.setVillagerBWGBiomes(); } diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/BWGEntities.java b/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/BWGEntities.java index 41df690b9..ea4ec13b4 100644 --- a/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/BWGEntities.java +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/BWGEntities.java @@ -12,6 +12,7 @@ import net.potionstudios.biomeswevegone.world.entity.pumpkinwarden.PumpkinWarden; import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.function.Supplier; /** @@ -36,11 +37,14 @@ private static Supplier> createEntity(String id return PlatformHandler.PLATFORM_HANDLER.registerEntity(id, factory, category, width, height, trackingRange); } - public static void registerSpawnPlacements() { - SpawnPlacements.register(MAN_O_WAR.get(), SpawnPlacements.Type.IN_WATER, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, ManOWar::checkManOWarSpawnRules); - SpawnPlacements.register(ODDION.get(), SpawnPlacements.Type.ON_GROUND, Heightmap.Types.WORLD_SURFACE, Oddion::checkOddionSpawnRules); + @SuppressWarnings("unchecked") + public static void registerSpawnPlacements(Consumer> consumer) { + consumer.accept((SpawnPlacement)new SpawnPlacement<>(MAN_O_WAR.get(), SpawnPlacements.Type.IN_WATER, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, ManOWar::checkManOWarSpawnRules)); + consumer.accept((SpawnPlacement)new SpawnPlacement<>(ODDION.get(), SpawnPlacements.Type.ON_GROUND, Heightmap.Types.WORLD_SURFACE, Oddion::checkOddionSpawnRules)); } + public record SpawnPlacement(EntityType entityType, SpawnPlacements.Type spawnPlacementType, Heightmap.Types heightmapType, SpawnPlacements.SpawnPredicate predicate) {} + /** * Registers Entity Attributes */ diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/manowar/ManOWar.java b/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/manowar/ManOWar.java index e0bdad9f4..dc0c3adac 100644 --- a/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/manowar/ManOWar.java +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/manowar/ManOWar.java @@ -131,9 +131,7 @@ public boolean canBeLeashed(@NotNull Player player) { } public static boolean checkManOWarSpawnRules(EntityType entity, LevelAccessor world, MobSpawnType spawnType, BlockPos pos, RandomSource rand) { - int i = world.getSeaLevel(); - int j = i - 2; - return pos.getY() <= j && world.getFluidState(pos.below()).is(FluidTags.WATER); + return pos.getY() <= (world.getSeaLevel() - 2) && world.getFluidState(pos.below()).is(FluidTags.WATER); } @Override @@ -208,7 +206,7 @@ public boolean hasMovementVector() { @Override - public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor serverLevelAccessor, @NotNull DifficultyInstance difficultyInstance, @NotNull MobSpawnType mobSpawnType, SpawnGroupData spawnGroupData, CompoundTag compoundTag) { + public @NotNull SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor serverLevelAccessor, @NotNull DifficultyInstance difficultyInstance, @NotNull MobSpawnType mobSpawnType, SpawnGroupData spawnGroupData, CompoundTag compoundTag) { spawnGroupData = super.finalizeSpawn(serverLevelAccessor, difficultyInstance, mobSpawnType, spawnGroupData, compoundTag); if (mobSpawnType == MobSpawnType.BUCKET && compoundTag != null && compoundTag.contains("BucketVariantTag", 3)) { this.setRawFlag(compoundTag.getInt("BucketVariantTag")); diff --git a/Fabric/src/main/java/net/potionstudios/biomeswevegone/fabric/BiomesWeveGoneFabric.java b/Fabric/src/main/java/net/potionstudios/biomeswevegone/fabric/BiomesWeveGoneFabric.java index acec1a8f0..97ffb6f95 100644 --- a/Fabric/src/main/java/net/potionstudios/biomeswevegone/fabric/BiomesWeveGoneFabric.java +++ b/Fabric/src/main/java/net/potionstudios/biomeswevegone/fabric/BiomesWeveGoneFabric.java @@ -4,6 +4,7 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; +import net.minecraft.world.entity.SpawnPlacements; import net.potionstudios.biomeswevegone.BiomesWeveGone; import net.potionstudios.biomeswevegone.world.entity.BWGEntities; @@ -33,6 +34,7 @@ public static void initializeBiomesWeveGone(String initializedFrom) { BiomesWeveGone.init(); VanillaCompatFabric.init(); BWGEntities.registerEntityAttributes(FabricDefaultAttributeRegistry::register); + BWGEntities.registerSpawnPlacements(consumer -> SpawnPlacements.register(consumer.entityType(), consumer.spawnPlacementType(), consumer.heightmapType(), consumer.predicate())); BiomesWeveGone.commonSetup(); BiomesWeveGone.postInit(); ServerLifecycleEvents.SERVER_STARTING.register(BiomesWeveGone::serverStart); diff --git a/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/BiomesWeveGoneForge.java b/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/BiomesWeveGoneForge.java index c9ce6393b..af7ae3eae 100644 --- a/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/BiomesWeveGoneForge.java +++ b/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/BiomesWeveGoneForge.java @@ -3,6 +3,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.EntityAttributeCreationEvent; +import net.minecraftforge.event.entity.SpawnPlacementRegisterEvent; import net.minecraftforge.event.server.ServerAboutToStartEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.DistExecutor; @@ -20,8 +21,6 @@ import software.bernie.geckolib.GeckoLib; import terrablender.api.SurfaceRuleManager; -import java.util.function.Consumer; - /** * Main class for the mod on the Forge platform. * @see Mod @@ -38,7 +37,8 @@ public BiomesWeveGoneForge() { MOD_BUS.addListener(this::onInitialize); MOD_BUS.addListener(this::onPostInitialize); EVENT_BUS.addListener(this::onServerStarting); - MOD_BUS.addListener((Consumer) event -> BWGEntities.registerEntityAttributes(event::put)); + MOD_BUS.addListener((EntityAttributeCreationEvent event) -> BWGEntities.registerEntityAttributes(event::put)); + MOD_BUS.addListener((SpawnPlacementRegisterEvent event) -> BWGEntities.registerSpawnPlacements(consumer -> event.register(consumer.entityType(), consumer.spawnPlacementType(), consumer.heightmapType(), consumer.predicate(), SpawnPlacementRegisterEvent.Operation.OR))); VanillaCompatForge.registerVanillaCompatEvents(EVENT_BUS); DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> BiomesWeveGoneClientForge.init(MOD_BUS)); GeckoLib.initialize();