Search in sources :

Example 11 with CraftInventory

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory 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 12 with CraftInventory

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory 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 13 with CraftInventory

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory in project LoliServer by Loli-Server.

the class CraftLootTable method fillInventory.

@Override
public void fillInventory(Inventory inventory, Random random, LootContext context) {
    net.minecraft.loot.LootContext nmsContext = convertContext(context);
    CraftInventory craftInventory = (CraftInventory) inventory;
    IInventory handle = craftInventory.getInventory();
    // TODO: When events are added, call event here w/ custom reason?
    getHandle().fill(handle, nmsContext);
}
Also used : IInventory(net.minecraft.inventory.IInventory) CraftInventory(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory)

Example 14 with CraftInventory

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory in project Denizen-For-Bukkit by DenizenScript.

the class ImprovedOfflinePlayerImpl method getEnderChest.

@Override
public Inventory getEnderChest() {
    if (offlineEnderChests.containsKey(getUniqueId())) {
        return offlineEnderChests.get(getUniqueId());
    }
    PlayerEnderChestContainer endchest = new PlayerEnderChestContainer(null);
    endchest.fromTag(((CompoundTagImpl) this.compound).toNMSTag().getList("EnderItems", 10));
    org.bukkit.inventory.Inventory inv = new CraftInventory(endchest);
    offlineEnderChests.put(getUniqueId(), inv);
    return inv;
}
Also used : PlayerEnderChestContainer(net.minecraft.world.inventory.PlayerEnderChestContainer) CraftInventory(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory) Inventory(org.bukkit.inventory.Inventory) CompoundTagImpl(com.denizenscript.denizen.nms.v1_18.impl.jnbt.CompoundTagImpl)

Example 15 with CraftInventory

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory in project Denizen-For-Bukkit by DenizenScript.

the class ImprovedOfflinePlayerImpl method getEnderChest.

@Override
public Inventory getEnderChest() {
    if (offlineEnderChests.containsKey(getUniqueId())) {
        return offlineEnderChests.get(getUniqueId());
    }
    PlayerEnderChestContainer endchest = new PlayerEnderChestContainer(null);
    endchest.fromTag(((CompoundTagImpl) this.compound).toNMSTag().getList("EnderItems", 10));
    org.bukkit.inventory.Inventory inv = new CraftInventory(endchest);
    offlineEnderChests.put(getUniqueId(), inv);
    return inv;
}
Also used : PlayerEnderChestContainer(net.minecraft.world.inventory.PlayerEnderChestContainer) CraftInventory(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory) Inventory(org.bukkit.inventory.Inventory) CompoundTagImpl(com.denizenscript.denizen.nms.v1_17.impl.jnbt.CompoundTagImpl)

Aggregations

Field (java.lang.reflect.Field)16 Inventory (org.bukkit.inventory.Inventory)11 CraftInventory (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory)9 CraftInventory (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory)6 PlayerEnderChestContainer (net.minecraft.world.inventory.PlayerEnderChestContainer)5 CraftInventory (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftInventory)4 IInventory (net.minecraft.inventory.IInventory)3 INamedContainerProvider (net.minecraft.inventory.container.INamedContainerProvider)3 CraftInventory (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventory)3 CraftInventoryDoubleChest (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryDoubleChest)3 CompoundTagImpl (com.denizenscript.denizen.nms.v1_16.impl.jnbt.CompoundTagImpl)2 CompoundTagImpl (com.denizenscript.denizen.nms.v1_17.impl.jnbt.CompoundTagImpl)2 CompoundTagImpl (com.denizenscript.denizen.nms.v1_18.impl.jnbt.CompoundTagImpl)2 ChestBlock (net.minecraft.block.ChestBlock)2 MenuProvider (net.minecraft.world.MenuProvider)2 CraftInventory (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventory)2 CraftInventory (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventory)2 CraftInventory (org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventory)2 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)2 CraftInventoryDoubleChest (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryDoubleChest)2