Java 类net.minecraftforge.fluids.FluidActionResult 实例源码

项目:pnc-repressurized    文件:FluidUtils.java   
private static boolean doFluidInteraction(TileEntity te, EnumFacing face, EntityPlayer player, EnumHand hand, boolean isInserting) {
    ItemStack stack = player.getHeldItem(hand);
    IFluidHandlerItem stackHandler = FluidUtil.getFluidHandler(stack);
    if (stackHandler != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face)) {
        int capacity = stackHandler.getTankProperties()[0].getCapacity();
        IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face);
        PlayerInvWrapper invWrapper = new PlayerInvWrapper(player.inventory);
        FluidActionResult result = isInserting ?
                FluidUtil.tryEmptyContainerAndStow(player.getHeldItem(hand), handler, invWrapper, capacity, player) :
                FluidUtil.tryFillContainerAndStow(player.getHeldItem(hand), handler, invWrapper, capacity, player);
        if (result.isSuccess()) {
            player.setHeldItem(hand, result.getResult());
            return true;
        }
    }
    return false;
}
项目:BetterChests    文件:BlockBTank.java   
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack original = player.getHeldItem(hand);
    if (!original.isEmpty()) {
        ItemStack stack = original.copy();
        stack.setCount(1);
        TileEntity tank = getTileEntity(world, pos);
        if (tank instanceof TileEntityBTank) {
            IFluidHandler handler = ((TileEntityBTank) tank).getFluidHandler();
            FluidActionResult result = FluidUtil.tryEmptyContainer(stack, handler, Fluid.BUCKET_VOLUME, player, true);
            if (!result.success) {
                result = FluidUtil.tryFillContainer(stack, handler, Fluid.BUCKET_VOLUME, player, true);
            }
            if (result.success) {
                original.setCount(original.getCount() - 1);
                stack = InvUtil.putStackInInventory(result.result, player.inventory, true, false, false, null);
                if (!stack.isEmpty()) {
                    WorldUtil.dropItemsRandom(world, stack, player.getPosition());
                }
                return true;
            }
        }
    }
    return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);
}
项目:OpenBlocks    文件:TileEntityTank.java   
@Override
public boolean onBlockActivated(EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (world.isRemote) return true;

    if (hand == EnumHand.MAIN_HAND) {
        final ItemStack heldItem = player.getHeldItemMainhand();
        if (!heldItem.isEmpty()) {
            final FluidActionResult result = tryEmptyItem(player, heldItem.copy());
            if (result.success) {
                if (!player.isCreative())
                    player.setHeldItem(EnumHand.MAIN_HAND, result.result);
                return true;
            }
        } else
            return tryDrainXp(player);
    }

    return false;
}
项目:pnc-repressurized    文件:FluidUtils.java   
/**
 * Attempt to extract fluid from the given fluid handler into the given fluid-containing item.
 *
 * @param srcHandler fluid handler into which to place the fluid
 * @param destStack the fluid container item to extract from
 * @param returnedItems the modified fluid container after extraction
 * @return true if any fluid was moved, false otherwise
 */
public static boolean tryFluidExtraction(IFluidHandler srcHandler, ItemStack destStack, NonNullList<ItemStack> returnedItems) {
    FluidActionResult result = FluidUtil.tryFillContainer(destStack, srcHandler, 1000, null, true);
    if (result.isSuccess()) {
        returnedItems.add(result.getResult());
        destStack.shrink(1);
        return true;
    } else {
        return false;
    }
}
项目:pnc-repressurized    文件:FluidUtils.java   
/**
 * Attempt to insert fluid into the given fluid handler from the given fluid container item.
 *
 * @param handler the handler to extract from
 * @param srcStack the fluid container item to insert to
 * @param returnedItems the modified fluid container after insertion
 * @return true if any fluid was moved, false otherwise
 */
public static boolean tryFluidInsertion(IFluidHandler handler, ItemStack srcStack, NonNullList<ItemStack> returnedItems) {
    FluidActionResult result = FluidUtil.tryEmptyContainer(srcStack, handler, 1000, null, true);
    if (result.isSuccess()) {
        returnedItems.add(result.getResult());
        srcStack.shrink(1);
        return true;
    } else {
        return false;
    }
}
项目:Thermionics    文件:FluidTransport.java   
public static FluidActionResult tryEmptyOrFillContainer(ItemStack stack, IFluidHandler handler, int maxTransfer, EntityPlayer player) {
    FluidActionResult result = FluidUtil.tryEmptyContainer(stack, handler, maxTransfer, player, true);
    if (result.success) {
        return result;
    } else {
        FluidActionResult resultFill = FluidUtil.tryFillContainer(stack, handler, maxTransfer, player, true);
        return resultFill;
    }
}
项目:Thermionics    文件:FluidTransport.java   
public static boolean handleRightClickFluidStorage(EntityPlayer player, EnumHand hand, IFluidHandler tank, int maxTransfer) {
    ItemStack fluidItem = player.getHeldItem(hand);
    if (fluidItem==null || fluidItem.isEmpty()) return false;
    if (!fluidItem.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
        return false;
    }

    FluidActionResult result = tryEmptyOrFillContainer(fluidItem, tank, maxTransfer, player);
    if (result.isSuccess()) {
        player.setHeldItem(hand, result.result);
        return true;
    } else {
        return false;
    }
}
项目:UsefulNullifiers    文件:FluidVoidInventory.java   
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
    if (index < 0 || index >= this.getSizeInventory())
        return;

    if (!stack.isEmpty() && stack.getCount() > this.getInventoryStackLimit())
        stack.setCount(this.getInventoryStackLimit());

    if (!stack.isEmpty() && stack.getCount() == 0)
        stack = ItemStack.EMPTY;

    ItemStack emptyContainer = ItemStack.EMPTY;
    if (!stack.isEmpty()) {
        FluidStack fluid = FluidUtil.getFluidContained(stack);
        if (fluid != null) {
            FluidActionResult result = FluidUtil.tryEmptyContainer(stack, new FluidTank(Integer.MAX_VALUE), 1000,
                    null, true);
            if (result.success)
                emptyContainer = result.getResult();                    
        }
        if (stack.getItem() == Items.WATER_BUCKET) {
            emptyContainer = new ItemStack(Items.BUCKET);
        }
        if (stack.getItem() == Items.LAVA_BUCKET) {
            emptyContainer = new ItemStack(Items.BUCKET);
        }
        if (stack.getItem() == Items.MILK_BUCKET) {
            emptyContainer = new ItemStack(Items.BUCKET);
        }
    }

    if (!emptyContainer.isEmpty())
        this.inventory.set(index, emptyContainer);
    else
        this.inventory.set(index, stack);
    this.markDirty();

}
项目:Toms-Mod    文件:TomsModUtils.java   
@SuppressWarnings("deprecation")
public static boolean interactWithFluidHandler(IFluidHandler tankOnSide, EntityPlayer playerIn, EnumHand hand) {
    if (tankOnSide != null) {
        FluidActionResult r = FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand), tankOnSide, playerIn);
        if (r.success)
            playerIn.setHeldItem(hand, r.result);
        return r.success;
    } else
        return false;
}
项目:Minecraft-Flux    文件:BlockFluxGen.java   
@Override
public boolean onBlockActivated(World w, BlockPos pos, IBlockState state, EntityPlayer p, EnumHand h, EnumFacing f, float x, float y, float z) {
    ItemStack is = p.getHeldItem(h);
    if (!w.isRemote) {
        TileEntity te = w.getTileEntity(pos);
        if (te instanceof TileEntityFluxGen) {
            FluidActionResult far = FluidUtil.tryEmptyContainerAndStow(is, (TileEntityFluxGen) te, new InvWrapper(p.inventory), TileEntityFluxGen.fluidCap, p);
            if (far.success)
                p.setHeldItem(h, far.result);
            else
                p.openGui(MCFlux.MF, R.MF_GUI_FLUXGEN, w, pos.getX(), pos.getY(), pos.getZ());
        }
    }
    return true;
}
项目:Cyclic    文件:UtilFluid.java   
/**
 * Picks up fluid fills a container with it.
 */
public static FluidActionResult fillContainer(World world, BlockPos pos, ItemStack stackIn, EnumFacing facing) {
  //    ItemStack result = stackIn.copy();
  return FluidUtil.tryPickUpFluid(stackIn, null, world, pos, facing);
  //  if (--stackIn.stackSize == 0) {
  //    stackIn.deserializeNBT(result.serializeNBT());
  //  }
  //    if (res == FluidActionResult.FAILURE) { return stackIn; }
  //    return res.getResult();
}
项目:Cyclic    文件:TileEntityHydrator.java   
public void tryFillTankFromItems() {
  ItemStack maybeBucket = this.getStackInSlot(SLOT_INFLUID);
  FluidStack f = FluidUtil.getFluidContained(maybeBucket);
  IFluidHandlerItem bucketHandler = FluidUtil.getFluidHandler(maybeBucket);
  if (f != null && bucketHandler != null && f.getFluid().equals(FluidRegistry.WATER)) {
    //https://github.com/BluSunrize/ImmersiveEngineering/blob/fc022675bb550318cbadc879b3f28dde511e29c3/src/main/java/blusunrize/immersiveengineering/common/blocks/wooden/TileEntityWoodenBarrel.java
    FluidActionResult r = FluidUtil.tryEmptyContainer(maybeBucket, tank, Fluid.BUCKET_VOLUME, null, true);
    //in the case of a full bucket, it becomes empty. 
    //also supports any other fluid holding item, simply draining that fixed amount each round
    if (r.success) {
      this.setInventorySlotContents(SLOT_INFLUID, r.result);
    }
  }
}
项目:OpenBlocks    文件:TileEntityTank.java   
protected FluidActionResult tryEmptyItem(EntityPlayer player, @Nonnull ItemStack container) {
    // not using FluidUtils.tryEmptyContainer, since it limits stack size to 1
    final IFluidHandlerItem containerFluidHandler = FluidUtil.getFluidHandler(container);
    if (containerFluidHandler != null) {
        FluidStack transfer = FluidUtil.tryFluidTransfer(tankCapabilityWrapper, containerFluidHandler, Fluid.BUCKET_VOLUME, true);
        if (transfer != null) {
            SoundEvent soundevent = transfer.getFluid().getEmptySound(transfer);
            player.playSound(soundevent, 1f, 1f);
            return new FluidActionResult(containerFluidHandler.getContainer());
        }
    }

    return FluidActionResult.FAILURE;
}
项目:Thermionics    文件:TileEntityPotStill.java   
@Override
public void update() {
    boolean curTickPower = world.isBlockIndirectlyGettingPowered(pos)!=0;

    //TODO: Actually lock tanks


    { //Bottle fluids out
        ItemStack bottles = itemStorage.getStackInSlot(SLOT_EMPTY_BUCKET_IN);
        ItemStack outputItem = itemStorage.getStackInSlot(SLOT_FULL_BUCKET_OUT);
        FluidStack outputFluid = outputTank.getFluid();
        //Are there bottles to fill, is there room to put them, is there fluid to fill them with, and is there *enough* of that fluid?
        if (!bottles.isEmpty() && outputItem.getCount()<outputItem.getMaxStackSize() && outputFluid!=null && outputFluid.amount>250) {
            ItemStack outBottle = new ItemStack(ThermionicsItems.SPIRIT_BOTTLE);
            outBottle.setTagCompound(outputFluid.tag.copy());

            if (itemStorage.insertItem(SLOT_FULL_BUCKET_OUT, outBottle, true).isEmpty()) {
                outputTank.drainInternal(250,  true);
                itemStorage.insertItem(SLOT_FULL_BUCKET_OUT, outBottle, false);
                itemStorage.extractItem(SLOT_EMPTY_BUCKET_IN, 1, false);
            }
        }
    }

    if (!tanksLocked) {
        if (curTickPower & !lastTickPower) {
            //Lock the tanks on a rising current edge.
            setTanksLocked(true);
            processTime = 0;
        } else {
            //Fluid loading/unloading mode
            ItemStack inBucket = itemStorage.getStackInSlot(SLOT_FULL_BUCKET_IN);
            FluidActionResult result = FluidUtil.tryEmptyContainer(inBucket, inputTank, inputTank.getCapacity(), null, true);
            if (result.isSuccess()) {
                itemStorage.setStackInSlot(SLOT_FULL_BUCKET_IN, ItemStack.EMPTY);
                itemStorage.setStackInSlot(SLOT_EMPTY_BUCKET_OUT, result.getResult());
            }
        }
    } else {
        if (processTime<MAX_PROCESS_TIME) processTime++;
        FluidStack in = inputTank.getFluid();
        if (in==null) {
            //Batch is done...?
            setTanksLocked(false);
        } else {
            //Find a recipe, let's go :D
            //For the moment, use Water->Rum
            PotStillRecipe recipe = MachineRecipes.getPotStill(inputTank);
            if (recipe!=null) {
                FluidStack output = recipe.getOutput();
                int filled = outputTank.fillInternal(output, false);
                int extracted = heat.extractHeat(HEAT_REQUIRED, true);
                if (output.amount==filled && extracted==HEAT_REQUIRED) {
                    recipe.consumeIngredients(inputTank);
                    outputTank.fillInternal(output, true);
                    heat.extractHeat(HEAT_REQUIRED, false);
                }

            }
        }
    }

    lastTickPower = curTickPower;
}
项目:Cyclic    文件:TileEntityUser.java   
private boolean rightClickFluidAttempt(BlockPos targetPos) {
  ItemStack maybeTool = fakePlayer.get().getHeldItemMainhand();
  if (maybeTool != null && !maybeTool.isEmpty() && UtilFluid.stackHasFluidHandler(maybeTool)) {
    if (UtilFluid.hasFluidHandler(world.getTileEntity(targetPos), this.getCurrentFacing().getOpposite())) {//tile has fluid
      ItemStack originalRef = maybeTool.copy();
      int hack = (maybeTool.getCount() == 1) ? 1 : 0;//HAX: if bucket stack size is 1, it somehow doesnt work so yeah. good enough EH?
      maybeTool.grow(hack);
      boolean success = UtilFluid.interactWithFluidHandler(fakePlayer.get(), this.world, targetPos, this.getCurrentFacing().getOpposite());
      if (success) {
        if (UtilFluid.isEmptyOfFluid(originalRef)) { //original was empty.. maybe its full now IDK
          maybeTool.shrink(1 + hack);
        }
        else {//original had fluid in it. so make sure we drain it now hey
          ItemStack drained = UtilFluid.drainOneBucket(maybeTool.splitStack(1));
          // drained.setCount(1);
          // UtilItemStack.dropItemStackInWorld(this.world, getCurrentFacingPos(), drained);
          maybeTool.shrink(1 + hack);
        }
        this.tryDumpFakePlayerInvo();
      }
    }
    else {//no tank, just open world
      //dispense stack so either pickup or place liquid
      if (UtilFluid.isEmptyOfFluid(maybeTool)) {
        FluidActionResult res = UtilFluid.fillContainer(world, targetPos, maybeTool, this.getCurrentFacing());
        if (res != FluidActionResult.FAILURE) {
          maybeTool.shrink(1);
          UtilItemStack.dropItemStackInWorld(this.world, getCurrentFacingPos(), res.getResult());
          return true;
        }
      }
      else {
        ItemStack drainedStackOrNull = UtilFluid.dumpContainer(world, targetPos, maybeTool);
        if (drainedStackOrNull != null) {
          maybeTool.shrink(1);
          UtilItemStack.dropItemStackInWorld(this.world, getCurrentFacingPos(), drainedStackOrNull);
        }
      }
      return true;
    }
  }
  return false;
}