Illusioner .java

net.minecraft.world.entity.monster.illager.Illusioner (class, 282 lines): members: IllusionerBlindnessSpellGoal, ILLUSION_TRANSITION_TICKS, NUM_ILLUSIONS.

net.minecraft.world.entity.monster.illagerclass282 linescommonextends SpellcasterIllager9.9 KB

Implements

API Surface (25)

void registerGoals()
AttributeSupplier.Builder createAttributes()
SpawnGroupData finalizeSpawn(final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, final @Nullable SpawnGroupData groupData)
void aiStep()
SoundEvent getCelebrateSound()
Vec3[] getIllusionOffsets(final float a)
SoundEvent getAmbientSound()
SoundEvent getDeathSound()
SoundEvent getHurtSound(final DamageSource source)
SoundEvent getCastingSoundEvent()
void applyRaidBuffs(final ServerLevel level, final int wave, final boolean isCaptain)
void performRangedAttack(final LivingEntity target, final float power)
AbstractIllager.IllagerArmPose getArmPose()
boolean canUse()
void start()
int getCastingTime()
int getCastingInterval()
void performSpellCasting()
SoundEvent getSpellPrepareSound()
SpellcasterIllager.IllagerSpell getSpell()
boolean canUse()
int getCastingTime()
int getCastingInterval()
void performSpellCasting()
SpellcasterIllager.IllagerSpell getSpell()

Fields & Constants (6)

NUM_ILLUSIONS
ILLUSION_TRANSITION_TICKS
ILLUSION_SPREAD
clientSideIllusionTicks
clientSideIllusionOffsets
spawnReason

Full Source

Illusioner.java282 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.monster.illager;
2
3
import net.minecraft.core.particles.ParticleTypes;
4
import net.minecraft.server.level.ServerLevel;
5
import net.minecraft.sounds.SoundEvent;
6
import net.minecraft.sounds.SoundEvents;
7
import net.minecraft.world.Difficulty;
8
import net.minecraft.world.DifficultyInstance;
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.EntitySpawnReason;
13
import net.minecraft.world.entity.EntityType;
14
import net.minecraft.world.entity.EquipmentSlot;
15
import net.minecraft.world.entity.LivingEntity;
16
import net.minecraft.world.entity.Mob;
17
import net.minecraft.world.entity.SpawnGroupData;
18
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
19
import net.minecraft.world.entity.ai.attributes.Attributes;
20
import net.minecraft.world.entity.ai.goal.AvoidEntityGoal;
21
import net.minecraft.world.entity.ai.goal.FloatGoal;
22
import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
23
import net.minecraft.world.entity.ai.goal.RandomStrollGoal;
24
import net.minecraft.world.entity.ai.goal.RangedBowAttackGoal;
25
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
26
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
27
import net.minecraft.world.entity.animal.golem.IronGolem;
28
import net.minecraft.world.entity.monster.Monster;
29
import net.minecraft.world.entity.monster.RangedAttackMob;
30
import net.minecraft.world.entity.monster.creaking.Creaking;
31
import net.minecraft.world.entity.npc.villager.AbstractVillager;
32
import net.minecraft.world.entity.player.Player;
33
import net.minecraft.world.entity.projectile.Projectile;
34
import net.minecraft.world.entity.projectile.ProjectileUtil;
35
import net.minecraft.world.entity.projectile.arrow.AbstractArrow;
36
import net.minecraft.world.entity.raid.Raider;
37
import net.minecraft.world.item.ItemStack;
38
import net.minecraft.world.item.Items;
39
import net.minecraft.world.level.Level;
40
import net.minecraft.world.level.ServerLevelAccessor;
41
import net.minecraft.world.phys.Vec3;
42
import org.jspecify.annotations.Nullable;
43
44
public class Illusioner extends SpellcasterIllager implements RangedAttackMob {
45
	private static final int NUM_ILLUSIONS = 4;
46
	private static final int ILLUSION_TRANSITION_TICKS = 3;
47
	public static final int ILLUSION_SPREAD = 3;
48
	private int clientSideIllusionTicks;
49
	private final Vec3[][] clientSideIllusionOffsets;
50
51
	public Illusioner(final EntityType<? extends Illusioner> type, final Level level) {
52
		super(type, level);
53
		this.xpReward = 5;
54
		this.clientSideIllusionOffsets = new Vec3[2][4];
55
56
		for (int i = 0; i < 4; i++) {
57
			this.clientSideIllusionOffsets[0][i] = Vec3.ZERO;
58
			this.clientSideIllusionOffsets[1][i] = Vec3.ZERO;
59
		}
60
	}
61
62
	@Override
63
	protected void registerGoals() {
64
		super.registerGoals();
65
		this.goalSelector.addGoal(0, new FloatGoal(this));
66
		this.goalSelector.addGoal(1, new SpellcasterIllager.SpellcasterCastingSpellGoal());
67
		this.goalSelector.addGoal(3, new AvoidEntityGoal<>(this, Creaking.class, 8.0F, 1.0, 1.2));
68
		this.goalSelector.addGoal(4, new Illusioner.IllusionerMirrorSpellGoal());
69
		this.goalSelector.addGoal(5, new Illusioner.IllusionerBlindnessSpellGoal());
70
		this.goalSelector.addGoal(6, new RangedBowAttackGoal<>(this, 0.5, 20, 15.0F));
71
		this.goalSelector.addGoal(8, new RandomStrollGoal(this, 0.6));
72
		this.goalSelector.addGoal(9, new LookAtPlayerGoal(this, Player.class, 3.0F, 1.0F));
73
		this.goalSelector.addGoal(10, new LookAtPlayerGoal(this, Mob.class, 8.0F));
74
		this.targetSelector.addGoal(1, new HurtByTargetGoal(this, Raider.class).setAlertOthers());
75
		this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true).setUnseenMemoryTicks(300));
76
		this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, AbstractVillager.class, false).setUnseenMemoryTicks(300));
77
		this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, IronGolem.class, false).setUnseenMemoryTicks(300));
78
	}
79
80
	public static AttributeSupplier.Builder createAttributes() {
81
		return Monster.createMonsterAttributes().add(Attributes.MOVEMENT_SPEED, 0.5).add(Attributes.FOLLOW_RANGE, 18.0).add(Attributes.MAX_HEALTH, 32.0);
82
	}
83
84
	@Override
85
	public SpawnGroupData finalizeSpawn(
86
		final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, final @Nullable SpawnGroupData groupData
87
	) {
88
		this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.BOW));
89
		return super.finalizeSpawn(level, difficulty, spawnReason, groupData);
90
	}
91
92
	@Override
93
	public void aiStep() {
94
		super.aiStep();
95
		if (this.level().isClientSide() && this.isInvisible()) {
96
			this.clientSideIllusionTicks--;
97
			if (this.clientSideIllusionTicks < 0) {
98
				this.clientSideIllusionTicks = 0;
99
			}
100
101
			if (this.hurtTime == 1 || this.tickCount % 1200 == 0) {
102
				this.clientSideIllusionTicks = 3;
103
				float minSpread = -6.0F;
104
				int spreadSpan = 13;
105
106
				for (int i = 0; i < 4; i++) {
107
					this.clientSideIllusionOffsets[0][i] = this.clientSideIllusionOffsets[1][i];
108
					this.clientSideIllusionOffsets[1][i] = new Vec3(
109
						(-6.0F + this.random.nextInt(13)) * 0.5, Math.max(0, this.random.nextInt(6) - 4), (-6.0F + this.random.nextInt(13)) * 0.5
110
					);
111
				}
112
113
				for (int i = 0; i < 16; i++) {
114
					this.level().addParticle(ParticleTypes.CLOUD, this.getRandomX(0.5), this.getRandomY(), this.getZ(0.5), 0.0, 0.0, 0.0);
115
				}
116
117
				this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), SoundEvents.ILLUSIONER_MIRROR_MOVE, this.getSoundSource(), 1.0F, 1.0F, false);
118
			} else if (this.hurtTime == this.hurtDuration - 1) {
119
				this.clientSideIllusionTicks = 3;
120
121
				for (int i = 0; i < 4; i++) {
122
					this.clientSideIllusionOffsets[0][i] = this.clientSideIllusionOffsets[1][i];
123
					this.clientSideIllusionOffsets[1][i] = new Vec3(0.0, 0.0, 0.0);
124
				}
125
			}
126
		}
127
	}
128
129
	@Override
130
	public SoundEvent getCelebrateSound() {
131
		return SoundEvents.ILLUSIONER_AMBIENT;
132
	}
133
134
	public Vec3[] getIllusionOffsets(final float a) {
135
		if (this.clientSideIllusionTicks <= 0) {
136
			return this.clientSideIllusionOffsets[1];
137
		}
138
139
		double scale = (this.clientSideIllusionTicks - a) / 3.0F;
140
		scale = Math.pow(scale, 0.25);
141
		Vec3[] offsets = new Vec3[4];
142
143
		for (int i = 0; i < 4; i++) {
144
			offsets[i] = this.clientSideIllusionOffsets[1][i].scale(1.0 - scale).add(this.clientSideIllusionOffsets[0][i].scale(scale));
145
		}
146
147
		return offsets;
148
	}
149
150
	@Override
151
	protected SoundEvent getAmbientSound() {
152
		return SoundEvents.ILLUSIONER_AMBIENT;
153
	}
154
155
	@Override
156
	protected SoundEvent getDeathSound() {
157
		return SoundEvents.ILLUSIONER_DEATH;
158
	}
159
160
	@Override
161
	protected SoundEvent getHurtSound(final DamageSource source) {
162
		return SoundEvents.ILLUSIONER_HURT;
163
	}
164
165
	@Override
166
	protected SoundEvent getCastingSoundEvent() {
167
		return SoundEvents.ILLUSIONER_CAST_SPELL;
168
	}
169
170
	@Override
171
	public void applyRaidBuffs(final ServerLevel level, final int wave, final boolean isCaptain) {
172
	}
173
174
	@Override
175
	public void performRangedAttack(final LivingEntity target, final float power) {
176
		ItemStack bowItem = this.getItemInHand(ProjectileUtil.getWeaponHoldingHand(this, Items.BOW));
177
		ItemStack projectile = this.getProjectile(bowItem);
178
		AbstractArrow arrow = ProjectileUtil.getMobArrow(this, projectile, power, bowItem);
179
		double xd = target.getX() - this.getX();
180
		double yd = target.getY(0.3333333333333333) - arrow.getY();
181
		double zd = target.getZ() - this.getZ();
182
		double distanceToTarget = Math.sqrt(xd * xd + zd * zd);
183
		if (this.level() instanceof ServerLevel serverLevel) {
184
			Projectile.spawnProjectileUsingShoot(arrow, serverLevel, projectile, xd, yd + distanceToTarget * 0.2F, zd, 1.6F, this.rangedAttackUncertainty(serverLevel));
185
		}
186
187
		this.playSound(SoundEvents.SKELETON_SHOOT, 1.0F, 1.0F / (this.getRandom().nextFloat() * 0.4F + 0.8F));
188
	}
189
190
	@Override
191
	public AbstractIllager.IllagerArmPose getArmPose() {
192
		if (this.isCastingSpell()) {
193
			return AbstractIllager.IllagerArmPose.SPELLCASTING;
194
		} else {
195
			return this.isAggressive() ? AbstractIllager.IllagerArmPose.BOW_AND_ARROW : AbstractIllager.IllagerArmPose.CROSSED;
196
		}
197
	}
198
199
	private class IllusionerBlindnessSpellGoal extends SpellcasterIllager.SpellcasterUseSpellGoal {
200
		private int lastTargetId;
201
202
		@Override
203
		public boolean canUse() {
204
			if (!super.canUse()) {
205
				return false;
206
			} else if (Illusioner.this.getTarget() == null) {
207
				return false;
208
			} else {
209
				return Illusioner.this.getTarget().getId() == this.lastTargetId
210
					? false
211
					: getServerLevel(Illusioner.this).getCurrentDifficultyAt(Illusioner.this.blockPosition()).isHarderThan(Difficulty.NORMAL.ordinal());
212
			}
213
		}
214
215
		@Override
216
		public void start() {
217
			super.start();
218
			LivingEntity target = Illusioner.this.getTarget();
219
			if (target != null) {
220
				this.lastTargetId = target.getId();
221
			}
222
		}
223
224
		@Override
225
		protected int getCastingTime() {
226
			return 20;
227
		}
228
229
		@Override
230
		protected int getCastingInterval() {
231
			return 180;
232
		}
233
234
		@Override
235
		protected void performSpellCasting() {
236
			Illusioner.this.getTarget().addEffect(new MobEffectInstance(MobEffects.BLINDNESS, 400), Illusioner.this);
237
		}
238
239
		@Override
240
		protected SoundEvent getSpellPrepareSound() {
241
			return SoundEvents.ILLUSIONER_PREPARE_BLINDNESS;
242
		}
243
244
		@Override
245
		protected SpellcasterIllager.IllagerSpell getSpell() {
246
			return SpellcasterIllager.IllagerSpell.BLINDNESS;
247
		}
248
	}
249
250
	private class IllusionerMirrorSpellGoal extends SpellcasterIllager.SpellcasterUseSpellGoal {
251
		@Override
252
		public boolean canUse() {
253
			return !super.canUse() ? false : !Illusioner.this.hasEffect(MobEffects.INVISIBILITY);
254
		}
255
256
		@Override
257
		protected int getCastingTime() {
258
			return 20;
259
		}
260
261
		@Override
262
		protected int getCastingInterval() {
263
			return 340;
264
		}
265
266
		@Override
267
		protected void performSpellCasting() {
268
			Illusioner.this.addEffect(new MobEffectInstance(MobEffects.INVISIBILITY, 1200));
269
		}
270
271
		@Override
272
		protected @Nullable SoundEvent getSpellPrepareSound() {
273
			return SoundEvents.ILLUSIONER_PREPARE_MIRROR;
274
		}
275
276
		@Override
277
		protected SpellcasterIllager.IllagerSpell getSpell() {
278
			return SpellcasterIllager.IllagerSpell.DISAPPEAR;
279
		}
280
	}
281
}
282

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