MagmaCube .java

net.minecraft.world.entity.monster.cubemob.MagmaCube (class): members: checkMagmaCubeSpawnRules, getAttackDamage, decreaseSquish, getJumpDelay, canBeABaby.

net.minecraft.world.entity.monster.cubemobclass158 linescommonextends AbstractCubeMob4.8 KB

Implements

API Surface (19)

void addBehaviourGoals()
void addTargetingGoals()
AttributeSupplier.Builder createAttributes()
boolean checkMagmaCubeSpawnRules(final EntityType<MagmaCube> type, final LevelAccessor level, final EntitySpawnReason spawnReason, final BlockPos pos, final RandomSource random)
void setSize(final int size, final boolean updateHealth)
float getLightLevelDependentMagicValue()
ParticleOptions getParticleType()
boolean isOnFire()
int getJumpDelay()
void decreaseSquish()
void jumpFromGround()
void jumpInLiquid(final TagKey<Fluid> type)
boolean canDealDamage()
float getAttackDamage()
SoundEvent getHurtSound(final DamageSource source)
SoundEvent getDeathSound()
SoundEvent getSquishSound()
SoundEvent getJumpSound()
boolean canBeABaby()

Fields & Constants (2)

pos
spawnReason

Full Source

MagmaCube.java158 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.monster.cubemob;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.particles.ParticleOptions;
5
import net.minecraft.core.particles.ParticleTypes;
6
import net.minecraft.sounds.SoundEvent;
7
import net.minecraft.sounds.SoundEvents;
8
import net.minecraft.tags.FluidTags;
9
import net.minecraft.tags.TagKey;
10
import net.minecraft.util.RandomSource;
11
import net.minecraft.world.Difficulty;
12
import net.minecraft.world.DifficultyInstance;
13
import net.minecraft.world.damagesource.DamageSource;
14
import net.minecraft.world.entity.AgeableMob;
15
import net.minecraft.world.entity.EntitySpawnReason;
16
import net.minecraft.world.entity.EntityType;
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.target.NearestAttackableTargetGoal;
21
import net.minecraft.world.entity.animal.golem.IronGolem;
22
import net.minecraft.world.entity.monster.Enemy;
23
import net.minecraft.world.entity.monster.Monster;
24
import net.minecraft.world.entity.player.Player;
25
import net.minecraft.world.level.Level;
26
import net.minecraft.world.level.LevelAccessor;
27
import net.minecraft.world.level.ServerLevelAccessor;
28
import net.minecraft.world.level.material.Fluid;
29
import net.minecraft.world.phys.Vec3;
30
import org.jspecify.annotations.Nullable;
31
32
public class MagmaCube extends AbstractCubeMob implements Enemy {
33
	public MagmaCube(final EntityType<? extends MagmaCube> type, final Level level) {
34
		super(type, level);
35
	}
36
37
	@Override
38
	protected void addBehaviourGoals() {
39
		this.goalSelector.addGoal(2, new AbstractCubeMob.CubeMobAttackGoal(this));
40
	}
41
42
	@Override
43
	protected void addTargetingGoals() {
44
		this.targetSelector
45
			.addGoal(1, new NearestAttackableTargetGoal<>(this, Player.class, 10, true, false, (target, level) -> Math.abs(target.getY() - this.getY()) <= 4.0));
46
		this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, IronGolem.class, true));
47
	}
48
49
	public static AttributeSupplier.Builder createAttributes() {
50
		return Monster.createMonsterAttributes().add(Attributes.MOVEMENT_SPEED, 0.2F);
51
	}
52
53
	public static boolean checkMagmaCubeSpawnRules(
54
		final EntityType<MagmaCube> type, final LevelAccessor level, final EntitySpawnReason spawnReason, final BlockPos pos, final RandomSource random
55
	) {
56
		return level.getDifficulty() != Difficulty.PEACEFUL;
57
	}
58
59
	@Override
60
	public void setSize(final int size, final boolean updateHealth) {
61
		super.setSize(size, updateHealth);
62
		int actualSize = this.entityData.get(ID_SIZE);
63
		this.getAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(actualSize);
64
		this.getAttribute(Attributes.ARMOR).setBaseValue(size * 3);
65
		this.xpReward = actualSize;
66
	}
67
68
	@Override
69
	public float getLightLevelDependentMagicValue() {
70
		return 1.0F;
71
	}
72
73
	@Override
74
	protected ParticleOptions getParticleType() {
75
		return ParticleTypes.FLAME;
76
	}
77
78
	@Override
79
	public boolean isOnFire() {
80
		return false;
81
	}
82
83
	@Override
84
	protected int getJumpDelay() {
85
		return super.getJumpDelay() * 4;
86
	}
87
88
	@Override
89
	protected void decreaseSquish() {
90
		this.targetSquish *= 0.9F;
91
	}
92
93
	@Override
94
	public void jumpFromGround() {
95
		Vec3 movement = this.getDeltaMovement();
96
		float sizeJumpBoostPower = this.getSize() * 0.1F;
97
		this.setDeltaMovement(movement.x, this.getJumpPower() + sizeJumpBoostPower, movement.z);
98
		this.needsSync = true;
99
	}
100
101
	@Override
102
	protected void jumpInLiquid(final TagKey<Fluid> type) {
103
		if (type == FluidTags.LAVA) {
104
			Vec3 movement = this.getDeltaMovement();
105
			this.setDeltaMovement(movement.x, 0.22F + this.getSize() * 0.05F, movement.z);
106
			this.needsSync = true;
107
		} else {
108
			super.jumpInLiquid(type);
109
		}
110
	}
111
112
	@Override
113
	protected boolean canDealDamage() {
114
		return this.isEffectiveAi();
115
	}
116
117
	@Override
118
	protected float getAttackDamage() {
119
		return super.getAttackDamage() + 2.0F;
120
	}
121
122
	@Override
123
	protected SoundEvent getHurtSound(final DamageSource source) {
124
		return this.isTiny() ? SoundEvents.MAGMA_CUBE_HURT_SMALL : SoundEvents.MAGMA_CUBE_HURT;
125
	}
126
127
	@Override
128
	protected SoundEvent getDeathSound() {
129
		return this.isTiny() ? SoundEvents.MAGMA_CUBE_DEATH_SMALL : SoundEvents.MAGMA_CUBE_DEATH;
130
	}
131
132
	@Override
133
	protected SoundEvent getSquishSound() {
134
		return this.isTiny() ? SoundEvents.MAGMA_CUBE_SQUISH_SMALL : SoundEvents.MAGMA_CUBE_SQUISH;
135
	}
136
137
	@Override
138
	protected SoundEvent getJumpSound() {
139
		return SoundEvents.MAGMA_CUBE_JUMP;
140
	}
141
142
	@Override
143
	protected boolean canBeABaby() {
144
		return false;
145
	}
146
147
	@Override
148
	public @Nullable SpawnGroupData finalizeSpawn(
149
		final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, @Nullable SpawnGroupData groupData
150
	) {
151
		if (groupData == null) {
152
			groupData = new AgeableMob.AgeableMobGroupData(false);
153
		}
154
155
		return super.finalizeSpawn(level, difficulty, spawnReason, groupData);
156
	}
157
}
158

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