[change] change some settings for Pinguin/Rooster/Firefly

This commit is contained in:
2026-09-24 20:37:40 +02:00
parent 256313e32f
commit f6e1c46ebe
8 changed files with 149 additions and 195 deletions
@@ -1,6 +1,5 @@
package ovh.glitchlabs.masterwild.entity.custom;
import net.minecraft.Util;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
@@ -8,98 +7,90 @@ import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.AgeableMob;
import net.minecraft.world.entity.AnimationState;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.goal.*;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.Cod;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import org.jetbrains.annotations.Nullable;
import ovh.glitchlabs.masterwild.entity.ModEntities;
import ovh.glitchlabs.masterwild.entity.PinguinVariants;
import javax.annotation.Nullable;
public class PinguinEntity extends Animal {
public static final AnimationState idleAnimationState = new AnimationState();
private int idleAnimationTimeout = 0;
private static final Ingredient FOOD = Ingredient.of(Items.COD, Items.SALMON);
private static final float RARE_CHANCE = 0.1f;
private static final EntityDataAccessor<Integer> VARIANT =
SynchedEntityData.defineId(PinguinEntity.class, EntityDataSerializers.INT);
public final AnimationState idleAnimationState = new AnimationState();
public PinguinEntity(EntityType<? extends Animal> entityType, Level level) {
super(entityType, level);
xpReward = 0;
setNoAi(false);
}
public static AttributeSupplier.Builder createAttributes() {
AttributeSupplier.Builder builder = Mob.createMobAttributes();
builder = builder.add(Attributes.MOVEMENT_SPEED, 0.3);
builder = builder.add(Attributes.MAX_HEALTH, 6);
builder = builder.add(Attributes.ARMOR, 0);
builder = builder.add(Attributes.ATTACK_DAMAGE, 3);
builder = builder.add(Attributes.FOLLOW_RANGE, 4);
builder = builder.add(Attributes.STEP_HEIGHT, 0.6);
return builder;
return Mob.createMobAttributes()
.add(Attributes.MOVEMENT_SPEED, 0.3)
.add(Attributes.MAX_HEALTH, 6)
.add(Attributes.ARMOR, 0)
.add(Attributes.ATTACK_DAMAGE, 3)
.add(Attributes.FOLLOW_RANGE, 4)
.add(Attributes.STEP_HEIGHT, 0.6);
}
@Override
public boolean isFood(ItemStack stack) {
return Ingredient.of(new ItemStack(Items.COD)).test(stack);
return FOOD.test(stack);
}
@Override
protected void registerGoals() {
super.registerGoals();
this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1, false) {
@Override
protected boolean canPerformAttack(LivingEntity entity) {
return this.isTimeToAttack() && this.mob.distanceToSqr(entity) < (this.mob.getBbWidth() * this.mob.getBbWidth() + entity.getBbWidth()) && this.mob.getSensing().hasLineOfSight(entity);
}
});
this.targetSelector.addGoal(2, new NearestAttackableTargetGoal(this, Cod.class, true, true));
this.goalSelector.addGoal(3, new WaterAvoidingRandomStrollGoal(this, 0.8));
this.goalSelector.addGoal(4, new PanicGoal(this, 1));
this.goalSelector.addGoal(5, new FollowParentGoal(this, 0.8));
this.goalSelector.addGoal(6, new BreedGoal(this, 1));
this.goalSelector.addGoal(0, new FloatGoal(this));
this.goalSelector.addGoal(1, new PanicGoal(this, 1.0));
this.goalSelector.addGoal(2, new BreedGoal(this, 1.0));
this.goalSelector.addGoal(3, new TemptGoal(this, 1.0, FOOD, false));
this.goalSelector.addGoal(4, new FollowParentGoal(this, 0.8));
this.goalSelector.addGoal(5, new WaterAvoidingRandomStrollGoal(this, 0.8));
this.goalSelector.addGoal(6, new LookAtPlayerGoal(this, Player.class, 6.0F));
this.goalSelector.addGoal(7, new RandomLookAroundGoal(this));
this.goalSelector.addGoal(8, new FloatGoal(this));
this.goalSelector.addGoal(10, new TemptGoal(this, 1, (Ingredient.of(Items.COD, Items.SALMON)), false));
}
protected void dropCustomDeathLoot(ServerLevel serverLevel, DamageSource source, boolean recentlyHitIn) {
super.dropCustomDeathLoot(serverLevel, source, recentlyHitIn);
this.spawnAtLocation(new ItemStack(Items.COD));
}
@Override
public AgeableMob getBreedOffspring(ServerLevel serverWorld, AgeableMob ageable) {
PinguinEntity retval = ModEntities.PINGUIN.get().create(serverWorld);
retval.finalizeSpawn(serverWorld, serverWorld.getCurrentDifficultyAt(retval.blockPosition()), MobSpawnType.BREEDING, null);
return retval;
protected void dropCustomDeathLoot(ServerLevel serverLevel, DamageSource source, boolean recentlyHit) {
super.dropCustomDeathLoot(serverLevel, source, recentlyHit);
this.spawnAtLocation(new ItemStack(Items.COD));
}
private void setupAnimationStates() {
if(this.idleAnimationTimeout <= 0) {
this.idleAnimationTimeout = 5;
this.idleAnimationState.start(this.tickCount);
} else {
--this.idleAnimationTimeout;
@Nullable
@Override
public AgeableMob getBreedOffspring(ServerLevel level, AgeableMob partner) {
PinguinEntity baby = ModEntities.PINGUIN.get().create(level);
if (baby != null) {
baby.finalizeSpawn(level, level.getCurrentDifficultyAt(baby.blockPosition()), MobSpawnType.BREEDING, null);
PinguinEntity other = partner instanceof PinguinEntity p ? p : this;
baby.setVariant(this.random.nextBoolean() ? this.getVariant() : other.getVariant());
}
return baby;
}
@Override
public void tick() {
super.tick();
if(this.level().isClientSide()) {
this.setupAnimationStates();
if (this.level().isClientSide()) {
this.idleAnimationState.startIfStopped(this.tickCount);
}
}
@@ -136,9 +127,7 @@ public class PinguinEntity extends Animal {
@Override
public SpawnGroupData finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty,
MobSpawnType spawnType, @Nullable SpawnGroupData spawnGroupData) {
PinguinVariants variants = Util.getRandom(PinguinVariants.values(), this.random);
this.setVariant(variants);
this.setVariant(this.random.nextFloat() < RARE_CHANCE ? PinguinVariants.RARE : PinguinVariants.NORMAL);
return super.finalizeSpawn(level, difficulty, spawnType, spawnGroupData);
}
}
}