| 1 | package net.minecraft.entity.monster;
|
| 2 |
|
| 3 | import net.minecraft.block.material.Material;
|
| 4 | import net.minecraft.entity.EntityLiving;
|
| 5 | import net.minecraft.entity.EntityLivingBase;
|
| 6 | import net.minecraft.entity.IRangedAttackMob;
|
| 7 | import net.minecraft.entity.SharedMonsterAttributes;
|
| 8 | import net.minecraft.entity.ai.EntityAIArrowAttack;
|
| 9 | import net.minecraft.entity.ai.EntityAILookIdle;
|
| 10 | import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
|
| 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.entity.projectile.EntitySnowball;
|
| 15 | import net.minecraft.init.Blocks;
|
| 16 | import net.minecraft.init.Items;
|
| 17 | import net.minecraft.item.Item;
|
| 18 | import net.minecraft.pathfinding.PathNavigateGround;
|
| 19 | import net.minecraft.util.BlockPos;
|
| 20 | import net.minecraft.util.DamageSource;
|
| 21 | import net.minecraft.util.MathHelper;
|
| 22 | import net.minecraft.world.World;
|
| 23 |
|
| 24 | public class EntitySnowman extends EntityGolem implements IRangedAttackMob
|
| 25 | {
|
| 26 | public EntitySnowman(World worldIn)
|
| 27 | {
|
| 28 | super(worldIn);
|
| 29 | this.setSize(0.7F, 1.9F);
|
| 30 | ((PathNavigateGround)this.getNavigator()).setAvoidsWater(true);
|
| 31 | this.tasks.addTask(1, new EntityAIArrowAttack(this, 1.25D, 20, 10.0F));
|
| 32 | this.tasks.addTask(2, new EntityAIWander(this, 1.0D));
|
| 33 | this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F));
|
| 34 | this.tasks.addTask(4, new EntityAILookIdle(this));
|
| 35 | this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityLiving.class, 10, true, false, IMob.mobSelector));
|
| 36 | }
|
| 37 |
|
| 38 | protected void applyEntityAttributes()
|
| 39 | {
|
| 40 | super.applyEntityAttributes();
|
| 41 | this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(4.0D);
|
| 42 | this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.20000000298023224D);
|
| 43 | }
|
| 44 |
|
| 45 | /**
|
| 46 | * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
|
| 47 | * use this to react to sunlight and start to burn.
|
| 48 | */
|
| 49 | public void onLivingUpdate()
|
| 50 | {
|
| 51 | super.onLivingUpdate();
|
| 52 |
|
| 53 | if (!this.worldObj.isRemote)
|
| 54 | {
|
| 55 | int i = MathHelper.floor_double(this.posX);
|
| 56 | int j = MathHelper.floor_double(this.posY);
|
| 57 | int k = MathHelper.floor_double(this.posZ);
|
| 58 |
|
| 59 | if (this.isWet())
|
| 60 | {
|
| 61 | this.attackEntityFrom(DamageSource.drown, 1.0F);
|
| 62 | }
|
| 63 |
|
| 64 | if (this.worldObj.getBiomeGenForCoords(new BlockPos(i, 0, k)).getFloatTemperature(new BlockPos(i, j, k)) > 1.0F)
|
| 65 | {
|
| 66 | this.attackEntityFrom(DamageSource.onFire, 1.0F);
|
| 67 | }
|
| 68 |
|
| 69 | for (int l = 0; l < 4; ++l)
|
| 70 | {
|
| 71 | i = MathHelper.floor_double(this.posX + (double)((float)(l % 2 * 2 - 1) * 0.25F));
|
| 72 | j = MathHelper.floor_double(this.posY);
|
| 73 | k = MathHelper.floor_double(this.posZ + (double)((float)(l / 2 % 2 * 2 - 1) * 0.25F));
|
| 74 | BlockPos blockpos = new BlockPos(i, j, k);
|
| 75 |
|
| 76 | if (this.worldObj.getBlockState(blockpos).getBlock().getMaterial() == Material.air && this.worldObj.getBiomeGenForCoords(new BlockPos(i, 0, k)).getFloatTemperature(blockpos) < 0.8F && Blocks.snow_layer.canPlaceBlockAt(this.worldObj, blockpos))
|
| 77 | {
|
| 78 | this.worldObj.setBlockState(blockpos, Blocks.snow_layer.getDefaultState());
|
| 79 | }
|
| 80 | }
|
| 81 | }
|
| 82 | }
|
| 83 |
|
| 84 | protected Item getDropItem()
|
| 85 | {
|
| 86 | return Items.snowball;
|
| 87 | }
|
| 88 |
|
| 89 | /**
|
| 90 | * Drop 0-2 items of this living's type
|
| 91 | *
|
| 92 | * @param wasRecentlyHit true if this this entity was recently hit by appropriate entity (generally only if player
|
| 93 | * or tameable)
|
| 94 | * @param lootingModifier level of enchanment to be applied to this drop
|
| 95 | */
|
| 96 | protected void dropFewItems(boolean wasRecentlyHit, int lootingModifier)
|
| 97 | {
|
| 98 | int i = this.rand.nextInt(16);
|
| 99 |
|
| 100 | for (int j = 0; j < i; ++j)
|
| 101 | {
|
| 102 | this.dropItem(Items.snowball, 1);
|
| 103 | }
|
| 104 | }
|
| 105 |
|
| 106 | /**
|
| 107 | * Attack the specified entity using a ranged attack.
|
| 108 | */
|
| 109 | public void attackEntityWithRangedAttack(EntityLivingBase target, float p_82196_2_)
|
| 110 | {
|
| 111 | EntitySnowball entitysnowball = new EntitySnowball(this.worldObj, this);
|
| 112 | double d0 = target.posY + (double)target.getEyeHeight() - 1.100000023841858D;
|
| 113 | double d1 = target.posX - this.posX;
|
| 114 | double d2 = d0 - entitysnowball.posY;
|
| 115 | double d3 = target.posZ - this.posZ;
|
| 116 | float f = MathHelper.sqrt_double(d1 * d1 + d3 * d3) * 0.2F;
|
| 117 | entitysnowball.setThrowableHeading(d1, d2 + (double)f, d3, 1.6F, 12.0F);
|
| 118 | this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
|
| 119 | this.worldObj.spawnEntityInWorld(entitysnowball);
|
| 120 | }
|
| 121 |
|
| 122 | public float getEyeHeight()
|
| 123 | {
|
| 124 | return 1.7F;
|
| 125 | }
|
| 126 | }
|
| 127 |
|