summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Limiero <mike5713@gmail.com>2013-03-16 00:46:35 -0400
committerTravis Watkins <amaranth@ubuntu.com>2013-03-17 12:59:27 -0500
commitd802168cd58d4717fa3dcfee90a1f71063bad010 (patch)
treeacf927bb3b76849d30bf4c6a6fa2bb64d50cbaf7 /src/main/java
parent6f68fc4ba4aeff5091b6fa9bd5df70c573a2ce53 (diff)
downloadcraftbukkit-d802168cd58d4717fa3dcfee90a1f71063bad010.tar
craftbukkit-d802168cd58d4717fa3dcfee90a1f71063bad010.tar.gz
craftbukkit-d802168cd58d4717fa3dcfee90a1f71063bad010.tar.lz
craftbukkit-d802168cd58d4717fa3dcfee90a1f71063bad010.tar.xz
craftbukkit-d802168cd58d4717fa3dcfee90a1f71063bad010.zip
Implement Hopper block state and inventory methods. Adds BUKKIT-3749
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java2
-rw-r--r--src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java35
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java8
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java3
4 files changed, 47 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
index 02c7d676..90dae627 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 HOPPER:
+ return new CraftHopper(this);
case MOB_SPAWNER:
return new CraftCreatureSpawner(this);
case NOTE_BLOCK:
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java b/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java
new file mode 100644
index 00000000..6489e153
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftHopper.java
@@ -0,0 +1,35 @@
+package org.bukkit.craftbukkit.block;
+
+import net.minecraft.server.TileEntityHopper;
+import org.bukkit.block.Block;
+import org.bukkit.block.Hopper;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.inventory.Inventory;
+
+public class CraftHopper extends CraftBlockState implements Hopper {
+ private final CraftWorld world;
+ private final TileEntityHopper hopper;
+
+ public CraftHopper(final Block block) {
+ super(block);
+
+ world = (CraftWorld) block.getWorld();
+ hopper = (TileEntityHopper) world.getTileEntityAt(getX(), getY(), getZ());
+ }
+
+ public Inventory getInventory() {
+ return new CraftInventory(hopper);
+ }
+
+ @Override
+ public boolean update(boolean force) {
+ boolean result = super.update(force);
+
+ if (result) {
+ hopper.update();
+ }
+
+ return result;
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
index e79e5384..6dc5b1eb 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
@@ -10,6 +10,7 @@ import net.minecraft.server.Packet101CloseWindow;
import net.minecraft.server.TileEntityBrewingStand;
import net.minecraft.server.TileEntityDispenser;
import net.minecraft.server.TileEntityFurnace;
+import net.minecraft.server.TileEntityHopper;
import org.bukkit.GameMode;
import org.bukkit.Location;
@@ -215,7 +216,12 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
}
break;
case ENCHANTING:
- openCustomInventory(inventory, player, 4);
+ openCustomInventory(inventory, player, 4);
+ break;
+ case HOPPER:
+ if (craftinv.getInventory() instanceof TileEntityHopper) {
+ getHandle().openHopper((TileEntityHopper)craftinv.getInventory());
+ }
break;
case CREATIVE:
case CRAFTING:
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
index c2085a82..118e0d2e 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.TileEntityBeacon;
import net.minecraft.server.TileEntityBrewingStand;
import net.minecraft.server.TileEntityDispenser;
import net.minecraft.server.TileEntityFurnace;
+import net.minecraft.server.TileEntityHopper;
import org.apache.commons.lang.Validate;
import org.bukkit.entity.HumanEntity;
@@ -444,6 +445,8 @@ public class CraftInventory implements Inventory {
return InventoryType.BEACON;
} else if (inventory instanceof ContainerAnvilInventory) {
return InventoryType.ANVIL;
+ } else if (inventory instanceof TileEntityHopper) {
+ return InventoryType.HOPPER;
} else {
return InventoryType.CHEST;
}