Search in sources :

Example 1 with IPhantomSlot

use of buildcraft.lib.gui.slot.IPhantomSlot in project BuildCraft by BuildCraft.

the class ContainerBC_Neptune method slotClick.

@Nullable
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickType, EntityPlayer player) {
    Slot slot = slotId < 0 ? null : this.inventorySlots.get(slotId);
    if (slot == null) {
        return super.slotClick(slotId, dragType, clickType, player);
    }
    ItemStack playerStack = player.inventory.getItemStack();
    if (slot instanceof IPhantomSlot) {
        IPhantomSlot phantom = (IPhantomSlot) slot;
        if (playerStack.isEmpty()) {
            slot.putStack(ItemStack.EMPTY);
        } else if (!StackUtil.canMerge(playerStack, StackUtil.asNonNull(slot.getStack()))) {
            ItemStack copy = playerStack.copy();
            copy.setCount(1);
            slot.putStack(copy);
        } else if (phantom.canAdjustCount()) {
            ItemStack stack = slot.getStack();
            if (stack.getCount() < stack.getMaxStackSize()) {
                stack.grow(1);
                slot.putStack(stack);
            }
        }
        return playerStack;
    }
    return super.slotClick(slotId, dragType, clickType, player);
}
Also used : IPhantomSlot(buildcraft.lib.gui.slot.IPhantomSlot) Slot(net.minecraft.inventory.Slot) IPhantomSlot(buildcraft.lib.gui.slot.IPhantomSlot) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 2 with IPhantomSlot

use of buildcraft.lib.gui.slot.IPhantomSlot in project BuildCraft by BuildCraft.

the class BuildCraftContainer method slotClickPhantom.

// @Override
// public ItemStack slotClick(int slotNum, int mouseButton, ClickType clickType, EntityPlayer player) {
// Slot slot = slotNum < 0 ? null : (Slot) this.inventorySlots.get(slotNum);
// if (slot instanceof IPhantomSlot) {
// return slotClickPhantom(slot, mouseButton, clickType, player);
// }
// return super.slotClick(slotNum, mouseButton, clickType, player);
// }
private ItemStack slotClickPhantom(Slot slot, int mouseButton, ClickType clickType, EntityPlayer player) {
    ItemStack stack = null;
    if (mouseButton == 2) {
        if (((IPhantomSlot) slot).canAdjustCount()) {
            slot.putStack(null);
        }
    } else if (mouseButton == 0 || mouseButton == 1) {
        InventoryPlayer playerInv = player.inventory;
        slot.onSlotChanged();
        ItemStack stackSlot = slot.getStack();
        ItemStack stackHeld = playerInv.getItemStack();
        if (stackSlot != null) {
            stack = stackSlot.copy();
        }
        if (stackSlot == null) {
            if (stackHeld != null && slot.isItemValid(stackHeld)) {
                fillPhantomSlot(slot, stackHeld, mouseButton, clickType);
            }
        } else if (stackHeld == null) {
            adjustPhantomSlot(slot, mouseButton, clickType);
            slot.onPickupFromSlot(player, playerInv.getItemStack());
        } else if (slot.isItemValid(stackHeld)) {
            if (StackUtil.canMerge(stackSlot, stackHeld)) {
                adjustPhantomSlot(slot, mouseButton, clickType);
            } else {
                fillPhantomSlot(slot, stackHeld, mouseButton, clickType);
            }
        }
    }
    return stack;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) IPhantomSlot(buildcraft.lib.gui.slot.IPhantomSlot) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IPhantomSlot

use of buildcraft.lib.gui.slot.IPhantomSlot in project BuildCraft by BuildCraft.

the class GuiBuildCraft method mouseClickMove.

@Override
protected void mouseClickMove(int mouseX, int mouseY, int mouseButton, long time) {
    int mX = mouseX - guiLeft;
    int mY = mouseY - guiTop;
    for (Widget widget : container.getWidgets()) {
        if (widget.hidden) {
            continue;
        }
        widget.handleMouseMove(mX, mY, mouseButton, time);
    }
    Slot slot = getSlotAtPosition(mouseX, mouseY);
    if (mouseButton == 1 && slot instanceof IPhantomSlot) {
        return;
    }
    super.mouseClickMove(mouseX, mouseY, mouseButton, time);
}
Also used : Widget(buildcraft.core.lib.gui.widgets.Widget) IPhantomSlot(buildcraft.lib.gui.slot.IPhantomSlot) Slot(net.minecraft.inventory.Slot) IPhantomSlot(buildcraft.lib.gui.slot.IPhantomSlot)

Aggregations

IPhantomSlot (buildcraft.lib.gui.slot.IPhantomSlot)3 Slot (net.minecraft.inventory.Slot)2 ItemStack (net.minecraft.item.ItemStack)2 Widget (buildcraft.core.lib.gui.widgets.Widget)1 Nullable (javax.annotation.Nullable)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1