use of net.minecraft.inventory.Slot in project BetterStorage by copygirl.
the class ItemBackpack method onArmorTick.
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
// Replace the armor slot with a custom one, so the player
// can't unequip the backpack when there's items inside.
int index = 5 + armorType;
Slot slotBefore = player.inventoryContainer.getSlot(index);
if (slotBefore instanceof SlotArmorBackpack)
return;
int slotIndex = player.inventory.getSizeInventory() - getChestSlotOffset(player) - armorType;
SlotArmorBackpack slot = new SlotArmorBackpack(player.inventory, slotIndex, 8, 8 + armorType * 18);
slot.slotNumber = index;
player.inventoryContainer.inventorySlots.set(index, slot);
}
use of net.minecraft.inventory.Slot in project BetterStorage by copygirl.
the class ContainerBetterStorage method transferStackInSlot.
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotId) {
ItemStack stack = null;
Slot slot = (Slot) inventorySlots.get(slotId);
// If slot isn't empty and item can be stacked.
if ((slot != null) && slot.getHasStack()) {
ItemStack slotStack = slot.getStack();
stack = slotStack.copy();
if (!mergeItemStack(slotStack, transferStart(slotId), transferEnd(slotId), transferDirection(slotId)))
return null;
if (slotStack.stackSize != 0)
slot.onSlotChanged();
else
slot.putStack(null);
}
return stack;
}
use of net.minecraft.inventory.Slot in project compactsolars by cpw.
the class ContainerCompactSolar method transferStackInSlot.
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int i) {
ItemStack itemstack = null;
Slot slot = (Slot) inventorySlots.get(i);
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (i == 0) {
if (!mergeItemStack(itemstack1, 1, 37, true)) {
return null;
}
} else if (i >= 1 && i < 28) {
if (!mergeItemStack(itemstack1, 28, 37, false)) {
return null;
}
} else if (i >= 28 && i < 37) {
if (!mergeItemStack(itemstack1, 1, 27, false)) {
return null;
}
} else if (!mergeItemStack(itemstack1, 1, 37, false)) {
return null;
}
if (itemstack1.stackSize == 0) {
slot.putStack(null);
} else {
slot.onSlotChanged();
}
if (itemstack1.stackSize != itemstack.stackSize) {
slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
} else {
return null;
}
}
return itemstack;
}
use of net.minecraft.inventory.Slot 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.inventory.Slot in project BluePower by Qmunity.
the class ProjectTableOverlayHandler method assignIngredSlots.
private Slot[][] assignIngredSlots(GuiContainer gui, List<PositionedStack> ingredients, List<IngredientDistribution> assignedIngredients) {
// setup the slot map
Slot[][] recipeSlots = mapIngredSlots(gui, ingredients);
HashMap<Slot, Integer> distribution = new HashMap<Slot, Integer>();
for (Slot[] recipeSlot : recipeSlots) for (Slot slot : recipeSlot) if (!distribution.containsKey(slot))
distribution.put(slot, -1);
HashSet<Slot> avaliableSlots = new HashSet<Slot>(distribution.keySet());
HashSet<Integer> remainingIngreds = new HashSet<Integer>();
ArrayList<LinkedList<Slot>> assignedSlots = new ArrayList<LinkedList<Slot>>();
for (int i = 0; i < ingredients.size(); i++) {
remainingIngreds.add(i);
assignedSlots.add(new LinkedList<Slot>());
}
while (avaliableSlots.size() > 0 && remainingIngreds.size() > 0) {
for (Iterator<Integer> iterator = remainingIngreds.iterator(); iterator.hasNext(); ) {
int i = iterator.next();
boolean assigned = false;
DistributedIngred istack = assignedIngredients.get(i).distrib;
for (Slot slot : recipeSlots[i]) {
if (avaliableSlots.contains(slot)) {
avaliableSlots.remove(slot);
if (slot.getHasStack())
continue;
istack.numSlots++;
assignedSlots.get(i).add(slot);
assigned = true;
break;
}
}
if (!assigned || istack.numSlots * istack.stack.getMaxStackSize() >= istack.invAmount)
iterator.remove();
}
}
for (int i = 0; i < ingredients.size(); i++) assignedIngredients.get(i).slots = assignedSlots.get(i).toArray(new Slot[0]);
return recipeSlots;
}
Aggregations