From 2db8e30b1d2151fdde5d08a6c06aef55f0c397d2 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Fri, 27 Jan 2017 11:32:28 +0300 Subject: License, readme and stuff --- ihl/flexible_cable/IronWorkbenchTileEntity.java | 71 ++++++++++++++++++------- 1 file changed, 53 insertions(+), 18 deletions(-) (limited to 'ihl/flexible_cable/IronWorkbenchTileEntity.java') diff --git a/ihl/flexible_cable/IronWorkbenchTileEntity.java b/ihl/flexible_cable/IronWorkbenchTileEntity.java index 3821a0c..73a3eb1 100644 --- a/ihl/flexible_cable/IronWorkbenchTileEntity.java +++ b/ihl/flexible_cable/IronWorkbenchTileEntity.java @@ -3,9 +3,11 @@ package ihl.flexible_cable; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -14,29 +16,26 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import ic2.api.network.INetworkClientTileEntityEventListener; import ic2.api.network.INetworkTileEntityEventListener; import ic2.api.recipe.IRecipeInput; -import ic2.api.recipe.RecipeInputItemStack; import ic2.core.ContainerBase; -import ic2.core.IC2; import ic2.core.IHasGui; -import ic2.core.Ic2Items; import ic2.core.block.TileEntityInventory; import ic2.core.block.invslot.InvSlot.Access; import ihl.IHLMod; import ihl.interfaces.IWire; -import ihl.items_blocks.FlexibleCableItem; -import ihl.processing.chemistry.GaedesMercuryRotaryPumpTileEntity; -import ihl.processing.metallurgy.GasWeldingStationTileEntity; import ihl.recipes.IronWorkbenchRecipe; +import ihl.recipes.RecipeInputDetonator; import ihl.recipes.RecipeInputDie; import ihl.recipes.RecipeInputObjectInstance; import ihl.utils.IHLUtils; public class IronWorkbenchTileEntity extends TileEntityInventory implements IHasGui, INetworkClientTileEntityEventListener, INetworkTileEntityEventListener{ - public static List recipes = new ArrayList(); + public static List recipes = new ArrayList(); public int progress; public int currentSlot=-1; public final int maxProgress; @@ -49,7 +48,8 @@ public class IronWorkbenchTileEntity extends TileEntityInventory implements IHas private boolean outputDefined=false; private EntityPlayer crafter; public ContainerBase container; - private Map slotRecipeMap = new HashMap(); + private Map slotRecipeMap = new HashMap(); + private boolean firstTick = true; public IronWorkbenchTileEntity() { @@ -77,7 +77,18 @@ public class IronWorkbenchTileEntity extends TileEntityInventory implements IHas { return IHLUtils.getThisModItemStack("ironWorkbench"); } - + + @Override + @SideOnly(Side.CLIENT) + public void updateEntityClient() + { + if(firstTick) + { + IHLMod.proxy.requestTileEntityInitdataFromClientToServer(xCoord, yCoord, zCoord); + this.firstTick=false; + } + } + @Override public void updateEntityServer() { @@ -102,6 +113,13 @@ public class IronWorkbenchTileEntity extends TileEntityInventory implements IHas newOutputs = ((RecipeInputDie)rinput).transformOutput(this.getMatchedItemStack(rinput),recipe.outputs); } } + for(IRecipeInput rinput:recipe.materials) + { + if(rinput instanceof RecipeInputDetonator) + { + newOutputs = ((RecipeInputDetonator)rinput).transformOutput(this.getMatchedItemStack(rinput),recipe.outputs); + } + } int slot = this.output.put(newOutputs); if(slot<0)break; slotRecipeMap.put(slot, recipe); @@ -109,7 +127,6 @@ public class IronWorkbenchTileEntity extends TileEntityInventory implements IHas } } } - List processingMaterials = new ArrayList(); for(int i=0; i crafterEmptyInventorySlotsList = getCrafterEmptyInventorySlotsList(); + Set crafterEmptyInventorySlotsList = getCrafterEmptyInventorySlotsList(); if(startProcess && crafterEmptyInventorySlotsList.size()>=this.slotRecipeMap.get(currentSlot).outputs.size()) { if(++this.progress>=this.maxProgress) @@ -150,10 +167,8 @@ public class IronWorkbenchTileEntity extends TileEntityInventory implements IHas { int slot = emptySlotsIterator.next(); ItemStack stack = optsi.next(); - this.crafter.inventory.mainInventory[slot]=stack.copy(); if(stack.getItem() instanceof IWire) { - System.out.println(multiplier); this.crafter.inventory.mainInventory[slot]=IHLUtils.getWireItemStackCopyWithLengthMultiplied(stack,multiplier); } else @@ -162,8 +177,23 @@ public class IronWorkbenchTileEntity extends TileEntityInventory implements IHas this.crafter.inventory.mainInventory[slot].stackSize*=multiplier; } } + Iterator emptyContainers = this.inputMaterial.substract(crecipe.materials, multiplier).iterator(); + while(emptyContainers.hasNext()) + { + if(emptySlotsIterator.hasNext()) + { + int slot = emptySlotsIterator.next(); + ItemStack stack = emptyContainers.next(); + this.crafter.inventory.mainInventory[slot]=stack.copy(); + this.crafter.inventory.mainInventory[slot].stackSize*=multiplier; + } + else + { + EntityItem eistack = new EntityItem(this.worldObj, this.xCoord, this.yCoord+1, this.zCoord, emptyContainers.next()); + this.worldObj.spawnEntityInWorld(eistack); + } + } this.crafter.inventoryContainer.detectAndSendChanges(); - this.inputMaterial.substract(crecipe.materials, multiplier); this.tools.damage(crecipe.tools); if(!crecipe.workspaceElements.isEmpty()) { @@ -196,9 +226,9 @@ public class IronWorkbenchTileEntity extends TileEntityInventory implements IHas return null; } - private List getCrafterEmptyInventorySlotsList() + private Set getCrafterEmptyInventorySlotsList() { - List list = new ArrayList(); + Set list = new HashSet(4); if(this.crafter!=null) { for (int var1 = 0; var1 < this.crafter.inventory.mainInventory.length; ++var1) @@ -213,7 +243,7 @@ public class IronWorkbenchTileEntity extends TileEntityInventory implements IHas } private List getListOfSameWires(ItemStack stack1) { - List list = new ArrayList(); + List list = new ArrayList(); for(int i=0; i