Search in sources :

Example 1 with CraftInventoryLectern

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryLectern 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

ServerPlayer (net.minecraft.server.level.ServerPlayer)1 MenuProvider (net.minecraft.world.MenuProvider)1 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 CraftInventory (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventory)1 CraftInventoryDoubleChest (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryDoubleChest)1 CraftInventoryLectern (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryLectern)1