Example #1
0
  public void ProcessItems() {
    if (this.getInvCount() == 0) {
      if (getFluidStack() != null) {
        recipe =
            BarrelManager.getInstance()
                .findMatchingRecipe(getInputStack(), getFluidStack(), this.sealed);
        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().copy();
          FluidStack origFS = getFluidStack().copy();
          if (fluid.isFluidEqual(recipe.getResultFluid(origIS, origFS, time))) {
            fluid.amount -= recipe.getResultFluid(origIS, origFS, time).amount;
          } else {
            this.fluid = recipe.getResultFluid(origIS, origFS, time);
            this.fluid.amount = origFS.amount;
          }
          this.setInventorySlotContents(0, recipe.getResult(origIS, origFS, time));
        }
      }
    }
  }
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;
    }
  }