예제 #1
0
  public static boolean handleRightClick(
      IFluidHandler tank, ForgeDirection side, EntityPlayer player, boolean fill, boolean drain) {
    if (player == null) return false;
    ItemStack current = player.inventory.getCurrentItem();
    if (current != null) {

      FluidItemHelper.DrainReturn drainReturn =
          FluidItemHelper.drainContainer(current, PROCESS_VOLUME);

      if (fill && drainReturn.fluidDrained != null) {
        int used = tank.fill(side, drainReturn.fluidDrained, true);

        if (used > 0) {
          drainReturn = FluidItemHelper.drainContainer(current, used);
          if (!player.capabilities.isCreativeMode) {
            player.inventory.setInventorySlotContents(
                player.inventory.currentItem, drainReturn.container);
            player.inventory.markDirty();
          }
          return true;
        }
      } else if (drain) {

        FluidStack available = tank.drain(side, PROCESS_VOLUME, false);
        if (available != null) {
          FluidItemHelper.FillReturn fillReturn = FluidItemHelper.fillContainer(current, available);
          if (fillReturn.amount > 0) {
            if (current.stackSize > 1) {
              if (!player.inventory.addItemStackToInventory(fillReturn.container)) return false;
              player.inventory.setInventorySlotContents(
                  player.inventory.currentItem, InvTools.depleteItem(current));
              player.inventory.markDirty();
            } else {
              player.inventory.setInventorySlotContents(
                  player.inventory.currentItem, fillReturn.container);
              player.inventory.markDirty();
            }

            tank.drain(side, fillReturn.amount, true);
            return true;
          }
        }
      }
    }
    return false;
  }
예제 #2
0
 public static boolean drainContainers(
     IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot) {
   ItemStack input = inv.getStackInSlot(inputSlot);
   ItemStack output = inv.getStackInSlot(outputSlot);
   if (input != null) {
     FluidItemHelper.DrainReturn drain = FluidItemHelper.drainContainer(input, PROCESS_VOLUME);
     if (drain.fluidDrained != null
         && (drain.container == null || hasPlaceToPutContainer(output, drain.container))) {
       int used = fluidHandler.fill(ForgeDirection.UNKNOWN, drain.fluidDrained, false);
       if ((drain.isAtomic && used == drain.fluidDrained.amount)
           || (!drain.isAtomic && drain.fluidDrained.amount > 0)) {
         fluidHandler.fill(ForgeDirection.UNKNOWN, drain.fluidDrained, true);
         storeContainer(inv, inputSlot, outputSlot, drain.container);
         return true;
       }
     }
   }
   return false;
 }