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);
}
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;
}
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);
}
Aggregations