| 1 | package net.minecraft.entity.monster;
|
| 2 |
|
| 3 | import net.minecraft.entity.EntityLivingBase;
|
| 4 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 5 | import net.minecraft.entity.ai.EntityAIBase;
|
| 6 | import net.minecraft.entity.ai.EntityAIHurtByTarget;
|
| 7 | import net.minecraft.entity.ai.EntityAILookIdle;
|
| 8 | import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
|
| 9 | import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
|
| 10 | import net.minecraft.entity.ai.EntityAIWander;
|
| 11 | import net.minecraft.entity.ai.EntityAIWatchClosest;
|
| 12 | import net.minecraft.entity.player.EntityPlayer;
|
| 13 | import net.minecraft.entity.projectile.EntitySmallFireball;
|
| 14 | import net.minecraft.init.Items;
|
| 15 | import net.minecraft.item.Item;
|
| 16 | import net.minecraft.util.BlockPos;
|
| 17 | import net.minecraft.util.DamageSource;
|
| 18 | import net.minecraft.util.EnumParticleTypes;
|
| 19 | import net.minecraft.util.MathHelper;
|
| 20 | import net.minecraft.world.World;
|
| 21 |
|
| 22 | public class EntityBlaze extends EntityMob
|
| 23 | {
|
| 24 | /** Random offset used in floating behaviour */
|
| 25 | private float heightOffset = 0.5F;
|
| 26 |
|
| 27 | /** ticks until heightOffset is randomized */
|
| 28 | private int heightOffsetUpdateTime;
|
| 29 |
|
| 30 | public EntityBlaze(World worldIn)
|
| 31 | {
|
| 32 | super(worldIn);
|
| 33 | this.isImmuneToFire = true;
|
| 34 | this.experienceValue = 10;
|
| 35 | this.tasks.addTask(4, new EntityBlaze.AIFireballAttack(this));
|
| 36 | this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D));
|
| 37 | this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
|
| 38 | this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
|
| 39 | this.tasks.addTask(8, new EntityAILookIdle(this));
|
| 40 | this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[0]));
|
| 41 | this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
|
| 42 | }
|
| 43 |
|
| 44 | protected void applyEntityAttributes()
|
| 45 | {
|
| 46 | super.applyEntityAttributes();
|
| 47 | this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(6.0D);
|
| 48 | this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23000000417232513D);
|
| 49 | this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(48.0D);
|
| 50 | }
|
| 51 |
|
| 52 | protected void entityInit()
|
| 53 | {
|
| 54 | super.entityInit();
|
| 55 | this.dataWatcher.addObject(16, new Byte((byte)0));
|
| 56 | }
|
| 57 |
|
| 58 | /**
|
| 59 | * Returns the sound this mob makes while it's alive.
|
| 60 | */
|
| 61 | protected String getLivingSound()
|
| 62 | {
|
| 63 | return "mob.blaze.breathe";
|
| 64 | }
|
| 65 |
|
| 66 | /**
|
| 67 | * Returns the sound this mob makes when it is hurt.
|
| 68 | */
|
| 69 | protected String getHurtSound()
|
| 70 | {
|
| 71 | return "mob.blaze.hit";
|
| 72 | }
|
| 73 |
|
| 74 | /**
|
| 75 | * Returns the sound this mob makes on death.
|
| 76 | */
|
| 77 | protected String getDeathSound()
|
| 78 | {
|
| 79 | return "mob.blaze.death";
|
| 80 | }
|
| 81 |
|
| 82 | public int getBrightnessForRender(float partialTicks)
|
| 83 | {
|
| 84 | return 15728880;
|
| 85 | }
|
| 86 |
|
| 87 | /**
|
| 88 | * Gets how bright this entity is.
|
| 89 | */
|
| 90 | public float getBrightness(float partialTicks)
|
| 91 | {
|
| 92 | return 1.0F;
|
| 93 | }
|
| 94 |
|
| 95 | /**
|
| 96 | * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
|
| 97 | * use this to react to sunlight and start to burn.
|
| 98 | */
|
| 99 | public void onLivingUpdate()
|
| 100 | {
|
| 101 | if (!this.onGround && this.motionY < 0.0D)
|
| 102 | {
|
| 103 | this.motionY *= 0.6D;
|
| 104 | }
|
| 105 |
|
| 106 | if (this.worldObj.isRemote)
|
| 107 | {
|
| 108 | if (this.rand.nextInt(24) == 0 && !this.isSilent())
|
| 109 | {
|
| 110 | this.worldObj.playSound(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, "fire.fire", 1.0F + this.rand.nextFloat(), this.rand.nextFloat() * 0.7F + 0.3F, false);
|
| 111 | }
|
| 112 |
|
| 113 | for (int i = 0; i < 2; ++i)
|
| 114 | {
|
| 115 | this.worldObj.spawnParticle(EnumParticleTypes.SMOKE_LARGE, 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, 0.0D, 0.0D, 0.0D, new int[0]);
|
| 116 | }
|
| 117 | }
|
| 118 |
|
| 119 | super.onLivingUpdate();
|
| 120 | }
|
| 121 |
|
| 122 | protected void updateAITasks()
|
| 123 | {
|
| 124 | if (this.isWet())
|
| 125 | {
|
| 126 | this.attackEntityFrom(DamageSource.drown, 1.0F);
|
| 127 | }
|
| 128 |
|
| 129 | --this.heightOffsetUpdateTime;
|
| 130 |
|
| 131 | if (this.heightOffsetUpdateTime <= 0)
|
| 132 | {
|
| 133 | this.heightOffsetUpdateTime = 100;
|
| 134 | this.heightOffset = 0.5F + (float)this.rand.nextGaussian() * 3.0F;
|
| 135 | }
|
| 136 |
|
| 137 | EntityLivingBase entitylivingbase = this.getAttackTarget();
|
| 138 |
|
| 139 | if (entitylivingbase != null && entitylivingbase.posY + (double)entitylivingbase.getEyeHeight() > this.posY + (double)this.getEyeHeight() + (double)this.heightOffset)
|
| 140 | {
|
| 141 | this.motionY += (0.30000001192092896D - this.motionY) * 0.30000001192092896D;
|
| 142 | this.isAirBorne = true;
|
| 143 | }
|
| 144 |
|
| 145 | super.updateAITasks();
|
| 146 | }
|
| 147 |
|
| 148 | public void fall(float distance, float damageMultiplier)
|
| 149 | {
|
| 150 | }
|
| 151 |
|
| 152 | protected Item getDropItem()
|
| 153 | {
|
| 154 | return Items.blaze_rod;
|
| 155 | }
|
| 156 |
|
| 157 | /**
|
| 158 | * Returns true if the entity is on fire. Used by render to add the fire effect on rendering.
|
| 159 | */
|
| 160 | public boolean isBurning()
|
| 161 | {
|
| 162 | return this.func_70845_n();
|
| 163 | }
|
| 164 |
|
| 165 | /**
|
| 166 | * Drop 0-2 items of this living's type
|
| 167 | *
|
| 168 | * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
|
| 169 | * or tameable)
|
| 170 | * @param lootingModifier level of enchanment to be applied to this drop
|
| 171 | */
|
| 172 | protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
|
| 173 | {
|
| 174 | if (wasRecentlyHit)
|
| 175 | {
|
| 176 | int i = this.rand.nextInt(2 + lootingModifier);
|
| 177 |
|
| 178 | for (int j = 0; j < i; ++j)
|
| 179 | {
|
| 180 | this.dropItem(Items.blaze_rod, 1);
|
| 181 | }
|
| 182 | }
|
| 183 | }
|
| 184 |
|
| 185 | public boolean func_70845_n()
|
| 186 | {
|
| 187 | return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0;
|
| 188 | }
|
| 189 |
|
| 190 | public void setOnFire(boolean onFire)
|
| 191 | {
|
| 192 | byte b0 = this.dataWatcher.getWatchableObjectByte(16);
|
| 193 |
|
| 194 | if (onFire)
|
| 195 | {
|
| 196 | b0 = (byte)(b0 | 1);
|
| 197 | }
|
| 198 | else
|
| 199 | {
|
| 200 | b0 = (byte)(b0 & -2);
|
| 201 | }
|
| 202 |
|
| 203 | this.dataWatcher.updateObject(16, Byte.valueOf(b0));
|
| 204 | }
|
| 205 |
|
| 206 | /**
|
| 207 | * Checks to make sure the light is not too bright where the mob is spawning
|
| 208 | */
|
| 209 | protected boolean isValidLightLevel()
|
| 210 | {
|
| 211 | return true;
|
| 212 | }
|
| 213 |
|
| 214 | static class AIFireballAttack extends EntityAIBase
|
| 215 | {
|
| 216 | private EntityBlaze blaze;
|
| 217 | private int field_179467_b;
|
| 218 | private int field_179468_c;
|
| 219 |
|
| 220 | public AIFireballAttack(EntityBlaze p_i45846_1_)
|
| 221 | {
|
| 222 | this.blaze = p_i45846_1_;
|
| 223 | this.setMutexBits(3);
|
| 224 | }
|
| 225 |
|
| 226 | public boolean shouldExecute()
|
| 227 | {
|
| 228 | EntityLivingBase entitylivingbase = this.blaze.getAttackTarget();
|
| 229 | return entitylivingbase != null && entitylivingbase.isEntityAlive();
|
| 230 | }
|
| 231 |
|
| 232 | public void startExecuting()
|
| 233 | {
|
| 234 | this.field_179467_b = 0;
|
| 235 | }
|
| 236 |
|
| 237 | public void resetTask()
|
| 238 | {
|
| 239 | this.blaze.setOnFire(false);
|
| 240 | }
|
| 241 |
|
| 242 | public void updateTask()
|
| 243 | {
|
| 244 | --this.field_179468_c;
|
| 245 | EntityLivingBase entitylivingbase = this.blaze.getAttackTarget();
|
| 246 | double d0 = this.blaze.getDistanceSqToEntity(entitylivingbase);
|
| 247 |
|
| 248 | if (d0 < 4.0D)
|
| 249 | {
|
| 250 | if (this.field_179468_c <= 0)
|
| 251 | {
|
| 252 | this.field_179468_c = 20;
|
| 253 | this.blaze.attackEntityAsMob(entitylivingbase);
|
| 254 | }
|
| 255 |
|
| 256 | this.blaze.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
|
| 257 | }
|
| 258 | else if (d0 < 256.0D)
|
| 259 | {
|
| 260 | double d1 = entitylivingbase.posX - this.blaze.posX;
|
| 261 | double d2 = entitylivingbase.getEntityBoundingBox().minY + (double)(entitylivingbase.height / 2.0F) - (this.blaze.posY + (double)(this.blaze.height / 2.0F));
|
| 262 | double d3 = entitylivingbase.posZ - this.blaze.posZ;
|
| 263 |
|
| 264 | if (this.field_179468_c <= 0)
|
| 265 | {
|
| 266 | ++this.field_179467_b;
|
| 267 |
|
| 268 | if (this.field_179467_b == 1)
|
| 269 | {
|
| 270 | this.field_179468_c = 60;
|
| 271 | this.blaze.setOnFire(true);
|
| 272 | }
|
| 273 | else if (this.field_179467_b <= 4)
|
| 274 | {
|
| 275 | this.field_179468_c = 6;
|
| 276 | }
|
| 277 | else
|
| 278 | {
|
| 279 | this.field_179468_c = 100;
|
| 280 | this.field_179467_b = 0;
|
| 281 | this.blaze.setOnFire(false);
|
| 282 | }
|
| 283 |
|
| 284 | if (this.field_179467_b > 1)
|
| 285 | {
|
| 286 | float f = MathHelper.sqrt_float(MathHelper.sqrt_double(d0)) * 0.5F;
|
| 287 | this.blaze.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1009, new BlockPos((int)this.blaze.posX, (int)this.blaze.posY, (int)this.blaze.posZ), 0);
|
| 288 |
|
| 289 | for (int i = 0; i < 1; ++i)
|
| 290 | {
|
| 291 | EntitySmallFireball entitysmallfireball = new EntitySmallFireball(this.blaze.worldObj, this.blaze, d1 + this.blaze.getRNG().nextGaussian() * (double)f, d2, d3 + this.blaze.getRNG().nextGaussian() * (double)f);
|
| 292 | entitysmallfireball.posY = this.blaze.posY + (double)(this.blaze.height / 2.0F) + 0.5D;
|
| 293 | this.blaze.worldObj.spawnEntityInWorld(entitysmallfireball);
|
| 294 | }
|
| 295 | }
|
| 296 | }
|
| 297 |
|
| 298 | this.blaze.getLookHelper().setLookPositionWithEntity(entitylivingbase, 10.0F, 10.0F);
|
| 299 | }
|
| 300 | else
|
| 301 | {
|
| 302 | this.blaze.getNavigator().clearPathEntity();
|
| 303 | this.blaze.getMoveHelper().setMoveTo(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, 1.0D);
|
| 304 | }
|
| 305 |
|
| 306 | super.updateTask();
|
| 307 | }
|
| 308 | }
|
| 309 | }
|
| 310 |
|