Search in sources :

Example 1 with CraftInventoryView

use of org.bukkit.craftbukkit.v.inventory.CraftInventoryView in project Arclight by IzzelAliz.

the class ContainerMixin method getBukkitView.

// todo check this
public InventoryView getBukkitView() {
    if (bukkitView == null) {
        PlayerEntity candidate = null;
        Set<IInventory> set = new HashSet<>();
        for (Slot slot : this.inventorySlots) {
            if (slot.inventory != null) {
                if (slot.inventory instanceof PlayerInventory) {
                    if (candidate != null && ((PlayerInventory) slot.inventory).player != candidate) {
                        ArclightMod.LOGGER.warn("Duplicate PlayerInventory inside {}, previous {}, new {}", this, candidate, slot.inventory);
                    }
                    candidate = ((PlayerInventory) slot.inventory).player;
                } else {
                    set.add(slot.inventory);
                }
            }
        }
        if (candidate == null) {
            if (ArclightCaptures.getContainerOwner() != null) {
                candidate = ArclightCaptures.getContainerOwner();
            } else {
                throw new RuntimeException("candidate cannot be null");
            }
        }
        CraftResultInventory resultCandidate = null;
        IInventory mainCandidate = null;
        for (IInventory inventory : set) {
            if (inventory instanceof CraftResultInventory) {
                resultCandidate = (CraftResultInventory) inventory;
            } else {
                mainCandidate = inventory;
            }
        }
        Inventory inv;
        if (mainCandidate == null && resultCandidate != null) {
            mainCandidate = resultCandidate;
            resultCandidate = null;
        }
        if (mainCandidate != null) {
            if (resultCandidate != null) {
                inv = new org.bukkit.craftbukkit.v.inventory.CraftResultInventory(mainCandidate, resultCandidate);
            } else {
                inv = new CraftInventory(mainCandidate);
            }
        } else {
            // container has no slots
            inv = new CraftInventoryCustom(((PlayerEntityBridge) candidate).bridge$getBukkitEntity(), 0);
        }
        bukkitView = new CraftInventoryView(((PlayerEntityBridge) candidate).bridge$getBukkitEntity(), inv, (Container) (Object) this);
    }
    return bukkitView;
}
Also used : IInventory(net.minecraft.inventory.IInventory) CraftInventoryCustom(org.bukkit.craftbukkit.v.inventory.CraftInventoryCustom) CraftInventory(org.bukkit.craftbukkit.v.inventory.CraftInventory) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) PlayerInventory(net.minecraft.entity.player.PlayerInventory) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Container(net.minecraft.inventory.container.Container) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) Slot(net.minecraft.inventory.container.Slot) CraftResultInventory(net.minecraft.inventory.CraftResultInventory) Inventory(org.bukkit.inventory.Inventory) CraftInventory(org.bukkit.craftbukkit.v.inventory.CraftInventory) CraftResultInventory(net.minecraft.inventory.CraftResultInventory) PlayerInventory(net.minecraft.entity.player.PlayerInventory) IInventory(net.minecraft.inventory.IInventory) HashSet(java.util.HashSet)

Example 2 with CraftInventoryView

use of org.bukkit.craftbukkit.v.inventory.CraftInventoryView in project Arclight by IzzelAliz.

the class DispenserContainerMixin method getBukkitView.

@Override
public CraftInventoryView getBukkitView() {
    if (bukkitEntity != null) {
        return bukkitEntity;
    }
    CraftInventory inventory = new CraftInventory(this.dispenserInventory);
    bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
    return bukkitEntity;
}
Also used : CraftInventory(org.bukkit.craftbukkit.v.inventory.CraftInventory) Container(net.minecraft.inventory.container.Container) DispenserContainer(net.minecraft.inventory.container.DispenserContainer) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)

Example 3 with CraftInventoryView

use of org.bukkit.craftbukkit.v.inventory.CraftInventoryView in project Arclight by IzzelAliz.

the class EnchantmentContainerMixin method getBukkitView.

@Override
public CraftInventoryView getBukkitView() {
    if (bukkitEntity != null) {
        return bukkitEntity;
    }
    CraftInventoryEnchanting inventory = new CraftInventoryEnchanting(this.tableInventory);
    bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
    return bukkitEntity;
}
Also used : CraftInventoryEnchanting(org.bukkit.craftbukkit.v.inventory.CraftInventoryEnchanting) Container(net.minecraft.inventory.container.Container) EnchantmentContainer(net.minecraft.inventory.container.EnchantmentContainer) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)

Example 4 with CraftInventoryView

use of org.bukkit.craftbukkit.v.inventory.CraftInventoryView in project Arclight by IzzelAliz.

the class AbstractFurnaceContainerMixin method getBukkitView.

@Override
public CraftInventoryView getBukkitView() {
    if (bukkitEntity != null) {
        return bukkitEntity;
    }
    CraftInventoryFurnace inventory = new CraftInventoryFurnace((AbstractFurnaceTileEntity) this.furnaceInventory);
    bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
    return bukkitEntity;
}
Also used : Container(net.minecraft.inventory.container.Container) AbstractFurnaceContainer(net.minecraft.inventory.container.AbstractFurnaceContainer) CraftInventoryFurnace(org.bukkit.craftbukkit.v.inventory.CraftInventoryFurnace) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)

Example 5 with CraftInventoryView

use of org.bukkit.craftbukkit.v.inventory.CraftInventoryView in project Arclight by IzzelAliz.

the class BrewingStandContainerMixin method getBukkitView.

@Override
public CraftInventoryView getBukkitView() {
    if (bukkitEntity != null) {
        return bukkitEntity;
    }
    CraftInventoryBrewer inventory = new CraftInventoryBrewer(this.tileBrewingStand);
    bukkitEntity = new CraftInventoryView(((PlayerEntityBridge) this.playerInventory.player).bridge$getBukkitEntity(), inventory, (Container) (Object) this);
    return bukkitEntity;
}
Also used : Container(net.minecraft.inventory.container.Container) BrewingStandContainer(net.minecraft.inventory.container.BrewingStandContainer) CraftInventoryView(org.bukkit.craftbukkit.v.inventory.CraftInventoryView) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) CraftInventoryBrewer(org.bukkit.craftbukkit.v.inventory.CraftInventoryBrewer)

Aggregations

Container (net.minecraft.inventory.container.Container)16 CraftInventoryView (org.bukkit.craftbukkit.v.inventory.CraftInventoryView)16 PlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge)14 CraftInventory (org.bukkit.craftbukkit.v.inventory.CraftInventory)6 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)2 PlayerInventory (net.minecraft.entity.player.PlayerInventory)2 CraftInventoryCrafting (org.bukkit.craftbukkit.v.inventory.CraftInventoryCrafting)2 HashSet (java.util.HashSet)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 CraftResultInventory (net.minecraft.inventory.CraftResultInventory)1 DoubleSidedInventory (net.minecraft.inventory.DoubleSidedInventory)1 IInventory (net.minecraft.inventory.IInventory)1 AbstractFurnaceContainer (net.minecraft.inventory.container.AbstractFurnaceContainer)1 BeaconContainer (net.minecraft.inventory.container.BeaconContainer)1 BrewingStandContainer (net.minecraft.inventory.container.BrewingStandContainer)1 CartographyContainer (net.minecraft.inventory.container.CartographyContainer)1 ChestContainer (net.minecraft.inventory.container.ChestContainer)1 DispenserContainer (net.minecraft.inventory.container.DispenserContainer)1 EnchantmentContainer (net.minecraft.inventory.container.EnchantmentContainer)1