@Override
 public ItemStack getCraftingResult(InventoryCrafting inv) {
   ItemStack jerrycan = null;
   ItemStack container = null;
   FluidStack fs = 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;
         fs = FluidUtil.getFluidContained(jerrycan);
       } else if (container == null && FluidUtil.getFluidHandler(stackInSlot) != null)
         container = stackInSlot;
   }
   if (fs != null && container != null) {
     ItemStack newContainer = Utils.copyStackWithAmount(container, 1);
     IFluidHandler handler = FluidUtil.getFluidHandler(newContainer);
     int accepted = handler.fill(fs, false);
     if (accepted > 0) {
       handler.fill(fs, true);
       //				FluidUtil.getFluidHandler(jerrycan).drain(accepted,true);
       ItemNBTHelper.setInt(jerrycan, "jerrycanDrain", accepted);
     }
     return newContainer;
   }
   return null;
 }
Exemplo n.º 2
0
  private void activeEmit() {
    if (fluidTank.getFluid() != null) {
      TileEntity tileEntity = Coord4D.get(this).offset(EnumFacing.DOWN).getTileEntity(worldObj);

      if (tileEntity != null
          && CapabilityUtils.hasCapability(
              tileEntity, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.UP)) {
        IFluidHandler handler =
            CapabilityUtils.getCapability(
                tileEntity, CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.UP);
        FluidStack toDrain =
            new FluidStack(fluidTank.getFluid(), Math.min(tier.output, fluidTank.getFluidAmount()));
        fluidTank.drain(handler.fill(toDrain, true), true);
      }
    }
  }
Exemplo n.º 3
0
  public int pushUp(FluidStack fluid, boolean doFill) {
    Coord4D up = Coord4D.get(this).offset(EnumFacing.UP);

    if (up.getTileEntity(worldObj) instanceof TileEntityFluidTank) {
      IFluidHandler handler =
          CapabilityUtils.getCapability(
              up.getTileEntity(worldObj),
              CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
              EnumFacing.DOWN);

      if (PipeUtils.canFill(handler, fluid)) {
        return handler.fill(fluid, doFill);
      }
    }

    return 0;
  }
 @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;
 }