diff --git a/src/main/java/net/minecraft/server/EntityArrow.java b/src/main/java/net/minecraft/server/EntityArrow.java index 8b39b7bae9..fdad5657d8 100644 --- a/src/main/java/net/minecraft/server/EntityArrow.java +++ b/src/main/java/net/minecraft/server/EntityArrow.java @@ -370,6 +370,7 @@ public class EntityArrow extends Entity implements IProjectile { EntityItem item = new EntityItem(this.world, this.locX, this.locY, this.locZ, itemstack); PlayerPickupItemEvent event = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), new org.bukkit.craftbukkit.entity.CraftItem(this.world.getServer(), this, item), 0); + event.setCancelled(!entityhuman.canPickUpLoot); this.world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { diff --git a/src/main/java/net/minecraft/server/EntityItem.java b/src/main/java/net/minecraft/server/EntityItem.java index 93f93863e9..a1dca1628d 100644 --- a/src/main/java/net/minecraft/server/EntityItem.java +++ b/src/main/java/net/minecraft/server/EntityItem.java @@ -204,6 +204,7 @@ public class EntityItem extends Entity { if (this.pickupDelay <= 0 && canHold > 0) { this.itemStack.count = canHold; PlayerPickupItemEvent event = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining); + event.setCancelled(!entityhuman.canPickUpLoot); this.world.getServer().getPluginManager().callEvent(event); this.itemStack.count = canHold + remaining; diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java index c36c25b235..458e44f039 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -82,11 +82,11 @@ public abstract class EntityLiving extends Entity { private ChunkCoordinates bP = new ChunkCoordinates(0, 0, 0); private float bQ = -1.0F; private ItemStack[] equipment = new ItemStack[5]; - protected float[] dropChances = new float[5]; + public float[] dropChances = new float[5]; // CraftBukkit - protected -> public private ItemStack[] bS = new ItemStack[5]; public boolean bp = false; public int bq = 0; - protected boolean canPickUpLoot = false; + public boolean canPickUpLoot = false; // CraftBukkit - protected -> public public boolean persistent = !this.bj(); // CraftBukkit - private -> public, change value protected int bs; protected double bt; diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index 190fe582e9..7dcdc7d2db 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -28,6 +28,7 @@ import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer; import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.inventory.EntityEquipment; import org.bukkit.permissions.PermissibleBase; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionAttachment; @@ -56,6 +57,10 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { return inventory; } + public EntityEquipment getEquipment() { + return inventory; + } + public Inventory getEnderChest() { return enderChest; } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index 12c660eddb..68baf91197 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -27,6 +27,7 @@ import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.inventory.CraftEntityEquipment; import org.bukkit.entity.Arrow; import org.bukkit.entity.Egg; import org.bukkit.entity.Entity; @@ -40,14 +41,21 @@ import org.bukkit.entity.Projectile; import org.bukkit.entity.SmallFireball; import org.bukkit.entity.Snowball; import org.bukkit.entity.WitherSkull; +import org.bukkit.inventory.EntityEquipment; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.BlockIterator; import org.bukkit.util.Vector; public class CraftLivingEntity extends CraftEntity implements LivingEntity { + private CraftEntityEquipment equipment; + public CraftLivingEntity(final CraftServer server, final EntityLiving entity) { super(server, entity); + + if (!(this instanceof HumanEntity)) { + equipment = new CraftEntityEquipment(this); + } } public int getHealth() { @@ -312,4 +320,16 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { public void setRemoveWhenFarAway(boolean remove) { getHandle().persistent = !remove; } + + public EntityEquipment getEquipment() { + return equipment; + } + + public void setCanPickupItems(boolean pickup) { + getHandle().canPickUpLoot = pickup; + } + + public boolean canPickupItems() { + return getHandle().canPickUpLoot; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java new file mode 100644 index 0000000000..f4066ca786 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java @@ -0,0 +1,142 @@ +package org.bukkit.craftbukkit.inventory; + +import org.bukkit.craftbukkit.entity.CraftLivingEntity; +import org.bukkit.entity.Entity; +import org.bukkit.inventory.EntityEquipment; +import org.bukkit.inventory.ItemStack; + +public class CraftEntityEquipment implements EntityEquipment { + private static final int WEAPON_SLOT = 0; + private static final int HELMET_SLOT = 1; + private static final int CHEST_SLOT = 2; + private static final int LEG_SLOT = 3; + private static final int BOOT_SLOT = 4; + private static final int INVENTORY_SLOTS = 5; + + private final CraftLivingEntity entity; + + public CraftEntityEquipment(CraftLivingEntity entity) { + this.entity = entity; + } + + public ItemStack getItemInHand() { + return getEquipment(WEAPON_SLOT); + } + + public void setItemInHand(ItemStack stack) { + setEquipment(WEAPON_SLOT, stack); + } + + public ItemStack getHelmet() { + return getEquipment(HELMET_SLOT); + } + + public void setHelmet(ItemStack helmet) { + setEquipment(HELMET_SLOT, helmet); + } + + public ItemStack getChestplate() { + return getEquipment(CHEST_SLOT); + } + + public void setChestplate(ItemStack chestplate) { + setEquipment(CHEST_SLOT, chestplate); + } + + public ItemStack getLeggings() { + return getEquipment(LEG_SLOT); + } + + public void setLeggings(ItemStack leggings) { + setEquipment(LEG_SLOT, leggings); + } + + public ItemStack getBoots() { + return getEquipment(BOOT_SLOT); + } + + public void setBoots(ItemStack boots) { + setEquipment(BOOT_SLOT, boots); + } + + public ItemStack[] getArmorContents() { + ItemStack[] armor = new ItemStack[INVENTORY_SLOTS - 1]; + for(int slot = HELMET_SLOT; slot < INVENTORY_SLOTS; slot++) { + armor[slot - 1] = getEquipment(slot); + } + return armor; + } + + public void setArmorContents(ItemStack[] items) { + for(int slot = HELMET_SLOT; slot < INVENTORY_SLOTS; slot++) { + ItemStack equipment = items != null && slot <= items.length ? items[slot - 1] : null; + setEquipment(slot, equipment); + } + } + + private ItemStack getEquipment(int slot) { + return CraftItemStack.asBukkitStack(entity.getHandle().getEquipment(slot)); + } + + private void setEquipment(int slot, ItemStack stack) { + entity.getHandle().setEquipment(slot, CraftItemStack.createNMSItemStack(stack)); + } + + public void clear() { + for(int i = 0; i < INVENTORY_SLOTS; i++) { + setEquipment(i, null); + } + } + + public Entity getHolder() { + return entity; + } + + public float getItemInHandDropChance() { + return getDropChance(WEAPON_SLOT); + } + + public void setItemInHandDropChance(float chance) { + setDropChance(WEAPON_SLOT, chance); + } + + public float getHelmetDropChance() { + return getDropChance(HELMET_SLOT); + } + + public void setHelmetDropChance(float chance) { + setDropChance(HELMET_SLOT, chance); + } + + public float getChestPlateDropChance() { + return getDropChance(CHEST_SLOT); + } + + public void setChestPlateDropChance(float chance) { + setDropChance(CHEST_SLOT, chance); + } + + public float getLeggingsDropChance() { + return getDropChance(LEG_SLOT); + } + + public void setLeggingsDropChance(float chance) { + setDropChance(LEG_SLOT, chance); + } + + public float getBootsDropChance() { + return getDropChance(BOOT_SLOT); + } + + public void setBootsDropChance(float chance) { + setDropChance(BOOT_SLOT, chance); + } + + private void setDropChance(int slot, float chance) { + entity.getHandle().dropChances[slot] = chance - 0.1F; + } + + private float getDropChance(int slot) { + return entity.getHandle().dropChances[slot] + 0.1F; + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java index 70ea942b18..9b7172d3bc 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryPlayer.java @@ -3,9 +3,10 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.server.PlayerInventory; import org.bukkit.entity.HumanEntity; +import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.ItemStack; -public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.inventory.PlayerInventory { +public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.inventory.PlayerInventory, EntityEquipment { public CraftInventoryPlayer(net.minecraft.server.PlayerInventory inventory) { super(inventory); } @@ -120,4 +121,44 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i public HumanEntity getHolder() { return (HumanEntity) inventory.getOwner(); } + + public float getItemInHandDropChance() { + return 1; + } + + public void setItemInHandDropChance(float chance) { + throw new UnsupportedOperationException(); + } + + public float getHelmetDropChance() { + return 1; + } + + public void setHelmetDropChance(float chance) { + throw new UnsupportedOperationException(); + } + + public float getChestPlateDropChance() { + return 1; + } + + public void setChestPlateDropChance(float chance) { + throw new UnsupportedOperationException(); + } + + public float getLeggingsDropChance() { + return 1; + } + + public void setLeggingsDropChance(float chance) { + throw new UnsupportedOperationException(); + } + + public float getBootsDropChance() { + return 1; + } + + public void setBootsDropChance(float chance) { + throw new UnsupportedOperationException(); + } }