SulfurCube .java

net.minecraft.world.entity.monster.cubemob.SulfurCube (class): members: VEHICLE_PUSH_SPEED_SCALE_MULTIPLIER, PLAYER_PUSH_SPEED_SCALE_MULTIPLIER, MAX_FUSE.

net.minecraft.world.entity.monster.cubemobclass1,017 linescommonextends AbstractCubeMob34.5 KB

Implements

API Surface (73)

void defineSynchedData(final SynchedEntityData.Builder entityData)
void addBehaviourGoals()
boolean fromBucket()
int getFuse()
boolean isPrimed()
void onSyncedDataUpdated(final EntityDataAccessor<?> accessor)
void setFromBucket(final boolean fromBucket)
SoundEvent getPickupSound()
void saveToBucketTag(final ItemStack bucket)
boolean canBreatheUnderwater()
void travelInFluid(final Vec3 input)
double getFluidJumpThreshold()
void loadFromBucketTag(final CompoundTag tag)
ItemStack getBucketItemStack()
void addTargetingGoals()
float getLightLevelDependentMagicValue()
boolean canDealDamage()
boolean checkSulfurCubeSpawnRules(final EntityType<SulfurCube> type, final LevelAccessor level, final EntitySpawnReason spawnReason, final BlockPos pos, final RandomSource random)
boolean requiresCustomPersistence()
boolean canBeLeashed()
boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage)
boolean hasBodyItem()
boolean canExplode()
List<SulfurCubeArchetype> matchingArchetypes(final ItemStack stack)
void tick()
boolean primeTime(final boolean imminent)
void customServerAiStep(final ServerLevel level)
float maxUpStep()
boolean omnidirectionalAirMover()
boolean canFreeze()
InteractionResult mobInteract(final Player player, final InteractionHand hand)
boolean equipItem(final ItemStack heldItem)
void playEatingSound()
boolean canBePickedUpWithBucket(final ItemStack itemStack)
EquipmentSlot getEquipmentSlotForItem(final ItemStack itemStack)
boolean isEquippableInSlot(final ItemStack itemStack, final EquipmentSlot slot)
SoundSource getSoundSource()
SoundEvent getHurtSound(final DamageSource source)
SoundEvent getDeathSound()
SoundEvent getSquishSound()
SoundEvent getJumpSound()
void playStepSound(final BlockPos pos, final BlockState blockState)
AttributeSupplier.Builder createSulfurCubeAttributes()
void shear(final ServerLevel level, final SoundSource soundSource, final ItemStack tool)
boolean readyForShearing()
boolean canPickUpLoot()
boolean canUseSlot(final EquipmentSlot slot)
boolean canDispenserEquipIntoSlot(final EquipmentSlot slot)
boolean canHoldItem(final ItemStack itemStack)
void pickUpItem(final ServerLevel level, final ItemEntity entity)
int getBaseExperienceReward(final ServerLevel level)
int getSplitCount()
void setSpawnSize(final ServerLevelAccessor level, final DifficultyInstance difficulty)
void setSize(final int size, final boolean updateHealth)
void setUpSplitCube(final AbstractCubeMob cubeMob, final int halfSize, final float xd, final float zd)
void ageBoundaryReached()
void addAdditionalSaveData(final ValueOutput output)
void readAdditionalSaveData(final ValueInput input)
void doPush(final Entity entity)
void playerTouch(final Player player)
void knockback(final double power, double xd, double zd, final DamageSource source, final float damage, final boolean comesFromEffect)
void applyImplicitComponents(final DataComponentGetter components)
<T> boolean applyImplicitComponent(final DataComponentType<T> type, final T value)
Vec3 getLeashOffset()
void setCubeMobHealth(final int actualSize)
boolean isInvulnerableToPiercingWeapon()
boolean canBePickedFromInside()
void tick()
void tick()
boolean canUse()
void tick()
void stopNavigation()
void navigateTowards(final Player player)

Fields & Constants (36)

SPLIT_COUNT
MAX_SIZE
MIN_SIZE
PICKUP_TIMER_DURATION
PUSH_DISTANCE_THRESHOLD
MAX_PLAYER_PUSH_SPEED
PLAYER_PUSH_SPEED_SCALE_MULTIPLIER
VEHICLE_PUSH_SPEED_SCALE_MULTIPLIER
VERTICAL_PUSH_MULTIPLIER
MAX_FUSE
FROM_BUCKET
DEFAULT_FROM_BUCKET
HORIZONTAL_HIT_ANGLE_SCALE
VERTICAL_HIT_ANGLE_SCALE
VERTICAL_POSITION_ANGLE_SCALE
EXTRA_KNOCKBACK_DAMPENING
ALLOWED_ITEMS
pickupTimer
pushSoundCooldown
floatsInLiquids
explosionData
knockbackModifier
soundSettings
fuse
contactDamages
pos
attackerAimDirection
verticalHitAngleScale
horizontalPower
verticalPower
attackerPosition
targetCenteredPosition
verticalPositionAngleScale
originalHorizontalPower
originalVerticalPower
attackerFeetPosition

String literals (5)

"age_locked"
"block.minecraft.tnt.disabled"
"pickup_timer"
"from_bucket"
"fuse"

Code Graph: Dependencies (69)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

SulfurCube.java1017 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.monster.cubemob;
2
3
import com.google.common.annotations.VisibleForTesting;
4
import java.util.ArrayList;
5
import java.util.EnumSet;
6
import java.util.List;
7
import java.util.Map;
8
import java.util.Optional;
9
import java.util.function.Predicate;
10
import java.util.stream.Collectors;
11
import net.minecraft.advancements.triggers.CriteriaTriggers;
12
import net.minecraft.core.BlockPos;
13
import net.minecraft.core.Holder;
14
import net.minecraft.core.component.DataComponentGetter;
15
import net.minecraft.core.component.DataComponentType;
16
import net.minecraft.core.component.DataComponents;
17
import net.minecraft.core.particles.ParticleOptions;
18
import net.minecraft.core.particles.ParticleTypes;
19
import net.minecraft.core.registries.Registries;
20
import net.minecraft.nbt.CompoundTag;
21
import net.minecraft.network.chat.Component;
22
import net.minecraft.network.syncher.EntityDataAccessor;
23
import net.minecraft.network.syncher.EntityDataSerializers;
24
import net.minecraft.network.syncher.SynchedEntityData;
25
import net.minecraft.server.level.ServerLevel;
26
import net.minecraft.server.level.ServerPlayer;
27
import net.minecraft.sounds.SoundEvent;
28
import net.minecraft.sounds.SoundEvents;
29
import net.minecraft.sounds.SoundSource;
30
import net.minecraft.stats.Stats;
31
import net.minecraft.tags.DamageTypeTags;
32
import net.minecraft.tags.FluidTags;
33
import net.minecraft.tags.ItemTags;
34
import net.minecraft.util.Mth;
35
import net.minecraft.util.RandomSource;
36
import net.minecraft.util.Util;
37
import net.minecraft.world.DifficultyInstance;
38
import net.minecraft.world.InteractionHand;
39
import net.minecraft.world.InteractionResult;
40
import net.minecraft.world.damagesource.DamageSource;
41
import net.minecraft.world.entity.AgeableMob;
42
import net.minecraft.world.entity.Bucketable;
43
import net.minecraft.world.entity.Entity;
44
import net.minecraft.world.entity.EntityAttachment;
45
import net.minecraft.world.entity.EntitySpawnReason;
46
import net.minecraft.world.entity.EntityType;
47
import net.minecraft.world.entity.EntityTypes;
48
import net.minecraft.world.entity.EquipmentSlot;
49
import net.minecraft.world.entity.Mob;
50
import net.minecraft.world.entity.Shearable;
51
import net.minecraft.world.entity.SulfurCubeArchetype;
52
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
53
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
54
import net.minecraft.world.entity.ai.attributes.Attributes;
55
import net.minecraft.world.entity.ai.control.LookControl;
56
import net.minecraft.world.entity.ai.goal.Goal;
57
import net.minecraft.world.entity.ai.goal.TemptGoal;
58
import net.minecraft.world.entity.item.ItemEntity;
59
import net.minecraft.world.entity.item.PrimedTnt;
60
import net.minecraft.world.entity.player.Player;
61
import net.minecraft.world.entity.projectile.arrow.AbstractArrow;
62
import net.minecraft.world.item.Item;
63
import net.minecraft.world.item.ItemStack;
64
import net.minecraft.world.item.Items;
65
import net.minecraft.world.item.component.CustomData;
66
import net.minecraft.world.item.component.SulfurCubeContent;
67
import net.minecraft.world.level.Explosion;
68
import net.minecraft.world.level.Level;
69
import net.minecraft.world.level.LevelAccessor;
70
import net.minecraft.world.level.ServerLevelAccessor;
71
import net.minecraft.world.level.block.state.BlockState;
72
import net.minecraft.world.level.gameevent.GameEvent;
73
import net.minecraft.world.level.gamerules.GameRules;
74
import net.minecraft.world.level.storage.ValueInput;
75
import net.minecraft.world.level.storage.ValueOutput;
76
import net.minecraft.world.phys.Vec2;
77
import net.minecraft.world.phys.Vec3;
78
import org.jspecify.annotations.Nullable;
79
80
public class SulfurCube extends AbstractCubeMob implements Bucketable, Shearable {
81
	public static final int SPLIT_COUNT = 2;
82
	public static final int MAX_SIZE = 2;
83
	public static final int MIN_SIZE = 1;
84
	public static final int PICKUP_TIMER_DURATION = 100;
85
	public static final double PUSH_DISTANCE_THRESHOLD = 1.3F;
86
	private int pickupTimer = 0;
87
	private int pushSoundCooldown = 0;
88
	private boolean floatsInLiquids = false;
89
	private static final double MAX_PLAYER_PUSH_SPEED = 0.5;
90
	private static final float PLAYER_PUSH_SPEED_SCALE_MULTIPLIER = 0.3F;
91
	private static final float VEHICLE_PUSH_SPEED_SCALE_MULTIPLIER = 0.16F;
92
	private static final float VERTICAL_PUSH_MULTIPLIER = 0.3F;
93
	private Optional<SulfurCubeArchetype.ExplosionData> explosionData = Optional.empty();
94
	private SulfurCubeArchetype.KnockbackModifiers knockbackModifier = SulfurCubeArchetype.DEFAULT_KNOCKBACK_MODIFIERS;
95
	private SulfurCubeArchetype.SoundSettings soundSettings = SulfurCubeArchetype.DEFAULT_SOUND_SETTINGS;
96
	private int fuse = -1;
97
	private final List<SulfurCubeArchetype.ContactDamage> contactDamages = new ArrayList<>();
98
	private static final EntityDataAccessor<Integer> MAX_FUSE = SynchedEntityData.defineId(SulfurCube.class, EntityDataSerializers.INT);
99
	private static final EntityDataAccessor<Boolean> FROM_BUCKET = SynchedEntityData.defineId(SulfurCube.class, EntityDataSerializers.BOOLEAN);
100
	private static final boolean DEFAULT_FROM_BUCKET = false;
101
	private static final float HORIZONTAL_HIT_ANGLE_SCALE = 1.6F;
102
	private static final float VERTICAL_HIT_ANGLE_SCALE = 0.5F;
103
	private static final float VERTICAL_POSITION_ANGLE_SCALE = 0.8F;
104
	private static final float EXTRA_KNOCKBACK_DAMPENING = 0.25F;
105
	private static final Predicate<ItemEntity> ALLOWED_ITEMS = e -> !e.hasPickUpDelay() && e.isAlive() && isSwallowableItem(e.getItem());
106
107
	public SulfurCube(final EntityType<? extends SulfurCube> type, final Level level) {
108
		super(type, level);
109
		this.lookControl = new SulfurCube.SulfurCubeLookControl();
110
		this.moveControl = new SulfurCube.SulfurCubeMobMoveControl<>(this);
111
	}
112
113
	@Override
114
	protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
115
		super.defineSynchedData(entityData);
116
		entityData.define(FROM_BUCKET, false);
117
		entityData.define(MAX_FUSE, -1);
118
	}
119
120
	@Override
121
	protected void addBehaviourGoals() {
122
		this.goalSelector
123
			.addGoal(
124
				2,
125
				new SulfurCube.SulfurCubeTemptGoal(
126
					this, 1.0, itemStack -> this.isBaby() ? itemStack.is(ItemTags.SULFUR_CUBE_FOOD) : isSwallowableItem(itemStack), false, 1.0
127
				)
128
			);
129
		this.goalSelector.addGoal(3, new SulfurCube.SulfurCubeSearchForItemsGoal(this));
130
	}
131
132
	@Override
133
	public boolean fromBucket() {
134
		return this.entityData.get(FROM_BUCKET);
135
	}
136
137
	public int getFuse() {
138
		return this.fuse;
139
	}
140
141
	public boolean isPrimed() {
142
		return this.getFuse() >= 0;
143
	}
144
145
	private void setFuse(final int fuse) {
146
		this.fuse = fuse;
147
	}
148
149
	@Override
150
	public void onSyncedDataUpdated(final EntityDataAccessor<?> accessor) {
151
		if (MAX_FUSE.equals(accessor)) {
152
			this.setFuse(this.entityData.get(MAX_FUSE));
153
		}
154
155
		super.onSyncedDataUpdated(accessor);
156
	}
157
158
	@Override
159
	public void setFromBucket(final boolean fromBucket) {
160
		this.entityData.set(FROM_BUCKET, fromBucket);
161
	}
162
163
	@Override
164
	public SoundEvent getPickupSound() {
165
		return SoundEvents.BUCKET_FILL_SULFUR_CUBE;
166
	}
167
168
	@Override
169
	public void saveToBucketTag(final ItemStack bucket) {
170
		Bucketable.saveDefaultDataToBucketTag(this, bucket);
171
		bucket.copyFrom(DataComponents.SULFUR_CUBE_CONTENT, this);
172
		CustomData.update(DataComponents.BUCKET_ENTITY_DATA, bucket, tag -> {
173
			tag.putInt("age", this.getAge());
174
			tag.putBoolean("age_locked", this.isAgeLocked());
175
		});
176
	}
177
178
	@Override
179
	public boolean canBreatheUnderwater() {
180
		return this.hasBodyItem() || super.canBreatheUnderwater();
181
	}
182
183
	@Override
184
	protected void travelInFluid(final Vec3 input) {
185
		super.travelInFluid(input);
186
		if (this.hasBodyItem() && this.floatsInLiquids) {
187
			float vibeAmount = 0.2F * Mth.sin(this.tickCount * 0.4F);
188
			double immersion = this.getFluidHeight(this.isInWater() ? FluidTags.WATER : FluidTags.LAVA) - this.getFluidJumpThreshold() + vibeAmount;
189
			if (immersion > 0.0) {
190
				this.setDeltaMovement(this.getDeltaMovement().add(0.0, Math.min(1.0, immersion) * 0.04F, 0.0));
191
			}
192
		}
193
	}
194
195
	@Override
196
	public double getFluidJumpThreshold() {
197
		return this.getBbHeight() * 0.2;
198
	}
199
200
	@Override
201
	public void loadFromBucketTag(final CompoundTag tag) {
202
		Bucketable.loadDefaultDataFromBucketTag(this, tag);
203
		this.setAge(tag.getIntOr("age", 0));
204
		this.setAgeLocked(tag.getBooleanOr("age_locked", false));
205
	}
206
207
	@Override
208
	public ItemStack getBucketItemStack() {
209
		return new ItemStack(Items.SULFUR_CUBE_BUCKET);
210
	}
211
212
	@Override
213
	protected void addTargetingGoals() {
214
	}
215
216
	@Override
217
	public float getLightLevelDependentMagicValue() {
218
		return 1.0F;
219
	}
220
221
	@Override
222
	protected boolean canDealDamage() {
223
		return false;
224
	}
225
226
	public static boolean checkSulfurCubeSpawnRules(
227
		final EntityType<SulfurCube> type, final LevelAccessor level, final EntitySpawnReason spawnReason, final BlockPos pos, final RandomSource random
228
	) {
229
		return true;
230
	}
231
232
	@Override
233
	public boolean requiresCustomPersistence() {
234
		return super.requiresCustomPersistence() || this.hasBodyItem() || this.fromBucket();
235
	}
236
237
	@Override
238
	public boolean canBeLeashed() {
239
		return this.hasBodyItem();
240
	}
241
242
	@Override
243
	public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
244
		if (this.hasBodyItem()) {
245
			if (this.canExplode() && !this.isPrimed()) {
246
				Entity sourceEntity = source.getDirectEntity();
247
				if (source.is(DamageTypeTags.IS_FIRE) || sourceEntity instanceof AbstractArrow projectile && projectile.isOnFire()) {
248
					this.primeTime(false);
249
				} else if (source.is(DamageTypeTags.IS_EXPLOSION)) {
250
					this.primeTime(true);
251
				}
252
			}
253
254
			if (source.is(DamageTypeTags.SULFUR_CUBE_WITH_BLOCK_IMMUNE_TO)) {
255
				if (!source.is(DamageTypeTags.NO_KNOCKBACK)) {
256
					this.dealDefaultKnockback(source, damage, true);
257
				}
258
259
				return true;
260
			}
261
		}
262
263
		return super.hurtServer(level, source, damage);
264
	}
265
266
	public boolean hasBodyItem() {
267
		return !this.getItemBySlot(EquipmentSlot.BODY).isEmpty();
268
	}
269
270
	public boolean canExplode() {
271
		return this.explosionData.isPresent() && this.isAlive() && !this.isPrimed();
272
	}
273
274
	@VisibleForTesting
275
	public List<SulfurCubeArchetype> matchingArchetypes(final ItemStack stack) {
276
		return this.level()
277
			.registryAccess()
278
			.lookupOrThrow(Registries.SULFUR_CUBE_ARCHETYPE)
279
			.stream()
280
			.filter(arch -> stack.is(arch.items()))
281
			.collect(Collectors.toCollection(ArrayList::new));
282
	}
283
284
	@Override
285
	public void tick() {
286
		this.tickFuse();
287
		this.primeWhenOnPoweredPosition();
288
		super.tick();
289
	}
290
291
	private void tickFuse() {
292
		if (this.fuse > 0) {
293
			this.fuse--;
294
		}
295
296
		if (!this.explosionData.isEmpty()) {
297
			if (this.fuse == 0) {
298
				this.dropLeash();
299
				this.dead = true;
300
				if (this.level() instanceof ServerLevel level) {
301
					if (level.getGameRules().get(GameRules.TNT_EXPLODES)) {
302
						Level.ExplosionInteraction explosionInteraction = level.getGameRules().get(GameRules.MOB_GRIEFING)
303
							? Level.ExplosionInteraction.TNT
304
							: Level.ExplosionInteraction.NONE;
305
						level.explode(
306
							this,
307
							Explosion.getDefaultDamageSource(this.level(), this),
308
							this.getPortalCooldown() > 0 ? PrimedTnt.USED_PORTAL_DAMAGE_CALCULATOR : null,
309
							this.getX(),
310
							this.getY(0.0625),
311
							this.getZ(),
312
							this.explosionData.get().power(),
313
							this.explosionData.get().causesFire(),
314
							explosionInteraction
315
						);
316
					}
317
318
					this.triggerOnDeathMobEffects(level, Entity.RemovalReason.KILLED);
319
				}
320
321
				this.discard();
322
			}
323
		}
324
	}
325
326
	private void primeWhenOnPoweredPosition() {
327
		if (this.level() instanceof ServerLevel level && this.canExplode()) {
328
			BlockPos here = BlockPos.containing(this.position());
329
			if (level.getBestOwnOrNeighbourSignal(here) != 0) {
330
				this.primeTime(false);
331
			}
332
		}
333
	}
334
335
	public boolean primeTime(final boolean imminent) {
336
		if (!this.explosionData.isEmpty()
337
			&& this.isAlive()
338
			&& this.level() instanceof ServerLevel serverLevel
339
			&& serverLevel.getGameRules().get(GameRules.TNT_EXPLODES)
340
			&& !this.isPrimed()) {
341
			int fuse = this.explosionData.get().fuse();
342
			int fuseTime = imminent ? PrimedTnt.getRandomShortFuse(fuse, this.getRandom()) : fuse;
343
			this.setPermanentlyInvulnerable(true);
344
			this.setFuse(fuseTime);
345
			this.entityData.set(MAX_FUSE, fuseTime);
346
			this.makeSound(SoundEvents.TNT_PRIMED);
347
			this.gameEvent(GameEvent.PRIME_FUSE);
348
			return true;
349
		} else {
350
			return false;
351
		}
352
	}
353
354
	@Override
355
	protected void customServerAiStep(final ServerLevel level) {
356
		super.customServerAiStep(level);
357
		if (this.pickupTimer > 0) {
358
			this.pickupTimer--;
359
		}
360
361
		if (this.pushSoundCooldown > 0) {
362
			this.pushSoundCooldown--;
363
		}
364
	}
365
366
	@Override
367
	protected @Nullable Map<EquipmentSlot, ItemStack> collectEquipmentChanges(final Map<EquipmentSlot, ItemStack> lastEquipmentItems) {
368
		ItemStack previous = lastEquipmentItems.get(EquipmentSlot.BODY);
369
		ItemStack current = this.getItemBySlot(EquipmentSlot.BODY);
370
		if (this.equipmentHasChanged(previous, current)) {
371
			if (!current.isEmpty()) {
372
				this.removeAllGoals(g -> true);
373
				this.setSpeed(0.0F);
374
			} else {
375
				this.registerGoals();
376
			}
377
378
			for (SulfurCubeArchetype archetype : this.matchingArchetypes(previous)) {
379
				for (SulfurCubeArchetype.AttributeEntry mod : archetype.attributeModifiers()) {
380
					AttributeInstance attr = this.getAttribute(mod.attribute());
381
					if (attr != null) {
382
						attr.removeModifier(mod.modifier());
383
					}
384
				}
385
			}
386
387
			this.floatsInLiquids = false;
388
			this.explosionData = Optional.empty();
389
			this.contactDamages.clear();
390
			this.knockbackModifier = SulfurCubeArchetype.DEFAULT_KNOCKBACK_MODIFIERS;
391
			this.soundSettings = SulfurCubeArchetype.DEFAULT_SOUND_SETTINGS;
392
393
			for (SulfurCubeArchetype archetype : this.matchingArchetypes(current)) {
394
				if (archetype.buoyant()) {
395
					this.floatsInLiquids = true;
396
				}
397
398
				if (archetype.explosion().isPresent()) {
399
					this.explosionData = archetype.explosion();
400
				}
401
402
				if (archetype.contactDamage().isPresent()) {
403
					this.contactDamages.add(archetype.contactDamage().get());
404
				}
405
406
				this.knockbackModifier = archetype.knockbackModifiers();
407
				this.soundSettings = archetype.soundSettings();
408
409
				for (SulfurCubeArchetype.AttributeEntry mod : archetype.attributeModifiers()) {
410
					AttributeInstance attr = this.getAttribute(mod.attribute());
411
					if (attr != null) {
412
						attr.addOrUpdateTransientModifier(mod.modifier());
413
					}
414
				}
415
			}
416
		}
417
418
		return super.collectEquipmentChanges(lastEquipmentItems);
419
	}
420
421
	@Override
422
	public float maxUpStep() {
423
		return this.hasBodyItem() ? 0.0F : super.maxUpStep();
424
	}
425
426
	@Override
427
	protected boolean omnidirectionalAirMover() {
428
		return this.hasBodyItem();
429
	}
430
431
	@Override
432
	public boolean canFreeze() {
433
		return this.hasBodyItem() ? false : super.canFreeze();
434
	}
435
436
	@Override
437
	protected InteractionResult mobInteract(final Player player, final InteractionHand hand) {
438
		ItemStack heldItem = player.getItemInHand(hand);
439
		if (this.isBaby()) {
440
			if (this.isFood(heldItem) && this.canAgeUp()) {
441
				int age = this.getAge();
442
				this.usePlayerItem(player, hand, heldItem);
443
				this.ageUp(getSpeedUpSecondsWhenFeeding(-age), true);
444
				this.playEatingSound();
445
				return InteractionResult.SUCCESS;
446
			} else {
447
				return super.mobInteract(player, hand);
448
			}
449
		} else {
450
			if (this.isPrimed()) {
451
				return InteractionResult.PASS;
452
			}
453
454
			if (!this.canExplode() || !heldItem.is(Items.FLINT_AND_STEEL) && !heldItem.is(Items.FIRE_CHARGE)) {
455
				if (heldItem.is(Items.SHEARS) && this.readyForShearing()) {
456
					if (this.level() instanceof ServerLevel level) {
457
						ItemStack itemStackToShear = this.getItemBySlot(EquipmentSlot.BODY);
458
						this.shear(level, SoundSource.PLAYERS, heldItem);
459
						this.gameEvent(GameEvent.SHEAR, player);
460
						heldItem.hurtAndBreak(1, player, hand.asEquipmentSlot());
461
						CriteriaTriggers.PLAYER_SHEARED_EQUIPMENT.trigger((ServerPlayer)player, itemStackToShear, this);
462
					}
463
464
					return InteractionResult.SUCCESS;
465
				} else if (isSwallowableItem(heldItem)) {
466
					boolean itWorked = this.equipItem(heldItem);
467
					if (itWorked) {
468
						heldItem.consume(1, player);
469
						this.gameEvent(GameEvent.ENTITY_INTERACT);
470
					}
471
472
					return itWorked ? InteractionResult.SUCCESS_SERVER : InteractionResult.PASS;
473
				} else {
474
					return Bucketable.bucketMobPickup(player, hand, this).orElse(super.mobInteract(player, hand));
475
				}
476
			} else if (this.level() instanceof ServerLevel serverLevel && !serverLevel.getGameRules().get(GameRules.TNT_EXPLODES)) {
477
				player.sendOverlayMessage(Component.translatable("block.minecraft.tnt.disabled"));
478
				return InteractionResult.PASS;
479
			} else {
480
				this.primeTime(false);
481
				if (heldItem.is(Items.FLINT_AND_STEEL)) {
482
					heldItem.hurtAndBreak(1, player, hand.asEquipmentSlot());
483
				} else {
484
					heldItem.consume(1, player);
485
				}
486
487
				player.awardStat(Stats.ITEM_USED.get(heldItem.getItem()));
488
				return InteractionResult.SUCCESS_SERVER;
489
			}
490
		}
491
	}
492
493
	public boolean equipItem(final ItemStack heldItem) {
494
		if (this.isBaby()) {
495
			return false;
496
		}
497
498
		if (this.hasBodyItem()) {
499
			Item swallowedItem = this.getItemBySlot(EquipmentSlot.BODY).getItem();
500
			if (heldItem.is(swallowedItem)) {
501
				return false;
502
			}
503
504
			Vec3 equipmentSpawnOffset = this.getAttachments().getAverage(EntityAttachment.PASSENGER);
505
			if (this.level() instanceof ServerLevel serverLevel) {
506
				this.spawnAtLocation(serverLevel, this.getItemBySlot(EquipmentSlot.BODY), equipmentSpawnOffset);
507
			}
508
		}
509
510
		if (!this.level().isClientSide()) {
511
			ItemStack swallowedItem = this.getItemBySlot(EquipmentSlot.BODY);
512
			this.setItemSlotAndDropWhenKilled(EquipmentSlot.BODY, heldItem.copyWithCount(1));
513
			if (!swallowedItem.isEmpty()) {
514
				Map<EquipmentSlot, ItemStack> lastEquipmentItems = Util.makeEnumMap(EquipmentSlot.class, slot -> ItemStack.EMPTY);
515
				lastEquipmentItems.put(EquipmentSlot.BODY, swallowedItem);
516
				this.collectEquipmentChanges(lastEquipmentItems);
517
			}
518
		}
519
520
		this.playSound(this.getAbsorbSound());
521
		return true;
522
	}
523
524
	private void applyContactDamage(final Entity entity) {
525
		if (this.level() instanceof ServerLevel serverLevel) {
526
			for (SulfurCubeArchetype.ContactDamage damage : this.contactDamages) {
527
				Entity damageSource = !damage.attributeToSource() && !(entity instanceof Player) ? null : this;
528
				entity.hurtServer(serverLevel, new DamageSource(damage.damageType(), damageSource), damage.amount().sample(this.getRandom()));
529
			}
530
		}
531
	}
532
533
	protected void playEatingSound() {
534
		this.makeSound(SoundEvents.SULFUR_CUBE_SMALL_EAT);
535
	}
536
537
	@Override
538
	public boolean canBePickedUpWithBucket(final ItemStack itemStack) {
539
		return itemStack.getItem() == Items.BUCKET;
540
	}
541
542
	@Override
543
	public EquipmentSlot getEquipmentSlotForItem(final ItemStack itemStack) {
544
		return isSwallowableItem(itemStack) ? EquipmentSlot.BODY : super.getEquipmentSlotForItem(itemStack);
545
	}
546
547
	@Override
548
	public boolean isEquippableInSlot(final ItemStack itemStack, final EquipmentSlot slot) {
549
		return slot == EquipmentSlot.BODY ? isSwallowableItem(itemStack) : super.isEquippableInSlot(itemStack, slot);
550
	}
551
552
	@Override
553
	public SoundSource getSoundSource() {
554
		return SoundSource.NEUTRAL;
555
	}
556
557
	@Override
558
	protected SoundEvent getHurtSound(final DamageSource source) {
559
		return this.isTiny() ? SoundEvents.SULFUR_CUBE_SMALL_HURT : SoundEvents.SULFUR_CUBE_HURT;
560
	}
561
562
	@Override
563
	protected SoundEvent getDeathSound() {
564
		return this.isTiny() ? SoundEvents.SULFUR_CUBE_SMALL_DEATH : SoundEvents.SULFUR_CUBE_DEATH;
565
	}
566
567
	@Override
568
	protected SoundEvent getSquishSound() {
569
		if (this.isTiny()) {
570
			return SoundEvents.SULFUR_CUBE_SMALL_SQUISH;
571
		} else {
572
			return this.hasBodyItem() ? SoundEvents.SULFUR_CUBE_BOUNCE : SoundEvents.SULFUR_CUBE_SQUISH;
573
		}
574
	}
575
576
	@Override
577
	protected SoundEvent getJumpSound() {
578
		return this.isTiny() ? SoundEvents.SULFUR_CUBE_SMALL_JUMP : SoundEvents.SULFUR_CUBE_JUMP;
579
	}
580
581
	private SoundEvent getAbsorbSound() {
582
		return SoundEvents.SULFUR_CUBE_ABSORB;
583
	}
584
585
	private SoundEvent getEjectSound() {
586
		return SoundEvents.SULFUR_CUBE_EJECT;
587
	}
588
589
	@Override
590
	protected void playStepSound(final BlockPos pos, final BlockState blockState) {
591
		if (!this.hasBodyItem()) {
592
			super.playStepSound(pos, blockState);
593
		}
594
	}
595
596
	@Override
597
	protected @Nullable ParticleOptions getParticleType() {
598
		return ParticleTypes.SULFUR_CUBE_GOO;
599
	}
600
601
	public static AttributeSupplier.Builder createSulfurCubeAttributes() {
602
		return Mob.createMobAttributes().add(Attributes.TEMPT_RANGE, 8.0);
603
	}
604
605
	@Override
606
	public void shear(final ServerLevel level, final SoundSource soundSource, final ItemStack tool) {
607
		Vec3 equipmentSpawnOffset = this.getAttachments().getAverage(EntityAttachment.PASSENGER);
608
		ItemStack itemStackToShear = this.getItemBySlot(EquipmentSlot.BODY);
609
		this.setItemSlot(EquipmentSlot.BODY, ItemStack.EMPTY);
610
		this.spawnAtLocation(level, itemStackToShear, equipmentSpawnOffset);
611
		this.playSound(this.getEjectSound());
612
		this.pickupTimer = 100;
613
	}
614
615
	@Override
616
	public boolean readyForShearing() {
617
		return this.hasBodyItem();
618
	}
619
620
	@Override
621
	public boolean canPickUpLoot() {
622
		return !this.hasBodyItem();
623
	}
624
625
	private static boolean isSwallowableItem(final ItemStack itemStack) {
626
		return itemStack.is(ItemTags.SULFUR_CUBE_SWALLOWABLE);
627
	}
628
629
	@Override
630
	public boolean canUseSlot(final EquipmentSlot slot) {
631
		return slot != EquipmentSlot.BODY ? super.canUseSlot(slot) : this.isAlive() && !this.isBaby();
632
	}
633
634
	@Override
635
	protected boolean canDispenserEquipIntoSlot(final EquipmentSlot slot) {
636
		return slot == EquipmentSlot.BODY;
637
	}
638
639
	@Override
640
	public boolean canHoldItem(final ItemStack itemStack) {
641
		ItemStack heldItemStack = this.getItemBySlot(EquipmentSlot.BODY);
642
		return heldItemStack.isEmpty() && isSwallowableItem(itemStack) && !this.isBaby();
643
	}
644
645
	@Override
646
	protected void pickUpItem(final ServerLevel level, final ItemEntity entity) {
647
		ItemStack itemStack = entity.getItem();
648
		if (this.canHoldItem(itemStack) && this.pickupTimer <= 0) {
649
			this.onItemPickup(entity);
650
			this.setItemSlot(EquipmentSlot.BODY, itemStack.split(1));
651
			this.playSound(this.getAbsorbSound());
652
			this.setGuaranteedDrop(EquipmentSlot.BODY);
653
			this.take(entity, 1);
654
		}
655
	}
656
657
	@Override
658
	protected int getBaseExperienceReward(final ServerLevel level) {
659
		return this.isBaby() ? 0 : 1 + this.random.nextInt(2);
660
	}
661
662
	@Override
663
	protected int getSplitCount() {
664
		return this.isPrimed() ? 0 : 2;
665
	}
666
667
	@Override
668
	protected void setSpawnSize(final ServerLevelAccessor level, final DifficultyInstance difficulty) {
669
		if (this.isBaby()) {
670
			this.setSize(1, true);
671
		} else {
672
			this.setSize(2, true);
673
		}
674
	}
675
676
	@Override
677
	public void setSize(final int size, final boolean updateHealth) {
678
		super.setSize(size, updateHealth);
679
		if (updateHealth && size == 1 && !this.isBaby()) {
680
			this.setBaby(true);
681
		}
682
	}
683
684
	@Override
685
	protected void setUpSplitCube(final AbstractCubeMob cubeMob, final int halfSize, final float xd, final float zd) {
686
		super.setUpSplitCube(cubeMob, halfSize, xd, zd);
687
		cubeMob.setBaby(true);
688
	}
689
690
	@Override
691
	public @Nullable AbstractCubeMob getBreedOffspring(final ServerLevel level, final AgeableMob partner) {
692
		SulfurCube sulfurCube = EntityTypes.SULFUR_CUBE.create(level, EntitySpawnReason.BREEDING);
693
		if (sulfurCube != null) {
694
			sulfurCube.setSize(1, true);
695
		}
696
697
		return sulfurCube;
698
	}
699
700
	private boolean isFood(final ItemStack itemStack) {
701
		return itemStack.is(ItemTags.SULFUR_CUBE_FOOD);
702
	}
703
704
	@Override
705
	protected void ageBoundaryReached() {
706
		super.ageBoundaryReached();
707
		if (!this.isBaby()) {
708
			this.setSize(2, true);
709
		}
710
	}
711
712
	@Override
713
	protected void addAdditionalSaveData(final ValueOutput output) {
714
		super.addAdditionalSaveData(output);
715
		output.putInt("pickup_timer", this.pickupTimer);
716
		output.putBoolean("from_bucket", this.fromBucket());
717
		output.putInt("fuse", this.getFuse());
718
	}
719
720
	@Override
721
	protected void readAdditionalSaveData(final ValueInput input) {
722
		this.pickupTimer = input.getIntOr("pickup_timer", 0);
723
		this.setFromBucket(input.getBooleanOr("from_bucket", false));
724
		this.setFuse(input.getIntOr("fuse", -1));
725
		this.entityData.set(MAX_FUSE, this.getFuse());
726
		super.readAdditionalSaveData(input);
727
	}
728
729
	@Override
730
	protected void doPush(final Entity entity) {
731
		super.doPush(entity);
732
		this.applyContactDamage(entity);
733
	}
734
735
	@Override
736
	public void playerTouch(final Player player) {
737
		super.playerTouch(player);
738
		this.playerPush(player);
739
	}
740
741
	private void playerPush(final Player player) {
742
		if (this.hasBodyItem()) {
743
			Entity pusher = player.isPassenger() ? player.getRootVehicle() : player;
744
			Vec3 cubeToPusher = this.position().subtract(pusher.position());
745
			double pusherFeetPosition = pusher.getY();
746
			double sulfurCubeBottomPosition = this.getY();
747
			double sulfurCubeTopPosition = sulfurCubeBottomPosition + this.getBbHeight();
748
			double pusherTopPosition = pusherFeetPosition + pusher.getBbHeight();
749
			if (cubeToPusher.horizontalDistance() < 1.3F && pusherFeetPosition <= sulfurCubeTopPosition && pusherTopPosition > sulfurCubeBottomPosition) {
750
				double knockback = Math.max(0.0, 1.0 - this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE));
751
				Vec3 pushDirection = cubeToPusher.horizontal().normalize().scale(knockback);
752
				float pushSpeedScale = player.isPassenger() ? 0.16F : 0.3F;
753
				double playerSpeed = player.getKnownSpeed().length() * 2.0 * pushSpeedScale;
754
				playerSpeed = Mth.clamp(playerSpeed, 0.0, 0.5);
755
				Vec3 pushVelocity = new Vec3(pushDirection.x, this.onGround() ? knockback * 0.3F : 0.0, pushDirection.z).scale(playerSpeed);
756
				this.needsSync = true;
757
				float push_sound_threshold = this.soundSettings.pushSoundImpulseThreshold();
758
				if (pushVelocity.lengthSqr() > push_sound_threshold * push_sound_threshold && this.pushSoundCooldown <= 0) {
759
					this.pushSoundCooldown = (int)(this.soundSettings.pushSoundCooldown() * 20.0F);
760
					this.playSound(this.soundSettings.pushSound().value());
761
				}
762
763
				this.addDeltaMovement(pushVelocity);
764
				this.applyContactDamage(player);
765
			}
766
		}
767
	}
768
769
	private Vec2 applyHorizontalHitAngleScale(
770
		final float horizontalAngleScale, final Vec2 originalAngle, final Vec3 attackerPosition, final Vec3 attackerAimDirection, final Vec3 targetCenter
771
	) {
772
		Vec3 attackerToTarget = targetCenter.subtract(attackerPosition).normalize();
773
		float angleDiff = (float)Math.atan2(
774
			attackerAimDirection.x * attackerToTarget.z - attackerAimDirection.z * attackerToTarget.x,
775
			attackerAimDirection.x * attackerToTarget.x + attackerAimDirection.z * attackerToTarget.z
776
		);
777
		return originalAngle.rotate(angleDiff * horizontalAngleScale);
778
	}
779
780
	private Vec2 applyVerticalHitAnglePowerTransfer(
781
		final float verticalHitAngleScale,
782
		final float horizontalPower,
783
		final float verticalPower,
784
		final Vec3 attackerPosition,
785
		final Vec3 attackerAimDirection,
786
		final Vec3 targetCenteredPosition,
787
		final float targetHeight
788
	) {
789
		float targetHalfHeight = 0.5F * targetHeight;
790
		Vec3 targetTopPos = targetCenteredPosition.add(0.0, targetHalfHeight, 0.0);
791
		Vec3 tagetBottomPos = targetCenteredPosition.add(0.0, -targetHalfHeight, 0.0);
792
		Vec3 attackerToTargetTop = targetTopPos.subtract(attackerPosition).normalize();
793
		Vec3 attackerToTargetBottom = tagetBottomPos.subtract(attackerPosition).normalize();
794
		float verticalHitAngleFactor = (float)Mth.clampedMap(attackerAimDirection.y, attackerToTargetTop.y, attackerToTargetBottom.y, -1.0, 1.0);
795
		float transferredPowerRatio = Math.abs(verticalHitAngleFactor * verticalHitAngleScale);
796
		if (verticalHitAngleFactor < 0.0F) {
797
			transferredPowerRatio = -transferredPowerRatio;
798
		}
799
800
		float px = horizontalPower * (1.0F - transferredPowerRatio);
801
		float py = verticalPower * (1.0F + transferredPowerRatio);
802
		return new Vec2(px, py);
803
	}
804
805
	private Vec2 applyVerticalPositionAnglePowerRotation(
806
		final float verticalPositionAngleScale,
807
		final float horizontalPower,
808
		final float verticalPower,
809
		final float originalHorizontalPower,
810
		final float originalVerticalPower,
811
		final Vec3 attackerFeetPosition,
812
		final Vec3 targetFeetPosition
813
	) {
814
		Vec3 attackerFeetToTargetFeet = targetFeetPosition.subtract(attackerFeetPosition);
815
		float verticalPositionAngle = (float)Math.atan2(-attackerFeetToTargetFeet.y, attackerFeetToTargetFeet.horizontalDistance());
816
		Vec2 powerBeforeRotation = new Vec2(horizontalPower, verticalPower);
817
		Vec2 rotatedPower = powerBeforeRotation.rotate(-verticalPositionAngle * verticalPositionAngleScale);
818
		float horizontalRatio = originalHorizontalPower > 0.0F ? Mth.abs(rotatedPower.x) / originalHorizontalPower : 0.0F;
819
		float verticalRatio = originalVerticalPower > 0.0F ? Mth.abs(rotatedPower.y) / originalVerticalPower : 0.0F;
820
		float maxRatio = Math.max(horizontalRatio, verticalRatio);
821
		if (maxRatio > 1.0F) {
822
			rotatedPower = rotatedPower.scale(1.0F / maxRatio);
823
		}
824
825
		return rotatedPower;
826
	}
827
828
	@Override
829
	public void knockback(final double power, double xd, double zd, final DamageSource source, final float damage, final boolean comesFromEffect) {
830
		if (source.getEntity() != null && this.hasBodyItem()) {
831
			float horizontalHitAngleScale = 1.6F;
832
			float verticalHitAngleScale = 0.5F;
833
			float verticalPositionAngleScale = 0.8F;
834
			float horizontalPower = this.knockbackModifier.horizontalPower();
835
			float verticalPower = this.knockbackModifier.verticalPower();
836
			float originalHorizontalPower = horizontalPower;
837
			float originalVerticalPower = verticalPower;
838
			Holder<SoundEvent> hitSound = this.soundSettings.hitSound();
839
			Vec2 originalAngle = new Vec2((float)xd, (float)zd);
840
			Vec2 newAngle = this.applyHorizontalHitAngleScale(
841
				1.6F, originalAngle, source.getEntity().getEyePosition(), source.getEntity().getLookAngle().normalize(), this.getBoundingBox().getCenter()
842
			);
843
			Vec2 newPower = this.applyVerticalHitAnglePowerTransfer(
844
				0.5F,
845
				horizontalPower,
846
				verticalPower,
847
				source.getEntity().getEyePosition(),
848
				source.getEntity().getLookAngle().normalize(),
849
				this.getBoundingBox().getCenter(),
850
				this.getBbHeight()
851
			);
852
			horizontalPower = newPower.x;
853
			verticalPower = newPower.y;
854
			newPower = this.applyVerticalPositionAnglePowerRotation(
855
				0.8F, horizontalPower, verticalPower, originalHorizontalPower, originalVerticalPower, source.getEntity().position(), this.position()
856
			);
857
			horizontalPower = newPower.x;
858
			verticalPower = newPower.y;
859
			xd = newAngle.x;
860
			zd = newAngle.y;
861
			float powerMultiplier = Mth.sqrt(damage) * (comesFromEffect ? (float)power * 0.25F : 1.0F);
862
			horizontalPower *= powerMultiplier;
863
			verticalPower *= powerMultiplier;
864
			double knockBackResistance = this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE);
865
			horizontalPower *= (float)(1.0 - knockBackResistance);
866
			verticalPower *= (float)(1.0 - knockBackResistance);
867
			this.needsSync = true;
868
			Vec3 deltaMovement = this.getDeltaMovement();
869
			horizontalPower *= 0.4F;
870
			horizontalPower = Mth.clamp(horizontalPower, -128.0F, 128.0F);
871
			verticalPower = Mth.clamp(verticalPower, -128.0F, 128.0F);
872
			Vec3 horizontalKnockback = new Vec3(xd, 0.0, zd).normalize().scale(horizontalPower);
873
			this.setDeltaMovement(deltaMovement.x - horizontalKnockback.x, deltaMovement.y + verticalPower * 1.2, deltaMovement.z - horizontalKnockback.z);
874
			this.playSound(hitSound.value());
875
		} else {
876
			super.knockback(power, xd, zd, source, damage, comesFromEffect);
877
		}
878
	}
879
880
	@Override
881
	public <T> @Nullable T get(final DataComponentType<? extends T> type) {
882
		return type == DataComponents.SULFUR_CUBE_CONTENT
883
			? castComponentValue((DataComponentType<T>)type, getSulfurCubeContent(this.getBodyArmorItem()))
884
			: super.get(type);
885
	}
886
887
	@Override
888
	protected void applyImplicitComponents(final DataComponentGetter components) {
889
		this.applyImplicitComponentIfPresent(components, DataComponents.SULFUR_CUBE_CONTENT);
890
		super.applyImplicitComponents(components);
891
	}
892
893
	@Override
894
	protected <T> boolean applyImplicitComponent(final DataComponentType<T> type, final T value) {
895
		if (type == DataComponents.SULFUR_CUBE_CONTENT) {
896
			this.setSulfurCubeContent(castComponentValue(DataComponents.SULFUR_CUBE_CONTENT, value));
897
			return true;
898
		} else {
899
			return super.applyImplicitComponent(type, value);
900
		}
901
	}
902
903
	private static @Nullable SulfurCubeContent getSulfurCubeContent(final ItemStack itemStack) {
904
		return itemStack.isEmpty() ? null : SulfurCubeContent.ofNonEmpty(itemStack);
905
	}
906
907
	private void setSulfurCubeContent(final SulfurCubeContent sulfurCubeContent) {
908
		this.setItemSlotAndDropWhenKilled(EquipmentSlot.BODY, sulfurCubeContent.absorbedBlockItemStack().create());
909
	}
910
911
	@Override
912
	public Vec3 getLeashOffset() {
913
		return new Vec3(0.0, this.getBbHeight() / 2.0F, 0.0);
914
	}
915
916
	@Override
917
	protected void setCubeMobHealth(final int actualSize) {
918
		this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(4 * actualSize);
919
	}
920
921
	@Override
922
	public boolean isInvulnerableToPiercingWeapon() {
923
		return super.isInvulnerableToPiercingWeapon() && !this.isPrimed();
924
	}
925
926
	@Override
927
	public boolean canBePickedFromInside() {
928
		return !this.hasBodyItem();
929
	}
930
931
	private class SulfurCubeLookControl extends LookControl {
932
		private SulfurCubeLookControl() {
933
			super(SulfurCube.this);
934
		}
935
936
		@Override
937
		public void tick() {
938
			if (!SulfurCube.this.hasBodyItem()) {
939
				super.tick();
940
			} else {
941
				float closeAngle = Mth.wrapDegrees90(SulfurCube.this.getYRot());
942
				SulfurCube.this.setYRot(SulfurCube.this.getYRot() - closeAngle);
943
				SulfurCube.this.setYHeadRot(SulfurCube.this.getYRot());
944
			}
945
		}
946
	}
947
948
	protected static class SulfurCubeMobMoveControl<T extends SulfurCube> extends AbstractCubeMob.CubeMobMoveControl<T> {
949
		public SulfurCubeMobMoveControl(final T cubeMob) {
950
			super(cubeMob);
951
		}
952
953
		@Override
954
		public void tick() {
955
			if (!this.mob.hasBodyItem()) {
956
				super.tick();
957
			}
958
		}
959
	}
960
961
	private class SulfurCubeSearchForItemsGoal extends Goal {
962
		private final SulfurCube sulfurCube;
963
		private @Nullable ItemEntity targetItem;
964
965
		public SulfurCubeSearchForItemsGoal(final SulfurCube sulfurCube) {
966
			this.setFlags(EnumSet.of(Goal.Flag.LOOK));
967
			this.sulfurCube = sulfurCube;
968
		}
969
970
		@Override
971
		public boolean canUse() {
972
			if (!this.sulfurCube.isBaby() && this.sulfurCube.pickupTimer <= 0) {
973
				this.targetItem = getServerLevel(this.sulfurCube)
974
					.getNearestEntity(
975
						this.sulfurCube.level().getEntitiesOfClass(ItemEntity.class, this.sulfurCube.getBoundingBox().inflate(8.0, 8.0, 8.0), SulfurCube.ALLOWED_ITEMS),
976
						this.sulfurCube.getX(),
977
						this.sulfurCube.getY(),
978
						this.sulfurCube.getZ()
979
					);
980
				return this.targetItem != null;
981
			} else {
982
				return false;
983
			}
984
		}
985
986
		@Override
987
		public void tick() {
988
			SulfurCube.this.lookAt(this.targetItem, 10.0F, 10.0F);
989
			if (SulfurCube.this.getMoveControl() instanceof AbstractCubeMob.CubeMobMoveControl cubeMobMoveControl) {
990
				cubeMobMoveControl.setDirection(SulfurCube.this.getYRot(), true);
991
			}
992
		}
993
	}
994
995
	private static class SulfurCubeTemptGoal extends TemptGoal.ForNonPathfinders {
996
		public SulfurCubeTemptGoal(final Mob mob, final double speedModifier, final Predicate<ItemStack> items, final boolean canScare, final double stopDistance) {
997
			super(mob, speedModifier, items, canScare, stopDistance);
998
			this.setFlags(EnumSet.of(Goal.Flag.LOOK));
999
		}
1000
1001
		@Override
1002
		protected void stopNavigation() {
1003
			if (this.mob.getMoveControl() instanceof AbstractCubeMob.CubeMobMoveControl cubeMobMoveControl) {
1004
				cubeMobMoveControl.setWantedMovement(0.0);
1005
			}
1006
		}
1007
1008
		@Override
1009
		protected void navigateTowards(final Player player) {
1010
			this.mob.lookAt(player, 10.0F, 10.0F);
1011
			if (this.mob.getMoveControl() instanceof AbstractCubeMob.CubeMobMoveControl cubeMobMoveControl) {
1012
				cubeMobMoveControl.setDirection(this.mob.getYRot(), true);
1013
			}
1014
		}
1015
	}
1016
}
1017

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