| 1 | package net.minecraft.world.entity.boss.wither;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableList;
|
| 4 | import java.util.EnumSet;
|
| 5 | import java.util.List;
|
| 6 | import net.minecraft.core.BlockPos;
|
| 7 | import net.minecraft.core.particles.ColorParticleOption;
|
| 8 | import net.minecraft.core.particles.ParticleTypes;
|
| 9 | import net.minecraft.network.chat.Component;
|
| 10 | import net.minecraft.network.syncher.EntityDataAccessor;
|
| 11 | import net.minecraft.network.syncher.EntityDataSerializers;
|
| 12 | import net.minecraft.network.syncher.SynchedEntityData;
|
| 13 | import net.minecraft.server.level.ServerBossEvent;
|
| 14 | import net.minecraft.server.level.ServerLevel;
|
| 15 | import net.minecraft.server.level.ServerPlayer;
|
| 16 | import net.minecraft.sounds.SoundEvent;
|
| 17 | import net.minecraft.sounds.SoundEvents;
|
| 18 | import net.minecraft.tags.BlockTags;
|
| 19 | import net.minecraft.tags.DamageTypeTags;
|
| 20 | import net.minecraft.tags.EntityTypeTags;
|
| 21 | import net.minecraft.util.Mth;
|
| 22 | import net.minecraft.util.Util;
|
| 23 | import net.minecraft.world.BossEvent;
|
| 24 | import net.minecraft.world.Difficulty;
|
| 25 | import net.minecraft.world.damagesource.DamageSource;
|
| 26 | import net.minecraft.world.effect.MobEffectInstance;
|
| 27 | import net.minecraft.world.effect.MobEffects;
|
| 28 | import net.minecraft.world.entity.Entity;
|
| 29 | import net.minecraft.world.entity.EntityType;
|
| 30 | import net.minecraft.world.entity.LivingEntity;
|
| 31 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 32 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 33 | import net.minecraft.world.entity.ai.control.FlyingMoveControl;
|
| 34 | import net.minecraft.world.entity.ai.goal.Goal;
|
| 35 | import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
|
| 36 | import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
|
| 37 | import net.minecraft.world.entity.ai.goal.RangedAttackGoal;
|
| 38 | import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomFlyingGoal;
|
| 39 | import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
|
| 40 | import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
|
| 41 | import net.minecraft.world.entity.ai.navigation.FlyingPathNavigation;
|
| 42 | import net.minecraft.world.entity.ai.navigation.PathNavigation;
|
| 43 | import net.minecraft.world.entity.ai.targeting.TargetingConditions;
|
| 44 | import net.minecraft.world.entity.item.ItemEntity;
|
| 45 | import net.minecraft.world.entity.monster.Monster;
|
| 46 | import net.minecraft.world.entity.monster.RangedAttackMob;
|
| 47 | import net.minecraft.world.entity.player.Player;
|
| 48 | import net.minecraft.world.entity.projectile.arrow.AbstractArrow;
|
| 49 | import net.minecraft.world.entity.projectile.hurtingprojectile.WitherSkull;
|
| 50 | import net.minecraft.world.entity.projectile.hurtingprojectile.windcharge.WindCharge;
|
| 51 | import net.minecraft.world.item.Items;
|
| 52 | import net.minecraft.world.level.Level;
|
| 53 | import net.minecraft.world.level.block.state.BlockState;
|
| 54 | import net.minecraft.world.level.gamerules.GameRules;
|
| 55 | import net.minecraft.world.level.storage.ValueInput;
|
| 56 | import net.minecraft.world.level.storage.ValueOutput;
|
| 57 | import net.minecraft.world.phys.Vec3;
|
| 58 | import org.jspecify.annotations.Nullable;
|
| 59 |
|
| 60 | public class WitherBoss extends Monster implements RangedAttackMob {
|
| 61 | private static final EntityDataAccessor<Integer> DATA_TARGET_A = SynchedEntityData.defineId(WitherBoss.class, EntityDataSerializers.INT);
|
| 62 | private static final EntityDataAccessor<Integer> DATA_TARGET_B = SynchedEntityData.defineId(WitherBoss.class, EntityDataSerializers.INT);
|
| 63 | private static final EntityDataAccessor<Integer> DATA_TARGET_C = SynchedEntityData.defineId(WitherBoss.class, EntityDataSerializers.INT);
|
| 64 | private static final List<EntityDataAccessor<Integer>> DATA_TARGETS = ImmutableList.of(DATA_TARGET_A, DATA_TARGET_B, DATA_TARGET_C);
|
| 65 | private static final EntityDataAccessor<Integer> DATA_ID_INV = SynchedEntityData.defineId(WitherBoss.class, EntityDataSerializers.INT);
|
| 66 | private static final int INVULNERABLE_TICKS = 220;
|
| 67 | private static final int DEFAULT_INVULNERABLE_TICKS = 0;
|
| 68 | private final float[] xRotHeads = new float[2];
|
| 69 | private final float[] yRotHeads = new float[2];
|
| 70 | private final float[] xRotOHeads = new float[2];
|
| 71 | private final float[] yRotOHeads = new float[2];
|
| 72 | private final int[] nextHeadUpdate = new int[2];
|
| 73 | private final int[] idleHeadUpdates = new int[2];
|
| 74 | private int destroyBlocksTick;
|
| 75 | private final ServerBossEvent bossEvent = Util.make(
|
| 76 | new ServerBossEvent(Mth.createInsecureUUID(this.random), this.getDisplayName(), BossEvent.BossBarColor.PURPLE, BossEvent.BossBarOverlay.PROGRESS),
|
| 77 | e -> e.setDarkenScreen(true)
|
| 78 | );
|
| 79 | private static final TargetingConditions.Selector LIVING_ENTITY_SELECTOR = (target, level) -> !target.is(EntityTypeTags.WITHER_FRIENDS) && target.attackable();
|
| 80 | private static final TargetingConditions TARGETING_CONDITIONS = TargetingConditions.forCombat().range(20.0).selector(LIVING_ENTITY_SELECTOR);
|
| 81 |
|
| 82 | public WitherBoss(final EntityType<? extends WitherBoss> type, final Level level) {
|
| 83 | super(type, level);
|
| 84 | this.moveControl = new FlyingMoveControl<>(this, 10, false);
|
| 85 | this.setHealth(this.getMaxHealth());
|
| 86 | this.xpReward = 50;
|
| 87 | }
|
| 88 |
|
| 89 | @Override
|
| 90 | protected PathNavigation createNavigation(final Level level) {
|
| 91 | FlyingPathNavigation flyingPathNavigation = new FlyingPathNavigation(this, level);
|
| 92 | flyingPathNavigation.setCanOpenDoors(false);
|
| 93 | flyingPathNavigation.setCanFloat(true);
|
| 94 | return flyingPathNavigation;
|
| 95 | }
|
| 96 |
|
| 97 | @Override
|
| 98 | protected void registerGoals() {
|
| 99 | this.goalSelector.addGoal(0, new WitherBoss.WitherDoNothingGoal());
|
| 100 | this.goalSelector.addGoal(2, new RangedAttackGoal(this, 1.0, 40, 20.0F));
|
| 101 | this.goalSelector.addGoal(5, new WaterAvoidingRandomFlyingGoal(this, 1.0));
|
| 102 | this.goalSelector.addGoal(6, new LookAtPlayerGoal(this, Player.class, 8.0F));
|
| 103 | this.goalSelector.addGoal(7, new RandomLookAroundGoal(this));
|
| 104 | this.targetSelector.addGoal(1, new HurtByTargetGoal(this));
|
| 105 | this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, LivingEntity.class, 0, false, false, LIVING_ENTITY_SELECTOR));
|
| 106 | }
|
| 107 |
|
| 108 | @Override
|
| 109 | protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
|
| 110 | super.defineSynchedData(entityData);
|
| 111 | entityData.define(DATA_TARGET_A, 0);
|
| 112 | entityData.define(DATA_TARGET_B, 0);
|
| 113 | entityData.define(DATA_TARGET_C, 0);
|
| 114 | entityData.define(DATA_ID_INV, 0);
|
| 115 | }
|
| 116 |
|
| 117 | @Override
|
| 118 | protected void addAdditionalSaveData(final ValueOutput output) {
|
| 119 | super.addAdditionalSaveData(output);
|
| 120 | output.putInt("Invul", this.getInvulnerableTicks());
|
| 121 | }
|
| 122 |
|
| 123 | @Override
|
| 124 | protected void readAdditionalSaveData(final ValueInput input) {
|
| 125 | super.readAdditionalSaveData(input);
|
| 126 | this.setInvulnerableTicks(input.getIntOr("Invul", 0));
|
| 127 | if (this.hasCustomName()) {
|
| 128 | this.bossEvent.setName(this.getDisplayName());
|
| 129 | }
|
| 130 | }
|
| 131 |
|
| 132 | @Override
|
| 133 | public void setCustomName(final @Nullable Component name) {
|
| 134 | super.setCustomName(name);
|
| 135 | this.bossEvent.setName(this.getDisplayName());
|
| 136 | }
|
| 137 |
|
| 138 | @Override
|
| 139 | protected SoundEvent getAmbientSound() {
|
| 140 | return SoundEvents.WITHER_AMBIENT;
|
| 141 | }
|
| 142 |
|
| 143 | @Override
|
| 144 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 145 | return SoundEvents.WITHER_HURT;
|
| 146 | }
|
| 147 |
|
| 148 | @Override
|
| 149 | protected SoundEvent getDeathSound() {
|
| 150 | return SoundEvents.WITHER_DEATH;
|
| 151 | }
|
| 152 |
|
| 153 | @Override
|
| 154 | public void aiStep() {
|
| 155 | Vec3 deltaMovement = this.getDeltaMovement().multiply(1.0, 0.6, 1.0);
|
| 156 | if (!this.level().isClientSide() && this.getAlternativeTarget(0) > 0) {
|
| 157 | Entity entity = this.level().getEntity(this.getAlternativeTarget(0));
|
| 158 | if (entity != null) {
|
| 159 | double yd = deltaMovement.y;
|
| 160 | if (this.getY() < entity.getY() || !this.isPowered() && this.getY() < entity.getY() + 5.0) {
|
| 161 | yd = Math.max(0.0, yd);
|
| 162 | yd += 0.3 - yd * 0.6F;
|
| 163 | }
|
| 164 |
|
| 165 | deltaMovement = new Vec3(deltaMovement.x, yd, deltaMovement.z);
|
| 166 | Vec3 delta = new Vec3(entity.getX() - this.getX(), 0.0, entity.getZ() - this.getZ());
|
| 167 | if (delta.horizontalDistanceSqr() > 9.0) {
|
| 168 | Vec3 scale = delta.normalize();
|
| 169 | deltaMovement = deltaMovement.add(scale.x * 0.3 - deltaMovement.x * 0.6, 0.0, scale.z * 0.3 - deltaMovement.z * 0.6);
|
| 170 | }
|
| 171 | }
|
| 172 | }
|
| 173 |
|
| 174 | this.setDeltaMovement(deltaMovement);
|
| 175 | if (deltaMovement.horizontalDistanceSqr() > 0.05) {
|
| 176 | this.setYRot((float)Mth.atan2(deltaMovement.z, deltaMovement.x) * (180.0F / (float)Math.PI) - 90.0F);
|
| 177 | }
|
| 178 |
|
| 179 | super.aiStep();
|
| 180 |
|
| 181 | for (int i = 0; i < 2; i++) {
|
| 182 | this.yRotOHeads[i] = this.yRotHeads[i];
|
| 183 | this.xRotOHeads[i] = this.xRotHeads[i];
|
| 184 | }
|
| 185 |
|
| 186 | for (int i = 0; i < 2; i++) {
|
| 187 | int entityId = this.getAlternativeTarget(i + 1);
|
| 188 | Entity entity = null;
|
| 189 | if (entityId > 0) {
|
| 190 | entity = this.level().getEntity(entityId);
|
| 191 | }
|
| 192 |
|
| 193 | if (entity != null) {
|
| 194 | double hx = this.getHeadX(i + 1);
|
| 195 | double hy = this.getHeadY(i + 1);
|
| 196 | double hz = this.getHeadZ(i + 1);
|
| 197 | double xd = entity.getX() - hx;
|
| 198 | double yd = entity.getEyeY() - hy;
|
| 199 | double zd = entity.getZ() - hz;
|
| 200 | double sd = Math.sqrt(xd * xd + zd * zd);
|
| 201 | float yRotD = (float)(Mth.atan2(zd, xd) * 180.0F / (float)Math.PI) - 90.0F;
|
| 202 | float xRotD = (float)(-(Mth.atan2(yd, sd) * 180.0F / (float)Math.PI));
|
| 203 | this.xRotHeads[i] = this.rotlerp(this.xRotHeads[i], xRotD, 40.0F);
|
| 204 | this.yRotHeads[i] = this.rotlerp(this.yRotHeads[i], yRotD, 10.0F);
|
| 205 | } else {
|
| 206 | this.yRotHeads[i] = this.rotlerp(this.yRotHeads[i], this.yBodyRot, 10.0F);
|
| 207 | }
|
| 208 | }
|
| 209 |
|
| 210 | boolean isPowered = this.isPowered();
|
| 211 |
|
| 212 | for (int i = 0; i < 3; i++) {
|
| 213 | double hx = this.getHeadX(i);
|
| 214 | double hy = this.getHeadY(i);
|
| 215 | double hz = this.getHeadZ(i);
|
| 216 | float radius = 0.3F * this.getScale();
|
| 217 | this.level()
|
| 218 | .addParticle(
|
| 219 | ParticleTypes.SMOKE,
|
| 220 | hx + this.random.nextGaussian() * radius,
|
| 221 | hy + this.random.nextGaussian() * radius,
|
| 222 | hz + this.random.nextGaussian() * radius,
|
| 223 | 0.0,
|
| 224 | 0.0,
|
| 225 | 0.0
|
| 226 | );
|
| 227 | if (isPowered && this.level().getRandom().nextInt(4) == 0) {
|
| 228 | this.level()
|
| 229 | .addParticle(
|
| 230 | ColorParticleOption.create(ParticleTypes.ENTITY_EFFECT, 0.7F, 0.7F, 0.5F),
|
| 231 | hx + this.random.nextGaussian() * radius,
|
| 232 | hy + this.random.nextGaussian() * radius,
|
| 233 | hz + this.random.nextGaussian() * radius,
|
| 234 | 0.0,
|
| 235 | 0.0,
|
| 236 | 0.0
|
| 237 | );
|
| 238 | }
|
| 239 | }
|
| 240 |
|
| 241 | if (this.getInvulnerableTicks() > 0) {
|
| 242 | float height = 3.3F * this.getScale();
|
| 243 |
|
| 244 | for (int i = 0; i < 3; i++) {
|
| 245 | this.level()
|
| 246 | .addParticle(
|
| 247 | ColorParticleOption.create(ParticleTypes.ENTITY_EFFECT, 0.7F, 0.7F, 0.9F),
|
| 248 | this.getX() + this.random.nextGaussian(),
|
| 249 | this.getY() + this.random.nextFloat() * height,
|
| 250 | this.getZ() + this.random.nextGaussian(),
|
| 251 | 0.0,
|
| 252 | 0.0,
|
| 253 | 0.0
|
| 254 | );
|
| 255 | }
|
| 256 | }
|
| 257 | }
|
| 258 |
|
| 259 | @Override
|
| 260 | protected void customServerAiStep(final ServerLevel level) {
|
| 261 | if (this.getInvulnerableTicks() > 0) {
|
| 262 | int newCount = this.getInvulnerableTicks() - 1;
|
| 263 | this.bossEvent.setProgress(1.0F - newCount / 220.0F);
|
| 264 | if (newCount <= 0) {
|
| 265 | level.explode(this, this.getX(), this.getEyeY(), this.getZ(), 7.0F, false, Level.ExplosionInteraction.MOB);
|
| 266 | if (!this.isSilent()) {
|
| 267 | level.globalLevelEvent(1023, this.blockPosition(), 0);
|
| 268 | }
|
| 269 | }
|
| 270 |
|
| 271 | this.setInvulnerableTicks(newCount);
|
| 272 | if (this.tickCount % 10 == 0) {
|
| 273 | this.heal(10.0F);
|
| 274 | }
|
| 275 | } else {
|
| 276 | super.customServerAiStep(level);
|
| 277 |
|
| 278 | for (int i = 1; i < 3; i++) {
|
| 279 | if (this.tickCount >= this.nextHeadUpdate[i - 1]) {
|
| 280 | this.nextHeadUpdate[i - 1] = this.tickCount + 10 + this.random.nextInt(10);
|
| 281 | if ((level.getDifficulty() == Difficulty.NORMAL || level.getDifficulty() == Difficulty.HARD) && this.idleHeadUpdates[i - 1]++ > 15) {
|
| 282 | float hrange = 10.0F;
|
| 283 | float vrange = 5.0F;
|
| 284 | double xt = Mth.nextDouble(this.random, this.getX() - 10.0, this.getX() + 10.0);
|
| 285 | double yt = Mth.nextDouble(this.random, this.getY() - 5.0, this.getY() + 5.0);
|
| 286 | double zt = Mth.nextDouble(this.random, this.getZ() - 10.0, this.getZ() + 10.0);
|
| 287 | this.performRangedAttack(i + 1, xt, yt, zt, true);
|
| 288 | this.idleHeadUpdates[i - 1] = 0;
|
| 289 | }
|
| 290 |
|
| 291 | int headTarget = this.getAlternativeTarget(i);
|
| 292 | if (headTarget > 0) {
|
| 293 | LivingEntity current = (LivingEntity)level.getEntity(headTarget);
|
| 294 | if (current != null && this.canAttack(current) && !(this.distanceToSqr(current) > 900.0) && this.hasLineOfSight(current)) {
|
| 295 | this.performRangedAttack(i + 1, current);
|
| 296 | this.nextHeadUpdate[i - 1] = this.tickCount + 40 + this.random.nextInt(20);
|
| 297 | this.idleHeadUpdates[i - 1] = 0;
|
| 298 | } else {
|
| 299 | this.setAlternativeTarget(i, 0);
|
| 300 | }
|
| 301 | } else {
|
| 302 | List<LivingEntity> entities = level.getNearbyEntities(LivingEntity.class, TARGETING_CONDITIONS, this, this.getBoundingBox().inflate(20.0, 8.0, 20.0));
|
| 303 | if (!entities.isEmpty()) {
|
| 304 | LivingEntity selected = entities.get(this.random.nextInt(entities.size()));
|
| 305 | this.setAlternativeTarget(i, selected.getId());
|
| 306 | }
|
| 307 | }
|
| 308 | }
|
| 309 | }
|
| 310 |
|
| 311 | if (this.getTarget() != null) {
|
| 312 | this.setAlternativeTarget(0, this.getTarget().getId());
|
| 313 | } else {
|
| 314 | this.setAlternativeTarget(0, 0);
|
| 315 | }
|
| 316 |
|
| 317 | if (this.destroyBlocksTick > 0) {
|
| 318 | this.destroyBlocksTick--;
|
| 319 | if (this.destroyBlocksTick == 0 && level.getGameRules().get(GameRules.MOB_GRIEFING)) {
|
| 320 | boolean destroyed = false;
|
| 321 | int width = Mth.floor(this.getBbWidth() / 2.0F + 1.0F);
|
| 322 | int height = Mth.floor(this.getBbHeight());
|
| 323 |
|
| 324 | for (BlockPos blockPos : BlockPos.betweenClosed(
|
| 325 | this.getBlockX() - width, this.getBlockY(), this.getBlockZ() - width, this.getBlockX() + width, this.getBlockY() + height, this.getBlockZ() + width
|
| 326 | )) {
|
| 327 | BlockState state = level.getBlockState(blockPos);
|
| 328 | if (canDestroy(state)) {
|
| 329 | destroyed = level.destroyBlock(blockPos, true, this) || destroyed;
|
| 330 | }
|
| 331 | }
|
| 332 |
|
| 333 | if (destroyed) {
|
| 334 | level.levelEvent(null, 1022, this.blockPosition(), 0);
|
| 335 | }
|
| 336 | }
|
| 337 | }
|
| 338 |
|
| 339 | if (this.tickCount % 20 == 0) {
|
| 340 | this.heal(1.0F);
|
| 341 | }
|
| 342 |
|
| 343 | this.bossEvent.setProgress(this.getHealth() / this.getMaxHealth());
|
| 344 | }
|
| 345 | }
|
| 346 |
|
| 347 | public static boolean canDestroy(final BlockState state) {
|
| 348 | return !state.isAir() && !state.is(BlockTags.WITHER_IMMUNE);
|
| 349 | }
|
| 350 |
|
| 351 | public void makeInvulnerable() {
|
| 352 | this.setInvulnerableTicks(220);
|
| 353 | this.bossEvent.setProgress(0.0F);
|
| 354 | this.setHealth(this.getMaxHealth() / 3.0F);
|
| 355 | }
|
| 356 |
|
| 357 | @Override
|
| 358 | public void makeStuckInBlock(final BlockState blockState, final Vec3 speedMultiplier) {
|
| 359 | }
|
| 360 |
|
| 361 | @Override
|
| 362 | public void startSeenByPlayer(final ServerPlayer player) {
|
| 363 | super.startSeenByPlayer(player);
|
| 364 | this.bossEvent.addPlayer(player);
|
| 365 | }
|
| 366 |
|
| 367 | @Override
|
| 368 | public void stopSeenByPlayer(final ServerPlayer player) {
|
| 369 | super.stopSeenByPlayer(player);
|
| 370 | this.bossEvent.removePlayer(player);
|
| 371 | }
|
| 372 |
|
| 373 | private double getHeadX(final int index) {
|
| 374 | if (index <= 0) {
|
| 375 | return this.getX();
|
| 376 | }
|
| 377 |
|
| 378 | float headAngle = (this.yBodyRot + 180 * (index - 1)) * (float) (Math.PI / 180.0);
|
| 379 | float cos = Mth.cos(headAngle);
|
| 380 | return this.getX() + cos * 1.3 * this.getScale();
|
| 381 | }
|
| 382 |
|
| 383 | private double getHeadY(final int index) {
|
| 384 | float height = index <= 0 ? 3.0F : 2.2F;
|
| 385 | return this.getY() + height * this.getScale();
|
| 386 | }
|
| 387 |
|
| 388 | private double getHeadZ(final int index) {
|
| 389 | if (index <= 0) {
|
| 390 | return this.getZ();
|
| 391 | }
|
| 392 |
|
| 393 | float headAngle = (this.yBodyRot + 180 * (index - 1)) * (float) (Math.PI / 180.0);
|
| 394 | float sin = Mth.sin(headAngle);
|
| 395 | return this.getZ() + sin * 1.3 * this.getScale();
|
| 396 | }
|
| 397 |
|
| 398 | private float rotlerp(final float a, final float b, final float max) {
|
| 399 | float diff = Mth.wrapDegrees(b - a);
|
| 400 | if (diff > max) {
|
| 401 | diff = max;
|
| 402 | }
|
| 403 |
|
| 404 | if (diff < -max) {
|
| 405 | diff = -max;
|
| 406 | }
|
| 407 |
|
| 408 | return a + diff;
|
| 409 | }
|
| 410 |
|
| 411 | private void performRangedAttack(final int head, final LivingEntity target) {
|
| 412 | this.performRangedAttack(head, target.getX(), target.getY() + target.getEyeHeight() * 0.5, target.getZ(), head == 0 && this.random.nextFloat() < 0.001F);
|
| 413 | }
|
| 414 |
|
| 415 | private void performRangedAttack(final int head, final double tx, final double ty, final double tz, final boolean dangerous) {
|
| 416 | if (!this.isSilent()) {
|
| 417 | this.level().levelEvent(null, 1024, this.blockPosition(), 0);
|
| 418 | }
|
| 419 |
|
| 420 | double hx = this.getHeadX(head);
|
| 421 | double hy = this.getHeadY(head);
|
| 422 | double hz = this.getHeadZ(head);
|
| 423 | double xd = tx - hx;
|
| 424 | double yd = ty - hy;
|
| 425 | double zd = tz - hz;
|
| 426 | Vec3 direction = new Vec3(xd, yd, zd);
|
| 427 | WitherSkull entity = new WitherSkull(this.level(), this, direction.normalize());
|
| 428 | entity.setOwner(this);
|
| 429 | if (dangerous) {
|
| 430 | entity.setDangerous(true);
|
| 431 | }
|
| 432 |
|
| 433 | entity.setPos(hx, hy, hz);
|
| 434 | this.level().addFreshEntity(entity);
|
| 435 | }
|
| 436 |
|
| 437 | @Override
|
| 438 | public void performRangedAttack(final LivingEntity target, final float power) {
|
| 439 | this.performRangedAttack(0, target);
|
| 440 | }
|
| 441 |
|
| 442 | @Override
|
| 443 | public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
|
| 444 | if (this.isInvulnerableTo(level, source)) {
|
| 445 | return false;
|
| 446 | }
|
| 447 |
|
| 448 | if (source.is(DamageTypeTags.WITHER_IMMUNE_TO) || source.getEntity() instanceof WitherBoss) {
|
| 449 | return false;
|
| 450 | }
|
| 451 |
|
| 452 | if (this.getInvulnerableTicks() > 0 && !source.is(DamageTypeTags.BYPASSES_INVULNERABILITY)) {
|
| 453 | return false;
|
| 454 | }
|
| 455 |
|
| 456 | if (this.isPowered()) {
|
| 457 | Entity directEntity = source.getDirectEntity();
|
| 458 | if (directEntity instanceof AbstractArrow || directEntity instanceof WindCharge) {
|
| 459 | return false;
|
| 460 | }
|
| 461 | }
|
| 462 |
|
| 463 | Entity sourceEntity = source.getEntity();
|
| 464 | if (sourceEntity != null && sourceEntity.is(EntityTypeTags.WITHER_FRIENDS)) {
|
| 465 | return false;
|
| 466 | }
|
| 467 |
|
| 468 | if (this.destroyBlocksTick <= 0) {
|
| 469 | this.destroyBlocksTick = 20;
|
| 470 | }
|
| 471 |
|
| 472 | for (int i = 0; i < this.idleHeadUpdates.length; i++) {
|
| 473 | this.idleHeadUpdates[i] = this.idleHeadUpdates[i] + 3;
|
| 474 | }
|
| 475 |
|
| 476 | return super.hurtServer(level, source, damage);
|
| 477 | }
|
| 478 |
|
| 479 | @Override
|
| 480 | protected void dropCustomDeathLoot(final ServerLevel level, final DamageSource source, final boolean killedByPlayer) {
|
| 481 | super.dropCustomDeathLoot(level, source, killedByPlayer);
|
| 482 | ItemEntity netherStar = this.spawnAtLocation(level, Items.NETHER_STAR);
|
| 483 | if (netherStar != null) {
|
| 484 | netherStar.setExtendedLifetime();
|
| 485 | }
|
| 486 | }
|
| 487 |
|
| 488 | @Override
|
| 489 | public void checkDespawn() {
|
| 490 | if (this.level().getDifficulty() == Difficulty.PEACEFUL && !this.getType().isAllowedInPeaceful()) {
|
| 491 | this.discard();
|
| 492 | } else {
|
| 493 | this.noActionTime = 0;
|
| 494 | }
|
| 495 | }
|
| 496 |
|
| 497 | @Override
|
| 498 | public boolean addEffect(final MobEffectInstance newEffect, final @Nullable Entity source) {
|
| 499 | return false;
|
| 500 | }
|
| 501 |
|
| 502 | public static AttributeSupplier.Builder createAttributes() {
|
| 503 | return Monster.createMonsterAttributes()
|
| 504 | .add(Attributes.MAX_HEALTH, 300.0)
|
| 505 | .add(Attributes.MOVEMENT_SPEED, 0.6F)
|
| 506 | .add(Attributes.FLYING_SPEED, 0.6F)
|
| 507 | .add(Attributes.FOLLOW_RANGE, 40.0)
|
| 508 | .add(Attributes.ARMOR, 4.0);
|
| 509 | }
|
| 510 |
|
| 511 | public float[] getHeadYRots() {
|
| 512 | return this.yRotHeads;
|
| 513 | }
|
| 514 |
|
| 515 | public float[] getHeadXRots() {
|
| 516 | return this.xRotHeads;
|
| 517 | }
|
| 518 |
|
| 519 | public int getInvulnerableTicks() {
|
| 520 | return this.entityData.get(DATA_ID_INV);
|
| 521 | }
|
| 522 |
|
| 523 | public void setInvulnerableTicks(final int invulnerableTicks) {
|
| 524 | this.entityData.set(DATA_ID_INV, invulnerableTicks);
|
| 525 | }
|
| 526 |
|
| 527 | public int getAlternativeTarget(final int headIndex) {
|
| 528 | return this.entityData.get(DATA_TARGETS.get(headIndex));
|
| 529 | }
|
| 530 |
|
| 531 | public void setAlternativeTarget(final int headIndex, final int entityId) {
|
| 532 | this.entityData.set(DATA_TARGETS.get(headIndex), entityId);
|
| 533 | }
|
| 534 |
|
| 535 | public boolean isPowered() {
|
| 536 | return this.getHealth() <= this.getMaxHealth() / 2.0F;
|
| 537 | }
|
| 538 |
|
| 539 | @Override
|
| 540 | protected boolean canRide(final Entity vehicle) {
|
| 541 | return false;
|
| 542 | }
|
| 543 |
|
| 544 | @Override
|
| 545 | public boolean canUsePortal(final boolean ignorePassenger) {
|
| 546 | return false;
|
| 547 | }
|
| 548 |
|
| 549 | @Override
|
| 550 | public boolean canBeAffected(final MobEffectInstance newEffect) {
|
| 551 | return newEffect.is(MobEffects.WITHER) ? false : super.canBeAffected(newEffect);
|
| 552 | }
|
| 553 |
|
| 554 | private class WitherDoNothingGoal extends Goal {
|
| 555 | public WitherDoNothingGoal() {
|
| 556 | this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.JUMP, Goal.Flag.LOOK));
|
| 557 | }
|
| 558 |
|
| 559 | @Override
|
| 560 | public boolean canUse() {
|
| 561 | return WitherBoss.this.getInvulnerableTicks() > 0;
|
| 562 | }
|
| 563 | }
|
| 564 | }
|
| 565 |
|