Search in sources :

Example 1 with InventoryWrapper

use of org.bukkit.craftbukkit.v1_12_R1.inventory.InventoryWrapper in project Magma by magmafoundation.

the class CraftHumanEntity method openInventory.

public InventoryView openInventory(Inventory inventory) {
    if (!(getHandle() instanceof EntityPlayerMP))
        return null;
    EntityPlayerMP player = (EntityPlayerMP) getHandle();
    InventoryType type = inventory.getType();
    Container formerContainer = getHandle().openContainer;
    IInventory iinventory = (inventory instanceof CraftInventory) ? ((CraftInventory) inventory).getInventory() : new InventoryWrapper(inventory);
    switch(type) {
        case PLAYER:
        case CHEST:
        case ENDER_CHEST:
            getHandle().displayGUIChest(iinventory);
            break;
        case DISPENSER:
            if (iinventory instanceof TileEntityDispenser) {
                getHandle().displayGUIChest((TileEntityDispenser) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:dispenser");
            }
            break;
        case DROPPER:
            if (iinventory instanceof TileEntityDropper) {
                getHandle().displayGUIChest((TileEntityDropper) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:dropper");
            }
            break;
        case FURNACE:
            if (iinventory instanceof TileEntityFurnace) {
                getHandle().displayGUIChest((TileEntityFurnace) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:furnace");
            }
            break;
        case WORKBENCH:
            openCustomInventory(inventory, player, "minecraft:crafting_table");
            break;
        case BREWING:
            if (iinventory instanceof TileEntityBrewingStand) {
                getHandle().displayGUIChest((TileEntityBrewingStand) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:brewing_stand");
            }
            break;
        case ENCHANTING:
            openCustomInventory(inventory, player, "minecraft:enchanting_table");
            break;
        case HOPPER:
            if (iinventory instanceof TileEntityHopper) {
                getHandle().displayGUIChest((TileEntityHopper) iinventory);
            } else if (iinventory instanceof EntityMinecartHopper) {
                getHandle().displayGUIChest((EntityMinecartHopper) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:hopper");
            }
            break;
        case BEACON:
            if (iinventory instanceof TileEntityBeacon) {
                getHandle().displayGUIChest((TileEntityBeacon) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:beacon");
            }
            break;
        case ANVIL:
            if (iinventory instanceof BlockAnvil.Anvil) {
                getHandle().displayGui((BlockAnvil.Anvil) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:anvil");
            }
            break;
        case SHULKER_BOX:
            if (iinventory instanceof TileEntityShulkerBox) {
                getHandle().displayGUIChest((TileEntityShulkerBox) iinventory);
            } else {
                openCustomInventory(inventory, player, "minecraft:shulker_box");
            }
            break;
        case CREATIVE:
        case CRAFTING:
            throw new IllegalArgumentException("Can't open a " + type + " inventory!");
    }
    if (getHandle().openContainer == formerContainer) {
        return null;
    }
    getHandle().openContainer.checkReachable = false;
    return getHandle().openContainer.getBukkitView();
}
Also used : IInventory(net.minecraft.inventory.IInventory) TileEntityHopper(net.minecraft.tileentity.TileEntityHopper) CraftInventory(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory) TileEntityBeacon(net.minecraft.tileentity.TileEntityBeacon) InventoryWrapper(org.bukkit.craftbukkit.v1_12_R1.inventory.InventoryWrapper) TileEntityDropper(net.minecraft.tileentity.TileEntityDropper) InventoryType(org.bukkit.event.inventory.InventoryType) BlockAnvil(net.minecraft.block.BlockAnvil) TileEntityFurnace(net.minecraft.tileentity.TileEntityFurnace) TileEntityDispenser(net.minecraft.tileentity.TileEntityDispenser) BlockAnvil(net.minecraft.block.BlockAnvil) TileEntityShulkerBox(net.minecraft.tileentity.TileEntityShulkerBox) EntityMinecartHopper(net.minecraft.entity.item.EntityMinecartHopper) CraftContainer(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer) Container(net.minecraft.inventory.Container) TileEntityBrewingStand(net.minecraft.tileentity.TileEntityBrewingStand) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Aggregations

BlockAnvil (net.minecraft.block.BlockAnvil)1 EntityMinecartHopper (net.minecraft.entity.item.EntityMinecartHopper)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 Container (net.minecraft.inventory.Container)1 IInventory (net.minecraft.inventory.IInventory)1 TileEntityBeacon (net.minecraft.tileentity.TileEntityBeacon)1 TileEntityBrewingStand (net.minecraft.tileentity.TileEntityBrewingStand)1 TileEntityDispenser (net.minecraft.tileentity.TileEntityDispenser)1 TileEntityDropper (net.minecraft.tileentity.TileEntityDropper)1 TileEntityFurnace (net.minecraft.tileentity.TileEntityFurnace)1 TileEntityHopper (net.minecraft.tileentity.TileEntityHopper)1 TileEntityShulkerBox (net.minecraft.tileentity.TileEntityShulkerBox)1 CraftContainer (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer)1 CraftInventory (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory)1 InventoryWrapper (org.bukkit.craftbukkit.v1_12_R1.inventory.InventoryWrapper)1 InventoryType (org.bukkit.event.inventory.InventoryType)1