public float checkTemps(IInventory inv) { float temp = 0; float[] temp1 = new float[inv.getSizeInventory()]; for (int i = 0; i < inv.getSizeInventory(); i++) { ItemStack is = inv.getStackInSlot(i); if (is != null && is.hasTagCompound() && !is.getItem().getUnlocalizedName(is).contains("Clay")) { if (is.getTagCompound().hasKey("temperature")) { temp1[i] = is.getTagCompound().getFloat("temperature"); if (temp1[i] < TFC_ItemHeat.getMeltingPoint(is)) { return (float) -1; } } else { return (float) -1; } } else if (is == null) { temp1[i] = -1; } } int temp2 = 0; for (int i = 0; i < inv.getSizeInventory(); i++) { if (temp1[i] >= 0) { temp += temp1[i]; temp2++; } } if (temp2 > 0) { temp /= temp2; } return temp; }
@Override public void updateEntity() { if (!worldObj.isRemote) { inputTick++; outputTick++; tempTick++; /*Heat the crucible based on the Forge beneath it*/ if (worldObj.getBlockId(xCoord, yCoord - 1, zCoord) == TFCBlocks.Forge.blockID) { TileEntityForge te = (TileEntityForge) worldObj.getBlockTileEntity(xCoord, yCoord - 1, zCoord); if (te.fireTemperature > temperature) { temperature++; } } if (tempTick > 22) { tempTick = 0; if (temperature > TFC_Climate.getHeightAdjustedTemp(xCoord, yCoord, zCoord)) { temperature--; } } ItemStack stackToSmelt = storage[0]; if (stackToSmelt != null) { Item itemToSmelt = stackToSmelt.getItem(); if (itemToSmelt instanceof ItemMeltedMetal && TFC_ItemHeat.getIsLiquid(storage[0])) { if (inputTick > 5) { if (currentAlloy != null && currentAlloy.outputType != null && itemToSmelt.itemID == currentAlloy.outputType.MeltedItemID) { this.addMetal(MetalRegistry.instance.getMetalFromItem(itemToSmelt), (short) 1); if (stackToSmelt.getItemDamage() + 1 >= storage[0].getMaxDamage()) { storage[0] = new ItemStack(TFCItems.CeramicMold, 1, 1); } else { stackToSmelt.setItemDamage(stackToSmelt.getItemDamage() + 1); } } else { this.addMetal(MetalRegistry.instance.getMetalFromItem(itemToSmelt), (short) 1); if (stackToSmelt.getItemDamage() + 1 >= stackToSmelt.getMaxDamage()) { storage[0] = new ItemStack(TFCItems.CeramicMold, 1, 1); } else { stackToSmelt.setItemDamage(stackToSmelt.getItemDamage() + 1); } } inputTick = 0; updateGui((byte) 0); } } else if (itemToSmelt instanceof ISmeltable && ((ISmeltable) itemToSmelt).isSmeltable(stackToSmelt) && !TFC_Core.isOreIron(stackToSmelt) && temperature >= TFC_ItemHeat.getMeltingPoint(stackToSmelt)) { Metal mType = ((ISmeltable) itemToSmelt).GetMetalType(stackToSmelt); if (addMetal(mType, ((ISmeltable) itemToSmelt).GetMetalReturnAmount(stackToSmelt))) { temperature *= 0.9f; if (stackToSmelt.stackSize <= 1) { storage[0] = null; } updateGui((byte) 0); } } } // Metal Output handling if (currentAlloy != null && storage[1] != null && currentAlloy.outputType != null && outputTick >= 3 && temperature >= TFC_ItemHeat.getMeltingPoint(currentAlloy.outputType)) { if (storage[1].itemID == TFCItems.CeramicMold.itemID) { storage[1] = new ItemStack(Item.itemsList[currentAlloy.outputType.MeltedItemID], 1, 99); TFC_ItemHeat.SetTemperature(storage[1], temperature); // currentAlloy.outputAmount--; drainOutput(1.0f); updateGui((byte) 1); } else if (storage[1].itemID == currentAlloy.outputType.MeltedItemID && storage[1].getItemDamage() > 0) { storage[1].setItemDamage(storage[1].getItemDamage() - 1); float inTemp = TFC_ItemHeat.GetTemperature(storage[1]); float temp = (temperature - inTemp) / 2; TFC_ItemHeat.SetTemperature(storage[1], inTemp + temp); // System.out.println(temperature +", "+inTemp+", "+temp); // currentAlloy.outputAmount--; drainOutput(1.0f); storage[1].stackSize = 1; updateGui((byte) 1); } outputTick = 0; } if (currentAlloy != null && currentAlloy.outputAmount <= 0) { metals = new HashMap(); updateCurrentAlloy(); this.updateGui((byte) 2); currentAlloy = null; } if (storage[1] != null && storage[1].stackSize <= 0) { storage[1].stackSize = 1; } if (inputTick > 5) { inputTick = 0; } if (outputTick >= 3) { outputTick = 0; } } }
public void updateEntity() { TFC_ItemHeat.HandleContainerHeat( this.worldObj, storage, (int) xCoord, (int) yCoord, (int) zCoord); }
@Override public void updateEntity() { TFC_ItemHeat.HandleContainerHeat(this.worldObj, storage, xCoord, yCoord, zCoord); }
public void careForInventorySlot(int i, float startTemp) { NBTTagCompound inputCompound; float mod = 1; if (i == 0) { if (fireItemStacks[5] != null) { mod = 0.8F; } else { mod = 0.6F; if (fireItemStacks[6] == null) { mod = 0.3F; } } } else if (i == 1) { if (fireItemStacks[6] != null) { mod = 0.9F; } else { mod = 0.7F; if (fireItemStacks[7] == null) { mod = 0.4F; } } } else if (i == 2) { if (fireItemStacks[7] != null) { mod = 1.0F; } else { mod = 0.5F; } } else if (i == 3) { if (fireItemStacks[8] != null) { mod = 0.9F; } else { mod = 0.7F; if (fireItemStacks[7] == null) { mod = 0.4F; } } } else if (i == 4) { if (fireItemStacks[9] != null) { mod = 0.8F; } else { mod = 0.6F; if (fireItemStacks[8] == null) { mod = 0.3F; } } } HeatRegistry manager = HeatRegistry.getInstance(); if (fireItemStacks[i] != null && fireItemStacks[i].hasTagCompound()) { HeatIndex index = manager.findMatchingIndex(fireItemStacks[i]); inputCompound = fireItemStacks[i].getTagCompound(); if (inputCompound.hasKey("temperature")) { inputItemTemps[i] = inputCompound.getFloat("temperature"); } else { inputItemTemps[i] = ambientTemp; } if (fireTemperature * mod > inputItemTemps[i]) { float increase = TFC_ItemHeat.getTempIncrease(fireItemStacks[i], fireTemperature * mod, MaxFireTemp); inputItemTemps[i] += increase; } else if (fireTemperature * mod < inputItemTemps[i]) { float increase = TFC_ItemHeat.getTempDecrease(fireItemStacks[i]); inputItemTemps[i] -= increase; } inputCompound.setFloat("temperature", inputItemTemps[i]); fireItemStacks[i].setTagCompound(inputCompound); if (inputItemTemps[i] <= ambientTemp) { Collection C = fireItemStacks[i].getTagCompound().getTags(); Iterator itr = C.iterator(); while (itr.hasNext()) { Object tag = itr.next(); if (TFC_ItemHeat.canRemoveTag(tag, "temperature", NBTTagFloat.class)) { itr.remove(); break; } } // fireItemStacks[i].stackTagCompound = null; } } else if (fireItemStacks[i] != null && !fireItemStacks[i].hasTagCompound()) { if (TFC_ItemHeat.getMeltingPoint(fireItemStacks[i]) != -1) { inputCompound = new NBTTagCompound(); inputCompound.setFloat("temperature", startTemp); fireItemStacks[i].setTagCompound(inputCompound); inputItemTemps[i] = startTemp; } } else if (fireItemStacks[i] == null) { inputItemTemps[i] = 0; } }
@Override public void updateEntity() { if (!worldObj.isRemote) { // Here we take care of the items that we are cooking in the fire careForInventorySlot(0, 40); careForInventorySlot(1, 40); careForInventorySlot(2, 40); careForInventorySlot(3, 40); careForInventorySlot(4, 40); ItemStack[] FuelStack = new ItemStack[9]; FuelStack[0] = fireItemStacks[5]; FuelStack[1] = fireItemStacks[6]; FuelStack[2] = fireItemStacks[7]; FuelStack[3] = fireItemStacks[8]; FuelStack[4] = fireItemStacks[9]; FuelStack[5] = fireItemStacks[10]; FuelStack[6] = fireItemStacks[11]; FuelStack[7] = fireItemStacks[12]; FuelStack[8] = fireItemStacks[13]; TFC_ItemHeat.HandleContainerHeat(this.worldObj, FuelStack, xCoord, yCoord, zCoord); // Now we cook the input item CookItemsNew(0); CookItemsNew(1); CookItemsNew(2); CookItemsNew(3); CookItemsNew(4); // push the input fuel down the stack HandleFuelStack(); if (ambientTemp == -1000) { TFCBiome biome = (TFCBiome) worldObj.getBiomeGenForCoords(xCoord, zCoord); ambientTemp = biome.getHeightAdjustedTemperature(yCoord); } // here we set the various temperatures to range this.keepTempToRange(); // Play the fire sound Random R = new Random(); if (R.nextInt(10) == 0 && fireTemperature > 210) { worldObj.playSoundEffect( xCoord, yCoord, zCoord, "fire.fire", 0.4F + (R.nextFloat() / 2), 0.7F + R.nextFloat()); } if (fireTemperature >= 100 && worldObj.getBlockMetadata(xCoord, yCoord, zCoord) != 1) { worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 3); } else if (fireTemperature < 100 && worldObj.getBlockMetadata(xCoord, yCoord, zCoord) != 0) { worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 3); } // If the fire is still burning and has fuel if (fuelTimeLeft > 0 && fireTemperature >= 210 && (!worldObj.canBlockSeeTheSky(xCoord, yCoord, zCoord) || !worldObj.isRaining())) { float desiredTemp = handleTemp(); handleTempFlux(desiredTemp); } else if (fuelTimeLeft <= 0 && fireTemperature >= 210 && fireItemStacks[7] != null && (!worldObj.canBlockSeeTheSky(xCoord, yCoord, zCoord) || !worldObj.isRaining())) { // here we set the temp and burn time based on the fuel in the bottom slot. if (fireItemStacks[7] != null) { if (fireItemStacks[7].itemID == Item.coal.itemID && fireItemStacks[7].getItemDamage() == 0) { fuelTimeLeft = 1100; fuelBurnTemp = 1400; } if (fireItemStacks[7].itemID == Item.coal.itemID && fireItemStacks[7].getItemDamage() == 1) { fuelTimeLeft = 900; fuelBurnTemp = 1350; } fireItemStacks[7] = null; } } // If there is no more fuel and the fire is still hot, we start to cool it off. if (fuelTimeLeft <= 0 && fireTemperature > ambientTemp || (worldObj.isRaining() && worldObj.canBlockSeeTheSky(xCoord, yCoord, zCoord))) { if (airFromBellows == 0) { fireTemperature -= 0.125F; } else { fireTemperature -= 0.1F; } } // Here we handle the bellows if (airFromBellowsTime > 0) { airFromBellowsTime--; airFromBellows = airFromBellowsTime / 120 * 10; } // Here we make sure that the forge is valid isValid = CheckValidity(); // do a last minute check to verify stack size for (int c = 0; c < 5; c++) { if (fireItemStacks[c] != null) { if (fireItemStacks[c].stackSize <= 0) { fireItemStacks[c].stackSize = 1; } } } } }