Skip to content

Commit

Permalink
Remove Consumer Use for EntityAttributeCreation, USe SpawnPlacementRe…
Browse files Browse the repository at this point in the history
…gisterEvent on Forge

Signed-off-by: Joseph T. McQuigg <[email protected]>
  • Loading branch information
JT122406 committed Dec 20, 2024
1 parent 72a79e4 commit 4ff8137
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -36,11 +37,14 @@ private static <E extends Entity> Supplier<EntityType<E>> 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 <T extends Mob> void registerSpawnPlacements(Consumer<SpawnPlacement<T>> consumer) {
consumer.accept((SpawnPlacement<T>)new SpawnPlacement<>(MAN_O_WAR.get(), SpawnPlacements.Type.IN_WATER, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, ManOWar::checkManOWarSpawnRules));
consumer.accept((SpawnPlacement<T>)new SpawnPlacement<>(ODDION.get(), SpawnPlacements.Type.ON_GROUND, Heightmap.Types.WORLD_SURFACE, Oddion::checkOddionSpawnRules));
}

public record SpawnPlacement<T extends Mob>(EntityType<T> entityType, SpawnPlacements.Type spawnPlacementType, Heightmap.Types heightmapType, SpawnPlacements.SpawnPredicate<T> predicate) {}

/**
* Registers Entity Attributes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ public boolean canBeLeashed(@NotNull Player player) {
}

public static boolean checkManOWarSpawnRules(EntityType<? extends ManOWar> 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
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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<EntityAttributeCreationEvent>) 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();
Expand Down

0 comments on commit 4ff8137

Please sign in to comment.