Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 169 lines 5.8 kB view raw
1package net.minecraft.server; 2 3import org.bukkit.craftbukkit.event.CraftEventFactory; 4import org.bukkit.event.player.PlayerPickupItemEvent; 5 6public class EntityItem extends Entity { 7 8 public ItemStack itemStack; 9 private int e; 10 public int b = 0; 11 public int pickupDelay; 12 private int f = 5; 13 public float d = (float) (Math.random() * 3.141592653589793D * 2.0D); 14 private int lastTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit 15 16 public EntityItem(World world, double d0, double d1, double d2, ItemStack itemstack) { 17 super(world); 18 this.b(0.25F, 0.25F); 19 this.height = this.width / 2.0F; 20 this.setPosition(d0, d1, d2); 21 this.itemStack = itemstack; 22 // CraftBukkit start - infinite item fix 23 if (this.itemStack.count <= -1) { 24 this.itemStack.count = 1; 25 } 26 // CraftBukkit end 27 this.yaw = (float) (Math.random() * 360.0D); 28 this.motX = (double) ((float) (Math.random() * 0.20000000298023224D - 0.10000000149011612D)); 29 this.motY = 0.20000000298023224D; 30 this.motZ = (double) ((float) (Math.random() * 0.20000000298023224D - 0.10000000149011612D)); 31 } 32 33 protected boolean n() { 34 return false; 35 } 36 37 public EntityItem(World world) { 38 super(world); 39 this.b(0.25F, 0.25F); 40 this.height = this.width / 2.0F; 41 } 42 43 protected void b() { 44 } 45 46 public void m_() { 47 super.m_(); 48 // CraftBukkit start 49 int currentTick = (int) (System.currentTimeMillis() / 50); 50 this.pickupDelay -= (currentTick - this.lastTick); 51 this.lastTick = currentTick; 52 // CraftBukkit end 53 54 this.lastX = this.locX; 55 this.lastY = this.locY; 56 this.lastZ = this.locZ; 57 this.motY -= 0.03999999910593033D; 58 if (this.world.getMaterial(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)) == Material.LAVA) { 59 this.motY = 0.20000000298023224D; 60 this.motX = (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F); 61 this.motZ = (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F); 62 this.world.makeSound(this, "random.fizz", 0.4F, 2.0F + this.random.nextFloat() * 0.4F); 63 } 64 65 this.g(this.locX, (this.boundingBox.b + this.boundingBox.e) / 2.0D, this.locZ); 66 this.move(this.motX, this.motY, this.motZ); 67 float f = 0.98F; 68 69 if (this.onGround) { 70 f = 0.58800006F; 71 int i = this.world.getTypeId(MathHelper.floor(this.locX), MathHelper.floor(this.boundingBox.b) - 1, MathHelper.floor(this.locZ)); 72 73 if (i > 0) { 74 f = Block.byId[i].frictionFactor * 0.98F; 75 } 76 } 77 78 this.motX *= (double) f; 79 this.motY *= 0.9800000190734863D; 80 this.motZ *= (double) f; 81 if (this.onGround) { 82 this.motY *= -0.5D; 83 } 84 85 ++this.e; 86 ++this.b; 87 if (this.b >= 6000) { 88 //Project Poseidon Start 89 if (CraftEventFactory.callItemDespawnEvent(this).isCancelled()) { 90 this.b = 0; 91 return; 92 } 93 // CraftBukkit end 94 this.die(); 95 } 96 } 97 98 public boolean f_() { 99 return this.world.a(this.boundingBox, Material.WATER, this); 100 } 101 102 protected void burn(int i) { 103 this.damageEntity((Entity) null, i); 104 } 105 106 public boolean damageEntity(Entity entity, int i) { 107 this.af(); 108 this.f -= i; 109 if (this.f <= 0) { 110 this.die(); 111 } 112 113 return false; 114 } 115 116 public void b(NBTTagCompound nbttagcompound) { 117 nbttagcompound.a("Health", (short) ((byte) this.f)); 118 nbttagcompound.a("Age", (short) this.b); 119 nbttagcompound.a("Item", this.itemStack.a(new NBTTagCompound())); 120 } 121 122 public void a(NBTTagCompound nbttagcompound) { 123 this.f = nbttagcompound.d("Health") & 255; 124 this.b = nbttagcompound.d("Age"); 125 NBTTagCompound nbttagcompound1 = nbttagcompound.k("Item"); 126 127 this.itemStack = new ItemStack(nbttagcompound1); 128 } 129 130 public void b(EntityHuman entityhuman) { 131 if (!this.world.isStatic) { 132 int i = this.itemStack.count; 133 134 // CraftBukkit start 135 int canHold = entityhuman.inventory.canHold(this.itemStack); 136 int remaining = this.itemStack.count - canHold; 137 if (this.pickupDelay <= 0 && canHold > 0) { 138 this.itemStack.count = canHold; 139 PlayerPickupItemEvent event = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining); 140 this.world.getServer().getPluginManager().callEvent(event); 141 this.itemStack.count = canHold + remaining; 142 143 if (event.isCancelled()) { 144 return; 145 } 146 147 // Possibly < 0; fix here so we do not have to modify code below 148 this.pickupDelay = 0; 149 } 150 // CraftBukkit end 151 152 if (this.pickupDelay == 0 && entityhuman.inventory.pickup(this.itemStack)) { 153 if (this.itemStack.id == Block.LOG.id) { 154 entityhuman.a((Statistic) AchievementList.g); 155 } 156 157 if (this.itemStack.id == Item.LEATHER.id) { 158 entityhuman.a((Statistic) AchievementList.t); 159 } 160 161 this.world.makeSound(this, "random.pop", 0.2F, ((this.random.nextFloat() - this.random.nextFloat()) * 0.7F + 1.0F) * 2.0F); 162 entityhuman.receive(this, i); 163 if (this.itemStack.count <= 0) { 164 this.die(); 165 } 166 } 167 } 168 } 169}