EntitySpider .java

net.minecraft.entity.monster.EntitySpider (class): members: setBesideClimbableBlock, isBesideClimbableBlock, AISpiderAttack, AISpiderTarget, GroupData.

net.minecraft.entity.monsterclass312 linescommonextends EntityMob9.3 KB

API Surface (23)

double getMountedYOffset()
PathNavigate getNewNavigator(World worldIn)
void entityInit()
void onUpdate()
void applyEntityAttributes()
String getLivingSound()
String getHurtSound()
String getDeathSound()
void playStepSound(BlockPos pos, Block blockIn)
Item getDropItem()
void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
boolean isOnLadder()
void setInWeb()
EnumCreatureAttribute getCreatureAttribute()
boolean isPotionApplicable(PotionEffect potioneffectIn)
boolean isBesideClimbableBlock()
void setBesideClimbableBlock(boolean p_70839_1_)
IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
float getEyeHeight()
boolean continueExecuting()
double func_179512_a(EntityLivingBase attackTarget)
boolean shouldExecute()
void func_111104_a(Random rand)

String literals (3)

"mob.spider.say"
"mob.spider.death"
"mob.spider.step"

Full Source

EntitySpider.java312 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.monster;
2
3
import java.util.Random;
4
import net.minecraft.block.Block;
5
import net.minecraft.entity.Entity;
6
import net.minecraft.entity.EntityLivingBase;
7
import net.minecraft.entity.EnumCreatureAttribute;
8
import net.minecraft.entity.IEntityLivingData;
9
import net.minecraft.entity.SharedMonsterAttributes;
10
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
11
import net.minecraft.entity.ai.EntityAIHurtByTarget;
12
import net.minecraft.entity.ai.EntityAILeapAtTarget;
13
import net.minecraft.entity.ai.EntityAILookIdle;
14
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
15
import net.minecraft.entity.ai.EntityAISwimming;
16
import net.minecraft.entity.ai.EntityAIWander;
17
import net.minecraft.entity.ai.EntityAIWatchClosest;
18
import net.minecraft.entity.player.EntityPlayer;
19
import net.minecraft.init.Items;
20
import net.minecraft.item.Item;
21
import net.minecraft.pathfinding.PathNavigate;
22
import net.minecraft.pathfinding.PathNavigateClimber;
23
import net.minecraft.potion.Potion;
24
import net.minecraft.potion.PotionEffect;
25
import net.minecraft.util.BlockPos;
26
import net.minecraft.world.DifficultyInstance;
27
import net.minecraft.world.EnumDifficulty;
28
import net.minecraft.world.World;
29
30
public class EntitySpider extends EntityMob
31
{
32
    public EntitySpider(World worldIn)
33
    {
34
        super(worldIn);
35
        this.setSize(1.4F, 0.9F);
36
        this.tasks.addTask(1, new EntityAISwimming(this));
37
        this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F));
38
        this.tasks.addTask(4, new EntitySpider.AISpiderAttack(this, EntityPlayer.class));
39
        this.tasks.addTask(4, new EntitySpider.AISpiderAttack(this, EntityIronGolem.class));
40
        this.tasks.addTask(5, new EntityAIWander(this, 0.8D));
41
        this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
42
        this.tasks.addTask(6, new EntityAILookIdle(this));
43
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false, new Class[0]));
44
        this.targetTasks.addTask(2, new EntitySpider.AISpiderTarget(this, EntityPlayer.class));
45
        this.targetTasks.addTask(3, new EntitySpider.AISpiderTarget(this, EntityIronGolem.class));
46
    }
47
48
    /**
49
     * Returns the Y offset from the entity's position for any entity riding this one.
50
     */
51
    public double getMountedYOffset()
52
    {
53
        return (double)(this.height * 0.5F);
54
    }
55
56
    /**
57
     * Returns new PathNavigateGround instance
58
     */
59
    protected PathNavigate getNewNavigator(World worldIn)
60
    {
61
        return new PathNavigateClimber(this, worldIn);
62
    }
63
64
    protected void entityInit()
65
    {
66
        super.entityInit();
67
        this.dataWatcher.addObject(16, new Byte((byte)0));
68
    }
69
70
    /**
71
     * Called to update the entity's position/logic.
72
     */
73
    public void onUpdate()
74
    {
75
        super.onUpdate();
76
77
        if (!this.worldObj.isRemote)
78
        {
79
            this.setBesideClimbableBlock(this.isCollidedHorizontally);
80
        }
81
    }
82
83
    protected void applyEntityAttributes()
84
    {
85
        super.applyEntityAttributes();
86
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(16.0D);
87
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.30000001192092896D);
88
    }
89
90
    /**
91
     * Returns the sound this mob makes while it's alive.
92
     */
93
    protected String getLivingSound()
94
    {
95
        return "mob.spider.say";
96
    }
97
98
    /**
99
     * Returns the sound this mob makes when it is hurt.
100
     */
101
    protected String getHurtSound()
102
    {
103
        return "mob.spider.say";
104
    }
105
106
    /**
107
     * Returns the sound this mob makes on death.
108
     */
109
    protected String getDeathSound()
110
    {
111
        return "mob.spider.death";
112
    }
113
114
    protected void playStepSound(BlockPos pos, Block blockIn)
115
    {
116
        this.playSound("mob.spider.step", 0.15F, 1.0F);
117
    }
118
119
    protected Item getDropItem()
120
    {
121
        return Items.string;
122
    }
123
124
    /**
125
     * Drop 0-2 items of this living's type
126
     *  
127
     * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
128
     * or tameable)
129
     * @param lootingModifier level of enchanment to be applied to this drop
130
     */
131
    protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
132
    {
133
        super.dropFewItems(wasRecentlyHit, lootingModifier);
134
135
        if (wasRecentlyHit && (this.rand.nextInt(3) == 0 || this.rand.nextInt(1 + lootingModifier) > 0))
136
        {
137
            this.dropItem(Items.spider_eye, 1);
138
        }
139
    }
140
141
    /**
142
     * returns true if this entity is by a ladder, false otherwise
143
     */
144
    public boolean isOnLadder()
145
    {
146
        return this.isBesideClimbableBlock();
147
    }
148
149
    /**
150
     * Sets the Entity inside a web block.
151
     */
152
    public void setInWeb()
153
    {
154
    }
155
156
    /**
157
     * Get this Entity's EnumCreatureAttribute
158
     */
159
    public EnumCreatureAttribute getCreatureAttribute()
160
    {
161
        return EnumCreatureAttribute.ARTHROPOD;
162
    }
163
164
    public boolean isPotionApplicable(PotionEffect potioneffectIn)
165
    {
166
        return potioneffectIn.getPotionID() == Potion.poison.id ? false : super.isPotionApplicable(potioneffectIn);
167
    }
168
169
    /**
170
     * Returns true if the WatchableObject (Byte) is 0x01 otherwise returns false. The WatchableObject is updated using
171
     * setBesideClimableBlock.
172
     */
173
    public boolean isBesideClimbableBlock()
174
    {
175
        return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0;
176
    }
177
178
    /**
179
     * Updates the WatchableObject (Byte) created in entityInit(), setting it to 0x01 if par1 is true or 0x00 if it is
180
     * false.
181
     */
182
    public void setBesideClimbableBlock(boolean p_70839_1_)
183
    {
184
        byte b0 = this.dataWatcher.getWatchableObjectByte(16);
185
186
        if (p_70839_1_)
187
        {
188
            b0 = (byte)(b0 | 1);
189
        }
190
        else
191
        {
192
            b0 = (byte)(b0 & -2);
193
        }
194
195
        this.dataWatcher.updateObject(16, Byte.valueOf(b0));
196
    }
197
198
    /**
199
     * Called only once on an entity when first time spawned, via egg, mob spawner, natural spawning etc, but not called
200
     * when entity is reloaded from nbt. Mainly used for initializing attributes and inventory
201
     */
202
    public IEntityLivingData onInitialSpawn(DifficultyInstance difficulty, IEntityLivingData livingdata)
203
    {
204
        livingdata = super.onInitialSpawn(difficulty, livingdata);
205
206
        if (this.worldObj.rand.nextInt(100) == 0)
207
        {
208
            EntitySkeleton entityskeleton = new EntitySkeleton(this.worldObj);
209
            entityskeleton.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
210
            entityskeleton.onInitialSpawn(difficulty, (IEntityLivingData)null);
211
            this.worldObj.spawnEntityInWorld(entityskeleton);
212
            entityskeleton.mountEntity(this);
213
        }
214
215
        if (livingdata == null)
216
        {
217
            livingdata = new EntitySpider.GroupData();
218
219
            if (this.worldObj.getDifficulty() == EnumDifficulty.HARD && this.worldObj.rand.nextFloat() < 0.1F * difficulty.getClampedAdditionalDifficulty())
220
            {
221
                ((EntitySpider.GroupData)livingdata).func_111104_a(this.worldObj.rand);
222
            }
223
        }
224
225
        if (livingdata instanceof EntitySpider.GroupData)
226
        {
227
            int i = ((EntitySpider.GroupData)livingdata).potionEffectId;
228
229
            if (i > 0 && Potion.potionTypes[i] != null)
230
            {
231
                this.addPotionEffect(new PotionEffect(i, Integer.MAX_VALUE));
232
            }
233
        }
234
235
        return livingdata;
236
    }
237
238
    public float getEyeHeight()
239
    {
240
        return 0.65F;
241
    }
242
243
    static class AISpiderAttack extends EntityAIAttackOnCollide
244
    {
245
        public AISpiderAttack(EntitySpider spider, Class <? extends Entity > targetClass)
246
        {
247
            super(spider, targetClass, 1.0D, true);
248
        }
249
250
        public boolean continueExecuting()
251
        {
252
            float f = this.attacker.getBrightness(1.0F);
253
254
            if (f >= 0.5F && this.attacker.getRNG().nextInt(100) == 0)
255
            {
256
                this.attacker.setAttackTarget((EntityLivingBase)null);
257
                return false;
258
            }
259
            else
260
            {
261
                return super.continueExecuting();
262
            }
263
        }
264
265
        protected double func_179512_a(EntityLivingBase attackTarget)
266
        {
267
            return (double)(4.0F + attackTarget.width);
268
        }
269
    }
270
271
    static class AISpiderTarget<T extends EntityLivingBase> extends EntityAINearestAttackableTarget
272
    {
273
        public AISpiderTarget(EntitySpider spider, Class<T> classTarget)
274
        {
275
            super(spider, classTarget, true);
276
        }
277
278
        public boolean shouldExecute()
279
        {
280
            float f = this.taskOwner.getBrightness(1.0F);
281
            return f >= 0.5F ? false : super.shouldExecute();
282
        }
283
    }
284
285
    public static class GroupData implements IEntityLivingData
286
    {
287
        public int potionEffectId;
288
289
        public void func_111104_a(Random rand)
290
        {
291
            int i = rand.nextInt(5);
292
293
            if (i <= 1)
294
            {
295
                this.potionEffectId = Potion.moveSpeed.id;
296
            }
297
            else if (i <= 2)
298
            {
299
                this.potionEffectId = Potion.damageBoost.id;
300
            }
301
            else if (i <= 3)
302
            {
303
                this.potionEffectId = Potion.regeneration.id;
304
            }
305
            else if (i <= 4)
306
            {
307
                this.potionEffectId = Potion.invisibility.id;
308
            }
309
        }
310
    }
311
}
312

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