From 2642fbdf7e3612c5f8804b4f8fada6fea7641065 Mon Sep 17 00:00:00 2001 From: Michael Limiero Date: Sun, 17 Mar 2013 15:50:34 -0400 Subject: [PATCH] Make CraftMinecartHopper work as InventoryHolder. Adds BUKKIT-3796 --- .../bukkit/craftbukkit/entity/CraftHumanEntity.java | 11 +++++++---- .../craftbukkit/entity/CraftMinecartHopper.java | 11 ++++++++++- .../bukkit/craftbukkit/inventory/CraftInventory.java | 4 ++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index 6dc5b1eb68..eac032a803 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -4,6 +4,7 @@ import java.util.Set; import net.minecraft.server.Container; import net.minecraft.server.EntityHuman; +import net.minecraft.server.EntityMinecartHopper; import net.minecraft.server.EntityPlayer; import net.minecraft.server.Packet100OpenWindow; import net.minecraft.server.Packet101CloseWindow; @@ -193,14 +194,14 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { break; case DISPENSER: if (craftinv.getInventory() instanceof TileEntityDispenser) { - getHandle().openDispenser((TileEntityDispenser)craftinv.getInventory()); + getHandle().openDispenser((TileEntityDispenser) craftinv.getInventory()); } else { openCustomInventory(inventory, player, 3); } break; case FURNACE: if (craftinv.getInventory() instanceof TileEntityFurnace) { - getHandle().openFurnace((TileEntityFurnace)craftinv.getInventory()); + getHandle().openFurnace((TileEntityFurnace) craftinv.getInventory()); } else { openCustomInventory(inventory, player, 2); } @@ -210,7 +211,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { break; case BREWING: if (craftinv.getInventory() instanceof TileEntityBrewingStand) { - getHandle().openBrewingStand((TileEntityBrewingStand)craftinv.getInventory()); + getHandle().openBrewingStand((TileEntityBrewingStand) craftinv.getInventory()); } else { openCustomInventory(inventory, player, 5); } @@ -220,7 +221,9 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { break; case HOPPER: if (craftinv.getInventory() instanceof TileEntityHopper) { - getHandle().openHopper((TileEntityHopper)craftinv.getInventory()); + getHandle().openHopper((TileEntityHopper) craftinv.getInventory()); + } else if (craftinv.getInventory() instanceof EntityMinecartHopper) { + getHandle().openMinecartHopper((EntityMinecartHopper) craftinv.getInventory()); } break; case CREATIVE: diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartHopper.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartHopper.java index e34d082dd6..9bd358d3e9 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartHopper.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartHopper.java @@ -3,20 +3,29 @@ package org.bukkit.craftbukkit.entity; import net.minecraft.server.EntityMinecartHopper; import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.entity.EntityType; import org.bukkit.entity.minecart.HopperMinecart; +import org.bukkit.inventory.Inventory; final class CraftMinecartHopper extends CraftMinecart implements HopperMinecart { + private final CraftInventory inventory; + CraftMinecartHopper(CraftServer server, EntityMinecartHopper entity) { super(server, entity); + inventory = new CraftInventory(entity); } @Override public String toString() { - return "CraftMinecartHopper"; + return "CraftMinecartHopper{" + "inventory=" + inventory + '}'; } public EntityType getType() { return EntityType.MINECART_HOPPER; } + + public Inventory getInventory() { + return inventory; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java index 118e0d2eb8..ed2e9dc1d5 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java @@ -6,6 +6,7 @@ import java.util.ListIterator; import net.minecraft.server.ContainerAnvilInventory; import net.minecraft.server.ContainerEnchantTableInventory; +import net.minecraft.server.IHopper; import net.minecraft.server.IInventory; import net.minecraft.server.InventoryCrafting; import net.minecraft.server.InventoryEnderChest; @@ -15,7 +16,6 @@ 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; @@ -445,7 +445,7 @@ public class CraftInventory implements Inventory { return InventoryType.BEACON; } else if (inventory instanceof ContainerAnvilInventory) { return InventoryType.ANVIL; - } else if (inventory instanceof TileEntityHopper) { + } else if (inventory instanceof IHopper) { return InventoryType.HOPPER; } else { return InventoryType.CHEST;