Search in sources :

Example 1 with CraftInventoryDoubleChest

use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryDoubleChest in project Mohist by MohistMC.

the class CraftChest method getInventory.

@Override
public Inventory getInventory() {
    CraftInventory inventory = (CraftInventory) this.getBlockInventory();
    if (!isPlaced() || isWorldGeneration()) {
        return inventory;
    }
    // The logic here is basically identical to the logic in ChestBlock.interact
    CraftWorld world = (CraftWorld) this.getWorld();
    ChestBlock blockChest = (ChestBlock) (this.getType() == Material.CHEST ? Blocks.CHEST : Blocks.TRAPPED_CHEST);
    MenuProvider nms = blockChest.getMenuProvider(data, world.getHandle(), this.getPosition(), true);
    if (nms instanceof ChestBlock.DoubleInventory) {
        inventory = new CraftInventoryDoubleChest((ChestBlock.DoubleInventory) nms);
    }
    return inventory;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory) ChestBlock(net.minecraft.world.level.block.ChestBlock) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryDoubleChest) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) MenuProvider(net.minecraft.world.MenuProvider)

Example 2 with CraftInventoryDoubleChest

use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryDoubleChest in project Mohist by MohistMC.

the class CraftHumanEntity method openInventory.

@Override
public InventoryView openInventory(Inventory inventory) {
    if (!(getHandle() instanceof ServerPlayer))
        return null;
    ServerPlayer player = (ServerPlayer) getHandle();
    AbstractContainerMenu formerContainer = getHandle().containerMenu;
    MenuProvider iinventory = null;
    if (inventory instanceof CraftInventoryDoubleChest) {
        iinventory = ((CraftInventoryDoubleChest) inventory).tile;
    } else if (inventory instanceof CraftInventoryLectern) {
        iinventory = ((CraftInventoryLectern) inventory).tile;
    } else if (inventory instanceof CraftInventory) {
        CraftInventory craft = (CraftInventory) inventory;
        if (craft.getInventory() instanceof MenuProvider) {
            iinventory = (MenuProvider) craft.getInventory();
        }
    }
    if (iinventory instanceof MenuProvider) {
        if (iinventory instanceof BlockEntity) {
            BlockEntity te = (BlockEntity) iinventory;
            if (!te.hasLevel()) {
                te.setLevel(getHandle().level);
            }
        }
    }
    MenuType<?> container = CraftContainer.getNotchInventoryType(inventory);
    if (iinventory instanceof MenuProvider) {
        getHandle().openMenu(iinventory);
    } else {
        openCustomInventory(inventory, player, container);
    }
    if (getHandle().containerMenu == formerContainer) {
        return null;
    }
    getHandle().containerMenu.checkReachable = false;
    return getHandle().containerMenu.getBukkitView();
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftInventoryLectern(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryLectern) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryDoubleChest) MenuProvider(net.minecraft.world.MenuProvider) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 3 with CraftInventoryDoubleChest

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

the class CraftChest method getInventory.

@Override
public Inventory getInventory() {
    CraftInventory inventory = (CraftInventory) this.getBlockInventory();
    if (!isPlaced()) {
        return inventory;
    }
    // The logic here is basically identical to the logic in BlockChest.interact
    int x = this.getX();
    int y = this.getY();
    int z = this.getZ();
    CraftWorld world = (CraftWorld) this.getWorld();
    int id;
    if (world.getBlockTypeIdAt(x, y, z) == Material.CHEST.getId()) {
        id = Material.CHEST.getId();
    } else if (world.getBlockTypeIdAt(x, y, z) == Material.TRAPPED_CHEST.getId()) {
        id = Material.TRAPPED_CHEST.getId();
    } else {
        throw new IllegalStateException("CraftChest is not a chest but is instead " + world.getBlockAt(x, y, z));
    }
    if (world.getBlockTypeIdAt(x - 1, y, z) == id) {
        CraftInventory left = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(new BlockPos(x - 1, y, z)));
        inventory = new CraftInventoryDoubleChest(left, inventory);
    }
    if (world.getBlockTypeIdAt(x + 1, y, z) == id) {
        CraftInventory right = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(new BlockPos(x + 1, y, z)));
        inventory = new CraftInventoryDoubleChest(inventory, right);
    }
    if (world.getBlockTypeIdAt(x, y, z - 1) == id) {
        CraftInventory left = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(new BlockPos(x, y, z - 1)));
        inventory = new CraftInventoryDoubleChest(left, inventory);
    }
    if (world.getBlockTypeIdAt(x, y, z + 1) == id) {
        CraftInventory right = new CraftInventory((TileEntityChest) world.getHandle().getTileEntity(new BlockPos(x, y, z + 1)));
        inventory = new CraftInventoryDoubleChest(inventory, right);
    }
    return inventory;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory) BlockPos(net.minecraft.util.math.BlockPos) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryDoubleChest) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 4 with CraftInventoryDoubleChest

use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryDoubleChest 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)

Example 5 with CraftInventoryDoubleChest

use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryDoubleChest in project Magma-1.16.x by magmafoundation.

the class CraftChest method getInventory.

@Override
public Inventory getInventory() {
    CraftInventory inventory = (CraftInventory) this.getBlockInventory();
    if (!isPlaced()) {
        return inventory;
    }
    // The logic here is basically identical to the logic in ChestBlock.interact
    CraftWorld world = (CraftWorld) this.getWorld();
    ChestBlock blockChest = (ChestBlock) (this.getType() == Material.CHEST ? Blocks.CHEST : Blocks.TRAPPED_CHEST);
    INamedContainerProvider nms = blockChest.getMenuProvider(data, world.getHandle(), this.getPosition());
    if (nms instanceof ChestBlock.DoubleInventory) {
        inventory = new CraftInventoryDoubleChest((ChestBlock.DoubleInventory) nms);
    }
    return inventory;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) ChestBlock(net.minecraft.block.ChestBlock) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryDoubleChest) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Aggregations

INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)3 CraftInventory (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory)3 CraftInventoryDoubleChest (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryDoubleChest)3 ChestBlock (net.minecraft.block.ChestBlock)2 MenuProvider (net.minecraft.world.MenuProvider)2 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)2 CraftInventory (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory)2 CraftInventoryDoubleChest (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryDoubleChest)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 Container (net.minecraft.inventory.container.Container)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 LockableTileEntity (net.minecraft.tileentity.LockableTileEntity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)1 ChestBlock (net.minecraft.world.level.block.ChestBlock)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)1 CraftInventory (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory)1 CraftInventoryDoubleChest (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryDoubleChest)1