summaryrefslogtreecommitdiff
path: root/src/main/java/ihl/processing/invslots
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/ihl/processing/invslots')
-rw-r--r--src/main/java/ihl/processing/invslots/IHLInvSlotOutput.java166
-rw-r--r--src/main/java/ihl/processing/invslots/InvSlotConsumableLiquidIHL.java271
-rw-r--r--src/main/java/ihl/processing/invslots/InvSlotUpgradeIHL.java61
-rw-r--r--src/main/java/ihl/processing/invslots/SlotInvSlotIronWorkbench.java32
-rw-r--r--src/main/java/ihl/processing/invslots/SlotInvSlotOutputInProgress.java23
5 files changed, 553 insertions, 0 deletions
diff --git a/src/main/java/ihl/processing/invslots/IHLInvSlotOutput.java b/src/main/java/ihl/processing/invslots/IHLInvSlotOutput.java
new file mode 100644
index 0000000..d5186e2
--- /dev/null
+++ b/src/main/java/ihl/processing/invslots/IHLInvSlotOutput.java
@@ -0,0 +1,166 @@
+package ihl.processing.invslots;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import ic2.core.block.TileEntityInventory;
+import ic2.core.block.invslot.InvSlotOutput;
+import ihl.recipes.RecipeOutputItemStack;
+import ihl.utils.IHLUtils;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+
+public class IHLInvSlotOutput extends InvSlotOutput {
+
+ 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()) {
+ return true;
+ }
+ Iterator ioi = itemOutputs.iterator();
+ if (this.size() >= itemOutputs.size()) {
+ Object rois;
+ if (ioi.hasNext()) {
+ rois = ioi.next();
+ } 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()
+ && this.get(i).stackSize + this.getAmoutOfObject(rois) <= this.get(i).getMaxStackSize())) {
+ if (ioi.hasNext()) {
+ rois = ioi.next();
+ } else {
+ return true;
+ }
+ } else {
+ if (i == this.size() - 1) {
+ return false;
+ }
+ }
+ }
+
+ }
+ return false;
+ }
+
+ private float getAmoutOfObject(Object obj) {
+ if (obj instanceof ItemStack) {
+ return ((ItemStack) obj).stackSize;
+ } 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) {
+ return true;
+ } 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));
+ }
+ }
+ 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())) {
+ 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)) {
+ amount = this.substanceAmount.get(key);
+ }
+ amount += rois.quantity;
+ while (amount >= 1) {
+ amount--;
+ this.add(rois.itemStack.copy());
+ }
+ this.substanceAmount.put(key, amount);
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ public int add(List itemOutputs) {
+ if (itemOutputs == null || itemOutputs.isEmpty()) {
+ return 0;
+ }
+ Iterator ioi = itemOutputs.iterator();
+ 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) {
+ this.add(((ItemStack) rois).copy());
+ } else if (rois instanceof RecipeOutputItemStack) {
+ this.add(i, (RecipeOutputItemStack) rois);
+ }
+ if (ioi.hasNext()) {
+ rois = ioi.next();
+ } else {
+ return itemOutputs.size();
+ }
+ } else {
+ if (i == this.size() - 1) {
+ return 0;
+ }
+ }
+ }
+
+ }
+ return 0;
+ }
+
+ @Override
+ 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);
+ }
+ }
+ }
+
+ @Override
+ 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);
+ }
+}
diff --git a/src/main/java/ihl/processing/invslots/InvSlotConsumableLiquidIHL.java b/src/main/java/ihl/processing/invslots/InvSlotConsumableLiquidIHL.java
new file mode 100644
index 0000000..7bb6ecc
--- /dev/null
+++ b/src/main/java/ihl/processing/invslots/InvSlotConsumableLiquidIHL.java
@@ -0,0 +1,271 @@
+package ihl.processing.invslots;
+
+import java.util.Iterator;
+
+import org.apache.commons.lang3.mutable.MutableObject;
+
+import ic2.core.block.TileEntityInventory;
+import ic2.core.block.invslot.InvSlotConsumableLiquid;
+import ic2.core.util.StackUtil;
+import ihl.utils.IHLUtils;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.fluids.Fluid;
+import net.minecraftforge.fluids.FluidContainerRegistry;
+import net.minecraftforge.fluids.FluidStack;
+import net.minecraftforge.fluids.IFluidContainerItem;
+
+public class InvSlotConsumableLiquidIHL extends InvSlotConsumableLiquid{
+
+ private OpType opType;
+ private String additionalInputs;
+
+ public InvSlotConsumableLiquidIHL(TileEntityInventory base1, String name1,int oldStartIndex1, Access access1, int count,InvSide preferredSide1, OpType opType1)
+ {
+ super(base1, name1, oldStartIndex1, access1, count, preferredSide1, opType1);
+ opType=opType1;
+ }
+
+ public InvSlotConsumableLiquidIHL(TileEntityInventory base1, String name1,int oldStartIndex1, Access access1, int count,InvSide preferredSide1, OpType opType1, String additionalInputs1)
+ {
+ super(base1, name1, oldStartIndex1, access1, count, preferredSide1, opType1);
+ opType=opType1;
+ additionalInputs=additionalInputs1;
+ }
+
+ @Override
+ public FluidStack drain(Fluid fluid, int maxAmount, MutableObject<ItemStack> output, boolean simulate)
+ {
+ if(output!=null)
+ {
+ output.setValue((ItemStack)null);
+ }
+
+ if (this.opType != InvSlotConsumableLiquid.OpType.Drain && this.opType != InvSlotConsumableLiquid.OpType.Both)
+ {
+ return null;
+ }
+ else
+ {
+ ItemStack stack = this.get();
+
+ if (stack == null)
+ {
+ return null;
+ }
+ else if (!FluidContainerRegistry.isFilledContainer(stack))
+ {
+ if (stack.getItem() instanceof IFluidContainerItem)
+ {
+ IFluidContainerItem var9 = (IFluidContainerItem)stack.getItem();
+
+ if (var9.getFluid(stack) == null)
+ {
+ return null;
+ }
+ else if (fluid != null && var9.getFluid(stack).getFluid() != fluid)
+ {
+ return null;
+ }
+ else if (!this.acceptsLiquid(var9.getFluid(stack).getFluid()))
+ {
+ return null;
+ }
+ else
+ {
+ ItemStack singleStack = StackUtil.copyWithSize(stack, 1);
+ FluidStack fluidStack = var9.drain(singleStack, maxAmount, true);
+
+ if (fluidStack != null && fluidStack.amount > 0)
+ {
+ if (singleStack.stackSize <= 0)
+ {
+ if (!simulate)
+ {
+ --stack.stackSize;
+ }
+ }
+ else if (var9.getFluid(singleStack) == null)
+ {
+ if(output!=null)
+ {
+ output.setValue(singleStack);
+ }
+ if (!simulate)
+ {
+ --stack.stackSize;
+ }
+ }
+ else
+ {
+ if (stack.stackSize > 1)
+ {
+ return null;
+ }
+
+ if (!simulate)
+ {
+ this.put(singleStack);
+ }
+ }
+
+ if (stack.stackSize <= 0)
+ {
+ this.put((ItemStack)null);
+ }
+
+ return fluidStack;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+ else
+ {
+ FluidStack container = FluidContainerRegistry.getFluidForFilledItem(stack);
+
+ if (container != null && (fluid == null || fluid == container.getFluid()))
+ {
+ if (!this.acceptsLiquid(container.getFluid()))
+ {
+ return null;
+ }
+ else if (container.amount > 0 && container.amount <= maxAmount)
+ {
+ if (stack.getItem().hasContainerItem(stack) && output!=null)
+ {
+ output.setValue(stack.getItem().getContainerItem(stack));
+ }
+ else
+ {
+ ItemStack emptystack = FluidContainerRegistry.drainFluidContainer(stack);
+ if(emptystack!=null && output!=null)
+ {
+ output.setValue(emptystack);
+ }
+ }
+
+ if (!simulate)
+ {
+ --stack.stackSize;
+
+ if (stack.stackSize <= 0)
+ {
+ this.put((ItemStack)null);
+ }
+ }
+
+ return container;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean accepts(ItemStack stack)
+ {
+ if (stack == null)
+ {
+ return true;
+ }
+ Item item = stack.getItem();
+ if (item == null)
+ {
+ return false;
+ }
+ else
+ {
+ if(this.additionalInputs!=null)
+ {
+ String fon = IHLUtils.getFirstOreDictName(stack);
+ if(fon!=null && fon.contains(additionalInputs))
+ {
+ return true;
+ }
+ }
+ if (this.opType == InvSlotConsumableLiquid.OpType.Drain || this.opType == InvSlotConsumableLiquid.OpType.Both)
+ {
+ FluidStack containerItem = null;
+ if (FluidContainerRegistry.isFilledContainer(stack))
+ {
+ containerItem = FluidContainerRegistry.getFluidForFilledItem(stack);
+ }
+ else if (item instanceof IFluidContainerItem)
+ {
+ containerItem = ((IFluidContainerItem)item).getFluid(stack);
+ }
+
+ if (containerItem != null && containerItem.amount > 0)
+ {
+ return true;
+ }
+ }
+ if (this.opType == InvSlotConsumableLiquid.OpType.Fill || this.opType == InvSlotConsumableLiquid.OpType.Both)
+ {
+ if (FluidContainerRegistry.isEmptyContainer(stack))
+ {
+ if (this.getPossibleFluids() == null)
+ {
+ return true;
+ }
+
+ Iterator<Fluid> containerItem1 = this.getPossibleFluids().iterator();
+
+ while (containerItem1.hasNext())
+ {
+ Fluid prevFluid = containerItem1.next();
+
+ if (FluidContainerRegistry.fillFluidContainer(new FluidStack(prevFluid, Integer.MAX_VALUE), stack) != null)
+ {
+ return true;
+ }
+ }
+ }
+ else if (item instanceof IFluidContainerItem)
+ {
+ IFluidContainerItem containerItem2 = (IFluidContainerItem)item;
+ FluidStack prevFluid1 = containerItem2.getFluid(stack);
+
+ if (prevFluid1 == null || containerItem2.getCapacity(stack) > prevFluid1.amount)
+ {
+ if (this.getPossibleFluids() == null)
+ {
+ return true;
+ }
+
+ ItemStack singleStack = StackUtil.copyWithSize(stack, 1);
+ Iterator<Fluid> i$ = this.getPossibleFluids().iterator();
+
+ while (i$.hasNext())
+ {
+ Fluid fluid = i$.next();
+
+ if (containerItem2.fill(singleStack, new FluidStack(fluid, Integer.MAX_VALUE), false) > 0)
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+ }
+
+}
diff --git a/src/main/java/ihl/processing/invslots/InvSlotUpgradeIHL.java b/src/main/java/ihl/processing/invslots/InvSlotUpgradeIHL.java
new file mode 100644
index 0000000..5c1fff9
--- /dev/null
+++ b/src/main/java/ihl/processing/invslots/InvSlotUpgradeIHL.java
@@ -0,0 +1,61 @@
+package ihl.processing.invslots;
+
+import ic2.core.Ic2Items;
+import ic2.core.block.TileEntityInventory;
+import ic2.core.block.invslot.InvSlot;
+import ihl.utils.IHLUtils;
+import net.minecraft.item.ItemStack;
+
+public class InvSlotUpgradeIHL extends InvSlot {
+
+ public InvSlotUpgradeIHL(int count) {
+ super(count);
+ }
+
+ public InvSlotUpgradeIHL(TileEntityInventory base, int oldStartIndex, Access access, int count, InvSide side) {
+ super(base, "invSlotUpgrade", oldStartIndex, access, count, side);
+ }
+
+ public double getPowerConsumtionMultiplier() {
+ double base = 1d;
+ for (int i = 0; i < this.size(); i++) {
+ if (IHLUtils.isItemStacksIsEqual(this.get(i), Ic2Items.overclockerUpgrade, false)) {
+ int i1 = this.get(i).stackSize;
+ while (i1-- > 0 && base < 600) {
+ base *= 1.6f;
+ }
+ }
+ }
+ return base;
+ }
+
+ public float getProgressMultiplier() {
+ float base = 1f;
+ for (int i = 0; i < this.size(); i++) {
+ if (IHLUtils.isItemStacksIsEqual(this.get(i), Ic2Items.overclockerUpgrade, false)) {
+ int i1 = this.get(i).stackSize;
+ while (i1-- > 0 && base < 600) {
+ base *= 1.428571429f;
+ }
+ }
+ }
+ return base;
+ }
+
+ public int getAdditionalEnergyStorage() {
+ int base = 0;
+ for (int i = 0; i < this.size(); i++) {
+ if (IHLUtils.isItemStacksIsEqual(this.get(i), Ic2Items.energyStorageUpgrade, false)) {
+ base += this.get(i).stackSize * 10000;
+ }
+ }
+ return base;
+ }
+
+ @Override
+ public boolean accepts(ItemStack stack) {
+ return IHLUtils.isItemStacksIsEqual(stack, Ic2Items.overclockerUpgrade, false) ||
+ IHLUtils.isItemStacksIsEqual(stack, Ic2Items.energyStorageUpgrade, false);
+ }
+
+}
diff --git a/src/main/java/ihl/processing/invslots/SlotInvSlotIronWorkbench.java b/src/main/java/ihl/processing/invslots/SlotInvSlotIronWorkbench.java
new file mode 100644
index 0000000..7f00e06
--- /dev/null
+++ b/src/main/java/ihl/processing/invslots/SlotInvSlotIronWorkbench.java
@@ -0,0 +1,32 @@
+package ihl.processing.invslots;
+
+import ic2.core.slot.SlotInvSlot;
+import ihl.flexible_cable.IronWorkbenchInvSlot;
+import ihl.flexible_cable.IronWorkbenchTileEntity;
+import net.minecraft.entity.player.EntityPlayer;
+
+public class SlotInvSlotIronWorkbench extends SlotInvSlot {
+
+ public IronWorkbenchInvSlot invSlot;
+
+ public SlotInvSlotIronWorkbench(IronWorkbenchInvSlot invSlot1, int index1,
+ int xDisplayPosition1, int yDisplayPosition1) {
+ super(invSlot1, index1, xDisplayPosition1, yDisplayPosition1);
+ this.invSlot=invSlot1;
+
+ }
+
+ @Override
+ public boolean canTakeStack(EntityPlayer player)
+ {
+ return this.invSlot.getCanTakeStack();
+ }
+
+
+ @Override
+ public void onSlotChanged()
+ {
+ super.onSlotChanged();
+ ((IronWorkbenchTileEntity)this.invSlot.base).resetOutput();
+ }
+}
diff --git a/src/main/java/ihl/processing/invslots/SlotInvSlotOutputInProgress.java b/src/main/java/ihl/processing/invslots/SlotInvSlotOutputInProgress.java
new file mode 100644
index 0000000..25c0673
--- /dev/null
+++ b/src/main/java/ihl/processing/invslots/SlotInvSlotOutputInProgress.java
@@ -0,0 +1,23 @@
+package ihl.processing.invslots;
+
+import ic2.core.slot.SlotInvSlot;
+import ihl.flexible_cable.IronWorkbenchInvSlot;
+import net.minecraft.entity.player.EntityPlayer;
+
+public class SlotInvSlotOutputInProgress extends SlotInvSlot {
+
+ public IronWorkbenchInvSlot invSlot;
+
+ public SlotInvSlotOutputInProgress(IronWorkbenchInvSlot invSlot1, int index1,
+ int xDisplayPosition1, int yDisplayPosition1) {
+ super(invSlot1, index1, xDisplayPosition1, yDisplayPosition1);
+ this.invSlot=invSlot1;
+
+ }
+
+ @Override
+ public boolean canTakeStack(EntityPlayer player)
+ {
+ return this.invSlot.getCanTakeStack();
+ }
+}