[add] Rooster
- [add] Rooster sounds - [add] Rooster newday craw [add] firefly - [fix] firefly ai similar to bat ai [add] pinguin
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
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;
|
||||
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.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.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 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 EntityDataAccessor<Integer> VARIANT =
|
||||
SynchedEntityData.defineId(PinguinEntity.class, EntityDataSerializers.INT);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFood(ItemStack stack) {
|
||||
return Ingredient.of(new ItemStack(Items.COD)).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(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;
|
||||
}
|
||||
|
||||
private void setupAnimationStates() {
|
||||
if(this.idleAnimationTimeout <= 0) {
|
||||
this.idleAnimationTimeout = 5;
|
||||
this.idleAnimationState.start(this.tickCount);
|
||||
} else {
|
||||
--this.idleAnimationTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if(this.level().isClientSide()) {
|
||||
this.setupAnimationStates();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void defineSynchedData(SynchedEntityData.Builder builder) {
|
||||
super.defineSynchedData(builder);
|
||||
builder.define(VARIANT, 0);
|
||||
}
|
||||
|
||||
private int getTypeVariant() {
|
||||
return this.entityData.get(VARIANT);
|
||||
}
|
||||
|
||||
public PinguinVariants getVariant() {
|
||||
return PinguinVariants.byId(this.getTypeVariant() & 255);
|
||||
}
|
||||
|
||||
private void setVariant(PinguinVariants variant) {
|
||||
this.entityData.set(VARIANT, variant.getId() & 255);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAdditionalSaveData(CompoundTag compound) {
|
||||
super.addAdditionalSaveData(compound);
|
||||
compound.putInt("Variant", this.getTypeVariant());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readAdditionalSaveData(CompoundTag compound) {
|
||||
super.readAdditionalSaveData(compound);
|
||||
this.entityData.set(VARIANT, compound.getInt("Variant"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnGroupData finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty,
|
||||
MobSpawnType spawnType, @Nullable SpawnGroupData spawnGroupData) {
|
||||
PinguinVariants variants = Util.getRandom(PinguinVariants.values(), this.random);
|
||||
this.setVariant(variants);
|
||||
return super.finalizeSpawn(level, difficulty, spawnType, spawnGroupData);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user