[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,120 @@
|
||||
package ovh.glitchlabs.masterwild.entity.custom;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.AgeableMob;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
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.animal.Animal;
|
||||
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.block.state.BlockState;
|
||||
import net.minecraft.world.level.pathfinder.PathType;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.event.EventHooks;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ovh.glitchlabs.masterwild.Sounds.ModSounds;
|
||||
|
||||
public class RoosterEntity extends Animal {
|
||||
|
||||
boolean newDay = false;
|
||||
private long lastDay;
|
||||
|
||||
public RoosterEntity(EntityType<? extends Animal> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
xpReward = 10;
|
||||
setNoAi(false);
|
||||
this.setPathfindingMalus(PathType.WATER, 0.0F);
|
||||
}
|
||||
|
||||
public static AttributeSupplier.Builder createAttributes() {
|
||||
AttributeSupplier.Builder builder = Mob.createMobAttributes();
|
||||
builder = builder.add(Attributes.MOVEMENT_SPEED, 0.3);
|
||||
builder = builder.add(Attributes.MAX_HEALTH, 5);
|
||||
builder = builder.add(Attributes.ARMOR, 0);
|
||||
builder = builder.add(Attributes.ATTACK_DAMAGE, 0);
|
||||
builder = builder.add(Attributes.FOLLOW_RANGE, 16);
|
||||
builder = builder.add(Attributes.STEP_HEIGHT, 0.6);
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerGoals() {
|
||||
this.goalSelector.addGoal(0, new FloatGoal(this));
|
||||
this.goalSelector.addGoal(1, new PanicGoal(this, 1.4));
|
||||
this.goalSelector.addGoal(2, new BreedGoal(this, 1.0));
|
||||
this.goalSelector.addGoal(3, new TemptGoal(this, 1.0, p_335679_ -> p_335679_.is(ItemTags.CHICKEN_FOOD), false));
|
||||
this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1));
|
||||
this.goalSelector.addGoal(5, new WaterAvoidingRandomStrollGoal(this, 1.0));
|
||||
this.goalSelector.addGoal(6, new LookAtPlayerGoal(this, Player.class, 6.0F));
|
||||
this.goalSelector.addGoal(7, new RandomLookAroundGoal(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEvent getAmbientSound() {
|
||||
return SoundEvents.CHICKEN_AMBIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEvent getHurtSound(DamageSource damageSource) {
|
||||
return SoundEvents.CHICKEN_HURT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEvent getDeathSound() {
|
||||
return SoundEvents.CHICKEN_DEATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void playStepSound(BlockPos blockPos, BlockState blockState) {
|
||||
this.playSound(SoundEvents.CHICKEN_STEP, 0.15F, 1.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFood(ItemStack stack) {
|
||||
return Ingredient.of(new ItemStack(Items.WHEAT_SEEDS)).test(stack);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public @Nullable AgeableMob getBreedOffspring(ServerLevel serverLevel, AgeableMob ageableMob) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void dropCustomDeathLoot(ServerLevel serverLevel, DamageSource source, boolean recentlyHitIn) {
|
||||
super.dropCustomDeathLoot(serverLevel, source, recentlyHitIn);
|
||||
this.spawnAtLocation(new ItemStack(Items.CHICKEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!this.level().isClientSide() && !level().isRaining() && !level().isThundering()) {
|
||||
long day = this.level().getDayTime() / 24000L;
|
||||
long lastDay = -1;
|
||||
if (this.lastDay != -1 && day != this.lastDay) {
|
||||
this.onNewDay();
|
||||
}
|
||||
this.lastDay = day;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void onNewDay() {
|
||||
this.playSound(ModSounds.ROOSTER_CROW.get(), 2.0f, 0.8f + this.random.nextFloat() * 0.4f);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user