| 1 | package net.minecraft.world.entity.monster;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
|
| 5 | import net.minecraft.server.level.ServerLevel;
|
| 6 | import net.minecraft.server.level.ServerPlayer;
|
| 7 | import net.minecraft.sounds.SoundEvent;
|
| 8 | import net.minecraft.sounds.SoundEvents;
|
| 9 | import net.minecraft.world.damagesource.DamageSource;
|
| 10 | import net.minecraft.world.effect.MobEffectInstance;
|
| 11 | import net.minecraft.world.effect.MobEffectUtil;
|
| 12 | import net.minecraft.world.effect.MobEffects;
|
| 13 | import net.minecraft.world.entity.EntityType;
|
| 14 | import net.minecraft.world.entity.EntityTypes;
|
| 15 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 16 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 17 | import net.minecraft.world.level.Level;
|
| 18 |
|
| 19 | public class ElderGuardian extends Guardian {
|
| 20 | public static final float ELDER_SIZE_SCALE = EntityTypes.ELDER_GUARDIAN.getWidth() / EntityTypes.GUARDIAN.getWidth();
|
| 21 | private static final int EFFECT_INTERVAL = 1200;
|
| 22 | private static final int EFFECT_RADIUS = 50;
|
| 23 | private static final int EFFECT_DURATION = 6000;
|
| 24 | private static final int EFFECT_AMPLIFIER = 2;
|
| 25 | private static final int EFFECT_DISPLAY_LIMIT = 1200;
|
| 26 |
|
| 27 | public ElderGuardian(final EntityType<? extends ElderGuardian> type, final Level level) {
|
| 28 | super(type, level);
|
| 29 | this.setPersistenceRequired();
|
| 30 | if (this.randomStrollGoal != null) {
|
| 31 | this.randomStrollGoal.setInterval(400);
|
| 32 | }
|
| 33 | }
|
| 34 |
|
| 35 | public static AttributeSupplier.Builder createAttributes() {
|
| 36 | return Guardian.createAttributes().add(Attributes.MOVEMENT_SPEED, 0.3F).add(Attributes.ATTACK_DAMAGE, 8.0).add(Attributes.MAX_HEALTH, 80.0);
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | public int getAttackDuration() {
|
| 41 | return 60;
|
| 42 | }
|
| 43 |
|
| 44 | @Override
|
| 45 | protected SoundEvent getAmbientSound() {
|
| 46 | return this.isInWater() ? SoundEvents.ELDER_GUARDIAN_AMBIENT : SoundEvents.ELDER_GUARDIAN_AMBIENT_LAND;
|
| 47 | }
|
| 48 |
|
| 49 | @Override
|
| 50 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 51 | return this.isInWater() ? SoundEvents.ELDER_GUARDIAN_HURT : SoundEvents.ELDER_GUARDIAN_HURT_LAND;
|
| 52 | }
|
| 53 |
|
| 54 | @Override
|
| 55 | protected SoundEvent getDeathSound() {
|
| 56 | return this.isInWater() ? SoundEvents.ELDER_GUARDIAN_DEATH : SoundEvents.ELDER_GUARDIAN_DEATH_LAND;
|
| 57 | }
|
| 58 |
|
| 59 | @Override
|
| 60 | protected SoundEvent getFlopSound() {
|
| 61 | return SoundEvents.ELDER_GUARDIAN_FLOP;
|
| 62 | }
|
| 63 |
|
| 64 | @Override
|
| 65 | protected void customServerAiStep(final ServerLevel level) {
|
| 66 | super.customServerAiStep(level);
|
| 67 | if ((this.tickCount + this.getId()) % 1200 == 0) {
|
| 68 | MobEffectInstance miningFatigue = new MobEffectInstance(MobEffects.MINING_FATIGUE, 6000, 2);
|
| 69 | List<ServerPlayer> affectedPlayers = MobEffectUtil.addEffectToPlayersAround(level, this, this.position(), 50.0, miningFatigue, 1200);
|
| 70 | affectedPlayers.forEach(
|
| 71 | player -> player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.GUARDIAN_ELDER_EFFECT, this.isSilent() ? 0.0F : 1.0F))
|
| 72 | );
|
| 73 | }
|
| 74 |
|
| 75 | if (!this.hasHome()) {
|
| 76 | this.setHomeTo(this.blockPosition(), 16);
|
| 77 | }
|
| 78 | }
|
| 79 | }
|
| 80 |
|