Exemplo n.º 1
0
  @Override
  public void careForInventorySlot(ItemStack is) {
    if (is != null) {
      HeatRegistry manager = HeatRegistry.getInstance();
      HeatIndex index = manager.findMatchingIndex(is);

      if (index != null) {
        float temp = TFC_ItemHeat.getTemp(is);
        if (fuelTimeLeft > 0 && is.getItem() instanceof ICookableFood) {
          float inc = Food.getCooked(is) + Math.min(fireTemp / 700, 2f);
          Food.setCooked(is, inc);
          temp = inc;
          if (Food.isCooked(is)) {
            int[] cookedTasteProfile = new int[] {0, 0, 0, 0, 0};
            Random r =
                new Random(
                    ((ICookableFood) is.getItem()).getFoodID()
                        + (((int) Food.getCooked(is) - 600) / 120));
            cookedTasteProfile[0] = r.nextInt(31) - 15;
            cookedTasteProfile[1] = r.nextInt(31) - 15;
            cookedTasteProfile[2] = r.nextInt(31) - 15;
            cookedTasteProfile[3] = r.nextInt(31) - 15;
            cookedTasteProfile[4] = r.nextInt(31) - 15;
            Food.setCookedProfile(is, cookedTasteProfile);
            Food.setFuelProfile(is, EnumFuelMaterial.getFuelProfile(fuelTasteProfile));
          }
        } else if (fireTemp > temp && index.hasOutput()) {
          temp += TFC_ItemHeat.getTempIncrease(is);
        } else temp -= TFC_ItemHeat.getTempDecrease(is);
        TFC_ItemHeat.setTemp(is, temp);
      }
    }
  }
Exemplo n.º 2
0
  public void CookItem(int i) {
    ItemStack cookingItemStack = fireItemStacks[i];
    TECrucible crucibleTE =
        (worldObj.getTileEntity(xCoord, yCoord - 1, zCoord) instanceof TECrucible)
            ? (TECrucible) worldObj.getTileEntity(xCoord, yCoord - 1, zCoord)
            : null;

    /*
     * Only allow the ore to be smelted if there is a tuyere in the blast furnace,
     * a crucible below the blast furnace that isn't full, and the delay timer has completed.
     */
    if (cookingItemStack != null
        && crucibleTE != null
        && crucibleTE.getTotalMetal() < crucibleTE.MAX_UNITS
        && storage[1] != null /*Tuyere*/
        && cookDelay == 0) {
      Random R = new Random();
      HeatRegistry manager = HeatRegistry.getInstance();
      HeatIndex index = manager.findMatchingIndex(cookingItemStack);

      if (index != null && TFC_ItemHeat.GetTemp(cookingItemStack) >= index.meltTemp) {
        int output = 0;
        Item cookingItem = cookingItemStack.getItem();

        if (cookingItem instanceof ISmeltable) {
          output = ((ISmeltable) cookingItem).GetMetalReturnAmount(cookingItemStack);
          // Attempt to add metal to crucible.
          if (!crucibleTE.addMetal(
              ((ISmeltable) cookingItem).GetMetalType(cookingItemStack), output))
            return; // Do not decrease fuel or ore if the crucible is too full.
        } else {
          Metal m = MetalRegistry.instance.getMetalFromItem(cookingItem);
          output = index.getOutput(cookingItemStack, R).getItemDamage();
          if (m != null) {
            // Attempt to add metal to crucible.
            if (!crucibleTE.addMetal(m, (short) (100 - output)))
              return; // Do not decrease fuel or ore if the crucible is too full.
          }
        }

        oreCount--;
        charcoalCount--;
        cookDelay = 100; // Five seconds (20 tps) until the next piece of ore can be smelted
        fireItemStacks[i] = null; // Delete cooked item

        /*
         * Treat fireItemStacks as a queue, and shift everything forward when an item is melted.
         * This way the hottest item is always in the first slot - Kitty
         */
        Queue<ItemStack> buffer = new ArrayBlockingQueue<ItemStack>(fireItemStacks.length);
        for (ItemStack is : fireItemStacks) {
          if (is != null) {
            buffer.offer(is);
          }
        }

        fireItemStacks = buffer.toArray(new ItemStack[fireItemStacks.length]);

        // Damage the tuyere 1 point per item (not metal unit) smelted.
        storage[1].setItemDamage(storage[1].getItemDamage() + 1);
        if (storage[1] != null && storage[1].getItemDamage() == storage[1].getMaxDamage()) {
          setInventorySlotContents(1, null);
        }

        // Update crucible temperature
        crucibleTE.temperature = (int) fireTemp;
      }
    }
  }
Exemplo n.º 3
0
  public void cookItem() {
    HeatRegistry manager = HeatRegistry.getInstance();
    Random r = new Random();
    if (fireItemStacks[1] != null) {
      HeatIndex index = manager.findMatchingIndex(fireItemStacks[1]);
      if (index != null && TFC_ItemHeat.getTemp(fireItemStacks[1]) > index.meltTemp) {
        ItemStack output = index.getOutput(fireItemStacks[1], r);
        ItemCookEvent eventMelt = new ItemCookEvent(fireItemStacks[1], output, this);
        MinecraftForge.EVENT_BUS.post(eventMelt);
        output = eventMelt.result;
        int damage = 0;
        ItemStack mold = null;
        if (output != null) {
          damage = output.getItemDamage();
          if (output.getItem() == fireItemStacks[1].getItem())
            damage = fireItemStacks[1].getItemDamage();

          // If the input is unshaped metal
          if (fireItemStacks[1].getItem() instanceof ItemMeltedMetal) {
            // if both output slots are empty then just lower the input item into the first output
            // slot
            if (fireItemStacks[7] == null && fireItemStacks[8] == null) {
              fireItemStacks[7] = fireItemStacks[1].copy();
              fireItemStacks[1] = null;
              return;
            }
            // Otherwise if the first output has an item that doesnt match the input item then put
            // the item in the second output slot
            else if (fireItemStacks[7] != null
                && fireItemStacks[7].getItem() != TFCItems.ceramicMold
                && (fireItemStacks[7].getItem() != fireItemStacks[1].getItem()
                    || fireItemStacks[7].getItemDamage() == 0)) {
              if (fireItemStacks[8] == null) {
                fireItemStacks[8] = fireItemStacks[1].copy();
                fireItemStacks[1] = null;
                return;
              }
            }
            mold = new ItemStack(TFCItems.ceramicMold, 1);
            mold.stackSize = 1;
            mold.setItemDamage(1);
          }
        }
        // Morph the input
        float temp = TFC_ItemHeat.getTemp(fireItemStacks[1]);
        fireItemStacks[1] = index.getMorph();
        if (fireItemStacks[1] != null && manager.findMatchingIndex(fireItemStacks[1]) != null) {
          // if the input is a new item, then apply the old temperature to it
          TFC_ItemHeat.setTemp(fireItemStacks[1], temp);
        }

        // Check if we should combine the output with a pre-existing output
        if (output != null && output.getItem() instanceof ItemMeltedMetal) {
          int leftover = 0;
          boolean addLeftover = false;
          int fromSide = 0;
          if (fireItemStacks[7] != null
              && output.getItem() == fireItemStacks[7].getItem()
              && fireItemStacks[7].getItemDamage() > 0) {
            int amt1 = 100 - damage; // the percentage of the output
            int amt2 =
                100 - fireItemStacks[7].getItemDamage(); // the percentage currently in the out slot
            int amt3 = amt1 + amt2; // combined amount
            leftover =
                amt3
                    - 100; // assign the leftover so that we can add to the other slot if applicable
            if (leftover > 0) addLeftover = true;
            int amt4 = 100 - amt3; // convert the percent back to mc damage
            if (amt4 < 0) amt4 = 0; // stop the infinite glitch
            fireItemStacks[7] = output.copy();
            fireItemStacks[7].setItemDamage(amt4);

            TFC_ItemHeat.setTemp(fireItemStacks[7], temp);

            if (fireItemStacks[1] == null && mold != null) fireItemStacks[1] = mold;
          } else if (fireItemStacks[8] != null
              && output.getItem() == fireItemStacks[8].getItem()
              && fireItemStacks[8].getItemDamage() > 0) {
            int amt1 = 100 - damage; // the percentage of the output
            int amt2 =
                100 - fireItemStacks[8].getItemDamage(); // the percentage currently in the out slot
            int amt3 = amt1 + amt2; // combined amount
            leftover =
                amt3
                    - 100; // assign the leftover so that we can add to the other slot if applicable
            if (leftover > 0) addLeftover = true;
            fromSide = 1;
            int amt4 = 100 - amt3; // convert the percent back to mc damage
            if (amt4 < 0) amt4 = 0; // stop the infinite glitch
            fireItemStacks[8] = output.copy();
            fireItemStacks[8].setItemDamage(amt4);

            TFC_ItemHeat.setTemp(fireItemStacks[8], temp);

            if (fireItemStacks[1] == null && mold != null) fireItemStacks[1] = mold;
          } else if (fireItemStacks[7] != null
              && fireItemStacks[7].getItem() == TFCItems.ceramicMold) {
            fireItemStacks[7] = output.copy();
            fireItemStacks[7].setItemDamage(damage);

            TFC_ItemHeat.setTemp(fireItemStacks[7], temp);
          } else if (fireItemStacks[8] != null
              && fireItemStacks[8].getItem() == TFCItems.ceramicMold) {
            fireItemStacks[8] = output.copy();
            fireItemStacks[8].setItemDamage(damage);

            TFC_ItemHeat.setTemp(fireItemStacks[8], temp);
          }

          if (addLeftover) {
            int dest = fromSide == 1 ? 7 : 8;
            if (fireItemStacks[dest] != null
                && output.getItem() == fireItemStacks[dest].getItem()
                && fireItemStacks[dest].getItemDamage() > 0) {
              int amt1 = 100 - leftover; // the percentage of the output
              int amt2 =
                  100
                      - fireItemStacks[dest]
                          .getItemDamage(); // the percentage currently in the out slot
              int amt3 = amt1 + amt2; // combined amount
              int amt4 = 100 - amt3; // convert the percent back to mc damage
              if (amt4 < 0) amt4 = 0; // stop the infinite glitch
              fireItemStacks[dest] = output.copy();
              fireItemStacks[dest].setItemDamage(amt4);

              TFC_ItemHeat.setTemp(fireItemStacks[dest], temp);
            } else if (fireItemStacks[dest] != null
                && fireItemStacks[dest].getItem() == TFCItems.ceramicMold) {
              fireItemStacks[dest] = output.copy();
              fireItemStacks[dest].setItemDamage(100 - leftover);
              TFC_ItemHeat.setTemp(fireItemStacks[dest], temp);
            }
          }
        } else if (output != null) {
          if (fireItemStacks[7] != null
              && fireItemStacks[7].getItem() == output.getItem()
              && fireItemStacks[7].stackSize + output.stackSize
                  <= fireItemStacks[7].getMaxStackSize()) {
            fireItemStacks[7].stackSize += output.stackSize;
          } else if (fireItemStacks[8] != null
              && fireItemStacks[8].getItem() == output.getItem()
              && fireItemStacks[8].stackSize + output.stackSize
                  <= fireItemStacks[8].getMaxStackSize()) {
            fireItemStacks[8].stackSize += output.stackSize;
          } else if (fireItemStacks[7] == null) {
            fireItemStacks[7] = output.copy();
          } else if (fireItemStacks[8] == null) {
            fireItemStacks[8] = output.copy();
          } else if (fireItemStacks[7].stackSize == fireItemStacks[7].getMaxStackSize()
                  && fireItemStacks[8].stackSize == fireItemStacks[8].getMaxStackSize()
              || fireItemStacks[7].getItem() != output.getItem()
                  && fireItemStacks[8].getItem() != output.getItem()
              || fireItemStacks[7].stackSize == fireItemStacks[7].getMaxStackSize()
                  && fireItemStacks[8].getItem() != output.getItem()
              || fireItemStacks[7].getItem() != output.getItem()
                  && fireItemStacks[8].stackSize == fireItemStacks[8].getMaxStackSize()) {
            fireItemStacks[1] = output.copy();
          }
        }
      }
    }
  }