diff options
| author | Foghrye4 <foghrye4@gmail.com> | 2017-03-21 17:34:07 +0300 |
|---|---|---|
| committer | Foghrye4 <foghrye4@gmail.com> | 2017-03-21 17:34:07 +0300 |
| commit | 7305ba719930ea3fbf8aa987aeec48b33cdbd82e (patch) | |
| tree | 2307517925d965cd9228c8649013b07639987846 /ihl/processing/invslots/IHLInvSlotOutput.java | |
| parent | 5cb4c6e24033cf337812390d99a6817d24d21eab (diff) | |
Oregen
Diffstat (limited to 'ihl/processing/invslots/IHLInvSlotOutput.java')
| -rw-r--r-- | ihl/processing/invslots/IHLInvSlotOutput.java | 188 |
1 files changed, 72 insertions, 116 deletions
diff --git a/ihl/processing/invslots/IHLInvSlotOutput.java b/ihl/processing/invslots/IHLInvSlotOutput.java index 7e10ab3..d683221 100644 --- a/ihl/processing/invslots/IHLInvSlotOutput.java +++ b/ihl/processing/invslots/IHLInvSlotOutput.java @@ -16,114 +16,88 @@ import ic2.core.block.invslot.InvSlotOutput; import ihl.recipes.RecipeOutputItemStack;
import ihl.utils.IHLUtils;
-public class IHLInvSlotOutput extends InvSlotOutput{
+public class IHLInvSlotOutput extends InvSlotOutput {
+
+ private final Map<Long, Float> substanceAmount = new HashMap<Long, Float>();
- private final Map<Long,Float> substanceAmount = new HashMap<Long,Float>();
public IHLInvSlotOutput(TileEntityInventory base1, String name1, int oldStartIndex1, int count) {
super(base1, name1, oldStartIndex1, count);
}
@SuppressWarnings("rawtypes")
@Override
- public boolean canAdd(List itemOutputs)
- {
- if(itemOutputs==null || itemOutputs.isEmpty())
- {
+ public boolean canAdd(List itemOutputs) {
+ if (itemOutputs == null || itemOutputs.isEmpty()) {
return true;
}
Iterator ioi = itemOutputs.iterator();
- if(this.size()>=itemOutputs.size())
- {
+ if (this.size() >= itemOutputs.size()) {
Object rois;
- if(ioi.hasNext())
- {
+ if (ioi.hasNext()) {
rois = ioi.next();
- }
- else
- {
+ } else {
return true;
}
- for(int i=0;i<this.size();i++)
- {
- if(this.get(i)==null || (this.objectMatchesSlot(rois, i) && this.get(i).stackSize+this.getAmoutOfObject(rois)<this.getStackSizeLimit()))
- {
- if(ioi.hasNext())
- {
+ for (int i = 0; i < this.size(); i++) {
+ if (this.get(i) == null || (this.objectMatchesSlot(rois, i)
+ && this.get(i).stackSize + this.getAmoutOfObject(rois) < this.getStackSizeLimit()
+ && this.get(i).stackSize + this.getAmoutOfObject(rois) <= this.get(i).getMaxStackSize())) {
+ if (ioi.hasNext()) {
rois = ioi.next();
- }
- else
- {
+ } else {
return true;
}
- }
- else
- {
- if(i==this.size()-1)
- {
+ } else {
+ if (i == this.size() - 1) {
return false;
}
}
}
-
+
}
return false;
}
private float getAmoutOfObject(Object obj) {
- if(obj instanceof ItemStack)
- {
+ if (obj instanceof ItemStack) {
return ((ItemStack) obj).stackSize;
- }
- else if(obj instanceof RecipeOutputItemStack)
- {
- return ((RecipeOutputItemStack)obj).quantity;
+ } else if (obj instanceof RecipeOutputItemStack) {
+ return ((RecipeOutputItemStack) obj).quantity;
}
return Short.MAX_VALUE;
}
- public boolean objectMatchesSlot(Object obj, int slot)
- {
- if(this.get(slot)==null)
- {
+ public boolean objectMatchesSlot(Object obj, int slot) {
+ if (this.get(slot) == null) {
return true;
- }
- else
- {
- if(obj instanceof ItemStack)
- {
+ } else {
+ if (obj instanceof ItemStack) {
return IHLUtils.isItemStacksIsEqual(this.get(slot), (ItemStack) obj, true);
- }
- else if(obj instanceof RecipeOutputItemStack)
- {
- return ((RecipeOutputItemStack)obj).matches(this.get(slot));
+ } else if (obj instanceof RecipeOutputItemStack) {
+ return ((RecipeOutputItemStack) obj).matches(this.get(slot));
}
}
return false;
}
- public void add(RecipeOutputItemStack rois)
- {
- for(int i=0;i<this.size();i++)
- {
- if(this.get(i)==null || (this.objectMatchesSlot(rois, i) && this.get(i).stackSize+this.getAmoutOfObject(rois)<this.getStackSizeLimit()))
- {
+ public void add(RecipeOutputItemStack rois) {
+ for (int i = 0; i < this.size(); i++) {
+ if (this.get(i) == null || (this.objectMatchesSlot(rois, i)
+ && this.get(i).stackSize + this.getAmoutOfObject(rois) < this.getStackSizeLimit())) {
this.add(i, rois);
break;
}
}
}
- private void add(int i, RecipeOutputItemStack rois)
- {
- long key = (Item.getIdFromItem(rois.itemStack.getItem())<<32)+rois.itemStack.getItemDamage();
- float amount=0f;
- if(this.substanceAmount.containsKey(key))
- {
+ private void add(int i, RecipeOutputItemStack rois) {
+ long key = (Item.getIdFromItem(rois.itemStack.getItem()) << 32) + rois.itemStack.getItemDamage();
+ float amount = 0f;
+ if (this.substanceAmount.containsKey(key)) {
amount = this.substanceAmount.get(key);
}
- amount+=rois.quantity;
- while(amount>=1)
- {
+ amount += rois.quantity;
+ while (amount >= 1) {
amount--;
this.add(rois.itemStack.copy());
}
@@ -132,80 +106,62 @@ public class IHLInvSlotOutput extends InvSlotOutput{ @Override
@SuppressWarnings("rawtypes")
- public int add(List itemOutputs)
- {
- if(itemOutputs==null || itemOutputs.isEmpty())
- {
+ public int add(List itemOutputs) {
+ if (itemOutputs == null || itemOutputs.isEmpty()) {
return 0;
}
Iterator ioi = itemOutputs.iterator();
- if(this.size()>=itemOutputs.size() && ioi.hasNext())
- {
+ if (this.size() >= itemOutputs.size() && ioi.hasNext()) {
Object rois = ioi.next();
- for(int i=0;i<this.size();i++)
- {
- if(this.get(i)==null || (this.objectMatchesSlot(rois, i) && this.get(i).stackSize+this.getAmoutOfObject(rois)<this.getStackSizeLimit()))
- {
- if(rois instanceof ItemStack)
- {
+ for (int i = 0; i < this.size(); i++) {
+ if (this.get(i) == null || (this.objectMatchesSlot(rois, i)
+ && this.get(i).stackSize + this.getAmoutOfObject(rois) < this.getStackSizeLimit())) {
+ if (rois instanceof ItemStack) {
this.add(((ItemStack) rois).copy());
- }
- else if(rois instanceof RecipeOutputItemStack)
- {
+ } else if (rois instanceof RecipeOutputItemStack) {
this.add(i, (RecipeOutputItemStack) rois);
}
- if(ioi.hasNext())
- {
+ if (ioi.hasNext()) {
rois = ioi.next();
- }
- else
- {
+ } else {
return itemOutputs.size();
}
- }
- else
- {
- if(i==this.size()-1)
- {
+ } else {
+ if (i == this.size() - 1) {
return 0;
}
}
}
-
+
}
return 0;
}
-
+
@Override
- public void readFromNbt(NBTTagCompound nbtTagCompound)
- {
+ public void readFromNbt(NBTTagCompound nbtTagCompound) {
super.readFromNbt(nbtTagCompound);
NBTTagList amountTagList = nbtTagCompound.getTagList("substanceAmountMap", 10);
- for(int i=0;i<amountTagList.tagCount();i++)
- {
- if(amountTagList.getCompoundTagAt(i).hasKey("substanceKey"))
- {
- long substanceKey = amountTagList.getCompoundTagAt(i).getLong("substanceKey");
- float substanceAmount = amountTagList.getCompoundTagAt(i).getFloat("substanceAmount");
- this.substanceAmount.put(substanceKey, substanceAmount);
- }
- }
- }
-
+ for (int i = 0; i < amountTagList.tagCount(); i++) {
+ if (amountTagList.getCompoundTagAt(i).hasKey("substanceKey")) {
+ long substanceKey = amountTagList.getCompoundTagAt(i).getLong("substanceKey");
+ float substanceAmount = amountTagList.getCompoundTagAt(i).getFloat("substanceAmount");
+ this.substanceAmount.put(substanceKey, substanceAmount);
+ }
+ }
+ }
+
@Override
- public void writeToNbt(NBTTagCompound nbtTagCompound)
- {
+ public void writeToNbt(NBTTagCompound nbtTagCompound) {
super.writeToNbt(nbtTagCompound);
- NBTTagList sAmountsList = new NBTTagList();
- Iterator<Entry<Long, Float>> entrySetIterator = this.substanceAmount.entrySet().iterator();
- while(entrySetIterator.hasNext())
- {
- Entry<Long, Float> entry = entrySetIterator.next();
- NBTTagCompound tag = new NBTTagCompound();
- tag.setLong("substanceKey", entry.getKey());
- tag.setFloat("substanceAmount", entry.getValue());
- sAmountsList.appendTag(tag);
- }
- nbtTagCompound.setTag("substanceAmountMap", sAmountsList);
- }
+ NBTTagList sAmountsList = new NBTTagList();
+ Iterator<Entry<Long, Float>> entrySetIterator = this.substanceAmount.entrySet().iterator();
+ while (entrySetIterator.hasNext()) {
+ Entry<Long, Float> entry = entrySetIterator.next();
+ NBTTagCompound tag = new NBTTagCompound();
+ tag.setLong("substanceKey", entry.getKey());
+ tag.setFloat("substanceAmount", entry.getValue());
+ sAmountsList.appendTag(tag);
+ }
+ nbtTagCompound.setTag("substanceAmountMap", sAmountsList);
+ }
}
|
