WitherSkull .java

net.minecraft.world.entity.projectile.hurtingprojectile.WitherSkull (class): members: DEFAULT_DANGEROUS, DATA_DANGEROUS, setDangerous, isDangerous, fluid.

net.minecraft.world.entity.projectile.hurtingprojectileclass132 linescommonextends AbstractHurtingProjectile4.4 KB

API Surface (11)

float getInertia()
boolean isOnFire()
float getBlockExplosionResistance(final Explosion explosion, final BlockGetter level, final BlockPos pos, final BlockState block, final FluidState fluid, final float resistance)
void onHitEntity(final EntityHitResult hitResult)
void onHit(final HitResult hitResult)
void defineSynchedData(final SynchedEntityData.Builder entityData)
boolean isDangerous()
void setDangerous(final boolean value)
boolean shouldBurn()
void addAdditionalSaveData(final ValueOutput output)
void readAdditionalSaveData(final ValueInput input)

Fields & Constants (3)

DATA_DANGEROUS
DEFAULT_DANGEROUS
fluid

String literals (1)

"dangerous"

Full Source

WitherSkull.java132 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.projectile.hurtingprojectile;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.network.syncher.EntityDataAccessor;
5
import net.minecraft.network.syncher.EntityDataSerializers;
6
import net.minecraft.network.syncher.SynchedEntityData;
7
import net.minecraft.server.level.ServerLevel;
8
import net.minecraft.world.Difficulty;
9
import net.minecraft.world.damagesource.DamageSource;
10
import net.minecraft.world.effect.MobEffectInstance;
11
import net.minecraft.world.effect.MobEffects;
12
import net.minecraft.world.entity.Entity;
13
import net.minecraft.world.entity.EntityType;
14
import net.minecraft.world.entity.EntityTypes;
15
import net.minecraft.world.entity.LivingEntity;
16
import net.minecraft.world.entity.boss.wither.WitherBoss;
17
import net.minecraft.world.item.enchantment.EnchantmentHelper;
18
import net.minecraft.world.level.BlockGetter;
19
import net.minecraft.world.level.Explosion;
20
import net.minecraft.world.level.Level;
21
import net.minecraft.world.level.block.state.BlockState;
22
import net.minecraft.world.level.material.FluidState;
23
import net.minecraft.world.level.storage.ValueInput;
24
import net.minecraft.world.level.storage.ValueOutput;
25
import net.minecraft.world.phys.EntityHitResult;
26
import net.minecraft.world.phys.HitResult;
27
import net.minecraft.world.phys.Vec3;
28
29
public class WitherSkull extends AbstractHurtingProjectile {
30
	private static final EntityDataAccessor<Boolean> DATA_DANGEROUS = SynchedEntityData.defineId(WitherSkull.class, EntityDataSerializers.BOOLEAN);
31
	private static final boolean DEFAULT_DANGEROUS = false;
32
33
	public WitherSkull(final EntityType<? extends WitherSkull> type, final Level level) {
34
		super(type, level);
35
	}
36
37
	public WitherSkull(final Level level, final LivingEntity mob, final Vec3 direction) {
38
		super(EntityTypes.WITHER_SKULL, mob, direction, level);
39
	}
40
41
	@Override
42
	protected float getInertia() {
43
		return this.isDangerous() ? 0.73F : super.getInertia();
44
	}
45
46
	@Override
47
	public boolean isOnFire() {
48
		return false;
49
	}
50
51
	@Override
52
	public float getBlockExplosionResistance(
53
		final Explosion explosion, final BlockGetter level, final BlockPos pos, final BlockState block, final FluidState fluid, final float resistance
54
	) {
55
		return this.isDangerous() && WitherBoss.canDestroy(block) ? Math.min(0.8F, resistance) : resistance;
56
	}
57
58
	@Override
59
	protected void onHitEntity(final EntityHitResult hitResult) {
60
		super.onHitEntity(hitResult);
61
		if (this.level() instanceof ServerLevel serverLevel) {
62
			Entity var8 = hitResult.getEntity();
63
			boolean wasHurt;
64
			if (this.getOwner() instanceof LivingEntity livingOwner) {
65
				DamageSource damageSource = this.damageSources().witherSkull(this, livingOwner);
66
				wasHurt = var8.hurtServer(serverLevel, damageSource, 8.0F);
67
				if (wasHurt) {
68
					if (var8.isAlive()) {
69
						EnchantmentHelper.doPostAttackEffects(serverLevel, var8, damageSource);
70
					} else {
71
						livingOwner.heal(5.0F);
72
					}
73
				}
74
			} else {
75
				wasHurt = var8.hurtServer(serverLevel, this.damageSources().magic(), 5.0F);
76
			}
77
78
			if (wasHurt && var8 instanceof LivingEntity livingEntity) {
79
				int witherSeconds = 0;
80
				if (this.level().getDifficulty() == Difficulty.NORMAL) {
81
					witherSeconds = 10;
82
				} else if (this.level().getDifficulty() == Difficulty.HARD) {
83
					witherSeconds = 40;
84
				}
85
86
				if (witherSeconds > 0) {
87
					livingEntity.addEffect(new MobEffectInstance(MobEffects.WITHER, 20 * witherSeconds, 1), this.getEffectSource());
88
				}
89
			}
90
		}
91
	}
92
93
	@Override
94
	protected void onHit(final HitResult hitResult) {
95
		super.onHit(hitResult);
96
		if (!this.level().isClientSide()) {
97
			this.level().explode(this, this.getX(), this.getY(), this.getZ(), 1.0F, false, Level.ExplosionInteraction.MOB);
98
			this.discard();
99
		}
100
	}
101
102
	@Override
103
	protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
104
		entityData.define(DATA_DANGEROUS, false);
105
	}
106
107
	public boolean isDangerous() {
108
		return this.entityData.get(DATA_DANGEROUS);
109
	}
110
111
	public void setDangerous(final boolean value) {
112
		this.entityData.set(DATA_DANGEROUS, value);
113
	}
114
115
	@Override
116
	protected boolean shouldBurn() {
117
		return false;
118
	}
119
120
	@Override
121
	protected void addAdditionalSaveData(final ValueOutput output) {
122
		super.addAdditionalSaveData(output);
123
		output.putBoolean("dangerous", this.isDangerous());
124
	}
125
126
	@Override
127
	protected void readAdditionalSaveData(final ValueInput input) {
128
		super.readAdditionalSaveData(input);
129
		this.setDangerous(input.getBooleanOr("dangerous", false));
130
	}
131
}
132

Decompiled Minecraft 26.3 source of WitherSkull (net/minecraft/world/entity/projectile/hurtingprojectile/WitherSkull.java) with Mojang official mappings, stored verbatim on the site.