From 05c78126859231a68e199dc34613689bd0978e2f Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Mon, 11 Apr 2016 19:44:54 +0300 Subject: Initial commit --- ihl/processing/invslots/IHLInvSlotOutput.java | 211 ++++++++++++++++ .../invslots/InvSlotConsumableLiquidIHL.java | 271 +++++++++++++++++++++ .../invslots/InvSlotSignalProcessor.java | 125 ++++++++++ .../invslots/SlotInvSlotOutputInProgress.java | 23 ++ .../SlotRedstoneConverterCableInvSlot.java | 23 ++ 5 files changed, 653 insertions(+) create mode 100644 ihl/processing/invslots/IHLInvSlotOutput.java create mode 100644 ihl/processing/invslots/InvSlotConsumableLiquidIHL.java create mode 100644 ihl/processing/invslots/InvSlotSignalProcessor.java create mode 100644 ihl/processing/invslots/SlotInvSlotOutputInProgress.java create mode 100644 ihl/processing/invslots/SlotRedstoneConverterCableInvSlot.java (limited to 'ihl/processing/invslots') diff --git a/ihl/processing/invslots/IHLInvSlotOutput.java b/ihl/processing/invslots/IHLInvSlotOutput.java new file mode 100644 index 0000000..94bf3c8 --- /dev/null +++ b/ihl/processing/invslots/IHLInvSlotOutput.java @@ -0,0 +1,211 @@ +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 net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +import ic2.core.block.TileEntityInventory; +import ic2.core.block.invslot.InvSlotOutput; +import ihl.recipes.RecipeOutputItemStack; +import ihl.utils.IHLUtils; + +public class IHLInvSlotOutput extends InvSlotOutput{ + + private final Map substanceAmount = new HashMap(); + public IHLInvSlotOutput(TileEntityInventory base1, String name1, int oldStartIndex1, int count) { + super(base1, name1, oldStartIndex1, count); + } + + @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=1) + { + amount--; + this.add(rois.itemStack.copy()); + } + this.substanceAmount.put(key, amount); + } + + @Override + 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> entrySetIterator = this.substanceAmount.entrySet().iterator(); + while(entrySetIterator.hasNext()) + { + Entry 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/ihl/processing/invslots/InvSlotConsumableLiquidIHL.java b/ihl/processing/invslots/InvSlotConsumableLiquidIHL.java new file mode 100644 index 0000000..c88584e --- /dev/null +++ b/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 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; +import ic2.core.block.TileEntityInventory; +import ic2.core.block.invslot.InvSlotConsumableLiquid; +import ic2.core.util.StackUtil; +import ihl.utils.IHLUtils; + +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 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 containerItem1 = this.getPossibleFluids().iterator(); + + while (containerItem1.hasNext()) + { + Fluid prevFluid = (Fluid)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 i$ = this.getPossibleFluids().iterator(); + + while (i$.hasNext()) + { + Fluid fluid = (Fluid)i$.next(); + + if (containerItem2.fill(singleStack, new FluidStack(fluid, Integer.MAX_VALUE), false) > 0) + { + return true; + } + } + } + } + } + return false; + } + } + +} diff --git a/ihl/processing/invslots/InvSlotSignalProcessor.java b/ihl/processing/invslots/InvSlotSignalProcessor.java new file mode 100644 index 0000000..6663db0 --- /dev/null +++ b/ihl/processing/invslots/InvSlotSignalProcessor.java @@ -0,0 +1,125 @@ +package ihl.processing.invslots; + +import java.util.Iterator; +import net.minecraft.block.Block; +import net.minecraftforge.common.util.ForgeDirection; +import ic2.core.Ic2Items; +import ic2.core.block.invslot.InvSlot; +import ihl.IHLMod; +import ihl.datanet.Contact; +import ihl.datanet.RedstoneSignalConverterTileEntity; +import ihl.interfaces.IDataNode; +import ihl.utils.IHLUtils; + +public class InvSlotSignalProcessor extends InvSlot +{ + private RedstoneSignalConverterTileEntity rscBase; + public final boolean[] slotStatus;//false=normal;true=activated + public InvSlotSignalProcessor(RedstoneSignalConverterTileEntity base1, String name1, int oldStartIndex1, Access access1, int count, int linksPerSlot) { + super(base1, name1, oldStartIndex1, access1, count); + rscBase = base1; + slotStatus = new boolean[count]; + } + + public Contact getOppositeContact(IDataNode contact3) + { + for(Contact contact1 : this.rscBase.contacts) + { + if(contact1.attachedSlot==this && + contact3.getAttachedSlotNumber()==contact1.attachedSlotNumber) + { + switch(contact3.getType()) + { + case 0: + if(contact1.type==1) + { + return contact1; + } + break; + case 1: + if(contact1.type==0) + { + return contact1; + } + break; + case 2: + if(slotStatus[contact1.attachedSlotNumber]) + { + if(contact1.type==3) + { + return contact1; + } + } + else + { + if(contact1.type==4) + { + return contact1; + } + } + break; + case 3: + if(slotStatus[contact1.attachedSlotNumber]) + { + if(contact1.type==2) + { + return contact1; + } + } + break; + case 4: + if(!slotStatus[contact1.attachedSlotNumber]) + { + if(contact1.type==2) + { + return contact1; + } + } + break; + } + } + } + return null; + } + + public boolean isSlotActivated(int slot) + { + return this.slotStatus[slot]; + } + + public void notifyNeighbors() + { + int xyz[] = {0,0,1,0,0,-1,0,0}; + Block block; + int x,y,z; + for(int i=0;i<=5;i++) + { + x=rscBase.xCoord+xyz[i]; + y=rscBase.yCoord+xyz[i+1]; + z=rscBase.zCoord+xyz[i+2]; + block = rscBase.getWorldObj().getBlock(rscBase.xCoord,rscBase.yCoord,rscBase.zCoord); + rscBase.getWorldObj().notifyBlockOfNeighborChange(x,y,z,block); + } + } + + public boolean isIndirectlyConnectedWithContact(Contact contact, int id) + { + if(this.get(contact.attachedSlotNumber)!=null) + { + if(IHLUtils.isItemStacksIsEqual(this.get(contact.attachedSlotNumber), Ic2Items.splitterCableItem, true))//Redstone sensor + { + ForgeDirection dir1 = ForgeDirection.getOrientation(contact.attachedSlotNumber); + if(this.base.getWorldObj().getIndirectPowerOutput(base.xCoord+dir1.offsetX, base.yCoord+dir1.offsetY, base.zCoord+dir1.offsetZ, dir1.getOpposite().flag)) + { + Contact oppositeContact = this.getOppositeContact(contact); + if(oppositeContact.getDataGridID()!=contact.getDataGridID()) + { + return oppositeContact.isConnectedToContact(id); + } + } + } + } + return false; + } + +} \ No newline at end of file diff --git a/ihl/processing/invslots/SlotInvSlotOutputInProgress.java b/ihl/processing/invslots/SlotInvSlotOutputInProgress.java new file mode 100644 index 0000000..a1b3937 --- /dev/null +++ b/ihl/processing/invslots/SlotInvSlotOutputInProgress.java @@ -0,0 +1,23 @@ +package ihl.processing.invslots; + +import net.minecraft.entity.player.EntityPlayer; +import ic2.core.slot.SlotInvSlot; +import ihl.flexible_cable.IronWorkbenchInvSlot; + +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(); + } +} diff --git a/ihl/processing/invslots/SlotRedstoneConverterCableInvSlot.java b/ihl/processing/invslots/SlotRedstoneConverterCableInvSlot.java new file mode 100644 index 0000000..461c3cc --- /dev/null +++ b/ihl/processing/invslots/SlotRedstoneConverterCableInvSlot.java @@ -0,0 +1,23 @@ +package ihl.processing.invslots; + +import net.minecraft.entity.player.EntityPlayer; +import ic2.core.block.invslot.InvSlot; +import ic2.core.slot.SlotInvSlot; + +public class SlotRedstoneConverterCableInvSlot extends SlotInvSlot { + + public InvSlot invSlot; + + public SlotRedstoneConverterCableInvSlot(InvSlot invSlot1, int index1, + int xDisplayPosition1, int yDisplayPosition1) { + super(invSlot1, index1, xDisplayPosition1, yDisplayPosition1); + this.invSlot=invSlot1; + } + + @Override + public boolean canTakeStack(EntityPlayer player) + { + return false; + } + +} -- cgit v1.2.3