EntityWitch .java

net.minecraft.entity.monster.EntityWitch (class): members: witchAttackTimer, MODIFIER_UUID, getAggressive, setAggressive, witchDrops, MODIFIER, entityInit.

net.minecraft.entity.monsterclass288 linescommonextends EntityMob10.1 KB

Implements

API Surface (13)

void entityInit()
String getLivingSound()
String getHurtSound()
String getDeathSound()
void setAggressive(boolean aggressive)
boolean getAggressive()
void applyEntityAttributes()
void onLivingUpdate()
void handleStatusUpdate(byte id)
float applyPotionDamageCalculations(DamageSource source, float damage)
void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
void attackEntityWithRangedAttack(EntityLivingBase target, float p_82196_2_)
float getEyeHeight()

Fields & Constants (4)

MODIFIER_UUID
MODIFIER
witchDrops
witchAttackTimer

String literals (2)

"5CD17E52-A79A-43D3-A529-90FDE04B181E"
"Drinking speed penalty"

Full Source

EntityWitch.java288 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.monster;
2
3
import java.util.List;
4
import java.util.UUID;
5
import net.minecraft.block.material.Material;
6
import net.minecraft.entity.EntityLivingBase;
7
import net.minecraft.entity.IRangedAttackMob;
8
import net.minecraft.entity.SharedMonsterAttributes;
9
import net.minecraft.entity.ai.EntityAIArrowAttack;
10
import net.minecraft.entity.ai.EntityAIHurtByTarget;
11
import net.minecraft.entity.ai.EntityAILookIdle;
12
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
13
import net.minecraft.entity.ai.EntityAISwimming;
14
import net.minecraft.entity.ai.EntityAIWander;
15
import net.minecraft.entity.ai.EntityAIWatchClosest;
16
import net.minecraft.entity.ai.attributes.AttributeModifier;
17
import net.minecraft.entity.ai.attributes.IAttributeInstance;
18
import net.minecraft.entity.player.EntityPlayer;
19
import net.minecraft.entity.projectile.EntityPotion;
20
import net.minecraft.init.Items;
21
import net.minecraft.item.Item;
22
import net.minecraft.item.ItemStack;
23
import net.minecraft.potion.Potion;
24
import net.minecraft.potion.PotionEffect;
25
import net.minecraft.util.DamageSource;
26
import net.minecraft.util.EnumParticleTypes;
27
import net.minecraft.util.MathHelper;
28
import net.minecraft.world.World;
29
30
public class EntityWitch extends EntityMob implements IRangedAttackMob
31
{
32
    private static final UUID MODIFIER_UUID = UUID.fromString("5CD17E52-A79A-43D3-A529-90FDE04B181E");
33
    private static final AttributeModifier MODIFIER = (new AttributeModifier(MODIFIER_UUID, "Drinking speed penalty", -0.25D, 0)).setSaved(false);
34
35
    /** List of items a witch should drop on death. */
36
    private static final Item[] witchDrops = new Item[] {Items.glowstone_dust, Items.sugar, Items.redstone, Items.spider_eye, Items.glass_bottle, Items.gunpowder, Items.stick, Items.stick};
37
38
    /**
39
     * Timer used as interval for a witch's attack, decremented every tick if aggressive and when reaches zero the witch
40
     * will throw a potion at the target entity.
41
     */
42
    private int witchAttackTimer;
43
44
    public EntityWitch(World worldIn)
45
    {
46
        super(worldIn);
47
        this.setSize(0.6F, 1.95F);
48
        this.tasks.addTask(1, new EntityAISwimming(this));
49
        this.tasks.addTask(2, new EntityAIArrowAttack(this, 1.0D, 60, 10.0F));
50
        this.tasks.addTask(2, new EntityAIWander(this, 1.0D));
51
        this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
52
        this.tasks.addTask(3, new EntityAILookIdle(this));
53
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false, new Class[0]));
54
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
55
    }
56
57
    protected void entityInit()
58
    {
59
        super.entityInit();
60
        this.getDataWatcher().addObject(21, Byte.valueOf((byte)0));
61
    }
62
63
    /**
64
     * Returns the sound this mob makes while it's alive.
65
     */
66
    protected String getLivingSound()
67
    {
68
        return null;
69
    }
70
71
    /**
72
     * Returns the sound this mob makes when it is hurt.
73
     */
74
    protected String getHurtSound()
75
    {
76
        return null;
77
    }
78
79
    /**
80
     * Returns the sound this mob makes on death.
81
     */
82
    protected String getDeathSound()
83
    {
84
        return null;
85
    }
86
87
    /**
88
     * Set whether this witch is aggressive at an entity.
89
     */
90
    public void setAggressive(boolean aggressive)
91
    {
92
        this.getDataWatcher().updateObject(21, Byte.valueOf((byte)(aggressive ? 1 : 0)));
93
    }
94
95
    /**
96
     * Return whether this witch is aggressive at an entity.
97
     */
98
    public boolean getAggressive()
99
    {
100
        return this.getDataWatcher().getWatchableObjectByte(21) == 1;
101
    }
102
103
    protected void applyEntityAttributes()
104
    {
105
        super.applyEntityAttributes();
106
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(26.0D);
107
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.25D);
108
    }
109
110
    /**
111
     * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
112
     * use this to react to sunlight and start to burn.
113
     */
114
    public void onLivingUpdate()
115
    {
116
        if (!this.worldObj.isRemote)
117
        {
118
            if (this.getAggressive())
119
            {
120
                if (this.witchAttackTimer-- <= 0)
121
                {
122
                    this.setAggressive(false);
123
                    ItemStack itemstack = this.getHeldItem();
124
                    this.setCurrentItemOrArmor(0, (ItemStack)null);
125
126
                    if (itemstack != null && itemstack.getItem() == Items.potionitem)
127
                    {
128
                        List<PotionEffect> list = Items.potionitem.getEffects(itemstack);
129
130
                        if (list != null)
131
                        {
132
                            for (PotionEffect potioneffect : list)
133
                            {
134
                                this.addPotionEffect(new PotionEffect(potioneffect));
135
                            }
136
                        }
137
                    }
138
139
                    this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).removeModifier(MODIFIER);
140
                }
141
            }
142
            else
143
            {
144
                int i = -1;
145
146
                if (this.rand.nextFloat() < 0.15F && this.isInsideOfMaterial(Material.water) && !this.isPotionActive(Potion.waterBreathing))
147
                {
148
                    i = 8237;
149
                }
150
                else if (this.rand.nextFloat() < 0.15F && this.isBurning() && !this.isPotionActive(Potion.fireResistance))
151
                {
152
                    i = 16307;
153
                }
154
                else if (this.rand.nextFloat() < 0.05F && this.getHealth() < this.getMaxHealth())
155
                {
156
                    i = 16341;
157
                }
158
                else if (this.rand.nextFloat() < 0.25F && this.getAttackTarget() != null && !this.isPotionActive(Potion.moveSpeed) && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D)
159
                {
160
                    i = 16274;
161
                }
162
                else if (this.rand.nextFloat() < 0.25F && this.getAttackTarget() != null && !this.isPotionActive(Potion.moveSpeed) && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D)
163
                {
164
                    i = 16274;
165
                }
166
167
                if (i > -1)
168
                {
169
                    this.setCurrentItemOrArmor(0, new ItemStack(Items.potionitem, 1, i));
170
                    this.witchAttackTimer = this.getHeldItem().getMaxItemUseDuration();
171
                    this.setAggressive(true);
172
                    IAttributeInstance iattributeinstance = this.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
173
                    iattributeinstance.removeModifier(MODIFIER);
174
                    iattributeinstance.applyModifier(MODIFIER);
175
                }
176
            }
177
178
            if (this.rand.nextFloat() < 7.5E-4F)
179
            {
180
                this.worldObj.setEntityState(this, (byte)15);
181
            }
182
        }
183
184
        super.onLivingUpdate();
185
    }
186
187
    public void handleStatusUpdate(byte id)
188
    {
189
        if (id == 15)
190
        {
191
            for (int i = 0; i < this.rand.nextInt(35) + 10; ++i)
192
            {
193
                this.worldObj.spawnParticle(EnumParticleTypes.SPELL_WITCH, this.posX + this.rand.nextGaussian() * 0.12999999523162842D, this.getEntityBoundingBox().maxY + 0.5D + this.rand.nextGaussian() * 0.12999999523162842D, this.posZ + this.rand.nextGaussian() * 0.12999999523162842D, 0.0D, 0.0D, 0.0D, new int[0]);
194
            }
195
        }
196
        else
197
        {
198
            super.handleStatusUpdate(id);
199
        }
200
    }
201
202
    /**
203
     * Reduces damage, depending on potions
204
     */
205
    protected float applyPotionDamageCalculations(DamageSource source, float damage)
206
    {
207
        damage = super.applyPotionDamageCalculations(source, damage);
208
209
        if (source.getEntity() == this)
210
        {
211
            damage = 0.0F;
212
        }
213
214
        if (source.isMagicDamage())
215
        {
216
            damage = (float)((double)damage * 0.15D);
217
        }
218
219
        return damage;
220
    }
221
222
    /**
223
     * Drop 0-2 items of this living's type
224
     *  
225
     * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
226
     * or tameable)
227
     * @param lootingModifier level of enchanment to be applied to this drop
228
     */
229
    protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
230
    {
231
        int i = this.rand.nextInt(3) + 1;
232
233
        for (int j = 0; j < i; ++j)
234
        {
235
            int k = this.rand.nextInt(3);
236
            Item item = witchDrops[this.rand.nextInt(witchDrops.length)];
237
238
            if (lootingModifier > 0)
239
            {
240
                k += this.rand.nextInt(lootingModifier + 1);
241
            }
242
243
            for (int l = 0; l < k; ++l)
244
            {
245
                this.dropItem(item, 1);
246
            }
247
        }
248
    }
249
250
    /**
251
     * Attack the specified entity using a ranged attack.
252
     */
253
    public void attackEntityWithRangedAttack(EntityLivingBase target, float p_82196_2_)
254
    {
255
        if (!this.getAggressive())
256
        {
257
            EntityPotion entitypotion = new EntityPotion(this.worldObj, this, 32732);
258
            double d0 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D;
259
            entitypotion.rotationPitch -= -20.0F;
260
            double d1 = target.posX + target.motionX - this.posX;
261
            double d2 = d0 - this.posY;
262
            double d3 = target.posZ + target.motionZ - this.posZ;
263
            float f = MathHelper.sqrt_double(d1 * d1 + d3 * d3);
264
265
            if (f >= 8.0F && !target.isPotionActive(Potion.moveSlowdown))
266
            {
267
                entitypotion.setPotionDamage(32698);
268
            }
269
            else if (target.getHealth() >= 8.0F && !target.isPotionActive(Potion.poison))
270
            {
271
                entitypotion.setPotionDamage(32660);
272
            }
273
            else if (f <= 3.0F && !target.isPotionActive(Potion.weakness) && this.rand.nextFloat() < 0.25F)
274
            {
275
                entitypotion.setPotionDamage(32696);
276
            }
277
278
            entitypotion.setThrowableHeading(d1, d2 + (double)(f * 0.2F), d3, 0.75F, 8.0F);
279
            this.worldObj.spawnEntityInWorld(entitypotion);
280
        }
281
    }
282
283
    public float getEyeHeight()
284
    {
285
        return 1.62F;
286
    }
287
}
288

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