Search in sources :

Example 1 with LockableTileEntity

use of net.minecraft.tileentity.LockableTileEntity in project Magma-1.16.x by magmafoundation.

the class CraftHumanEntity method openInventory.

@Override
public InventoryView openInventory(Inventory inventory) {
    if (!(getHandle() instanceof ServerPlayerEntity))
        return null;
    ServerPlayerEntity player = (ServerPlayerEntity) getHandle();
    Container formerContainer = getHandle().containerMenu;
    INamedContainerProvider iinventory = null;
    if (inventory instanceof CraftInventoryDoubleChest) {
        iinventory = ((CraftInventoryDoubleChest) inventory).tile;
    } else if (inventory instanceof CraftInventory) {
        CraftInventory craft = (CraftInventory) inventory;
        if (craft.getInventory() instanceof INamedContainerProvider) {
            iinventory = (INamedContainerProvider) craft.getInventory();
        }
    }
    if (iinventory instanceof INamedContainerProvider) {
        if (iinventory instanceof TileEntity) {
            TileEntity te = (TileEntity) iinventory;
            if (!te.hasLevel()) {
                te.setLevelAndPosition(getHandle().level, getHandle().blockPosition());
            }
        }
    }
    ContainerType<?> container = CraftContainer.getNotchInventoryType(inventory);
    if (iinventory instanceof LockableTileEntity) {
        getHandle().openMenu(iinventory);
    } else {
        openCustomInventory(inventory, player, container);
    }
    if (getHandle().containerMenu == formerContainer) {
        return null;
    }
    getHandle().containerMenu.checkReachable = false;
    return getHandle().containerMenu.getBukkitView();
}
Also used : LockableTileEntity(net.minecraft.tileentity.LockableTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) CraftInventory(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory) Container(net.minecraft.inventory.container.Container) CraftContainer(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer) LockableTileEntity(net.minecraft.tileentity.LockableTileEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryDoubleChest)

Aggregations

ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 Container (net.minecraft.inventory.container.Container)1 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)1 LockableTileEntity (net.minecraft.tileentity.LockableTileEntity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 CraftContainer (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer)1 CraftInventory (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory)1 CraftInventoryDoubleChest (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryDoubleChest)1