EntityBat .java

net.minecraft.entity.passive.EntityBat (class): members: getIsBatHanging, setIsBatHanging, spawnPosition, doesEntityNotTriggerPressurePlate, getSoundPitch.

net.minecraft.entity.passiveclass290 linescommonextends EntityAmbientCreature8.2 KB

API Surface (23)

void entityInit()
float getSoundVolume()
float getSoundPitch()
String getLivingSound()
String getHurtSound()
String getDeathSound()
boolean canBePushed()
void collideWithEntity(Entity entityIn)
void collideWithNearbyEntities()
void applyEntityAttributes()
boolean getIsBatHanging()
void setIsBatHanging(boolean isHanging)
void onUpdate()
void updateAITasks()
boolean canTriggerWalking()
void fall(float distance, float damageMultiplier)
void updateFallState(double y, boolean onGroundIn, Block blockIn, BlockPos pos)
boolean doesEntityNotTriggerPressurePlate()
boolean attackEntityFrom(DamageSource source, float amount)
void readEntityFromNBT(NBTTagCompound tagCompund)
void writeEntityToNBT(NBTTagCompound tagCompound)
boolean getCanSpawnHere()
float getEyeHeight()

Fields & Constants (1)

spawnPosition

String literals (4)

"mob.bat.idle"
"mob.bat.hurt"
"mob.bat.death"
"BatFlags"

Full Source

EntityBat.java290 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity.passive;
2
3
import java.util.Calendar;
4
import net.minecraft.block.Block;
5
import net.minecraft.entity.Entity;
6
import net.minecraft.entity.SharedMonsterAttributes;
7
import net.minecraft.entity.player.EntityPlayer;
8
import net.minecraft.nbt.NBTTagCompound;
9
import net.minecraft.util.BlockPos;
10
import net.minecraft.util.DamageSource;
11
import net.minecraft.util.MathHelper;
12
import net.minecraft.world.World;
13
14
public class EntityBat extends EntityAmbientCreature
15
{
16
    /** Coordinates of where the bat spawned. */
17
    private BlockPos spawnPosition;
18
19
    public EntityBat(World worldIn)
20
    {
21
        super(worldIn);
22
        this.setSize(0.5F, 0.9F);
23
        this.setIsBatHanging(true);
24
    }
25
26
    protected void entityInit()
27
    {
28
        super.entityInit();
29
        this.dataWatcher.addObject(16, new Byte((byte)0));
30
    }
31
32
    /**
33
     * Returns the volume for the sounds this mob makes.
34
     */
35
    protected float getSoundVolume()
36
    {
37
        return 0.1F;
38
    }
39
40
    /**
41
     * Gets the pitch of living sounds in living entities.
42
     */
43
    protected float getSoundPitch()
44
    {
45
        return super.getSoundPitch() * 0.95F;
46
    }
47
48
    /**
49
     * Returns the sound this mob makes while it's alive.
50
     */
51
    protected String getLivingSound()
52
    {
53
        return this.getIsBatHanging() && this.rand.nextInt(4) != 0 ? null : "mob.bat.idle";
54
    }
55
56
    /**
57
     * Returns the sound this mob makes when it is hurt.
58
     */
59
    protected String getHurtSound()
60
    {
61
        return "mob.bat.hurt";
62
    }
63
64
    /**
65
     * Returns the sound this mob makes on death.
66
     */
67
    protected String getDeathSound()
68
    {
69
        return "mob.bat.death";
70
    }
71
72
    /**
73
     * Returns true if this entity should push and be pushed by other entities when colliding.
74
     */
75
    public boolean canBePushed()
76
    {
77
        return false;
78
    }
79
80
    protected void collideWithEntity(Entity entityIn)
81
    {
82
    }
83
84
    protected void collideWithNearbyEntities()
85
    {
86
    }
87
88
    protected void applyEntityAttributes()
89
    {
90
        super.applyEntityAttributes();
91
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(6.0D);
92
    }
93
94
    public boolean getIsBatHanging()
95
    {
96
        return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0;
97
    }
98
99
    public void setIsBatHanging(boolean isHanging)
100
    {
101
        byte b0 = this.dataWatcher.getWatchableObjectByte(16);
102
103
        if (isHanging)
104
        {
105
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 1)));
106
        }
107
        else
108
        {
109
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -2)));
110
        }
111
    }
112
113
    /**
114
     * Called to update the entity's position/logic.
115
     */
116
    public void onUpdate()
117
    {
118
        super.onUpdate();
119
120
        if (this.getIsBatHanging())
121
        {
122
            this.motionX = this.motionY = this.motionZ = 0.0D;
123
            this.posY = (double)MathHelper.floor_double(this.posY) + 1.0D - (double)this.height;
124
        }
125
        else
126
        {
127
            this.motionY *= 0.6000000238418579D;
128
        }
129
    }
130
131
    protected void updateAITasks()
132
    {
133
        super.updateAITasks();
134
        BlockPos blockpos = new BlockPos(this);
135
        BlockPos blockpos1 = blockpos.up();
136
137
        if (this.getIsBatHanging())
138
        {
139
            if (!this.worldObj.getBlockState(blockpos1).getBlock().isNormalCube())
140
            {
141
                this.setIsBatHanging(false);
142
                this.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1015, blockpos, 0);
143
            }
144
            else
145
            {
146
                if (this.rand.nextInt(200) == 0)
147
                {
148
                    this.rotationYawHead = (float)this.rand.nextInt(360);
149
                }
150
151
                if (this.worldObj.getClosestPlayerToEntity(this, 4.0D) != null)
152
                {
153
                    this.setIsBatHanging(false);
154
                    this.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1015, blockpos, 0);
155
                }
156
            }
157
        }
158
        else
159
        {
160
            if (this.spawnPosition != null && (!this.worldObj.isAirBlock(this.spawnPosition) || this.spawnPosition.getY() < 1))
161
            {
162
                this.spawnPosition = null;
163
            }
164
165
            if (this.spawnPosition == null || this.rand.nextInt(30) == 0 || this.spawnPosition.distanceSq((double)((int)this.posX), (double)((int)this.posY), (double)((int)this.posZ)) < 4.0D)
166
            {
167
                this.spawnPosition = new BlockPos((int)this.posX + this.rand.nextInt(7) - this.rand.nextInt(7), (int)this.posY + this.rand.nextInt(6) - 2, (int)this.posZ + this.rand.nextInt(7) - this.rand.nextInt(7));
168
            }
169
170
            double d0 = (double)this.spawnPosition.getX() + 0.5D - this.posX;
171
            double d1 = (double)this.spawnPosition.getY() + 0.1D - this.posY;
172
            double d2 = (double)this.spawnPosition.getZ() + 0.5D - this.posZ;
173
            this.motionX += (Math.signum(d0) * 0.5D - this.motionX) * 0.10000000149011612D;
174
            this.motionY += (Math.signum(d1) * 0.699999988079071D - this.motionY) * 0.10000000149011612D;
175
            this.motionZ += (Math.signum(d2) * 0.5D - this.motionZ) * 0.10000000149011612D;
176
            float f = (float)(MathHelper.atan2(this.motionZ, this.motionX) * 180.0D / Math.PI) - 90.0F;
177
            float f1 = MathHelper.wrapAngleTo180_float(f - this.rotationYaw);
178
            this.moveForward = 0.5F;
179
            this.rotationYaw += f1;
180
181
            if (this.rand.nextInt(100) == 0 && this.worldObj.getBlockState(blockpos1).getBlock().isNormalCube())
182
            {
183
                this.setIsBatHanging(true);
184
            }
185
        }
186
    }
187
188
    /**
189
     * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
190
     * prevent them from trampling crops
191
     */
192
    protected boolean canTriggerWalking()
193
    {
194
        return false;
195
    }
196
197
    public void fall(float distance, float damageMultiplier)
198
    {
199
    }
200
201
    protected void updateFallState(double y, boolean onGroundIn, Block blockIn, BlockPos pos)
202
    {
203
    }
204
205
    /**
206
     * Return whether this entity should NOT trigger a pressure plate or a tripwire.
207
     */
208
    public boolean doesEntityNotTriggerPressurePlate()
209
    {
210
        return true;
211
    }
212
213
    /**
214
     * Called when the entity is attacked.
215
     */
216
    public boolean attackEntityFrom(DamageSource source, float amount)
217
    {
218
        if (this.isEntityInvulnerable(source))
219
        {
220
            return false;
221
        }
222
        else
223
        {
224
            if (!this.worldObj.isRemote && this.getIsBatHanging())
225
            {
226
                this.setIsBatHanging(false);
227
            }
228
229
            return super.attackEntityFrom(source, amount);
230
        }
231
    }
232
233
    /**
234
     * (abstract) Protected helper method to read subclass entity data from NBT.
235
     */
236
    public void readEntityFromNBT(NBTTagCompound tagCompund)
237
    {
238
        super.readEntityFromNBT(tagCompund);
239
        this.dataWatcher.updateObject(16, Byte.valueOf(tagCompund.getByte("BatFlags")));
240
    }
241
242
    /**
243
     * (abstract) Protected helper method to write subclass entity data to NBT.
244
     */
245
    public void writeEntityToNBT(NBTTagCompound tagCompound)
246
    {
247
        super.writeEntityToNBT(tagCompound);
248
        tagCompound.setByte("BatFlags", this.dataWatcher.getWatchableObjectByte(16));
249
    }
250
251
    /**
252
     * Checks if the entity's current position is a valid location to spawn this entity.
253
     */
254
    public boolean getCanSpawnHere()
255
    {
256
        BlockPos blockpos = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ);
257
258
        if (blockpos.getY() >= this.worldObj.getSeaLevel())
259
        {
260
            return false;
261
        }
262
        else
263
        {
264
            int i = this.worldObj.getLightFromNeighbors(blockpos);
265
            int j = 4;
266
267
            if (this.isDateAroundHalloween(this.worldObj.getCurrentDate()))
268
            {
269
                j = 7;
270
            }
271
            else if (this.rand.nextBoolean())
272
            {
273
                return false;
274
            }
275
276
            return i > this.rand.nextInt(j) ? false : super.getCanSpawnHere();
277
        }
278
    }
279
280
    private boolean isDateAroundHalloween(Calendar p_175569_1_)
281
    {
282
        return p_175569_1_.get(2) + 1 == 10 && p_175569_1_.get(5) >= 20 || p_175569_1_.get(2) + 1 == 11 && p_175569_1_.get(5) <= 3;
283
    }
284
285
    public float getEyeHeight()
286
    {
287
        return this.height / 2.0F;
288
    }
289
}
290

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