Пример #1
0
 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;
 }
Пример #2
0
  @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;
      }
    }
  }
Пример #3
0
  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;
    }
  }