Skip to content

Commit

Permalink
Merge pull request #7 from gniftygnome/1.20
Browse files Browse the repository at this point in the history
Revise spawn conditions to be more similar to vanilla's.  Fix minor bugs.
  • Loading branch information
cybercat5555 authored Dec 27, 2024
2 parents 18966a7 + 1eea448 commit 038c263
Show file tree
Hide file tree
Showing 18 changed files with 170 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,47 +57,47 @@ private static void createConfig() {
configRegistry.addPairData(new Pair<>("constrictor_spawn_max_group", 3), "Constrictor spawn max group");

configRegistry.addComment("Crayfish");
configRegistry.addPairData(new Pair<>("crayfish_spawn_weight", 5), "Crayfish spawn weight");
configRegistry.addPairData(new Pair<>("crayfish_spawn_weight", 15), "Crayfish spawn weight");
configRegistry.addPairData(new Pair<>("crayfish_spawn_min_group", 1), "Crayfish spawn min group");
configRegistry.addPairData(new Pair<>("crayfish_spawn_max_group", 3), "Crayfish spawn max group");

configRegistry.addComment("Hoatzin");
configRegistry.addPairData(new Pair<>("hoatzin_spawn_weight", 5), "Hoatzin spawn weight");
configRegistry.addPairData(new Pair<>("hoatzin_spawn_weight", 25), "Hoatzin spawn weight");
configRegistry.addPairData(new Pair<>("hoatzin_spawn_min_group", 1), "Hoatzin spawn min group");
configRegistry.addPairData(new Pair<>("hoatzin_spawn_max_group", 3), "Hoatzin spawn max group");

configRegistry.addComment("Iguana");
configRegistry.addPairData(new Pair<>("iguana_spawn_weight", 5), "Iguana spawn weight");
configRegistry.addPairData(new Pair<>("iguana_spawn_weight", 25), "Iguana spawn weight");
configRegistry.addPairData(new Pair<>("iguana_spawn_min_group", 1), "Iguana spawn min group");
configRegistry.addPairData(new Pair<>("iguana_spawn_max_group", 3), "Iguana spawn max group");

configRegistry.addComment("Leech");
configRegistry.addPairData(new Pair<>("leech_spawn_weight", 5), "Leech spawn weight");
configRegistry.addPairData(new Pair<>("leech_spawn_weight", 15), "Leech spawn weight");
configRegistry.addPairData(new Pair<>("leech_spawn_min_group", 1), "Leech spawn min group");
configRegistry.addPairData(new Pair<>("leech_spawn_max_group", 3), "Leech spawn max group");

configRegistry.addComment("Piranha");
configRegistry.addPairData(new Pair<>("piranha_spawn_weight", 5), "Piranha spawn weight");
configRegistry.addPairData(new Pair<>("piranha_spawn_weight", 10), "Piranha spawn weight");
configRegistry.addPairData(new Pair<>("piranha_spawn_min_group", 1), "Piranha spawn min group");
configRegistry.addPairData(new Pair<>("piranha_spawn_max_group", 3), "Piranha spawn max group");

configRegistry.addComment("Quetzal");
configRegistry.addPairData(new Pair<>("quetzal_spawn_weight", 5), "Quetzal spawn weight");
configRegistry.addPairData(new Pair<>("quetzal_spawn_weight", 25), "Quetzal spawn weight");
configRegistry.addPairData(new Pair<>("quetzal_spawn_min_group", 1), "Quetzal spawn min group");
configRegistry.addPairData(new Pair<>("quetzal_spawn_max_group", 3), "Quetzal spawn max group");

configRegistry.addComment("Snapping Turtle");
configRegistry.addPairData(new Pair<>("snapping_turtle_spawn_weight", 5), "Snapping Turtle spawn weight");
configRegistry.addPairData(new Pair<>("snapping_turtle_spawn_weight", 15), "Snapping Turtle spawn weight");
configRegistry.addPairData(new Pair<>("snapping_turtle_spawn_min_group", 1), "Snapping Turtle spawn min group");
configRegistry.addPairData(new Pair<>("snapping_turtle_spawn_max_group", 3), "Snapping Turtle spawn max group");

configRegistry.addComment("Songbird");
configRegistry.addPairData(new Pair<>("songbird_spawn_weight", 5), "Songbird spawn weight");
configRegistry.addPairData(new Pair<>("songbird_spawn_weight", 25), "Songbird spawn weight");
configRegistry.addPairData(new Pair<>("songbird_spawn_min_group", 1), "Songbird spawn min group");
configRegistry.addPairData(new Pair<>("songbird_spawn_max_group", 3), "Songbird spawn max group");

configRegistry.addComment("Tapir");
configRegistry.addPairData(new Pair<>("tapir_spawn_weight", 5), "Tapir spawn weight");
configRegistry.addPairData(new Pair<>("tapir_spawn_weight", 10), "Tapir spawn weight");
configRegistry.addPairData(new Pair<>("tapir_spawn_min_group", 1), "Tapir spawn min group");
configRegistry.addPairData(new Pair<>("tapir_spawn_max_group", 3), "Tapir spawn max group");

Expand All @@ -107,7 +107,7 @@ private static void createConfig() {
configRegistry.addPairData(new Pair<>("tarantula_spawn_max_group", 3), "Tarantula spawn max group");

configRegistry.addComment("Yacare");
configRegistry.addPairData(new Pair<>("yacare_spawn_weight", 5), "Yacare spawn weight");
configRegistry.addPairData(new Pair<>("yacare_spawn_weight", 10), "Yacare spawn weight");
configRegistry.addPairData(new Pair<>("yacare_spawn_min_group", 1), "Yacare spawn min group");
configRegistry.addPairData(new Pair<>("yacare_spawn_max_group", 3), "Yacare spawn max group");

Expand Down
78 changes: 27 additions & 51 deletions src/main/java/cybercat5555/faunus/common/config/SpawnHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
import cybercat5555.faunus.core.EntityRegistry;
import cybercat5555.faunus.core.entity.livingEntity.*;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectionContext;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.fabricmc.fabric.api.biome.v1.ModificationPhase;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.SpawnRestriction;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.registry.tag.BiomeTags;
import net.minecraft.util.Identifier;
import net.minecraft.world.Heightmap;

import java.util.function.Predicate;

import static cybercat5555.faunus.common.config.MobSpawningConfig.*;

public class SpawnHandler {
Expand Down Expand Up @@ -45,10 +43,8 @@ public static void removeSpawn() {

public static void addSpawn() {
/* ARAPAIMA */
Predicate<BiomeSelectionContext> arapaimaSpawnPredicate = BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_ARAPAIMA);

BiomeModifications.addSpawn(
arapaimaSpawnPredicate,
BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_ARAPAIMA),
SpawnGroup.WATER_CREATURE,
EntityRegistry.ARAPAIMA,
ARAPAIMA_SPAWN_WEIGHT, ARAPAIMA_SPAWN_MIN_GROUP, ARAPAIMA_SPAWN_MAX_GROUP
Expand All @@ -61,10 +57,8 @@ public static void addSpawn() {
ArapaimaEntity::canMobSpawn);

/* CAPUCHIN */
Predicate<BiomeSelectionContext> capuchinSpawnPredicate = BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_CAPUCHIN);

BiomeModifications.addSpawn(
capuchinSpawnPredicate,
BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_CAPUCHIN),
SpawnGroup.AMBIENT,
EntityRegistry.CAPUCHIN,
CAPUCHIN_SPAWN_WEIGHT, CAPUCHIN_SPAWN_MIN_GROUP, CAPUCHIN_SPAWN_MAX_GROUP
Expand All @@ -73,14 +67,12 @@ public static void addSpawn() {
SpawnRestriction.register(
EntityRegistry.CAPUCHIN,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
CapuchinEntity::canMobSpawn);
Heightmap.Type.MOTION_BLOCKING,
CapuchinEntity::canSpawn);

/* CRAYFISH */
Predicate<BiomeSelectionContext> crayfishSpawnPredicate = BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_CRAYFISH);

BiomeModifications.addSpawn(
crayfishSpawnPredicate,
BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_CRAYFISH),
SpawnGroup.WATER_CREATURE,
EntityRegistry.CRAYFISH,
CRAYFISH_SPAWN_WEIGHT, CRAYFISH_SPAWN_MIN_GROUP, CRAYFISH_SPAWN_MAX_GROUP
Expand All @@ -90,13 +82,11 @@ public static void addSpawn() {
EntityRegistry.CRAYFISH,
SpawnRestriction.Location.IN_WATER,
Heightmap.Type.OCEAN_FLOOR,
CrayfishEntity::canMobSpawn);
CrayfishEntity::canSpawn);

/* HOATZIN */
Predicate<BiomeSelectionContext> hoatzinSpawnPredicate = BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_HOATZIN);

BiomeModifications.addSpawn(
hoatzinSpawnPredicate,
BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_HOATZIN),
SpawnGroup.CREATURE,
EntityRegistry.HOATZIN,
HOATZIN_SPAWN_WEIGHT, HOATZIN_SPAWN_MIN_GROUP, HOATZIN_SPAWN_MAX_GROUP
Expand All @@ -105,8 +95,8 @@ public static void addSpawn() {
SpawnRestriction.register(
EntityRegistry.HOATZIN,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
HoatzinEntity::canMobSpawn);
Heightmap.Type.MOTION_BLOCKING,
HoatzinEntity::canSpawnHoatzin);

/* IGUANA */
BiomeModifications.addSpawn(
Expand All @@ -120,13 +110,11 @@ public static void addSpawn() {
EntityRegistry.IGUANA,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING,
IguanaEntity::canMobSpawn);
IguanaEntity::canSpawn);

/* LEECH */
Predicate<BiomeSelectionContext> leechSpawnPredicate = BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_LEECH);

BiomeModifications.addSpawn(
leechSpawnPredicate,
BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_LEECH),
SpawnGroup.WATER_CREATURE,
EntityRegistry.LEECH,
LEECH_SPAWN_WEIGHT, LEECH_SPAWN_MIN_GROUP, LEECH_SPAWN_MAX_GROUP
Expand All @@ -136,13 +124,11 @@ public static void addSpawn() {
EntityRegistry.LEECH,
SpawnRestriction.Location.IN_WATER,
Heightmap.Type.OCEAN_FLOOR,
LeechEntity::canMobSpawn);
LeechEntity::canSpawn);

/* PIRANHA */
Predicate<BiomeSelectionContext> piranhaSpawnPredicate = BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_PIRANHA);

BiomeModifications.addSpawn(
piranhaSpawnPredicate,
BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_PIRANHA),
SpawnGroup.WATER_CREATURE,
EntityRegistry.PIRANHA,
PIRANHA_SPAWN_WEIGHT, PIRANHA_SPAWN_MIN_GROUP, PIRANHA_SPAWN_MAX_GROUP
Expand All @@ -152,13 +138,11 @@ public static void addSpawn() {
EntityRegistry.PIRANHA,
SpawnRestriction.Location.IN_WATER,
Heightmap.Type.OCEAN_FLOOR,
PiranhaEntity::canMobSpawn);
PiranhaEntity::canSpawn);

/* QUETZAL */
Predicate<BiomeSelectionContext> quetzalSpawnPredicate = BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_QUETZAL);

BiomeModifications.addSpawn(
quetzalSpawnPredicate,
BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_QUETZAL),
SpawnGroup.CREATURE,
EntityRegistry.QUETZAL,
QUETZAL_SPAWN_WEIGHT, QUETZAL_SPAWN_MIN_GROUP, QUETZAL_SPAWN_MAX_GROUP
Expand All @@ -167,14 +151,12 @@ public static void addSpawn() {
SpawnRestriction.register(
EntityRegistry.QUETZAL,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
QuetzalEntity::canMobSpawn);
Heightmap.Type.MOTION_BLOCKING,
QuetzalEntity::canSpawnQuetzal);

/* SNAPPING_TURTLE */
Predicate<BiomeSelectionContext> snappingTurtleSpawnPredicate = BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_SNAPPING_TURTLE);

BiomeModifications.addSpawn(
snappingTurtleSpawnPredicate,
BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_SNAPPING_TURTLE),
SpawnGroup.CREATURE,
EntityRegistry.SNAPPING_TURTLE,
SNAPPING_TURTLE_SPAWN_WEIGHT, SNAPPING_TURTLE_SPAWN_MIN_GROUP, SNAPPING_TURTLE_SPAWN_MAX_GROUP
Expand All @@ -184,13 +166,11 @@ public static void addSpawn() {
EntityRegistry.SNAPPING_TURTLE,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
SnappingTurtleEntity::canMobSpawn);
SnappingTurtleEntity::canSpawn);

/* SONGBIRD */
Predicate<BiomeSelectionContext> songbirdSpawnPredicate = BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_SONGBIRD);

BiomeModifications.addSpawn(
songbirdSpawnPredicate,
BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_SONGBIRD),
SpawnGroup.CREATURE,
EntityRegistry.SONGBIRD,
SONGBIRD_SPAWN_WEIGHT, SONGBIRD_SPAWN_MIN_GROUP, SONGBIRD_SPAWN_MAX_GROUP
Expand All @@ -199,14 +179,12 @@ public static void addSpawn() {
SpawnRestriction.register(
EntityRegistry.SONGBIRD,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
SongbirdEntity::canMobSpawn);
Heightmap.Type.MOTION_BLOCKING,
SongbirdEntity::canSpawnSongbird);

/* TAPIR */
Predicate<BiomeSelectionContext> tapirSpawnPredicate = BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_TAPIR);

BiomeModifications.addSpawn(
tapirSpawnPredicate,
BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_TAPIR),
SpawnGroup.CREATURE,
EntityRegistry.TAPIR,
TAPIR_SPAWN_WEIGHT, TAPIR_SPAWN_MIN_GROUP, TAPIR_SPAWN_MAX_GROUP
Expand All @@ -216,13 +194,11 @@ public static void addSpawn() {
EntityRegistry.TAPIR,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
TapirEntity::canMobSpawn);
AnimalEntity::isValidNaturalSpawn);

/* YACARE */
Predicate<BiomeSelectionContext> yacareSpawnPredicate = BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_YACARE);

BiomeModifications.addSpawn(
yacareSpawnPredicate,
BiomeSelectors.tag(FaunusBiomeTags.SPAWNS_YACARE),
SpawnGroup.CREATURE,
EntityRegistry.YACARE,
YACARE_SPAWN_WEIGHT, YACARE_SPAWN_MIN_GROUP, YACARE_SPAWN_MAX_GROUP
Expand All @@ -232,6 +208,6 @@ public static void addSpawn() {
EntityRegistry.YACARE,
SpawnRestriction.Location.ON_GROUND,
Heightmap.Type.MOTION_BLOCKING_NO_LEAVES,
YacareEntity::canMobSpawn);
YacareEntity::canSpawnYacare);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class FaunusBiomeTags {
public static final TagKey<Biome> SPAWNS_YACARE = FaunusBiomeTags.of("spawns_yacare");
public static final TagKey<Biome> SPAWNS_YACARE_MANEATER = FaunusBiomeTags.of("spawns_yacare_maneater");

public static final TagKey<Biome> IS_SWAMP = FaunusBiomeTags.of(Identifier.of("c", "is_swamp"));
// TODO: changes to c:is_swamp in 1.21
public static final TagKey<Biome> SWAMP = FaunusBiomeTags.of(Identifier.of("c", "swamp"));

@SuppressWarnings("UnnecessaryReturnStatement")
private FaunusBiomeTags() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class FlightWalkMoveControl extends MoveControl {
public FlightWalkMoveControl(MobEntity entity, int maxPitchChange, boolean noGravity) {
super(entity);
this.noGravity = noGravity;
this.type = MoveType.WALK;
}

public void changeMovementType(MoveType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import cybercat5555.faunus.core.entity.ai.goals.HangTreeGoal;
import cybercat5555.faunus.core.entity.projectile.CocoaBeanProjectile;
import cybercat5555.faunus.util.FaunusID;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.ai.goal.*;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
Expand All @@ -21,15 +23,19 @@
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.EntityView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import org.jetbrains.annotations.Nullable;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
Expand Down Expand Up @@ -85,8 +91,6 @@ protected void initGoals() {
this.goalSelector.add(4, new FollowOwnerGoal(this, 1.0, 5.0f, 1.0f, true));

targetSelector.add(1, new RevengeGoal(this));
targetSelector.add(2, new ActiveTargetGoal<>(this, LivingEntity.class, true,
target -> target instanceof CapuchinEntity || target instanceof PlayerEntity));
}

@Override
Expand Down Expand Up @@ -151,6 +155,26 @@ protected <E extends CapuchinEntity> PlayState attackAnimController(final Animat
return PlayState.STOP;
}

public static boolean canSpawn(EntityType<CapuchinEntity> type, WorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) {
return world.getBlockState(pos.down()).isIn(BlockTags.PARROTS_SPAWNABLE_ON);
}

public boolean canSpawn(WorldView world) {
if (world.doesNotIntersectEntities(this) && !world.containsFluid(this.getBoundingBox())) {
BlockPos blockPos = this.getBlockPos();
if (blockPos.getY() < world.getSeaLevel()) {
return false;
}

BlockState blockState = world.getBlockState(blockPos.down());
return blockState.isIn(BlockTags.ANIMALS_SPAWNABLE_ON) ||
blockState.isIn(BlockTags.LEAVES) ||
blockState.isIn(BlockTags.LOGS);
}

return false;
}

@Nullable
@Override
@SuppressWarnings("ConstantConditions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.LocalDifficulty;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.World;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.*;
import org.jetbrains.annotations.Nullable;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
Expand Down Expand Up @@ -115,6 +115,15 @@ protected <E extends CrayfishEntity> PlayState idleAnimController(final Animatio
return PlayState.CONTINUE;
}

public static boolean canSpawn(EntityType<CrayfishEntity> type, WorldAccess world, SpawnReason reason, BlockPos pos, Random random) {
return pos.getY() >= world.getSeaLevel() - 13;
}

@Override
public boolean canSpawn(WorldView world) {
return world.doesNotIntersectEntities(this);
}

@Override
public boolean cannotDespawn() {
return super.cannotDespawn() || hasBeenFed;
Expand Down
Loading

0 comments on commit 038c263

Please sign in to comment.