use of net.minecraft.entity.player.InventoryPlayer in project BluePower by Qmunity.
the class ProjectTableOverlayHandler method findInventoryQuantities.
@SuppressWarnings("unchecked")
private void findInventoryQuantities(GuiContainer gui, List<DistributedIngred> ingredStacks) {
for (// work out how much we have to go round
Slot slot : // work out how much we have to go round
(List<Slot>) gui.inventorySlots.inventorySlots) {
if (slot.getHasStack() && (slot.inventory instanceof TileProjectTable || slot.inventory instanceof InventoryPlayer)) {
ItemStack pstack = slot.getStack();
DistributedIngred istack = findIngred(ingredStacks, pstack);
if (istack != null)
istack.invAmount += pstack.stackSize;
}
}
}
use of net.minecraft.entity.player.InventoryPlayer in project BluePower by Qmunity.
the class ProjectTableOverlayHandler method moveIngredients.
@SuppressWarnings("unchecked")
private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int quantity) {
for (IngredientDistribution distrib : assignedIngredients) {
ItemStack pstack = distrib.permutation;
int transferCap = quantity * pstack.stackSize;
int transferred = 0;
int destSlotIndex = 0;
Slot dest = distrib.slots[0];
int slotTransferred = 0;
int slotTransferCap = pstack.getMaxStackSize();
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots) {
if (!slot.getHasStack() || !(slot.inventory instanceof TileProjectTable) && !(slot.inventory instanceof InventoryPlayer))
continue;
ItemStack stack = slot.getStack();
if (!InventoryUtils.canStack(stack, pstack))
continue;
FastTransferManager.clickSlot(gui, slot.slotNumber);
int amount = Math.min(transferCap - transferred, stack.stackSize);
for (int c = 0; c < amount; c++) {
FastTransferManager.clickSlot(gui, dest.slotNumber, 1);
transferred++;
slotTransferred++;
if (slotTransferred >= slotTransferCap) {
destSlotIndex++;
if (destSlotIndex == distrib.slots.length) {
dest = null;
break;
}
dest = distrib.slots[destSlotIndex];
slotTransferred = 0;
}
}
FastTransferManager.clickSlot(gui, slot.slotNumber);
if (transferred >= transferCap || dest == null)
break;
}
}
}
use of net.minecraft.entity.player.InventoryPlayer in project BluePower by Qmunity.
the class ContainerGhosts method slotClickPhantom.
/**
* This method is copied from the BuildCraft code, which can be found here: https://github.com/BuildCraft/BuildCraft
* @author CovertJaguar <http://www.railcraft.info>
*/
private ItemStack slotClickPhantom(Slot slot, int mouseButton, int modifier, EntityPlayer player) {
ItemStack stack = null;
if (mouseButton == 2) {
if (((IPhantomSlot) slot).canAdjust()) {
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, modifier);
}
} else if (stackHeld == null) {
adjustPhantomSlot(slot, mouseButton, modifier);
slot.onPickupFromSlot(player, playerInv.getItemStack());
} else if (slot.isItemValid(stackHeld)) {
if (canStacksMerge(stackSlot, stackHeld)) {
adjustPhantomSlot(slot, mouseButton, modifier);
} else {
fillPhantomSlot(slot, stackHeld, mouseButton, modifier);
}
}
}
return stack;
}
use of net.minecraft.entity.player.InventoryPlayer in project VoodooCraft by Mod-DevCafeTeam.
the class TileDeathGlyph method readPlayerInventory.
/**
* Reads the player's inventory from this tile entity and saves it to the player given
*/
public void readPlayerInventory(EntityPlayer player) {
InventoryPlayer playerInv = player.inventory;
List<ItemStack> excessStacks = new ArrayList<>();
excessStacks.addAll(setInvStackList(playerInv.mainInventory, readStacksFromNBT(playerInventory, "main")));
excessStacks.addAll(setInvStackList(playerInv.armorInventory, readStacksFromNBT(playerInventory, "armour")));
excessStacks.addAll(setInvStackList(playerInv.offHandInventory, readStacksFromNBT(playerInventory, "offhand")));
//Try add the rest of the items which couldn't be placed
for (ItemStack stack : excessStacks) if (playerInv.addItemStackToInventory(stack))
//Drop item if can't fit in inventory
player.dropItem(stack, true);
}
use of net.minecraft.entity.player.InventoryPlayer in project ConvenientAdditions by Necr0.
the class SlotFake method slotClick.
@Override
public ItemStack slotClick(Container container, int button, ClickType mode, EntityPlayer player) {
InventoryPlayer inventoryplayer = player.inventory;
ItemStack held = inventoryplayer.getItemStack().copy();
if (!held.isEmpty())
held.setCount(1);
if (mode == ClickType.THROW) {
this.putStack(ItemStack.EMPTY);
} else if (mode == ClickType.SWAP) {
return ItemStack.EMPTY;
} else if ((mode == ClickType.PICKUP || mode == ClickType.PICKUP_ALL) && (button == 0 || button == 1)) {
if (!held.isEmpty()) {
putStack(held);
} else {
putStack(ItemStack.EMPTY);
}
} else if ((mode == ClickType.QUICK_MOVE) && (button == 0 || button == 1)) {
this.putStack(ItemStack.EMPTY);
}
container.detectAndSendChanges();
return ItemStack.EMPTY;
}
Aggregations