| 1 | package net.minecraft.world.entity.monster;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.particles.ParticleTypes;
|
| 5 | import net.minecraft.sounds.SoundEvent;
|
| 6 | import net.minecraft.sounds.SoundEvents;
|
| 7 | import net.minecraft.util.RandomSource;
|
| 8 | import net.minecraft.world.damagesource.DamageSource;
|
| 9 | import net.minecraft.world.entity.Entity;
|
| 10 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 11 | import net.minecraft.world.entity.EntityType;
|
| 12 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 13 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 14 | import net.minecraft.world.entity.ai.goal.ClimbOnTopOfPowderSnowGoal;
|
| 15 | import net.minecraft.world.entity.ai.goal.FloatGoal;
|
| 16 | import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
|
| 17 | import net.minecraft.world.entity.ai.goal.MeleeAttackGoal;
|
| 18 | import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
|
| 19 | import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal;
|
| 20 | import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
|
| 21 | import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
|
| 22 | import net.minecraft.world.entity.player.Player;
|
| 23 | import net.minecraft.world.level.Level;
|
| 24 | import net.minecraft.world.level.LevelAccessor;
|
| 25 | import net.minecraft.world.level.block.state.BlockState;
|
| 26 | import net.minecraft.world.level.storage.ValueInput;
|
| 27 | import net.minecraft.world.level.storage.ValueOutput;
|
| 28 |
|
| 29 | public class Endermite extends Monster {
|
| 30 | private static final int MAX_LIFE = 2400;
|
| 31 | private static final int DEFAULT_LIFE = 0;
|
| 32 | private int life = 0;
|
| 33 |
|
| 34 | public Endermite(final EntityType<? extends Endermite> type, final Level level) {
|
| 35 | super(type, level);
|
| 36 | this.xpReward = 3;
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | protected void registerGoals() {
|
| 41 | this.goalSelector.addGoal(1, new FloatGoal(this));
|
| 42 | this.goalSelector.addGoal(1, new ClimbOnTopOfPowderSnowGoal(this, this.level()));
|
| 43 | this.goalSelector.addGoal(2, new MeleeAttackGoal(this, 1.0, false));
|
| 44 | this.goalSelector.addGoal(3, new WaterAvoidingRandomStrollGoal(this, 1.0));
|
| 45 | this.goalSelector.addGoal(7, new LookAtPlayerGoal(this, Player.class, 8.0F));
|
| 46 | this.goalSelector.addGoal(8, new RandomLookAroundGoal(this));
|
| 47 | this.targetSelector.addGoal(1, new HurtByTargetGoal(this).setAlertOthers());
|
| 48 | this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true));
|
| 49 | }
|
| 50 |
|
| 51 | public static AttributeSupplier.Builder createAttributes() {
|
| 52 | return Monster.createMonsterAttributes().add(Attributes.MAX_HEALTH, 8.0).add(Attributes.MOVEMENT_SPEED, 0.25).add(Attributes.ATTACK_DAMAGE, 2.0);
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | protected Entity.MovementEmission getMovementEmission() {
|
| 57 | return Entity.MovementEmission.EVENTS;
|
| 58 | }
|
| 59 |
|
| 60 | @Override
|
| 61 | protected SoundEvent getAmbientSound() {
|
| 62 | return SoundEvents.ENDERMITE_AMBIENT;
|
| 63 | }
|
| 64 |
|
| 65 | @Override
|
| 66 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 67 | return SoundEvents.ENDERMITE_HURT;
|
| 68 | }
|
| 69 |
|
| 70 | @Override
|
| 71 | protected SoundEvent getDeathSound() {
|
| 72 | return SoundEvents.ENDERMITE_DEATH;
|
| 73 | }
|
| 74 |
|
| 75 | @Override
|
| 76 | protected void playStepSound(final BlockPos pos, final BlockState blockState) {
|
| 77 | this.playSound(SoundEvents.ENDERMITE_STEP, 0.15F, 1.0F);
|
| 78 | }
|
| 79 |
|
| 80 | @Override
|
| 81 | protected void readAdditionalSaveData(final ValueInput input) {
|
| 82 | super.readAdditionalSaveData(input);
|
| 83 | this.life = input.getIntOr("Lifetime", 0);
|
| 84 | }
|
| 85 |
|
| 86 | @Override
|
| 87 | protected void addAdditionalSaveData(final ValueOutput output) {
|
| 88 | super.addAdditionalSaveData(output);
|
| 89 | output.putInt("Lifetime", this.life);
|
| 90 | }
|
| 91 |
|
| 92 | @Override
|
| 93 | public void tick() {
|
| 94 | this.yBodyRot = this.getYRot();
|
| 95 | super.tick();
|
| 96 | }
|
| 97 |
|
| 98 | @Override
|
| 99 | public void setYBodyRot(final float yBodyRot) {
|
| 100 | this.setYRot(yBodyRot);
|
| 101 | super.setYBodyRot(yBodyRot);
|
| 102 | }
|
| 103 |
|
| 104 | @Override
|
| 105 | public void aiStep() {
|
| 106 | super.aiStep();
|
| 107 | if (this.level().isClientSide()) {
|
| 108 | for (int i = 0; i < 2; i++) {
|
| 109 | this.level()
|
| 110 | .addParticle(
|
| 111 | ParticleTypes.PORTAL,
|
| 112 | this.getRandomX(0.5),
|
| 113 | this.getRandomY(),
|
| 114 | this.getRandomZ(0.5),
|
| 115 | (this.random.nextDouble() - 0.5) * 2.0,
|
| 116 | -this.random.nextDouble(),
|
| 117 | (this.random.nextDouble() - 0.5) * 2.0
|
| 118 | );
|
| 119 | }
|
| 120 | } else {
|
| 121 | if (!this.isPersistenceRequired()) {
|
| 122 | this.life++;
|
| 123 | }
|
| 124 |
|
| 125 | if (this.life >= 2400) {
|
| 126 | this.discard();
|
| 127 | }
|
| 128 | }
|
| 129 | }
|
| 130 |
|
| 131 | public static boolean checkEndermiteSpawnRules(
|
| 132 | final EntityType<Endermite> type, final LevelAccessor level, final EntitySpawnReason spawnReason, final BlockPos pos, final RandomSource random
|
| 133 | ) {
|
| 134 | if (!checkAnyLightMonsterSpawnRules(type, level, spawnReason, pos, random)) {
|
| 135 | return false;
|
| 136 | }
|
| 137 |
|
| 138 | if (EntitySpawnReason.isSpawner(spawnReason)) {
|
| 139 | return true;
|
| 140 | }
|
| 141 |
|
| 142 | Player nearestPlayer = level.getNearestPlayer(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 5.0, true);
|
| 143 | return nearestPlayer == null;
|
| 144 | }
|
| 145 | }
|
| 146 |
|