From e0416ca7fb4057496d1fcd9159e3602a44416d18 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Tue, 1 Feb 2011 23:16:25 +0000 Subject: [PATCH] Added CraftDispenser.dispense() --- .../net/minecraft/server/BlockDispenser.java | 3 +- .../craftbukkit/block/CraftDispenser.java | 97 +++++++++++-------- 2 files changed, 59 insertions(+), 41 deletions(-) diff --git a/src/main/java/net/minecraft/server/BlockDispenser.java b/src/main/java/net/minecraft/server/BlockDispenser.java index 7a0231f785..aabbd03e97 100644 --- a/src/main/java/net/minecraft/server/BlockDispenser.java +++ b/src/main/java/net/minecraft/server/BlockDispenser.java @@ -84,7 +84,8 @@ public class BlockDispenser extends BlockContainer { } } - private void b(World world, int i, int j, int k, Random random) { + // Craftbukkit - following method should be public + public void b(World world, int i, int j, int k, Random random) { int l = world.getData(i, j, k); float f = 0.0F; float f1 = 0.0F; diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java b/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java index 6c51214030..0a023326cb 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftDispenser.java @@ -1,40 +1,57 @@ -package org.bukkit.craftbukkit.block; - -import net.minecraft.server.TileEntityDispenser; -import org.bukkit.block.Block; -import org.bukkit.block.Dispenser; -import org.bukkit.craftbukkit.CraftWorld; -import org.bukkit.craftbukkit.inventory.CraftInventory; -import org.bukkit.inventory.Inventory; - -/** - * Represents a dispenser. - * - * @author sk89q - */ -public class CraftDispenser extends CraftBlockState implements Dispenser { - private final CraftWorld world; - private final TileEntityDispenser dispenser; - - public CraftDispenser(final Block block) { - super(block); - - world = (CraftWorld)block.getWorld(); - dispenser = (TileEntityDispenser)world.getTileEntityAt(getX(), getY(), getZ()); - } - - public Inventory getInventory() { - return new CraftInventory(dispenser); - } - - @Override - public boolean update(boolean force) { - boolean result = super.update(force); - - if (result) { - dispenser.d(); - } - - return result; - } -} +package org.bukkit.craftbukkit.block; + +import java.util.Random; +import net.minecraft.server.BlockDispenser; +import net.minecraft.server.TileEntityDispenser; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Dispenser; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.inventory.CraftInventory; +import org.bukkit.inventory.Inventory; + +/** + * Represents a dispenser. + * + * @author sk89q + */ +public class CraftDispenser extends CraftBlockState implements Dispenser { + private final CraftWorld world; + private final TileEntityDispenser dispenser; + + public CraftDispenser(final Block block) { + super(block); + + world = (CraftWorld)block.getWorld(); + dispenser = (TileEntityDispenser)world.getTileEntityAt(getX(), getY(), getZ()); + } + + public Inventory getInventory() { + return new CraftInventory(dispenser); + } + + public boolean dispense() { + Block block = getBlock(); + + synchronized (block) { + if (block.getType() == Material.DISPENSER) { + BlockDispenser dispense = (BlockDispenser)net.minecraft.server.Block.DISPENSER; + dispense.b(world.getHandle(), getX(), getY(), getZ(), new Random()); + return true; + } else { + return false; + } + } + } + + @Override + public boolean update(boolean force) { + boolean result = super.update(force); + + if (result) { + dispenser.d(); + } + + return result; + } +}