Пример #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;
  }
Пример #2
0
  public boolean processItem() {
    if (storage[0] != null) {
      QuernRecipe qr = QuernManager.getInstance().findMatchingRecipe(storage[0]);
      if (qr == null) {
        TerraFirmaCraft.LOG.warn(
            "QUERN RECIPE NOT FOUND! This is a BUG! -- "
                + storage[0].getItem().getUnlocalizedName());
        return false; // If this happens, it's a bug!
      }

      // If the output item can not be combined or is different from what is being made, eject and
      // make room for the new output
      if (storage[1] != null
          && !(storage[1].getItem() == qr.getResult().getItem()
              && storage[1].getItemDamage() == qr.getResult().getItemDamage())) {
        ejectItem(storage[1]);
        storage[1] = null;
      }

      if (qr.getInItem().getItem() instanceof IFood) {
        if (storage[1] != null) {
          float slot0Weight = Food.getWeight(storage[0]);
          float slot1Weight = Food.getWeight(storage[1]);
          float newWeight = slot0Weight + slot1Weight;

          if (newWeight > Global.FOOD_MAX_WEIGHT) {
            Food.setWeight(storage[1], newWeight - Global.FOOD_MAX_WEIGHT);

            ItemStack tossStack = storage[1].copy();
            Food.setWeight(tossStack, Global.FOOD_MAX_WEIGHT);
            ejectItem(tossStack);
          } else {
            Food.setWeight(storage[1], newWeight);
          }
          storage[0] = null;
          worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
          return true;
        }

        if (storage[1] == null) {
          storage[1] = qr.getResult().copy();
          float flourWeight = Food.getWeight(storage[0]);
          float flourDecay = Food.getDecay(storage[0]);
          ItemFoodTFC.createTag(storage[1], flourWeight, flourDecay);
          storage[0] = null;
          worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
          return true;
        }
      } else {
        if (storage[0].stackSize == qr.getInItem().stackSize) {
          storage[0] = null;
          worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
        } else storage[0].stackSize -= qr.getInItem().stackSize;

        if (storage[1] == null) storage[1] = qr.getResult().copy();
        else if (storage[1].stackSize < storage[1].getMaxStackSize()) {
          if ((qr.getResult().stackSize + storage[1].stackSize) > storage[1].getMaxStackSize()) {
            int amountleft =
                qr.getResult().stackSize - (storage[1].getMaxStackSize() - storage[1].stackSize);
            ItemStack tossStack = qr.getResult().copy();
            tossStack.stackSize = tossStack.getMaxStackSize();
            ejectItem(tossStack);
            ItemStack remainStack = qr.getResult().copy();
            remainStack.stackSize = amountleft;
            storage[1] = remainStack;
          } else storage[1].stackSize += qr.getResult().stackSize;
        } else {
          ejectItem(storage[1]);
          storage[1] = qr.getResult().copy();
        }
        return true;
      }
    }
    return false;
  }
Пример #3
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;
    }
  }