diff options
author | Xephi <xephirot59@gmail.com> | 2013-03-21 13:43:10 +0100 |
---|---|---|
committer | Nate Mortensen <nate.richard.mortensen@gmail.com> | 2013-03-21 22:33:16 -0600 |
commit | ae19f2c46f8232239488d8218ce69a6e5e5ae22a (patch) | |
tree | 119995329787f451fc5921b42f87325b0c5fbc88 /src/main/java/org | |
parent | 978de7e9da9218c736b20612356db7da4c9daef7 (diff) | |
download | craftbukkit-ae19f2c46f8232239488d8218ce69a6e5e5ae22a.tar craftbukkit-ae19f2c46f8232239488d8218ce69a6e5e5ae22a.tar.gz craftbukkit-ae19f2c46f8232239488d8218ce69a6e5e5ae22a.tar.lz craftbukkit-ae19f2c46f8232239488d8218ce69a6e5e5ae22a.tar.xz craftbukkit-ae19f2c46f8232239488d8218ce69a6e5e5ae22a.zip |
Implement Dropper interface. Adds BUKKIT-3750
Diffstat (limited to 'src/main/java/org')
3 files changed, 56 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index ecd08eb6..f1c0e419 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 00000000..ace93e08 --- /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 ed2e9dc1..9231bf70 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) { |