Example #1
0
  /**
   * We have to handle cheese by itself because the barrel recipe manager doesnt take kindly to null
   * input items.
   */
  private boolean handleCheese() {
    ItemStack inIS = this.getInputStack();
    if (this.getSealed()
        && this.fluid != null
        && this.fluid.getFluid() == TFCFluids.MILKCURDLED
        && (inIS == null
            || inIS.getItem() instanceof IFood
                && ((IFood) inIS.getItem()).getFoodGroup() != EnumFoodGroup.Dairy
                && ((IFood) inIS.getItem()).isEdible(inIS)
                && Food.getWeight(inIS) <= 20.0f)) {
      recipe =
          new BarrelRecipe(
                  null,
                  new FluidStack(TFCFluids.MILKCURDLED, 10000),
                  ItemFoodTFC.createTag(new ItemStack(TFCItems.cheese, 1), 160),
                  null)
              .setMinTechLevel(0);
      if (!worldObj.isRemote) {
        int time = 0;
        if (sealtime > 0) time = (int) TFC_Time.getTotalHours() - sealtime;
        else if (unsealtime > 0) time = (int) TFC_Time.getTotalHours() - unsealtime;

        // Make sure that the recipe meets the time requirements
        if (time < recipe.sealTime) return true;
        float w = this.fluid.amount / 62.5f;

        ItemStack is = ItemFoodTFC.createTag(new ItemStack(TFCItems.cheese), w);

        if (inIS != null && inIS.getItem() instanceof IFood) {
          int[] profile = Food.getFoodTasteProfile(inIS);
          float ratio =
              Math.min(
                  (Food.getWeight(getInputStack()) - Food.getDecay(inIS))
                      / (Global.FOOD_MAX_WEIGHT / 8),
                  1.0f);
          Food.setSweetMod(is, (int) Math.floor(profile[INPUT_SLOT] * ratio));
          Food.setSourMod(is, (int) Math.floor(profile[1] * ratio));
          Food.setSaltyMod(is, (int) Math.floor(profile[2] * ratio));
          Food.setBitterMod(is, (int) Math.floor(profile[3] * ratio));
          Food.setSavoryMod(is, (int) Math.floor(profile[4] * ratio));
          Food.setInfusion(is, inIS.getItem().getUnlocalizedName());
          this.storage[INPUT_SLOT] = null;
        }

        this.actionEmpty();
        this.setInventorySlotContents(0, is);
      }
      return true;
    }
    return false;
  }
Example #2
0
  public void processItems() {
    if (this.getInvCount() == 0) {
      // Before we handle standard barrel processing we have to see if we are handling cheese and
      // run that code first
      // since it has to be handled specially.
      boolean isCheese = handleCheese();

      if (getFluidStack() != null && !isCheese) {
        recipe =
            BarrelManager.getInstance()
                .findMatchingRecipe(getInputStack(), getFluidStack(), this.sealed, getTechLevel());
        if (recipe != null && !worldObj.isRemote) {
          int time = 0;
          if (sealtime > 0) time = (int) TFC_Time.getTotalHours() - sealtime;
          else if (unsealtime > 0) time = (int) TFC_Time.getTotalHours() - unsealtime;

          // Make sure that the recipe meets the time requirements
          if (recipe.isSealedRecipe() && time < recipe.sealTime) return;

          ItemStack origIS = getInputStack() != null ? getInputStack().copy() : null;
          FluidStack origFS = getFluidStack() != null ? getFluidStack().copy() : null;
          if (fluid.isFluidEqual(recipe.getResultFluid(origIS, origFS, time))
              && recipe.removesLiquid) {
            if (fluid.getFluid() == TFCFluids.BRINE
                && origIS != null
                && origIS.getItem() instanceof IFood)
              fluid.amount -=
                  recipe.getResultFluid(origIS, origFS, time).amount * Food.getWeight(origIS);
            else fluid.amount -= recipe.getResultFluid(origIS, origFS, time).amount;
          } else {
            this.fluid = recipe.getResultFluid(origIS, origFS, time);
            if (fluid != null && !(recipe instanceof BarrelLiquidToLiquidRecipe) && origFS != null)
              this.fluid.amount = origFS.amount;
          }

          if (origFS != null
              && origFS.getFluid() != TFCFluids.MILKCURDLED
              && this.fluid.getFluid() == TFCFluids.MILKCURDLED)
            this.sealtime = (int) TFC_Time.getTotalHours();

          Stack<ItemStack> resultStacks = recipe.getResult(origIS, origFS, time);
          if (!resultStacks.isEmpty()) {
            ItemStack result = resultStacks.pop();
            if (fluid != null && fluid.getFluid() == TFCFluids.BRINE) {
              if (result == null && origIS != null) result = origIS.copy();
              if (result != null
                  && result.getItem() instanceof IFood
                  && (result.getItem() == TFCItems.cheese
                      || ((IFood) result.getItem()).getFoodGroup() != EnumFoodGroup.Grain)) {
                if (!Food.isBrined(result)) Food.setBrined(result, true);
              }
            }

            storage[INPUT_SLOT] = result;

            for (int i = 1; i < storage.length; i++) {
              if (storage[i] == null && !resultStacks.isEmpty())
                this.setInventorySlotContents(i, resultStacks.pop());
            }

            while (!resultStacks.isEmpty())
              worldObj.spawnEntityInWorld(
                  new EntityItem(worldObj, xCoord, yCoord, zCoord, resultStacks.pop()));

            this.setInventorySlotContents(0, result);
          }
        }
      } else if (getFluidStack() == null && !isCheese) recipe = null;
    }
  }
Example #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()));
        }
      }
    }
  }