Esempio n. 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;
  }
Esempio n. 2
0
 public static Collection<ItemStack> getContainersFilledWith(FluidStack fluidStack) {
   List<ItemStack> containers = new ArrayList<ItemStack>();
   for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
     FluidStack inContainer = FluidItemHelper.getFluidStackInContainer(data.filledContainer);
     if (inContainer != null && inContainer.containsFluid(fluidStack))
       containers.add(data.filledContainer.copy());
   }
   return containers;
 }
Esempio n. 3
0
 public static boolean fillContainers(
     IFluidHandler fluidHandler,
     IInventory inv,
     int inputSlot,
     int outputSlot,
     Fluid fluidToFill) {
   if (fluidToFill == null) return false;
   ItemStack input = inv.getStackInSlot(inputSlot);
   ItemStack output = inv.getStackInSlot(outputSlot);
   FluidItemHelper.FillReturn fill =
       FluidItemHelper.fillContainer(input, new FluidStack(fluidToFill, PROCESS_VOLUME));
   if (fill.container != null && hasPlaceToPutContainer(output, fill.container)) {
     FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN, fill.amount, false);
     if (drain != null && drain.amount == fill.amount) {
       fill = FluidItemHelper.fillContainer(input, drain);
       if (fill.container != null && fill.amount == drain.amount) {
         fluidHandler.drain(ForgeDirection.UNKNOWN, fill.amount, true);
         storeContainer(inv, inputSlot, outputSlot, fill.container);
       }
       return true;
     }
   }
   return false;
 }
Esempio n. 4
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;
 }