summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/EntityItem.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/minecraft/server/EntityItem.java')
-rw-r--r--src/main/java/net/minecraft/server/EntityItem.java201
1 files changed, 126 insertions, 75 deletions
diff --git a/src/main/java/net/minecraft/server/EntityItem.java b/src/main/java/net/minecraft/server/EntityItem.java
index 584102ed..bbcf6746 100644
--- a/src/main/java/net/minecraft/server/EntityItem.java
+++ b/src/main/java/net/minecraft/server/EntityItem.java
@@ -2,19 +2,25 @@ package net.minecraft.server;
import java.util.Iterator;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
import org.bukkit.event.player.PlayerPickupItemEvent; // CraftBukkit
public class EntityItem extends Entity {
+ private static final Logger d = LogManager.getLogger();
public int age;
public int pickupDelay;
- private int d;
+ private int e;
+ private String f;
+ private String g;
public float c;
private int lastTick = MinecraftServer.currentTick; // CraftBukkit
public EntityItem(World world, double d0, double d1, double d2) {
super(world);
- this.d = 5;
+ this.e = 5;
this.c = (float) (Math.random() * 3.141592653589793D * 2.0D);
this.a(0.25F, 0.25F);
this.height = this.length / 2.0F;
@@ -35,83 +41,82 @@ public class EntityItem extends Entity {
this.setItemStack(itemstack);
}
- protected boolean e_() {
+ protected boolean g_() {
return false;
}
public EntityItem(World world) {
super(world);
- this.d = 5;
+ this.e = 5;
this.c = (float) (Math.random() * 3.141592653589793D * 2.0D);
this.a(0.25F, 0.25F);
this.height = this.length / 2.0F;
}
- protected void a() {
+ protected void c() {
this.getDataWatcher().a(10, 5);
}
- public void l_() {
- super.l_();
- // CraftBukkit start - Use wall time for pickup and despawn timers
- int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
- this.pickupDelay -= elapsedTicks;
- this.age += elapsedTicks;
- this.lastTick = MinecraftServer.currentTick;
- // CraftBukkit end
+ public void h() {
+ if (this.getItemStack() == null) {
+ this.die();
+ } else {
+ super.h();
+ // CraftBukkit start - Use wall time for pickup and despawn timers
+ int elapsedTicks = MinecraftServer.currentTick - this.lastTick;
+ this.pickupDelay -= elapsedTicks;
+ this.age += elapsedTicks;
+ this.lastTick = MinecraftServer.currentTick;
+ // CraftBukkit end
- this.lastX = this.locX;
- this.lastY = this.locY;
- this.lastZ = this.locZ;
- this.motY -= 0.03999999910593033D;
- this.Z = this.i(this.locX, (this.boundingBox.b + this.boundingBox.e) / 2.0D, this.locZ);
- this.move(this.motX, this.motY, this.motZ);
- boolean flag = (int) this.lastX != (int) this.locX || (int) this.lastY != (int) this.locY || (int) this.lastZ != (int) this.locZ;
-
- if (flag || this.ticksLived % 25 == 0) {
- if (this.world.getMaterial(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)) == Material.LAVA) {
- this.motY = 0.20000000298023224D;
- this.motX = (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F);
- this.motZ = (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F);
- this.makeSound("random.fizz", 0.4F, 2.0F + this.random.nextFloat() * 0.4F);
- }
+ this.lastX = this.locX;
+ this.lastY = this.locY;
+ this.lastZ = this.locZ;
+ this.motY -= 0.03999999910593033D;
+ this.Y = this.j(this.locX, (this.boundingBox.b + this.boundingBox.e) / 2.0D, this.locZ);
+ this.move(this.motX, this.motY, this.motZ);
+ boolean flag = (int) this.lastX != (int) this.locX || (int) this.lastY != (int) this.locY || (int) this.lastZ != (int) this.locZ;
+
+ if (flag || this.ticksLived % 25 == 0) {
+ if (this.world.getType(MathHelper.floor(this.locX), MathHelper.floor(this.locY), MathHelper.floor(this.locZ)).getMaterial() == Material.LAVA) {
+ this.motY = 0.20000000298023224D;
+ this.motX = (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F);
+ this.motZ = (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.2F);
+ this.makeSound("random.fizz", 0.4F, 2.0F + this.random.nextFloat() * 0.4F);
+ }
- if (!this.world.isStatic) {
- this.e();
+ if (!this.world.isStatic) {
+ this.k();
+ }
}
- }
-
- float f = 0.98F;
- if (this.onGround) {
- f = 0.58800006F;
- int i = this.world.getTypeId(MathHelper.floor(this.locX), MathHelper.floor(this.boundingBox.b) - 1, MathHelper.floor(this.locZ));
+ float f = 0.98F;
- if (i > 0) {
- f = Block.byId[i].frictionFactor * 0.98F;
+ if (this.onGround) {
+ f = this.world.getType(MathHelper.floor(this.locX), MathHelper.floor(this.boundingBox.b) - 1, MathHelper.floor(this.locZ)).frictionFactor * 0.98F;
}
- }
- this.motX *= (double) f;
- this.motY *= 0.9800000190734863D;
- this.motZ *= (double) f;
- if (this.onGround) {
- this.motY *= -0.5D;
- }
+ this.motX *= (double) f;
+ this.motY *= 0.9800000190734863D;
+ this.motZ *= (double) f;
+ if (this.onGround) {
+ this.motY *= -0.5D;
+ }
- // ++this.age; // CraftBukkit - Moved up
- if (!this.world.isStatic && this.age >= 6000) {
- // CraftBukkit start
- if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
- this.age = 0;
- return;
+ // ++this.age; // CraftBukkit - Moved up
+ if (!this.world.isStatic && this.age >= 6000) {
+ // CraftBukkit start
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callItemDespawnEvent(this).isCancelled()) {
+ this.age = 0;
+ return;
+ }
+ // CraftBukkit end
+ this.die();
}
- // CraftBukkit end
- this.die();
}
}
- private void e() {
+ private void k() {
Iterator iterator = this.world.a(EntityItem.class, this.boundingBox.grow(0.5D, 0.0D, 0.5D)).iterator();
while (iterator.hasNext()) {
@@ -134,6 +139,8 @@ public class EntityItem extends Entity {
return false;
} else if (itemstack1.hasTag() && !itemstack1.getTag().equals(itemstack.getTag())) {
return false;
+ } else if (itemstack1.getItem() == null) {
+ return false;
} else if (itemstack1.getItem().n() && itemstack1.getData() != itemstack.getData()) {
return false;
} else if (itemstack1.count < itemstack.count) {
@@ -153,11 +160,11 @@ public class EntityItem extends Entity {
}
}
- public void c() {
+ public void e() {
this.age = 4800;
}
- public boolean I() {
+ public boolean N() {
return this.world.a(this.boundingBox, Material.WATER, (Entity) this);
}
@@ -168,12 +175,12 @@ public class EntityItem extends Entity {
public boolean damageEntity(DamageSource damagesource, float f) {
if (this.isInvulnerable()) {
return false;
- } else if (this.getItemStack() != null && this.getItemStack().id == Item.NETHER_STAR.id && damagesource.c()) {
+ } else if (this.getItemStack() != null && this.getItemStack().getItem() == Items.NETHER_STAR && damagesource.c()) {
return false;
} else {
- this.K();
- this.d = (int) ((float) this.d - f);
- if (this.d <= 0) {
+ this.Q();
+ this.e = (int) ((float) this.e - f);
+ if (this.e <= 0) {
this.die();
}
@@ -182,16 +189,32 @@ public class EntityItem extends Entity {
}
public void b(NBTTagCompound nbttagcompound) {
- nbttagcompound.setShort("Health", (short) ((byte) this.d));
+ nbttagcompound.setShort("Health", (short) ((byte) this.e));
nbttagcompound.setShort("Age", (short) this.age);
+ if (this.j() != null) {
+ nbttagcompound.setString("Thrower", this.f);
+ }
+
+ if (this.i() != null) {
+ nbttagcompound.setString("Owner", this.g);
+ }
+
if (this.getItemStack() != null) {
- nbttagcompound.setCompound("Item", this.getItemStack().save(new NBTTagCompound()));
+ nbttagcompound.set("Item", this.getItemStack().save(new NBTTagCompound()));
}
}
public void a(NBTTagCompound nbttagcompound) {
- this.d = nbttagcompound.getShort("Health") & 255;
+ this.e = nbttagcompound.getShort("Health") & 255;
this.age = nbttagcompound.getShort("Age");
+ if (nbttagcompound.hasKey("Owner")) {
+ this.g = nbttagcompound.getString("Owner");
+ }
+
+ if (nbttagcompound.hasKey("Thrower")) {
+ this.f = nbttagcompound.getString("Thrower");
+ }
+
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("Item");
// CraftBukkit start
@@ -236,24 +259,36 @@ public class EntityItem extends Entity {
}
// CraftBukkit end
- if (this.pickupDelay == 0 && entityhuman.inventory.pickup(itemstack)) {
- if (itemstack.id == Block.LOG.id) {
+ if (this.pickupDelay == 0 && (this.g == null || 6000 - this.age <= 200 || this.g.equals(entityhuman.getName())) && entityhuman.inventory.pickup(itemstack)) {
+ if (itemstack.getItem() == Item.getItemOf(Blocks.LOG)) {
entityhuman.a((Statistic) AchievementList.g);
}
- if (itemstack.id == Item.LEATHER.id) {
+ if (itemstack.getItem() == Item.getItemOf(Blocks.LOG2)) {
+ entityhuman.a((Statistic) AchievementList.g);
+ }
+
+ if (itemstack.getItem() == Items.LEATHER) {
entityhuman.a((Statistic) AchievementList.t);
}
- if (itemstack.id == Item.DIAMOND.id) {
+ if (itemstack.getItem() == Items.DIAMOND) {
entityhuman.a((Statistic) AchievementList.w);
}
- if (itemstack.id == Item.BLAZE_ROD.id) {
- entityhuman.a((Statistic) AchievementList.z);
+ if (itemstack.getItem() == Items.BLAZE_ROD) {
+ entityhuman.a((Statistic) AchievementList.A);
}
- this.makeSound("random.pop", 0.2F, ((this.random.nextFloat() - this.random.nextFloat()) * 0.7F + 1.0F) * 2.0F);
+ if (itemstack.getItem() == Items.DIAMOND && this.j() != null) {
+ EntityHuman entityhuman1 = this.world.a(this.j());
+
+ if (entityhuman1 != null && entityhuman1 != entityhuman) {
+ entityhuman1.a((Statistic) AchievementList.x);
+ }
+ }
+
+ this.world.makeSound(entityhuman, "random.pop", 0.2F, ((this.random.nextFloat() - this.random.nextFloat()) * 0.7F + 1.0F) * 2.0F);
entityhuman.receive(this, i);
if (itemstack.count <= 0) {
this.die();
@@ -262,18 +297,18 @@ public class EntityItem extends Entity {
}
}
- public String getLocalizedName() {
+ public String getName() {
return LocaleI18n.get("item." + this.getItemStack().a());
}
- public boolean aq() {
+ public boolean av() {
return false;
}
public void b(int i) {
super.b(i);
if (!this.world.isStatic) {
- this.e();
+ this.k();
}
}
@@ -282,10 +317,10 @@ public class EntityItem extends Entity {
if (itemstack == null) {
if (this.world != null) {
- this.world.getLogger().severe("Item entity " + this.id + " has no item?!");
+ d.error("Item entity " + this.getId() + " has no item?!");
}
- return new ItemStack(Block.STONE);
+ return new ItemStack(Blocks.STONE);
} else {
return itemstack;
}
@@ -295,4 +330,20 @@ public class EntityItem extends Entity {
this.getDataWatcher().watch(10, itemstack);
this.getDataWatcher().h(10);
}
+
+ public String i() {
+ return this.g;
+ }
+
+ public void a(String s) {
+ this.g = s;
+ }
+
+ public String j() {
+ return this.f;
+ }
+
+ public void b(String s) {
+ this.f = s;
+ }
}