Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.letsdo.wildernature.entity;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.goal.*;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.AbstractFish;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.PolarBear;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.item.crafting.Ingredient;
import org.jetbrains.annotations.Nullable;

public class SealEntity extends Animal {

private int fishInMouthTimer = 0;
private boolean hasFish = false;

public SealEntity(EntityType<? extends Animal> type, Level level) {
super(type, level);
}

@Override
protected void registerGoals() {
this.goalSelector.addGoal(0, new FloatGoal(this));
this.goalSelector.addGoal(1, new PanicGoal(this, 1.25D));
this.goalSelector.addGoal(2, new AvoidEntityGoal<>(this, PolarBear.class, 12.0F, 1.2D, 1.4D));
this.goalSelector.addGoal(3, new BreedGoal(this, 1.0D));
this.goalSelector.addGoal(4, new TemptGoal(this, 1.1D, Ingredient.of(ItemTags.FISHES), false));
this.goalSelector.addGoal(5, new RandomSwimmingGoal(this, 1.0D, 20));
this.goalSelector.addGoal(6, new RandomStrollGoal(this, 0.8D));
this.goalSelector.addGoal(7, new LookAtPlayerGoal(this, Player.class, 6.0F));
this.goalSelector.addGoal(8, new RandomLookAroundGoal(this));
this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, AbstractFish.class, true));
}

@Override
public void tick() {
super.tick();
if (hasFish) {
if (--fishInMouthTimer <= 0) {
hasFish = false;
}
}
}

@Override
public boolean doHurtTarget(Entity target) {
boolean flag = super.doHurtTarget(target);
if (flag && target instanceof AbstractFish) {
hasFish = true;
fishInMouthTimer = 250; // 10 seconds at 20 ticks/sec
target.discard(); // instantly consume fish entity
}
return flag;
}

public boolean hasFishInMouth() {
return hasFish;
}

@Override
public boolean isFood(ItemStack stack) {
return stack.is(ItemTags.FISHES);
}

@Nullable
@Override
public AgeableMob getBreedOffspring(ServerLevel serverLevel, AgeableMob partner) {
return EntityTypeRegistry.SEAL.get().create(serverLevel);
}

@Override
protected float getSoundVolume() {
return 0.6F;
}

@Override
protected SoundEvent getAmbientSound() {
return SoundRegistry.SEAL_AMBIENT.get();
}

@Override
protected SoundEvent getHurtSound(DamageSource damageSource) {
return SoundRegistry.SEAL_HURT.get();
}

@Override
protected SoundEvent getDeathSound() {
return SoundRegistry.SEAL_DEATH.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class EntityTypeRegistry {
public static final RegistrySupplier<EntityType<PenguinEntity>> PENGUIN = createEntity("penguin", () -> EntityType.Builder.of(PenguinEntity::new, MobCategory.CREATURE).sized(0.7f, 0.9f).clientTrackingRange(10).build(WilderNature.identifier("penguin").toString()));
public static final RegistrySupplier<EntityType<RaccoonEntity>> RACCOON = createEntity("raccoon", () -> EntityType.Builder.of(RaccoonEntity::new, MobCategory.CREATURE).sized(0.6f, 0.6f).build(WilderNature.identifier("raccoon").toString()));
public static final RegistrySupplier<EntityType<RedWolfEntity>> RED_WOLF = createEntity("red_wolf", () -> EntityType.Builder.of(RedWolfEntity::new, MobCategory.CREATURE).sized(0.7f, 0.9f).clientTrackingRange(10).build(String.valueOf(WilderNature.identifier("red_wolf"))));
public static final RegistrySupplier<EntityType<SealEntity>> SEAL = createEntity("seal", () -> EntityType.Builder.of(SealEntity::new, MobCategory.CREATURE).sized(1.2f, 0.9f).clientTrackingRange(10).build(String.valueOf(WilderNature.identifier("seal"))));
public static final RegistrySupplier<EntityType<SquirrelEntity>> SQUIRREL = createEntity("squirrel", () -> EntityType.Builder.of(SquirrelEntity::new, MobCategory.CREATURE).sized(0.4f, 0.9f).build(WilderNature.identifier("squirrel").toString()));
public static final RegistrySupplier<EntityType<TurkeyEntity>> TURKEY = createEntity("turkey", () -> EntityType.Builder.of(TurkeyEntity::new, MobCategory.CREATURE).sized(0.6F, 1.0F).build(WilderNature.identifier("turkey").toString()));
public static final RegistrySupplier<EntityType<BulletEntity>> BULLET = createEntity("bullet", () -> EntityType.Builder.<BulletEntity>of(BulletEntity::new, MobCategory.MISC).sized(0.3125f, 0.3125f).clientTrackingRange(64).updateInterval(2).build(WilderNature.identifier("bullet").toString()));
Expand Down Expand Up @@ -64,6 +65,7 @@ public static void init() {
EntityAttributeRegistry.register(PENGUIN, PenguinEntity::createMobAttributes);
EntityAttributeRegistry.register(RACCOON, RaccoonEntity::createMobAttributes);
EntityAttributeRegistry.register(RED_WOLF, RedWolfEntity::createMobAttributes);
EntityAttributeRegistry.register(SEAL, SquirrelEntity::createMobAttributes);
EntityAttributeRegistry.register(SQUIRREL, SquirrelEntity::createMobAttributes);
EntityAttributeRegistry.register(TURKEY, TurkeyEntity::createMobAttributes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class TagsRegistry {
public static final TagKey<Biome> SPAWNS_HEDGEHOG = TagKey.create(Registries.BIOME, WilderNature.identifier("spawns_hedgehog"));
public static final TagKey<Biome> SPAWNS_FLAMINGO = TagKey.create(Registries.BIOME, WilderNature.identifier("spawns_flamingo"));
public static final TagKey<Biome> SPAWNS_PELICAN = TagKey.create(Registries.BIOME, WilderNature.identifier("spawns_pelican"));
public static final TagKey<Biome> SPAWNS_SEAL = TagKey.create(Registries.BIOME, WilderNature.identifier("spawns_seal"));
public static final TagKey<EntityType<?>> OWL_TARGETS = TagKey.create(Registries.ENTITY_TYPE, WilderNature.identifier("owl_targets"));
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"replace": false,
"values": [
"#minecraft:is_river",
"minecraft:beach",
"minecraft:frozen_ocean",
"minecraft:deep_frozen_ocean"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ void addSpawns() {
addMobSpawn(TagsRegistry.SPAWNS_CASSOWARY, EntityTypeRegistry.CASSOWARY.get(), config.CassowarySpawnWeight, config.CassowaryMinGroupSize, config.CassowaryMaxGroupSize);
addMobSpawn(TagsRegistry.SPAWNS_FLAMINGO, EntityTypeRegistry.FLAMINGO.get(), config.FlamingoSpawnWeight, config.FlamingoMinGroupSize, config.FlamingoMaxGroupSize);
addMobSpawn(TagsRegistry.SPAWNS_HEDGEHOG, EntityTypeRegistry.HEDGEHOG.get(), config.HedgehogSpawnWeight, config.HedgehogMinGroupSize, config.HedgehogMaxGroupSize);

addMobSpawn(TagsRegistry.SPAWNS_SEAL, EntityTypeRegistry.SEAL.get(), config.SealSpawnWeight, config.SealMinGroupSize, config.SealMaxGroupSize);

if (config.removeSavannaAnimals) {
removeSpawn(BiomeTags.IS_SAVANNA, List.of(EntityType.SHEEP, EntityType.PIG, EntityType.CHICKEN, EntityType.COW));
}
Expand Down Expand Up @@ -146,6 +147,8 @@ void addSpawns() {
Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, AmbientCreature::checkMobSpawnRules);
SpawnPlacements.register(EntityTypeRegistry.CASSOWARY.get(), SpawnPlacementTypes.ON_GROUND,
Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, AmbientCreature::checkMobSpawnRules);
SpawnPlacements.register(EntityTypeRegistry.SEAL.get(), SpawnPlacementTypes.ON_GROUND,
Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, AmbientCreature::checkMobSpawnRules);
}

void addMobSpawn(TagKey<Biome> tag, EntityType<?> entityType, int weight, int minGroupSize, int maxGroupSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ public class ConfigFabric implements ConfigData {
public int HedgehogSpawnWeight = 13;
public int HedgehogMinGroupSize = 1;
public int HedgehogMaxGroupSize = 3;
}
public int SealSpawnWeight = 8;
public int SealMinGroupSize = 4;
public int SealMaxGroupSize = 8;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void registerEntities() {
registerEntity(EntityTypeRegistry.CASSOWARY.get(), Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, AmbientCreature::checkMobSpawnRules);
registerEntity(EntityTypeRegistry.HEDGEHOG.get(), Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, AmbientCreature::checkMobSpawnRules);
registerEntity(EntityTypeRegistry.FLAMINGO.get(), Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, AmbientCreature::checkMobSpawnRules);
registerEntity(EntityTypeRegistry.SEAL.get(), Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, AmbientCreature::checkMobSpawnRules);
}

@Override
Expand All @@ -66,8 +67,9 @@ public void modify(Holder<Biome> biome, Phase phase, ModifiableBiomeInfo.BiomeIn
addMobSpawn(builder, biome, TagsRegistry.SPAWNS_CASSOWARY, EntityTypeRegistry.CASSOWARY.get(), 12, 3, 4);
addMobSpawn(builder, biome, TagsRegistry.SPAWNS_HEDGEHOG, EntityTypeRegistry.HEDGEHOG.get(), 9, 2, 3);
addMobSpawn(builder, biome, TagsRegistry.SPAWNS_FLAMINGO, EntityTypeRegistry.FLAMINGO.get(), 10, 4, 6);
addMobSpawn(builder, biome, TagsRegistry.SPAWNS_SEAL, EntityTypeRegistry.SEAL.get(), 8, 2, 6);
addMobSpawn(builder, biome, BiomeTags.IS_JUNGLE, EntityType.FROG, 8, 3, 4);

}
}

Expand Down