This commit is contained in:
MachineMuse 2013-01-10 00:37:11 -07:00
parent 8b053a2d45
commit 4196caf663
2 changed files with 33 additions and 3 deletions

View file

@ -202,6 +202,22 @@ public class ItemUtils {
return slots; return slots;
} }
public static List<Integer> findInInventoryForCost(List<ItemStack> workingUpgradeCost,
InventoryPlayer inventory) {
List<Integer> slots = new LinkedList<Integer>();
for (ItemStack stackInCost : workingUpgradeCost) {
int found = 0;
for (int i = 0; i < inventory.getSizeInventory() && found < stackInCost.stackSize; i++) {
ItemStack stackInInventory = inventory.getStackInSlot(i);
if (isSameItem(stackInInventory, stackInCost)) {
found += stackInInventory.stackSize;
slots.add(i);
}
}
}
return slots;
}
/** /**
* Checks the given NBTTag and returns the value if it exists, otherwise 0. * Checks the given NBTTag and returns the value if it exists, otherwise 0.
*/ */

View file

@ -7,6 +7,9 @@ import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import universalelectricity.core.implement.IItemElectric;
import net.machinemuse.powersuits.common.Config;
import net.machinemuse.powersuits.item.ItemUtils; import net.machinemuse.powersuits.item.ItemUtils;
import net.machinemuse.powersuits.powermodule.PowerModule; import net.machinemuse.powersuits.powermodule.PowerModule;
import net.machinemuse.powersuits.powermodule.ModuleManager; import net.machinemuse.powersuits.powermodule.ModuleManager;
@ -76,11 +79,22 @@ public class MusePacketInstallModuleRequest extends MusePacket {
List<ItemStack> cost = moduleType.getInstallCost(); List<ItemStack> cost = moduleType.getInstallCost();
if (ItemUtils.hasInInventory(cost, playerEntity.inventory)) { if (ItemUtils.hasInInventory(cost, playerEntity.inventory)) {
List<Integer> slots = ItemUtils.deleteFromInventory( List<Integer> slots = ItemUtils.findInInventoryForCost(cost, playerEntity.inventory);
double amps=0;
double volts = ItemUtils.getAsModular(stack.getItem()).getVoltage();
for(Integer slot : slots) {
ItemStack stackInSlot = playerEntity.inventory.getStackInSlot(slot);
if(stackInSlot != null && stackInSlot.getItem() instanceof IItemElectric) {
IItemElectric electricItem = (IItemElectric)stackInSlot.getItem();
amps = electricItem.getJoules(stackInSlot)/volts;
}
}
List<Integer> slotsToUpdate = ItemUtils.deleteFromInventory(
cost, inventory); cost, inventory);
ItemUtils.itemAddModule(stack, moduleType); ItemUtils.itemAddModule(stack, moduleType);
slots.add(this.itemSlot); slots.add(this.itemSlot);
for (Integer slotiter : slots) { ItemUtils.getAsModular(stack.getItem()).onReceive(amps, volts, stack);
for (Integer slotiter : slotsToUpdate) {
MusePacket reply = new MusePacketInventoryRefresh( MusePacket reply = new MusePacketInventoryRefresh(
player, player,
slotiter, inventory.getStackInSlot(slotiter)); slotiter, inventory.getStackInSlot(slotiter));