@Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   if (!formed) return 0;
   if (master() != null) {
     if (pos != 15 && pos != 19) return 0;
     return master().fill(from, resource, doFill);
   } else if (resource != null) {
     int fill = 0;
     if (resource.isFluidEqual(tank0.getFluid())) fill = tank0.fill(resource, doFill);
     else if (resource.isFluidEqual(tank1.getFluid())) fill = tank1.fill(resource, doFill);
     else if (tank0.getFluidAmount() <= 0 && tank1.getFluidAmount() <= 0)
       fill =
           (DieselHandler.findIncompleteRefineryRecipe(resource, null) != null
               ? tank0.fill(resource, doFill)
               : 0);
     else {
       if (tank0.getFluidAmount() > 0)
         fill =
             (DieselHandler.findIncompleteRefineryRecipe(resource, tank0.getFluid()) != null
                 ? tank1.fill(resource, doFill)
                 : 0);
       else if (tank1.getFluidAmount() > 0)
         fill =
             (DieselHandler.findIncompleteRefineryRecipe(resource, tank1.getFluid()) != null
                 ? tank0.fill(resource, doFill)
                 : 0);
     }
     markDirty();
     worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
     return fill;
   }
   return 0;
 }
 @Override
 public boolean isItemValidForSlot(int slot, ItemStack stack) {
   if (!formed) return false;
   if (master() != null) return master().isItemValidForSlot(slot, stack);
   if (slot == 1 || slot == 3 || slot == 5) return false;
   if (slot == 4)
     return (tank2.getFluidAmount() <= 0
         ? FluidContainerRegistry.isEmptyContainer(stack)
         : FluidContainerRegistry.fillFluidContainer(
                 tank2.getFluid(), Utils.copyStackWithAmount(stack, 1))
             != null);
   FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(stack);
   if (fs == null) return false;
   RefineryRecipe partialRecipe = DieselHandler.findIncompleteRefineryRecipe(fs, null);
   if (partialRecipe == null) return false;
   if (slot == 0)
     return (tank0.getFluidAmount() <= 0 || fs.isFluidEqual(tank0.getFluid()))
         && (tank1.getFluidAmount() <= 0
             || DieselHandler.findIncompleteRefineryRecipe(fs, tank1.getFluid()) != null);
   if (slot == 2)
     return (tank1.getFluidAmount() <= 0 || fs.isFluidEqual(tank1.getFluid()))
         && (tank0.getFluidAmount() <= 0
             || DieselHandler.findIncompleteRefineryRecipe(fs, tank0.getFluid()) != null);
   return false;
 }
Exemplo n.º 3
0
 @Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   if (resource.isFluidEqual(this.src1)) {
     int ret = Math.min(this.buf - this.src1.amount, resource.amount);
     if (doFill) this.src1.amount += ret;
     return ret;
   } else if (resource.isFluidEqual(this.src2)) {
     int ret = Math.min(this.buf - this.src2.amount, resource.amount);
     if (doFill) this.src2.amount += ret;
     return ret;
   } else if (this.src1 == null) {
     int ret = Math.min(this.buf, resource.amount);
     if (doFill) {
       this.src1 = resource.copy();
       this.src1.amount = ret;
     }
     return ret;
   } else if (this.src2 == null) {
     int ret = Math.min(this.buf, resource.amount);
     if (doFill) {
       this.src2 = resource.copy();
       this.src2.amount = ret;
     }
     return ret;
   }
   return 0;
 }
Exemplo n.º 4
0
  public int fill_(ItemStack container, FluidStack resource, boolean doFill) {
    if (resource == null) {
      return 0;
    }

    if (!doFill) {
      if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) {
        return Math.min(fluidCapacity, resource.amount);
      }

      FluidStack stack =
          FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid"));

      if (stack == null) {
        return Math.min(fluidCapacity, resource.amount);
      }

      if (!stack.isFluidEqual(resource)) {
        return 0;
      }

      return Math.min(fluidCapacity - stack.amount, resource.amount);
    }

    if (container.stackTagCompound == null) {
      container.stackTagCompound = new NBTTagCompound();
    }

    if (!container.stackTagCompound.hasKey("Fluid")) {
      NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound());

      if (fluidCapacity < resource.amount) {
        fluidTag.setInteger("Amount", fluidCapacity);
        container.stackTagCompound.setTag("Fluid", fluidTag);
        return fluidCapacity;
      }

      container.stackTagCompound.setTag("Fluid", fluidTag);
      return resource.amount;
    }

    NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid");
    FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag);

    if (!stack.isFluidEqual(resource)) {
      return 0;
    }

    int filled = fluidCapacity - stack.amount;
    if (resource.amount < filled) {
      stack.amount += resource.amount;
      filled = resource.amount;
    } else {
      stack.amount = fluidCapacity;
    }

    container.stackTagCompound.setTag("Fluid", stack.writeToNBT(fluidTag));
    return filled;
  }
Exemplo n.º 5
0
  public boolean addLiquid(FluidStack inFS) {
    if (inFS != null) {
      // We dont want very hot liquids stored here so if they are much hotter than boiling water, we
      // prevent it.
      if (inFS.getFluid() != null && inFS.getFluid().getTemperature(inFS) > 385) return false;

      if (fluid == null) {
        fluid = inFS.copy();
        if (fluid.amount > this.getMaxLiquid()) {
          fluid.amount = getMaxLiquid();
          inFS.amount = inFS.amount - this.getMaxLiquid();

        } else inFS.amount = 0;
      } else {
        // check if the barrel is full or if the fluid being added does not match the barrel liquid
        if (fluid.amount == getMaxLiquid() || !fluid.isFluidEqual(inFS)) return false;

        int a = fluid.amount + inFS.amount - getMaxLiquid();
        fluid.amount = Math.min(fluid.amount + inFS.amount, getMaxLiquid());
        if (a > 0) inFS.amount = a;
        else inFS.amount = 0;
      }
      worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
      return true;
    }

    return false;
  }
Exemplo n.º 6
0
  /**
   * Whether or not this PressurizedReactants's FluidStack entry's fluid type is equal to the fluid
   * type of the given fluid.
   *
   * @param stack - stack to check
   * @return if the stack's fluid type is contained in this PressurizedReactants
   */
  public boolean containsType(FluidStack stack) {
    if (stack == null || stack.amount == 0) {
      return false;
    }

    return stack.isFluidEqual(theFluid);
  }
 @Override
 public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
   if (resource == null || !resource.isFluidEqual(drain(from, resource.amount, false))) {
     return null;
   }
   return drain(from, resource.amount, doDrain);
 }
Exemplo n.º 8
0
  /* ITANKCONTAINER */
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
    if (resource == null) {
      return 0;
    }

    resource = resource.copy();
    int totalUsed = 0;
    TileTank tankToFill = getBottomTank();

    FluidStack liquid = tankToFill.tank.getFluid();
    if (liquid != null && liquid.amount > 0 && !liquid.isFluidEqual(resource)) {
      return 0;
    }

    while (tankToFill != null && resource.amount > 0) {
      int used = tankToFill.tank.fill(resource, doFill);
      resource.amount -= used;
      if (used > 0) {
        tankToFill.hasUpdate = true;
      }

      totalUsed += used;
      tankToFill = getTankAbove(tankToFill);
    }
    return totalUsed;
  }
 @Override
 public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
   if (resource != null)
     for (FluidTank _tank : (FluidTank[]) getTanks())
       if (resource.isFluidEqual(_tank.getFluid())) return _tank.drain(resource.amount, doDrain);
   return null;
 }
Exemplo n.º 10
0
 @Override
 public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
   if (resource == null || !resource.isFluidEqual(theTank.getFluid())) {
     return null;
   }
   return theTank.drain(resource.amount, doDrain);
 }
Exemplo n.º 11
0
 @Override
 public boolean match(FluidStack aStack, IInventory inv) {
   if (inv instanceof TileEntityCeramicFurnaceOutlet && aStack != null) {
     return stack.isFluidEqual(aStack) && stack.amount <= aStack.amount;
   }
   return false;
 }
Exemplo n.º 12
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));
        }
      }
    }
  }
Exemplo n.º 13
0
  public int addFluid(FluidStack stack) {
    if (stack == null || stack.amount == 0) {
      return 0;
    }
    // TODO: Caching. Later.
    recalculateFillLevel();

    int current = fillLevel;
    int free = capacity - current;

    if (free < 1) {
      return 0;
    }
    int insert = Math.min(stack.amount, free);

    for (FluidStack contentStack : content) {
      if (contentStack.isFluidEqual(stack)) {
        contentStack.amount += insert;
        return insert;
      }
    }
    FluidStack copy = stack.copy();
    copy.amount = insert;
    content.add(copy);

    return insert;
  }
Exemplo n.º 14
0
  @Override
  public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
    if (resource == null) {
      return 0;
    }

    FluidStack resourceCopy = resource.copy();
    int totalUsed = 0;

    FluidStack liquid = tank.getFluid();
    if (liquid != null && liquid.amount > 0 && !liquid.isFluidEqual(resourceCopy)) {
      return 0;
    }

    while (resourceCopy.amount > 0) {
      int used = tank.fill(resourceCopy, doFill);
      resourceCopy.amount -= used;
      if (used > 0) {
        markDirty();
      }

      totalUsed += used;
    }

    return totalUsed;
  }
 @Override
 public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
   if (resource != null)
     for (FluidTank _tank : (FluidTank[]) getTanks())
       if (_tank.getFluidAmount() == 0 || resource.isFluidEqual(_tank.getFluid()))
         return _tank.fill(resource, doFill);
   return 0;
 }
Exemplo n.º 16
0
  public boolean addLiquid(FluidStack f) {
    if (fluid == null) fluid = f;
    else {
      if (fluid.amount == 10000 || !fluid.isFluidEqual(f)) return false;

      fluid.amount = Math.min(fluid.amount + f.amount, 10000);
    }
    return true;
  }
 @Override
 public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
   if ((from == ForgeDirection.UNKNOWN) || (this.sideCache[from.ordinal()] != 2)) {
     return null;
   }
   if ((resource == null) || (!resource.isFluidEqual(this.tank.getFluid()))) {
     return null;
   }
   return this.tank.drain(resource.amount, doDrain);
 }
Exemplo n.º 18
0
  public int getFluidAmount(FluidStack like) {
    if (like == null) {
      return 0;
    }

    for (int i = 0; i < content.size(); i++) {
      FluidStack contentStack = content.get(i);
      if (contentStack.isFluidEqual(like)) {
        return contentStack.amount;
      }
    }
    return 0;
  }
Exemplo n.º 19
0
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float hitX,
      float hitY,
      float hitZ) {
    if (world.isRemote) return true;
    TileEntityJarOHoney tile = Utils.getTileEntity(world, x, y, z, TileEntityJarOHoney.class);
    if (tile == null) return false;

    ItemStack stack = player.getCurrentEquippedItem();
    if (FluidContainerRegistry.isFilledContainer(stack)) {
      FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack);
      if (fluidStack.isFluidEqual(tile.getHoney()))
        if (fluidStack.amount + tile.getHoney().amount > TileEntityJarOHoney.HONEY_MAX_AMOUNT)
          return true;
        else {
          tile.addHoney(fluidStack.amount);
          ItemStack container = stack.getItem().getContainerItem(stack);
          stack.stackSize--;
          if (stack.stackSize <= 0) player.setCurrentItemOrArmor(0, container);
          else if (!player.inventory.addItemStackToInventory(container))
            Utils.dropStack(world, x, y, z, container);

          return true;
        }
    } else if (FluidContainerRegistry.isEmptyContainer(stack)) {
      ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(tile.getHoney(), stack);
      if (filledContainer != null) {
        stack.stackSize--;
        if (stack.stackSize <= 0) player.setCurrentItemOrArmor(0, filledContainer);
        else if (!player.inventory.addItemStackToInventory(filledContainer))
          Utils.dropStack(world, x, y, z, filledContainer);

        tile.drainHoney(FluidContainerRegistry.getFluidForFilledItem(filledContainer).amount);
        return true;
      }
    } else {
      player.getFoodStats().addStats(1, 0.8F);
      player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 100, 1));
      tile.drainHoney(100);
    }
    return false;
  }
 @Override
 public int fill(ItemStack container, FluidStack resource, boolean doFill) {
   if (resource != null) {
     FluidStack fs = getFluid(container);
     if (fs == null || resource.isFluidEqual(fs)) {
       int space = fs == null ? getCapacity(container) : getCapacity(container) - fs.amount;
       int accepted = Math.min(space, resource.amount);
       if (fs == null) fs = Utils.copyFluidStackWithAmount(resource, accepted, false);
       else fs.amount += accepted;
       if (doFill) ItemNBTHelper.setFluidStack(container, "fluid", fs);
       return accepted;
     }
   }
   return 0;
 }
Exemplo n.º 21
0
 @Override
 public int fill(FluidStack resource, boolean doFill) {
   if (resource == null) {
     return 0;
   }
   if (acceptableFluids.length == 0) {
     return super.fill(resource, doFill);
   }
   for (FluidStack acceptableFluid : acceptableFluids) {
     if (acceptableFluid.isFluidEqual(resource)) {
       return super.fill(resource, doFill);
     }
   }
   return 0;
 }
  /**
   * Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
   *
   * @param from Orientation the Fluid is drained to.
   * @param resource FluidStack representing the Fluid and maximum amount of fluid to be drained.
   * @param doDrain If false, drain will only be simulated.
   * @return FluidStack representing the Fluid and amount that was (or would have been, if
   *     simulated) drained.
   */
  public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
    int tankToDrain = 0;
    if (from != ForgeDirection.UNKNOWN) {
      tankToDrain = getExposedTankFromSide(from.ordinal());
    }

    if (tankToDrain == FLUIDTANK_NONE) {
      return null;
    } else {
      // Can't drain that fluid from that side.
      if (!resource.isFluidEqual(tanks[tankToDrain].getFluid())) {
        return null;
      }

      return drain(tankToDrain, resource.amount, doDrain);
    }
  }
Exemplo n.º 23
0
  @Override
  public void updateEntity() {
    if (!worldObj.isRemote) {
      careForInventorySlot();
      if (worldObj.isRaining()
          && !this.getSealed()
          && worldObj.canBlockSeeTheSky(xCoord, yCoord, zCoord)) {
        if (this.fluid == null) fluid = new FluidStack(TFCFluid.FRESHWATER, 1);
        else if (this.fluid != null && fluid.getFluid() == TFCFluid.FRESHWATER)
          fluid.amount = Math.min(fluid.amount + 1, 10000);
      }

      processTimer++;

      if (processTimer > 100) {
        ProcessItems();
        processTimer = 0;
      }

      if (fluid != null && fluid.amount == 0) fluid = null;

      if (mode == MODE_IN) {
        FluidStack inLiquid = FluidContainerRegistry.getFluidForFilledItem(getInputStack());
        if (inLiquid != null) {
          if (this.fluid == null) {
            this.fluid = inLiquid.copy();
            this.setInventorySlotContents(
                0, getInputStack().getItem().getContainerItem(getInputStack()));
          } else if (inLiquid.isFluidEqual(this.fluid)) {
            if (addLiquid(inLiquid.amount)) {
              this.setInventorySlotContents(
                  0, getInputStack().getItem().getContainerItem(getInputStack()));
            }
          }
        }
      } else if (mode == MODE_OUT) {
        if (FluidContainerRegistry.isEmptyContainer(getInputStack())) {
          this.setInventorySlotContents(0, this.removeLiquid(getInputStack()));
        }
      }
    }
  }
 @Override
 public boolean matches(InventoryCrafting inv, World world) {
   ItemStack jerrycan = null;
   ItemStack container = null;
   for (int i = 0; i < inv.getSizeInventory(); i++) {
     ItemStack stackInSlot = inv.getStackInSlot(i);
     if (stackInSlot != null)
       if (jerrycan == null
           && IEContent.itemJerrycan.equals(stackInSlot.getItem())
           && FluidUtil.getFluidContained(stackInSlot) != null) jerrycan = stackInSlot;
       else if (container == null && FluidUtil.getFluidHandler(stackInSlot) != null)
         container = stackInSlot;
       else return false;
   }
   if (jerrycan != null && container != null) {
     IFluidHandler handler = FluidUtil.getFluidHandler(container);
     FluidStack fs = handler.drain(Integer.MAX_VALUE, false);
     if (fs == null
         || (fs.amount < handler.getTankProperties()[0].getCapacity()
             && fs.isFluidEqual(FluidUtil.getFluidContained(jerrycan)))) return true;
   }
   return false;
 }
Exemplo n.º 25
0
  public int removeFluid(FluidStack stack) {
    if (stack == null || stack.amount == 0) {
      return 0;
    }

    for (int i = 0; i < content.size(); i++) {
      FluidStack contentStack = content.get(i);
      if (contentStack.isFluidEqual(stack)) {
        int removeAmount = Math.min(contentStack.amount, stack.amount);

        // Remove the fluid
        contentStack.amount -= removeAmount;
        if (contentStack.amount <= 0) {
          content.remove(i);
        }
        recalculateFillLevel();

        // And return the amount
        return removeAmount;
      }
    }
    return 0;
  }
Exemplo n.º 26
0
 /**
  * This attempts to remove a portion of the water in this container and put it into a valid
  * Container Item
  */
 public ItemStack removeLiquid(ItemStack is) {
   if (is == null || is.stackSize > 1) return is;
   if (FluidContainerRegistry.isEmptyContainer(is)) {
     ItemStack out = FluidContainerRegistry.fillFluidContainer(fluid, is);
     if (out != null) {
       FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(out);
       fluid.amount -= fs.amount;
       is = null;
       if (fluid.amount == 0) {
         fluid = null;
       }
       worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
       return out;
     }
   } else if (fluid != null && is.getItem() instanceof IFluidContainerItem) {
     FluidStack isfs = ((IFluidContainerItem) is.getItem()).getFluid(is);
     if (isfs == null || fluid.isFluidEqual(isfs)) {
       fluid.amount -= ((IFluidContainerItem) is.getItem()).fill(is, fluid, true);
       if (fluid.amount == 0) fluid = null;
       worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
     }
   }
   return is;
 }
Exemplo n.º 27
0
 @Override
 public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
   if (resource != null && !resource.isFluidEqual(tank.getFluid())) return null;
   return drain(from, resource.amount, doDrain);
 }
Exemplo n.º 28
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()));
        }
      }
    }
  }
Exemplo n.º 29
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;
    }
  }