예제 #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);
      }
    }
  }
예제 #2
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();
          }
        }
      }
    }
  }
예제 #3
0
  @Override
  public void updateEntity() {
    if (!worldObj.isRemote) {
      ItemStack itemstack = storage[INPUT_SLOT];
      BarrelPreservativeRecipe preservative =
          BarrelManager.getInstance()
              .findMatchingPreservativeRepice(this, itemstack, fluid, sealed);
      if (itemstack != null && fluid != null && fluid.getFluid() == TFCFluids.FRESHWATER) {
        if (TFC_ItemHeat.hasTemp(itemstack)) {
          float temp = TFC_ItemHeat.getTemp(itemstack);
          if (fluid.amount >= 1 && temp > 1) {
            temp -= 50;
            fluid.amount -= 1;
            TFC_ItemHeat.setTemp(itemstack, temp);
            TFC_ItemHeat.handleItemHeat(itemstack);
          }
        }
      }
      if (fluid != null && itemstack != null && itemstack.getItem() instanceof IFood) {
        float w = ((IFood) itemstack.getItem()).getFoodWeight(itemstack);
        if (fluid.getFluid() == TFCFluids.VINEGAR) {
          // If the food is brined then we attempt to pickle it
          if (Food.isBrined(itemstack)
              && !Food.isPickled(itemstack)
              && w / fluid.amount <= Global.FOOD_MAX_WEIGHT / this.getMaxLiquid()
              && this.getSealed()
              && sealtime != 0
              && TFC_Time.getTotalHours() - sealtime >= 4) {
            fluid.amount -= 1 * w;
            Food.setPickled(itemstack, true);
          }
        }
      }

      if (preservative == null) {
        // No preservative was matched - decay normally
        TFC_Core.handleItemTicking(this, this.worldObj, xCoord, yCoord, zCoord);
      } else {
        float env = preservative.getEnvironmentalDecayFactor();
        float base = preservative.getBaseDecayModifier();
        if (Float.isNaN(env) || env < 0.0) {
          TFC_Core.handleItemTicking(this, this.worldObj, xCoord, yCoord, zCoord);
        } else if (Float.isNaN(base) || base < 0.0) {
          TFC_Core.handleItemTicking(this, this.worldObj, xCoord, yCoord, zCoord, env);
        } else {
          TFC_Core.handleItemTicking(this, this.worldObj, xCoord, yCoord, zCoord, env, base);
        }
      }

      // If lightning can strike here then it means that the barrel can see the sky, so rain can hit
      // it. If true then we fill
      // the barrel when its raining.
      if (!this.getSealed() && worldObj.canLightningStrikeAt(xCoord, yCoord + 1, zCoord)) {
        int count = getInvCount();
        if (count == 0 || count == 1 && this.getInputStack() != null) {
          if (this.fluid == null) fluid = new FluidStack(TFCFluids.FRESHWATER, 1);
          else if (this.fluid != null && fluid.getFluid() == TFCFluids.FRESHWATER)
            fluid.amount = Math.min(fluid.amount + 1, getMaxLiquid());
        }
      }

      // We only want to bother ticking food once per 5 seconds to keep overhead low.
      processTimer++;
      if (processTimer > 100) {
        processItems();
        processTimer = 0;
      }

      // Here we handle item stacks that are too big for MC to handle such as when making mortar.
      // If the stack is > its own max stack size then we split it and add it to the invisible solid
      // storage area or
      // spawn the item in the world if there is no room left.
      if (this.getFluidLevel() > 0 && getInputStack() != null) {
        int count = 1;
        while (this.getInputStack().stackSize > getInputStack().getMaxStackSize()) {
          ItemStack is = getInputStack().splitStack(getInputStack().getMaxStackSize());
          if (count < this.storage.length && this.getStackInSlot(count) == null) {
            this.setInventorySlotContents(count, is);
          } else {
            worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord, yCoord, zCoord, is));
          }
          count++;
        }
      }

      // Move any items in the solid storage slots to the main slot if they exist and the barrel has
      // liquid.
      else if (this.getFluidLevel() > 0 && getInputStack() == null && this.getInvCount() > 0) {
        for (int i = 0; i < storage.length; i++) {
          if (storage[i] != null) {
            storage[INPUT_SLOT] = storage[i].copy();
            storage[i] = null;
            break;
          }
        }
      }

      // Reset our fluid if all of the liquid is gone.
      if (fluid != null && fluid.amount == 0) fluid = null;

      // Handle adding fluids to the barrel if the barrel is currently in input mode.
      if (mode == MODE_IN) {
        ItemStack container = getInputStack();
        FluidStack inLiquid = FluidContainerRegistry.getFluidForFilledItem(container);

        if (container != null && container.getItem() instanceof IFluidContainerItem) {
          FluidStack isfs = ((IFluidContainerItem) container.getItem()).getFluid(container);
          if (isfs != null && addLiquid(isfs)) {
            ((IFluidContainerItem) container.getItem())
                .drain(
                    container,
                    ((IFluidContainerItem) container.getItem()).getCapacity(container),
                    true);
          }
        } else if (inLiquid != null && container != null && container.stackSize == 1) {
          if (addLiquid(inLiquid)) {
            this.setInventorySlotContents(0, FluidContainerRegistry.drainFluidContainer(container));
          }
        }
      }
      // Drain liquid from the barrel to a container if the barrel is in output mode.
      else if (mode == MODE_OUT) {
        ItemStack container = getInputStack();

        if (container != null
            && fluid != null
            && container.getItem() instanceof IFluidContainerItem) {
          FluidStack isfs = ((IFluidContainerItem) container.getItem()).getFluid(container);
          if (isfs == null || fluid.isFluidEqual(isfs)) {
            fluid.amount -=
                ((IFluidContainerItem) container.getItem()).fill(container, fluid, true);
            if (fluid.amount == 0) fluid = null;
          }
        } else if (FluidContainerRegistry.isEmptyContainer(container)) {
          this.setInventorySlotContents(0, this.removeLiquid(getInputStack()));
        }
      }
    }
  }