EntityPigZombie .java

net.minecraft.entity.monster.EntityPigZombie (class): members: ATTACK_SPEED_BOOST_MODIFIER_UUID, ATTACK_SPEED_BOOST_MODIFIER, AIHurtByAggressor, isAngry.

net.minecraft.entity.monsterclass318 linescommonextends EntityZombie9.6 KB

API Surface (21)

void setRevengeTarget(EntityLivingBase livingBase)
void applyEntityAI()
void applyEntityAttributes()
void onUpdate()
void updateAITasks()
boolean getCanSpawnHere()
boolean isNotColliding()
void writeEntityToNBT(NBTTagCompound tagCompound)
void readEntityFromNBT(NBTTagCompound tagCompund)
boolean attackEntityFrom(DamageSource source, float amount)
boolean isAngry()
String getLivingSound()
String getHurtSound()
String getDeathSound()
void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
boolean interact(EntityPlayer player)
void addRandomDrop()
void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty)
IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
void setEntityAttackTarget(EntityCreature creatureIn, EntityLivingBase entityLivingBaseIn)
boolean shouldExecute()

Fields & Constants (5)

ATTACK_SPEED_BOOST_MODIFIER_UUID
ATTACK_SPEED_BOOST_MODIFIER
angerLevel
randomSoundDelay
angerTargetUUID

String literals (7)

"Attacking speed boost"
"mob.zombiepig.zpigangry"
"Anger"
"HurtBy"
"mob.zombiepig.zpig"
"mob.zombiepig.zpighurt"
"mob.zombiepig.zpigdeath"

Full Source

EntityPigZombie.java318 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.monster;
2
3
import java.util.UUID;
4
import net.minecraft.entity.Entity;
5
import net.minecraft.entity.EntityCreature;
6
import net.minecraft.entity.EntityLivingBase;
7
import net.minecraft.entity.IEntityLivingData;
8
import net.minecraft.entity.SharedMonsterAttributes;
9
import net.minecraft.entity.ai.EntityAIHurtByTarget;
10
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
11
import net.minecraft.entity.ai.attributes.AttributeModifier;
12
import net.minecraft.entity.ai.attributes.IAttributeInstance;
13
import net.minecraft.entity.player.EntityPlayer;
14
import net.minecraft.init.Items;
15
import net.minecraft.item.ItemStack;
16
import net.minecraft.nbt.NBTTagCompound;
17
import net.minecraft.util.DamageSource;
18
import net.minecraft.world.DifficultyInstance;
19
import net.minecraft.world.EnumDifficulty;
20
import net.minecraft.world.World;
21
22
public class EntityPigZombie extends EntityZombie
23
{
24
    private static final UUID ATTACK_SPEED_BOOST_MODIFIER_UUID = UUID.fromString("49455A49-7EC5-45BA-B886-3B90B23A1718");
25
    private static final AttributeModifier ATTACK_SPEED_BOOST_MODIFIER = (new AttributeModifier(ATTACK_SPEED_BOOST_MODIFIER_UUID, "Attacking speed boost", 0.05D, 0)).setSaved(false);
26
27
    /** Above zero if this PigZombie is Angry. */
28
    private int angerLevel;
29
30
    /** A random delay until this PigZombie next makes a sound. */
31
    private int randomSoundDelay;
32
    private UUID angerTargetUUID;
33
34
    public EntityPigZombie(World worldIn)
35
    {
36
        super(worldIn);
37
        this.isImmuneToFire = true;
38
    }
39
40
    public void setRevengeTarget(EntityLivingBase livingBase)
41
    {
42
        super.setRevengeTarget(livingBase);
43
44
        if (livingBase != null)
45
        {
46
            this.angerTargetUUID = livingBase.getUniqueID();
47
        }
48
    }
49
50
    protected void applyEntityAI()
51
    {
52
        this.targetTasks.addTask(1, new EntityPigZombie.AIHurtByAggressor(this));
53
        this.targetTasks.addTask(2, new EntityPigZombie.AITargetAggressor(this));
54
    }
55
56
    protected void applyEntityAttributes()
57
    {
58
        super.applyEntityAttributes();
59
        this.getEntityAttribute(reinforcementChance).setBaseValue(0.0D);
60
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23000000417232513D);
61
        this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(5.0D);
62
    }
63
64
    /**
65
     * Called to update the entity's position/logic.
66
     */
67
    public void onUpdate()
68
    {
69
        super.onUpdate();
70
    }
71
72
    protected void updateAITasks()
73
    {
74
        IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
75
76
        if (this.isAngry())
77
        {
78
            if (!this.isChild() && !iattributeinstance.hasModifier(ATTACK_SPEED_BOOST_MODIFIER))
79
            {
80
                iattributeinstance.applyModifier(ATTACK_SPEED_BOOST_MODIFIER);
81
            }
82
83
            --this.angerLevel;
84
        }
85
        else if (iattributeinstance.hasModifier(ATTACK_SPEED_BOOST_MODIFIER))
86
        {
87
            iattributeinstance.removeModifier(ATTACK_SPEED_BOOST_MODIFIER);
88
        }
89
90
        if (this.randomSoundDelay > 0 && --this.randomSoundDelay == 0)
91
        {
92
            this.playSound("mob.zombiepig.zpigangry", this.getSoundVolume() * 2.0F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F) * 1.8F);
93
        }
94
95
        if (this.angerLevel > 0 && this.angerTargetUUID != null && this.getAITarget() == null)
96
        {
97
            EntityPlayer entityplayer = this.worldObj.getPlayerEntityByUUID(this.angerTargetUUID);
98
            this.setRevengeTarget(entityplayer);
99
            this.attackingPlayer = entityplayer;
100
            this.recentlyHit = this.getRevengeTimer();
101
        }
102
103
        super.updateAITasks();
104
    }
105
106
    /**
107
     * Checks if the entity's current position is a valid location to spawn this entity.
108
     */
109
    public boolean getCanSpawnHere()
110
    {
111
        return this.worldObj.getDifficulty() != EnumDifficulty.PEACEFUL;
112
    }
113
114
    /**
115
     * Checks that the entity is not colliding with any blocks / liquids
116
     */
117
    public boolean isNotColliding()
118
    {
119
        return this.worldObj.checkNoEntityCollision(this.getEntityBoundingBox(), this) && this.worldObj.getCollidingBoundingBoxes(this, this.getEntityBoundingBox()).isEmpty() && !this.worldObj.isAnyLiquid(this.getEntityBoundingBox());
120
    }
121
122
    /**
123
     * (abstract) Protected helper method to write subclass entity data to NBT.
124
     */
125
    public void writeEntityToNBT(NBTTagCompound tagCompound)
126
    {
127
        super.writeEntityToNBT(tagCompound);
128
        tagCompound.setShort("Anger", (short)this.angerLevel);
129
130
        if (this.angerTargetUUID != null)
131
        {
132
            tagCompound.setString("HurtBy", this.angerTargetUUID.toString());
133
        }
134
        else
135
        {
136
            tagCompound.setString("HurtBy", "");
137
        }
138
    }
139
140
    /**
141
     * (abstract) Protected helper method to read subclass entity data from NBT.
142
     */
143
    public void readEntityFromNBT(NBTTagCompound tagCompund)
144
    {
145
        super.readEntityFromNBT(tagCompund);
146
        this.angerLevel = tagCompund.getShort("Anger");
147
        String s = tagCompund.getString("HurtBy");
148
149
        if (s.length() > 0)
150
        {
151
            this.angerTargetUUID = UUID.fromString(s);
152
            EntityPlayer entityplayer = this.worldObj.getPlayerEntityByUUID(this.angerTargetUUID);
153
            this.setRevengeTarget(entityplayer);
154
155
            if (entityplayer != null)
156
            {
157
                this.attackingPlayer = entityplayer;
158
                this.recentlyHit = this.getRevengeTimer();
159
            }
160
        }
161
    }
162
163
    /**
164
     * Called when the entity is attacked.
165
     */
166
    public boolean attackEntityFrom(DamageSource source, float amount)
167
    {
168
        if (this.isEntityInvulnerable(source))
169
        {
170
            return false;
171
        }
172
        else
173
        {
174
            Entity entity = source.getEntity();
175
176
            if (entity instanceof EntityPlayer)
177
            {
178
                this.becomeAngryAt(entity);
179
            }
180
181
            return super.attackEntityFrom(source, amount);
182
        }
183
    }
184
185
    /**
186
     * Causes this PigZombie to become angry at the supplied Entity (which will be a player).
187
     */
188
    private void becomeAngryAt(Entity p_70835_1_)
189
    {
190
        this.angerLevel = 400 + this.rand.nextInt(400);
191
        this.randomSoundDelay = this.rand.nextInt(40);
192
193
        if (p_70835_1_ instanceof EntityLivingBase)
194
        {
195
            this.setRevengeTarget((EntityLivingBase)p_70835_1_);
196
        }
197
    }
198
199
    public boolean isAngry()
200
    {
201
        return this.angerLevel > 0;
202
    }
203
204
    /**
205
     * Returns the sound this mob makes while it's alive.
206
     */
207
    protected String getLivingSound()
208
    {
209
        return "mob.zombiepig.zpig";
210
    }
211
212
    /**
213
     * Returns the sound this mob makes when it is hurt.
214
     */
215
    protected String getHurtSound()
216
    {
217
        return "mob.zombiepig.zpighurt";
218
    }
219
220
    /**
221
     * Returns the sound this mob makes on death.
222
     */
223
    protected String getDeathSound()
224
    {
225
        return "mob.zombiepig.zpigdeath";
226
    }
227
228
    /**
229
     * Drop 0-2 items of this living's type
230
     *  
231
     * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
232
     * or tameable)
233
     * @param lootingModifier level of enchanment to be applied to this drop
234
     */
235
    protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
236
    {
237
        int i = this.rand.nextInt(2 + lootingModifier);
238
239
        for (int j = 0; j < i; ++j)
240
        {
241
            this.dropItem(Items.rotten_flesh, 1);
242
        }
243
244
        i = this.rand.nextInt(2 + lootingModifier);
245
246
        for (int k = 0; k < i; ++k)
247
        {
248
            this.dropItem(Items.gold_nugget, 1);
249
        }
250
    }
251
252
    /**
253
     * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
254
     */
255
    public boolean interact(EntityPlayer player)
256
    {
257
        return false;
258
    }
259
260
    /**
261
     * Causes this Entity to drop a random item.
262
     */
263
    protected void addRandomDrop()
264
    {
265
        this.dropItem(Items.gold_ingot, 1);
266
    }
267
268
    /**
269
     * Gives armor or weapon for entity based on given DifficultyInstance
270
     */
271
    protected void setEquipmentBasedOnDifficulty(DifficultyInstance difficulty)
272
    {
273
        this.setCurrentItemOrArmor(0, new ItemStack(Items.golden_sword));
274
    }
275
276
    /**
277
     * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
278
     * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
279
     */
280
    public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
281
    {
282
        super.onInitialSpawn(difficulty, livingdata);
283
        this.setVillager(false);
284
        return livingdata;
285
    }
286
287
    static class AIHurtByAggressor extends EntityAIHurtByTarget
288
    {
289
        public AIHurtByAggressor(EntityPigZombie p_i45828_1_)
290
        {
291
            super(p_i45828_1_, true, new Class[0]);
292
        }
293
294
        protected void setEntityAttackTarget(EntityCreature creatureIn, EntityLivingBase entityLivingBaseIn)
295
        {
296
            super.setEntityAttackTarget(creatureIn, entityLivingBaseIn);
297
298
            if (creatureIn instanceof EntityPigZombie)
299
            {
300
                ((EntityPigZombie)creatureIn).becomeAngryAt(entityLivingBaseIn);
301
            }
302
        }
303
    }
304
305
    static class AITargetAggressor extends EntityAINearestAttackableTarget<EntityPlayer>
306
    {
307
        public AITargetAggressor(EntityPigZombie p_i45829_1_)
308
        {
309
            super(p_i45829_1_, EntityPlayer.class, true);
310
        }
311
312
        public boolean shouldExecute()
313
        {
314
            return ((EntityPigZombie)this.taskOwner).isAngry() && super.shouldExecute();
315
        }
316
    }
317
}
318

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