EntityMob .java

net.minecraft.entity.monster.EntityMob (class): members: canDropLoot, getFallSoundString, getSplashSound, getSwimSound, isValidLightLevel, getCanSpawnHere.

net.minecraft.entity.monsterclass193 linescommonextends EntityCreature5.2 KB

Implements

API Surface (14)

void onLivingUpdate()
void onUpdate()
String getSwimSound()
String getSplashSound()
boolean attackEntityFrom(DamageSource source, float amount)
String getHurtSound()
String getDeathSound()
String getFallSoundString(int damageValue)
boolean attackEntityAsMob(Entity entityIn)
float getBlockPathWeight(BlockPos pos)
boolean isValidLightLevel()
boolean getCanSpawnHere()
void applyEntityAttributes()
boolean canDropLoot()

String literals (6)

"game.hostile.swim"
"game.hostile.swim.splash"
"game.hostile.hurt"
"game.hostile.die"
"game.hostile.hurt.fall.big"
"game.hostile.hurt.fall.small"

Full Source

EntityMob.java193 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.monster;
2
3
import net.minecraft.enchantment.EnchantmentHelper;
4
import net.minecraft.entity.Entity;
5
import net.minecraft.entity.EntityCreature;
6
import net.minecraft.entity.EntityLivingBase;
7
import net.minecraft.entity.SharedMonsterAttributes;
8
import net.minecraft.util.BlockPos;
9
import net.minecraft.util.DamageSource;
10
import net.minecraft.util.MathHelper;
11
import net.minecraft.world.EnumDifficulty;
12
import net.minecraft.world.EnumSkyBlock;
13
import net.minecraft.world.World;
14
15
public abstract class EntityMob extends EntityCreature implements IMob
16
{
17
    public EntityMob(World worldIn)
18
    {
19
        super(worldIn);
20
        this.experienceValue = 5;
21
    }
22
23
    /**
24
     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
25
     * use this to react to sunlight and start to burn.
26
     */
27
    public void onLivingUpdate()
28
    {
29
        this.updateArmSwingProgress();
30
        float f = this.getBrightness(1.0F);
31
32
        if (f > 0.5F)
33
        {
34
            this.entityAge += 2;
35
        }
36
37
        super.onLivingUpdate();
38
    }
39
40
    /**
41
     * Called to update the entity's position/logic.
42
     */
43
    public void onUpdate()
44
    {
45
        super.onUpdate();
46
47
        if (!this.worldObj.isRemote && this.worldObj.getDifficulty() == EnumDifficulty.PEACEFUL)
48
        {
49
            this.setDead();
50
        }
51
    }
52
53
    protected String getSwimSound()
54
    {
55
        return "game.hostile.swim";
56
    }
57
58
    protected String getSplashSound()
59
    {
60
        return "game.hostile.swim.splash";
61
    }
62
63
    /**
64
     * Called when the entity is attacked.
65
     */
66
    public boolean attackEntityFrom(DamageSource source, float amount)
67
    {
68
        if (this.isEntityInvulnerable(source))
69
        {
70
            return false;
71
        }
72
        else if (super.attackEntityFrom(source, amount))
73
        {
74
            Entity entity = source.getEntity();
75
            return this.riddenByEntity != entity && this.ridingEntity != entity ? true : true;
76
        }
77
        else
78
        {
79
            return false;
80
        }
81
    }
82
83
    /**
84
     * Returns the sound this mob makes when it is hurt.
85
     */
86
    protected String getHurtSound()
87
    {
88
        return "game.hostile.hurt";
89
    }
90
91
    /**
92
     * Returns the sound this mob makes on death.
93
     */
94
    protected String getDeathSound()
95
    {
96
        return "game.hostile.die";
97
    }
98
99
    protected String getFallSoundString(int damageValue)
100
    {
101
        return damageValue > 4 ? "game.hostile.hurt.fall.big" : "game.hostile.hurt.fall.small";
102
    }
103
104
    public boolean attackEntityAsMob(Entity entityIn)
105
    {
106
        float f = (float)this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
107
        int i = 0;
108
109
        if (entityIn instanceof EntityLivingBase)
110
        {
111
            f += EnchantmentHelper.getModifierForCreature(this.getHeldItem(), ((EntityLivingBase)entityIn).getCreatureAttribute());
112
            i += EnchantmentHelper.getKnockbackModifier(this);
113
        }
114
115
        boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), f);
116
117
        if (flag)
118
        {
119
            if (i > 0)
120
            {
121
                entityIn.addVelocity((double)(-MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F), 0.1D, (double)(MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F));
122
                this.motionX *= 0.6D;
123
                this.motionZ *= 0.6D;
124
            }
125
126
            int j = EnchantmentHelper.getFireAspectModifier(this);
127
128
            if (j > 0)
129
            {
130
                entityIn.setFire(j * 4);
131
            }
132
133
            this.applyEnchantments(this, entityIn);
134
        }
135
136
        return flag;
137
    }
138
139
    public float getBlockPathWeight(BlockPos pos)
140
    {
141
        return 0.5F - this.worldObj.getLightBrightness(pos);
142
    }
143
144
    /**
145
     * Checks to make sure the light is not too bright where the mob is spawning
146
     */
147
    protected boolean isValidLightLevel()
148
    {
149
        BlockPos blockpos = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ);
150
151
        if (this.worldObj.getLightFor(EnumSkyBlock.SKY, blockpos) > this.rand.nextInt(32))
152
        {
153
            return false;
154
        }
155
        else
156
        {
157
            int i = this.worldObj.getLightFromNeighbors(blockpos);
158
159
            if (this.worldObj.isThundering())
160
            {
161
                int j = this.worldObj.getSkylightSubtracted();
162
                this.worldObj.setSkylightSubtracted(10);
163
                i = this.worldObj.getLightFromNeighbors(blockpos);
164
                this.worldObj.setSkylightSubtracted(j);
165
            }
166
167
            return i <= this.rand.nextInt(8);
168
        }
169
    }
170
171
    /**
172
     * Checks if the entity's current position is a valid location to spawn this entity.
173
     */
174
    public boolean getCanSpawnHere()
175
    {
176
        return this.worldObj.getDifficulty() != EnumDifficulty.PEACEFUL && this.isValidLightLevel() && super.getCanSpawnHere();
177
    }
178
179
    protected void applyEntityAttributes()
180
    {
181
        super.applyEntityAttributes();
182
        this.getAttributeMap().registerAttribute(SharedMonsterAttributes.attackDamage);
183
    }
184
185
    /**
186
     * Entity won't drop items or experience points if this returns false
187
     */
188
    protected boolean canDropLoot()
189
    {
190
        return true;
191
    }
192
}
193

Deobfuscated MCP 1.8.9 source of EntityMob from Marcelektro/MavenMCP-1.8.9 (net/minecraft/entity/monster/EntityMob.java), stored verbatim.