| 1 | package net.minecraft.entity.monster;
|
| 2 |
|
| 3 | import net.minecraft.block.Block;
|
| 4 | import net.minecraft.entity.EnumCreatureAttribute;
|
| 5 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 6 | import net.minecraft.entity.ai.EntityAIAttackOnCollide;
|
| 7 | import net.minecraft.entity.ai.EntityAIHurtByTarget;
|
| 8 | import net.minecraft.entity.ai.EntityAILookIdle;
|
| 9 | import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
|
| 10 | import net.minecraft.entity.ai.EntityAISwimming;
|
| 11 | import net.minecraft.entity.ai.EntityAIWander;
|
| 12 | import net.minecraft.entity.ai.EntityAIWatchClosest;
|
| 13 | import net.minecraft.entity.player.EntityPlayer;
|
| 14 | import net.minecraft.item.Item;
|
| 15 | import net.minecraft.nbt.NBTTagCompound;
|
| 16 | import net.minecraft.util.BlockPos;
|
| 17 | import net.minecraft.util.EnumParticleTypes;
|
| 18 | import net.minecraft.world.World;
|
| 19 |
|
| 20 | public class EntityEndermite extends EntityMob
|
| 21 | {
|
| 22 | private int lifetime = 0;
|
| 23 | private boolean playerSpawned = false;
|
| 24 |
|
| 25 | public EntityEndermite(World worldIn)
|
| 26 | {
|
| 27 | super(worldIn);
|
| 28 | this.experienceValue = 3;
|
| 29 | this.setSize(0.4F, 0.3F);
|
| 30 | this.tasks.addTask(1, new EntityAISwimming(this));
|
| 31 | this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
|
| 32 | this.tasks.addTask(3, new EntityAIWander(this, 1.0D));
|
| 33 | this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
|
| 34 | this.tasks.addTask(8, new EntityAILookIdle(this));
|
| 35 | this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[0]));
|
| 36 | this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
|
| 37 | }
|
| 38 |
|
| 39 | public float getEyeHeight()
|
| 40 | {
|
| 41 | return 0.1F;
|
| 42 | }
|
| 43 |
|
| 44 | protected void applyEntityAttributes()
|
| 45 | {
|
| 46 | super.applyEntityAttributes();
|
| 47 | this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(8.0D);
|
| 48 | this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.25D);
|
| 49 | this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(2.0D);
|
| 50 | }
|
| 51 |
|
| 52 | /**
|
| 53 | * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
|
| 54 | * prevent them from trampling crops
|
| 55 | */
|
| 56 | protected boolean canTriggerWalking()
|
| 57 | {
|
| 58 | return false;
|
| 59 | }
|
| 60 |
|
| 61 | /**
|
| 62 | * Returns the sound this mob makes while it's alive.
|
| 63 | */
|
| 64 | protected String getLivingSound()
|
| 65 | {
|
| 66 | return "mob.silverfish.say";
|
| 67 | }
|
| 68 |
|
| 69 | /**
|
| 70 | * Returns the sound this mob makes when it is hurt.
|
| 71 | */
|
| 72 | protected String getHurtSound()
|
| 73 | {
|
| 74 | return "mob.silverfish.hit";
|
| 75 | }
|
| 76 |
|
| 77 | /**
|
| 78 | * Returns the sound this mob makes on death.
|
| 79 | */
|
| 80 | protected String getDeathSound()
|
| 81 | {
|
| 82 | return "mob.silverfish.kill";
|
| 83 | }
|
| 84 |
|
| 85 | protected void playStepSound(BlockPos pos, Block blockIn)
|
| 86 | {
|
| 87 | this.playSound("mob.silverfish.step", 0.15F, 1.0F);
|
| 88 | }
|
| 89 |
|
| 90 | protected Item getDropItem()
|
| 91 | {
|
| 92 | return null;
|
| 93 | }
|
| 94 |
|
| 95 | /**
|
| 96 | * (abstract) Protected helper method to read subclass entity data from NBT.
|
| 97 | */
|
| 98 | public void readEntityFromNBT(NBTTagCompound tagCompund)
|
| 99 | {
|
| 100 | super.readEntityFromNBT(tagCompund);
|
| 101 | this.lifetime = tagCompund.getInteger("Lifetime");
|
| 102 | this.playerSpawned = tagCompund.getBoolean("PlayerSpawned");
|
| 103 | }
|
| 104 |
|
| 105 | /**
|
| 106 | * (abstract) Protected helper method to write subclass entity data to NBT.
|
| 107 | */
|
| 108 | public void writeEntityToNBT(NBTTagCompound tagCompound)
|
| 109 | {
|
| 110 | super.writeEntityToNBT(tagCompound);
|
| 111 | tagCompound.setInteger("Lifetime", this.lifetime);
|
| 112 | tagCompound.setBoolean("PlayerSpawned", this.playerSpawned);
|
| 113 | }
|
| 114 |
|
| 115 | /**
|
| 116 | * Called to update the entity's position/logic.
|
| 117 | */
|
| 118 | public void onUpdate()
|
| 119 | {
|
| 120 | this.renderYawOffset = this.rotationYaw;
|
| 121 | super.onUpdate();
|
| 122 | }
|
| 123 |
|
| 124 | public boolean isSpawnedByPlayer()
|
| 125 | {
|
| 126 | return this.playerSpawned;
|
| 127 | }
|
| 128 |
|
| 129 | /**
|
| 130 | * Sets if this mob was spawned by a player or not.
|
| 131 | */
|
| 132 | public void setSpawnedByPlayer(boolean spawnedByPlayer)
|
| 133 | {
|
| 134 | this.playerSpawned = spawnedByPlayer;
|
| 135 | }
|
| 136 |
|
| 137 | /**
|
| 138 | * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
|
| 139 | * use this to react to sunlight and start to burn.
|
| 140 | */
|
| 141 | public void onLivingUpdate()
|
| 142 | {
|
| 143 | super.onLivingUpdate();
|
| 144 |
|
| 145 | if (this.worldObj.isRemote)
|
| 146 | {
|
| 147 | for (int i = 0; i < 2; ++i)
|
| 148 | {
|
| 149 | this.worldObj.spawnParticle(EnumParticleTypes.PORTAL, this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, (this.rand.nextDouble() - 0.5D) * 2.0D, -this.rand.nextDouble(), (this.rand.nextDouble() - 0.5D) * 2.0D, new int[0]);
|
| 150 | }
|
| 151 | }
|
| 152 | else
|
| 153 | {
|
| 154 | if (!this.isNoDespawnRequired())
|
| 155 | {
|
| 156 | ++this.lifetime;
|
| 157 | }
|
| 158 |
|
| 159 | if (this.lifetime >= 2400)
|
| 160 | {
|
| 161 | this.setDead();
|
| 162 | }
|
| 163 | }
|
| 164 | }
|
| 165 |
|
| 166 | /**
|
| 167 | * Checks to make sure the light is not too bright where the mob is spawning
|
| 168 | */
|
| 169 | protected boolean isValidLightLevel()
|
| 170 | {
|
| 171 | return true;
|
| 172 | }
|
| 173 |
|
| 174 | /**
|
| 175 | * Checks if the entity's current position is a valid location to spawn this entity.
|
| 176 | */
|
| 177 | public boolean getCanSpawnHere()
|
| 178 | {
|
| 179 | if (super.getCanSpawnHere())
|
| 180 | {
|
| 181 | EntityPlayer entityplayer = this.worldObj.getClosestPlayerToEntity(this, 5.0D);
|
| 182 | return entityplayer == null;
|
| 183 | }
|
| 184 | else
|
| 185 | {
|
| 186 | return false;
|
| 187 | }
|
| 188 | }
|
| 189 |
|
| 190 | /**
|
| 191 | * Get this Entity's EnumCreatureAttribute
|
| 192 | */
|
| 193 | public EnumCreatureAttribute getCreatureAttribute()
|
| 194 | {
|
| 195 | return EnumCreatureAttribute.ARTHROPOD;
|
| 196 | }
|
| 197 | }
|
| 198 |
|