Search in sources :

Example 6 with CraftInventory

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory in project PublicCrafters by BananaPuncher714.

the class ContainerManager_v1_8_R3 method getLocation.

public Location getLocation(Inventory inventory) {
    if (inventory == null) {
        return null;
    }
    if (!(inventory instanceof CraftInventory)) {
        return null;
    }
    try {
        Field ic = CraftInventory.class.getDeclaredField("inventory");
        ic.setAccessible(true);
        Object crafting = ic.get(inventory);
        if (crafting instanceof CustomInventoryCrafting) {
            CustomInventoryCrafting table = (CustomInventoryCrafting) crafting;
            return table.getLocation();
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return null;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory) Field(java.lang.reflect.Field)

Example 7 with CraftInventory

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory in project PublicCrafters by BananaPuncher714.

the class ContainerManager_v1_18_R2 method getLocation.

public Location getLocation(Inventory inventory) {
    if (inventory == null) {
        return null;
    }
    if (!(inventory instanceof CraftInventory)) {
        return null;
    }
    try {
        Field ic = CraftInventory.class.getDeclaredField("inventory");
        ic.setAccessible(true);
        Object crafting = ic.get(inventory);
        if (crafting instanceof CustomInventoryCrafting) {
            CustomInventoryCrafting table = (CustomInventoryCrafting) crafting;
            return table.getLocation();
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return null;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory) Field(java.lang.reflect.Field)

Example 8 with CraftInventory

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftInventory in project PublicCrafters by BananaPuncher714.

the class ContainerManager_v1_9_R2 method getLocation.

public Location getLocation(Inventory inventory) {
    if (inventory == null) {
        return null;
    }
    if (!(inventory instanceof CraftInventory)) {
        return null;
    }
    try {
        Field ic = CraftInventory.class.getDeclaredField("inventory");
        ic.setAccessible(true);
        Object crafting = ic.get(inventory);
        if (crafting instanceof CustomInventoryCrafting) {
            CustomInventoryCrafting table = (CustomInventoryCrafting) crafting;
            return table.getLocation();
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return null;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftInventory) Field(java.lang.reflect.Field)

Example 9 with CraftInventory

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

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

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