79 lines
3.2 KiB
Java
79 lines
3.2 KiB
Java
package ovh.glitchlabs.masterwild.entity.custom;
|
|
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.sounds.SoundEvent;
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
import net.minecraft.world.entity.AgeableMob;
|
|
import net.minecraft.world.entity.EntityType;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.ai.attributes.Attribute;
|
|
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 org.jetbrains.annotations.Nullable;
|
|
import ovh.glitchlabs.masterwild.Item.ModItems;
|
|
import ovh.glitchlabs.masterwild.Sounds.ModSounds;
|
|
import ovh.glitchlabs.masterwild.entity.ModEntities;
|
|
|
|
public class MonkeyEntity extends Animal {
|
|
private static final Ingredient FOOD = Ingredient.of(ModItems.BANANA);
|
|
|
|
public MonkeyEntity(EntityType<? extends Animal> entityType, Level level) {
|
|
super(entityType, level);
|
|
}
|
|
|
|
public static AttributeSupplier.Builder createAttributes() {
|
|
return AgeableMob.createMobAttributes()
|
|
.add(Attributes.MAX_HEALTH, 8)
|
|
.add(Attributes.MOVEMENT_SPEED, 0.25)
|
|
.add(Attributes.FOLLOW_RANGE, 10)
|
|
.add(Attributes.STEP_HEIGHT, 0.6);
|
|
}
|
|
|
|
@Override
|
|
protected void 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.goalSelector.addGoal(1, new PanicGoal(this, 1.5));
|
|
this.goalSelector.addGoal(2, new BreedGoal(this, 1.0));
|
|
this.goalSelector.addGoal(3, new TemptGoal(this, 1.1, FOOD, false));
|
|
this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1));
|
|
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(0, new FloatGoal(this));
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void dropCustomDeathLoot(ServerLevel serverLevel, DamageSource source, boolean recentlyHit) {
|
|
super.dropCustomDeathLoot(serverLevel, source, recentlyHit);
|
|
this.spawnAtLocation(new ItemStack(ModItems.BANANA_PEEL.get()));
|
|
}
|
|
|
|
@Override
|
|
public boolean isFood(ItemStack itemStack) {
|
|
return FOOD.test(itemStack);
|
|
}
|
|
|
|
@Override
|
|
public @Nullable AgeableMob getBreedOffspring(ServerLevel serverLevel, AgeableMob ageableMob) {
|
|
return ModEntities.MONKEY.get().create(serverLevel);
|
|
}
|
|
|
|
@Override
|
|
public SoundEvent getHurtSound(DamageSource damageSource) {
|
|
return ModSounds.MONKEY_HURT.get();
|
|
}
|
|
}
|