From ae19f2c46f8232239488d8218ce69a6e5e5ae22a Mon Sep 17 00:00:00 2001 From: Xephi Date: Thu, 21 Mar 2013 13:43:10 +0100 Subject: [PATCH] Implement Dropper interface. Adds BUKKIT-3750 --- .../net/minecraft/server/BlockDropper.java | 2 +- .../bukkit/craftbukkit/block/CraftBlock.java | 2 + .../craftbukkit/block/CraftDropper.java | 50 +++++++++++++++++++ .../craftbukkit/inventory/CraftInventory.java | 4 ++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java diff --git a/src/main/java/net/minecraft/server/BlockDropper.java b/src/main/java/net/minecraft/server/BlockDropper.java index afcc8a84ad..856aadab7a 100644 --- a/src/main/java/net/minecraft/server/BlockDropper.java +++ b/src/main/java/net/minecraft/server/BlockDropper.java @@ -16,7 +16,7 @@ public class BlockDropper extends BlockDispenser { return new TileEntityDropper(); } - protected void dispense(World world, int i, int j, int k) { + public void dispense(World world, int i, int j, int k) { // CraftBukkit - protected -> public SourceBlock sourceblock = new SourceBlock(world, i, j, k); TileEntityDispenser tileentitydispenser = (TileEntityDispenser) sourceblock.getTileEntity(); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index ecd08eb6f8..f1c0e4199a 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -249,6 +249,8 @@ public class CraftBlock implements Block { return new CraftFurnace(this); case DISPENSER: return new CraftDispenser(this); + case DROPPER: + return new CraftDropper(this); case HOPPER: return new CraftHopper(this); case MOB_SPAWNER: diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java b/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java new file mode 100644 index 0000000000..ace93e0840 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftDropper.java @@ -0,0 +1,50 @@ +package org.bukkit.craftbukkit.block; + +import net.minecraft.server.BlockDropper; +import net.minecraft.server.TileEntityDropper; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Dropper; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.inventory.CraftInventory; +import org.bukkit.inventory.Inventory; + +public class CraftDropper extends CraftBlockState implements Dropper { + private final CraftWorld world; + private final TileEntityDropper dropper; + + public CraftDropper(final Block block) { + super(block); + + world = (CraftWorld) block.getWorld(); + dropper = (TileEntityDropper) world.getTileEntityAt(getX(), getY(), getZ()); + } + + public Inventory getInventory() { + return new CraftInventory(dropper); + } + + public void drop() { + Block block = getBlock(); + + synchronized (block) { + if (block.getType() == Material.DROPPER) { + BlockDropper drop = (BlockDropper) net.minecraft.server.Block.DROPPER; + + drop.dispense(world.getHandle(), getX(), getY(), getZ()); + } + } + } + + @Override + public boolean update(boolean force) { + boolean result = super.update(force); + + if (result) { + dropper.update(); + } + + return result; + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index ed2e9dc1d5..9231bf70c4 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -15,6 +15,7 @@ import net.minecraft.server.PlayerInventory; import net.minecraft.server.TileEntityBeacon; import net.minecraft.server.TileEntityBrewingStand; import net.minecraft.server.TileEntityDispenser; +import net.minecraft.server.TileEntityDropper; import net.minecraft.server.TileEntityFurnace; import org.apache.commons.lang.Validate; @@ -423,10 +424,13 @@ public class CraftInventory implements Inventory { } public InventoryType getType() { + // Thanks to Droppers extending Dispensers, order is important. if (inventory instanceof InventoryCrafting) { return inventory.getSize() >= 9 ? InventoryType.WORKBENCH : InventoryType.CRAFTING; } else if (inventory instanceof PlayerInventory) { return InventoryType.PLAYER; + } else if (inventory instanceof TileEntityDropper) { + return InventoryType.DROPPER; } else if (inventory instanceof TileEntityDispenser) { return InventoryType.DISPENSER; } else if (inventory instanceof TileEntityFurnace) {