From 5cb4c6e24033cf337812390d99a6817d24d21eab Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Sun, 12 Feb 2017 20:43:03 +0300 Subject: Removed explosion radius limitations. Explosion calculation optimized (reduced memory usage). One more detonator and explosive pack recipe. GT6 recipes for both chemical reactors and cryogenic distiller. Max stack size of muffle furnace is limited to 32. A lot of old features are removed. --- ihl/flexible_cable/IronWorkbenchTileEntity.java | 393 +++++++++++------------- 1 file changed, 171 insertions(+), 222 deletions(-) (limited to 'ihl/flexible_cable/IronWorkbenchTileEntity.java') diff --git a/ihl/flexible_cable/IronWorkbenchTileEntity.java b/ihl/flexible_cable/IronWorkbenchTileEntity.java index 73a3eb1..d21b4c9 100644 --- a/ihl/flexible_cable/IronWorkbenchTileEntity.java +++ b/ihl/flexible_cable/IronWorkbenchTileEntity.java @@ -33,192 +33,166 @@ import ihl.recipes.RecipeInputDie; import ihl.recipes.RecipeInputObjectInstance; import ihl.utils.IHLUtils; -public class IronWorkbenchTileEntity extends TileEntityInventory implements IHasGui, INetworkClientTileEntityEventListener, INetworkTileEntityEventListener{ +public class IronWorkbenchTileEntity extends TileEntityInventory + implements IHasGui, INetworkClientTileEntityEventListener, INetworkTileEntityEventListener { public static List recipes = new ArrayList(); public int progress; - public int currentSlot=-1; + public int currentSlot = -1; public final int maxProgress; - public final InvSlotTool tools; - public final InvSlotWorkspaceElement workspaceElements; - public final InvSlotProcessableIronWorkbench inputMaterial; - public final InvSlotOutputInProgress output; - public boolean isGuiScreenOpened=false; - private boolean startProcess=false; - private boolean outputDefined=false; + public final InvSlotTool tools; + public final InvSlotWorkspaceElement workspaceElements; + public final InvSlotProcessableIronWorkbench inputMaterial; + public final InvSlotOutputInProgress output; + public boolean isGuiScreenOpened = false; + private boolean startProcess = false; + private boolean outputDefined = false; private EntityPlayer crafter; public ContainerBase container; private Map slotRecipeMap = new HashMap(); private boolean firstTick = true; - - public IronWorkbenchTileEntity() - { - this.maxProgress=80; - this.workspaceElements = new InvSlotWorkspaceElement(this, "workspaceElements", 3, Access.NONE, 6); - this.tools=new InvSlotTool(this, "tools", 0, Access.IO, 12); - this.inputMaterial=new InvSlotProcessableIronWorkbench(this, "input", 1, Access.IO, 12); - this.output=new InvSlotOutputInProgress(this, "output", 2, 18); - } - - public static void addRecipe(IronWorkbenchRecipe recipe) - { - IronWorkbenchTileEntity.recipes.add(recipe); - } - + + public IronWorkbenchTileEntity() { + this.maxProgress = 80; + this.workspaceElements = new InvSlotWorkspaceElement(this, "workspaceElements", 3, Access.NONE, 6); + this.tools = new InvSlotTool(this, "tools", 0, Access.IO, 12); + this.inputMaterial = new InvSlotProcessableIronWorkbench(this, "input", 1, Access.IO, 12); + this.output = new InvSlotOutputInProgress(this, "output", 2, 18); + } + + public static void addRecipe(IronWorkbenchRecipe recipe) { + IronWorkbenchTileEntity.recipes.add(recipe); + } + @Override - public String getInventoryName() - { + public String getInventoryName() { return "ironWorkbench"; } - @Override - public ItemStack getWrenchDrop(EntityPlayer player) - { + public ItemStack getWrenchDrop(EntityPlayer player) { return IHLUtils.getThisModItemStack("ironWorkbench"); } - + @Override @SideOnly(Side.CLIENT) - public void updateEntityClient() - { - if(firstTick) - { + public void updateEntityClient() { + if (firstTick) { IHLMod.proxy.requestTileEntityInitdataFromClientToServer(xCoord, yCoord, zCoord); - this.firstTick=false; + this.firstTick = false; } } - + @Override - public void updateEntityServer() - { - if(this.isGuiScreenOpened) - { - if(this.output.isEmpty() && !outputDefined) - { + public void updateEntityServer() { + if (this.isGuiScreenOpened) { + if (this.output.isEmpty() && !outputDefined) { this.workspaceElements.reset(); - Iterator iwri=IronWorkbenchTileEntity.recipes.iterator(); - while(iwri.hasNext()) - { + Iterator iwri = IronWorkbenchTileEntity.recipes.iterator(); + while (iwri.hasNext()) { IronWorkbenchRecipe recipe = iwri.next(); - if(recipe.isCanBeCrafted(this.tools.getItemStackList(), this.inputMaterial.getItemStackList(), this.workspaceElements.getItemStackList())) - { - if(recipe.workspaceElements==null || recipe.workspaceElements.isEmpty() || this.workspaceElements.containsAndCanUse(recipe.workspaceElements)) - { + if (recipe.isCanBeCrafted(this.tools.getItemStackList(), this.inputMaterial.getItemStackList(), + this.workspaceElements.getItemStackList())) { + if (recipe.workspaceElements == null || recipe.workspaceElements.isEmpty() + || this.workspaceElements.containsAndCanUse(recipe.workspaceElements)) { List newOutputs = recipe.outputs; - for(IRecipeInput rinput:recipe.tools) - { - if(rinput instanceof RecipeInputDie) - { - newOutputs = ((RecipeInputDie)rinput).transformOutput(this.getMatchedItemStack(rinput),recipe.outputs); + for (IRecipeInput rinput : recipe.tools) { + if (rinput instanceof RecipeInputDie) { + 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); + 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; + if (slot < 0) + break; slotRecipeMap.put(slot, recipe); - this.startProcess=false; + this.startProcess = false; } } } - for(int i=0; i list = this.getListOfSameWires(stack); ItemStack result = stack.copy(); result.stackTagCompound.setInteger("length", fullLength); result.stackTagCompound.setInteger("fullLength", fullLength); - IronWorkbenchRecipe recipe = new IronWorkbenchRecipe(null, list, Arrays.asList(new ItemStack[] {result})); + IronWorkbenchRecipe recipe = new IronWorkbenchRecipe(null, list, + Arrays.asList(new ItemStack[] { result })); int slot = this.output.put(recipe.outputs); - if(slot<0)break; + if (slot < 0) + break; slotRecipeMap.put(slot, recipe); - this.startProcess=false; + this.startProcess = false; break; } } - outputDefined=true; - } - else if(!this.output.isEmpty()) - { + outputDefined = true; + } else if (!this.output.isEmpty()) { Set crafterEmptyInventorySlotsList = getCrafterEmptyInventorySlotsList(); - if(startProcess && crafterEmptyInventorySlotsList.size()>=this.slotRecipeMap.get(currentSlot).outputs.size()) - { - if(++this.progress>=this.maxProgress) - { - IronWorkbenchRecipe crecipe = this.slotRecipeMap.get(currentSlot); - List opts = this.output.getRecipeOutputs(currentSlot); - int multiplier = this.inputMaterial.getMultiplier(crecipe.materials); - Iterator optsi = opts.iterator(); - Iterator emptySlotsIterator = crafterEmptyInventorySlotsList.iterator(); - while(optsi.hasNext()) - { - int slot = emptySlotsIterator.next(); - ItemStack stack = optsi.next(); - if(stack.getItem() instanceof IWire) - { - this.crafter.inventory.mainInventory[slot]=IHLUtils.getWireItemStackCopyWithLengthMultiplied(stack,multiplier); - } - else - { - this.crafter.inventory.mainInventory[slot]=stack.copy(); - this.crafter.inventory.mainInventory[slot].stackSize*=multiplier; - } + if (startProcess && crafterEmptyInventorySlotsList.size() >= this.slotRecipeMap.get(currentSlot).outputs + .size()) { + if (++this.progress >= this.maxProgress) { + IronWorkbenchRecipe crecipe = this.slotRecipeMap.get(currentSlot); + List opts = this.output.getRecipeOutputs(currentSlot); + int multiplier = this.inputMaterial.getMultiplier(crecipe.materials); + Iterator optsi = opts.iterator(); + Iterator emptySlotsIterator = crafterEmptyInventorySlotsList.iterator(); + while (optsi.hasNext()) { + int slot = emptySlotsIterator.next(); + ItemStack stack = optsi.next(); + if (stack.getItem() instanceof IWire) { + this.crafter.inventory.mainInventory[slot] = IHLUtils + .getWireItemStackCopyWithLengthMultiplied(stack, multiplier); + } else { + this.crafter.inventory.mainInventory[slot] = stack.copy(); + 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.tools.damage(crecipe.tools); - if(!crecipe.workspaceElements.isEmpty()) - { - this.workspaceElements.use(crecipe.workspaceElements); + } + 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.resetOutput(); } + this.crafter.inventoryContainer.detectAndSendChanges(); + this.tools.damage(crecipe.tools); + if (!crecipe.workspaceElements.isEmpty()) { + this.workspaceElements.use(crecipe.workspaceElements); + } + this.resetOutput(); } + } } } } - private ItemStack getMatchedItemStack(IRecipeInput rinput) - { - for(ItemStack tool:this.tools.getItemStackList()) - { - if(rinput.matches(tool)) - { + private ItemStack getMatchedItemStack(IRecipeInput rinput) { + for (ItemStack tool : this.tools.getItemStackList()) { + if (rinput.matches(tool)) { return tool; } } - for(ItemStack material:this.inputMaterial.getItemStackList()) - { - if(rinput.matches(material)) - { + for (ItemStack material : this.inputMaterial.getItemStackList()) { + if (rinput.matches(material)) { return material; } } @@ -226,46 +200,38 @@ public class IronWorkbenchTileEntity extends TileEntityInventory implements IHas return null; } - private Set getCrafterEmptyInventorySlotsList() - { + private Set getCrafterEmptyInventorySlotsList() { Set list = new HashSet(4); - if(this.crafter!=null) - { - for (int var1 = 0; var1 < this.crafter.inventory.mainInventory.length; ++var1) - { - if (this.crafter.inventory.mainInventory[var1] == null) - { - list.add(var1); - } - } + if (this.crafter != null) { + for (int var1 = 0; var1 < this.crafter.inventory.mainInventory.length; ++var1) { + if (this.crafter.inventory.mainInventory[var1] == null) { + list.add(var1); + } + } } return list; } - - private List getListOfSameWires(ItemStack stack1) { - List list = new ArrayList(); - for(int i=0; i getListOfSameWires(ItemStack stack1) { + List list = new ArrayList(); + for (int i = 0; i < this.inputMaterial.size(); i++) { ItemStack stack = this.inputMaterial.get(i); - if(stack!=null && ((IWire)stack1.getItem()).isSameWire(stack1, stack)) - { + if (stack != null && ((IWire) stack1.getItem()).isSameWire(stack1, stack)) { list.add(new RecipeInputObjectInstance(stack)); } } - return list; + return list; } private int getFullLengthOfSameWires(ItemStack stack1) { - int fullLength=0; - for(int i=0; i getGuiContainer(EntityPlayer player) { resetOutput(); - this.isGuiScreenOpened=true; - this.crafter=player; + this.isGuiScreenOpened = true; + this.crafter = player; container = new IronWorkbenchContainer(player, this); return container; } @Override - public void onGuiClosed(EntityPlayer arg0) - { - this.isGuiScreenOpened=false; + public void onGuiClosed(EntityPlayer arg0) { + this.isGuiScreenOpened = false; } @Override - public void onNetworkEvent(EntityPlayer player, int event) - { - if(event==16) - { - this.isGuiScreenOpened=false; - this.crafter=null; - this.container=null; + public void onNetworkEvent(EntityPlayer player, int event) { + if (event == 16) { + this.isGuiScreenOpened = false; + this.crafter = null; + this.container = null; return; } - for(int i=event;i>=0;i--) - { - if(this.slotRecipeMap.containsKey(i)) - { - if(!this.slotRecipeMap.get(i).isCanBeCrafted(this.tools.getItemStackList(), this.inputMaterial.getItemStackList(), this.workspaceElements.getItemStackList())) - { + for (int i = event; i >= 0; i--) { + if (this.slotRecipeMap.containsKey(i)) { + if (!this.slotRecipeMap.get(i).isCanBeCrafted(this.tools.getItemStackList(), + this.inputMaterial.getItemStackList(), this.workspaceElements.getItemStackList())) { resetOutput(); - } - else - { - this.currentSlot=i; - this.startProcess=true; + } else { + this.currentSlot = i; + this.startProcess = true; return; } } } } - public void resetOutput() - { + public void resetOutput() { this.output.clear(); this.slotRecipeMap.clear(); - this.progress=0; - this.startProcess=false; - this.currentSlot=-1; - this.outputDefined=false; + this.progress = 0; + this.startProcess = false; + this.currentSlot = -1; + this.outputDefined = false; } - public void dropContents() { - for(int i=0;i recipeOutputsItems) - { + public static void removeRecipeByOutput(List recipeOutputsItems) { Iterator ri = recipes.iterator(); - while(ri.hasNext()) - { + while (ri.hasNext()) { IronWorkbenchRecipe recipe = ri.next(); - boolean removeEntry=false; + boolean removeEntry = false; Iterator roi = recipe.outputs.iterator(); - while(roi.hasNext()) - { - if(IHLUtils.isItemStacksIsEqual(recipeOutputsItems.get(0), roi.next(), true)) - { - removeEntry=true; + while (roi.hasNext()) { + if (IHLUtils.isItemStacksIsEqual(recipeOutputsItems.get(0), roi.next(), true)) { + removeEntry = true; } } - if(removeEntry) - { + if (removeEntry) { ri.remove(); } } } - public static void removeRecipeByInput(List recipeInputsTools1,List recipeInputsItems1,List recipeInputsMachines) { + public static void removeRecipeByInput(List recipeInputsTools1, List recipeInputsItems1, + List recipeInputsMachines) { List recipeInputsTools = IHLUtils.convertRecipeInputToItemStackList(recipeInputsTools1); List recipeInputsItems = IHLUtils.convertRecipeInputToItemStackList(recipeInputsItems1); Iterator ri = recipes.iterator(); - while(ri.hasNext()) - { + while (ri.hasNext()) { IronWorkbenchRecipe recipe = ri.next(); - if(recipe.isCanBeCrafted(recipeInputsTools, recipeInputsItems, recipeInputsMachines)) - { + if (recipe.isCanBeCrafted(recipeInputsTools, recipeInputsItems, recipeInputsMachines)) { ri.remove(); } } } - + @Override - public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) - { + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { this.readFromNBT(pkt.func_148857_g()); - } + } } -- cgit v1.2.3