List of usage examples for net.minecraftforge.fluids FluidActionResult isSuccess
public boolean isSuccess()
From source file:com.buuz135.industrial.tile.block.BlackHoleTankBlock.java
License:Open Source License
@Override public boolean onBlockActivated(@Nullable World worldIn, @Nullable BlockPos pos, @Nullable IBlockState state, @Nullable EntityPlayer playerIn, @Nullable EnumHand hand, @Nullable EnumFacing facing, float hitX, float hitY, float hitZ) { if (playerIn != null && hand != null && worldIn != null && pos != null) { ItemStack stack = playerIn.getHeldItem(hand); if (!stack.isEmpty() && stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null) && worldIn.getTileEntity(pos) instanceof BlackHoleTankTile) { BlackHoleTankTile tile = (BlackHoleTankTile) worldIn.getTileEntity(pos); FluidActionResult result = FluidUtil.tryFillContainer(stack, (IFluidHandler) tile.getTank(), Integer.MAX_VALUE, playerIn, true); if (result.isSuccess()) { stack.shrink(1);/*from www . ja va 2 s .c o m*/ if (stack.isEmpty()) { playerIn.setHeldItem(hand, result.result); } else { playerIn.addItemStackToInventory(result.result); } return true; } } } return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ); }
From source file:com.buuz135.industrial.utils.ItemStackUtils.java
License:Open Source License
public static void fillItemFromTank(ItemStackHandler fluidItems, IFluidTank tank) { if (tank.getFluid() == null) return;/*from w w w . j a va 2s . c o m*/ ItemStack stack = fluidItems.getStackInSlot(0).copy(); if (!stack.isEmpty()) { if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { FluidActionResult result = FluidUtil.tryFillContainer(stack, (IFluidHandler) tank, tank.getCapacity(), null, false); if (result.isSuccess() && (fluidItems.getStackInSlot(1).isEmpty() || (ItemHandlerHelper.canItemStacksStack(result.getResult(), fluidItems.getStackInSlot(1)) && result.getResult().getCount() + fluidItems.getStackInSlot(1).getCount() <= result .getResult().getMaxStackSize()))) { result = FluidUtil.tryFillContainer(stack, (IFluidHandler) tank, tank.getCapacity(), null, true); if (fluidItems.getStackInSlot(1).isEmpty()) { fluidItems.setStackInSlot(1, result.getResult()); } else { fluidItems.getStackInSlot(1).grow(1); } fluidItems.getStackInSlot(0).shrink(1); } } } }
From source file:com.buuz135.industrial.utils.ItemStackUtils.java
License:Open Source License
public static void fillTankFromItem(ItemStackHandler fluidItems, IFluidTank tank) { ItemStack stack = fluidItems.getStackInSlot(0).copy(); if (!stack.isEmpty()) { if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { IFluidHandlerItem cap = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);/*from ww w . j a v a 2s.com*/ FluidStack fluidStack = cap.drain(1000, false); if (fluidStack != null && tank.fill(fluidStack, false) == 0) return; FluidActionResult result = FluidUtil.tryEmptyContainer(stack, (IFluidHandler) tank, 1000, null, false); if (result.isSuccess() && (fluidItems.getStackInSlot(1).isEmpty() || (ItemHandlerHelper.canItemStacksStack(result.getResult(), fluidItems.getStackInSlot(1)) && result.getResult().getCount() + fluidItems.getStackInSlot(1).getCount() <= result .getResult().getMaxStackSize()))) { result = FluidUtil.tryEmptyContainer(stack, (IFluidHandler) tank, tank.getCapacity(), null, true); if (fluidItems.getStackInSlot(1).isEmpty()) { fluidItems.setStackInSlot(1, result.getResult()); } else { fluidItems.getStackInSlot(1).grow(1); } fluidItems.getStackInSlot(0).shrink(1); } } } }
From source file:com.elytradev.thermionics.tileentity.TileEntityPotStill.java
License:Open Source License
@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); }//from www .j a v a2 s .c om } } 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; }
From source file:com.elytradev.thermionics.transport.FluidTransport.java
License:Open Source License
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; }// w w w .ja v a 2 s. c o m FluidActionResult result = tryEmptyOrFillContainer(fluidItem, tank, maxTransfer, player); if (result.isSuccess()) { player.setHeldItem(hand, result.result); return true; } else { return false; } }
From source file:com.teambrmodding.neotech.common.blocks.machines.BlockMachine.java
License:Creative Commons License
/** * Called when the block is clicked on// ww w . ja va2s .co m * @return True to prevent future logic */ @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { // Make sure our machine is reachable if (worldIn.getTileEntity(pos) != null && worldIn.getTileEntity(pos) instanceof AbstractMachine) { AbstractMachine machine = (AbstractMachine) worldIn.getTileEntity(pos); // First interact with fluid handlers if (machine.isFluidHandler()) { IFluidHandler fluidHandler = machine.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); FluidActionResult result = FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand), fluidHandler, playerIn); if (result.isSuccess()) { playerIn.setHeldItem(hand, result.getResult()); return true; } } // Open a GUI if (!playerIn.isSneaking()) { playerIn.openGui(Bookshelf.INSTANCE, 0, worldIn, pos.getX(), pos.getY(), pos.getZ()); return true; } } return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ); }
From source file:com.teambrmodding.neotech.common.blocks.storage.BlockFluidStorage.java
License:Creative Commons License
/** * Called when the block is clicked on/*w w w .jav a 2 s . c om*/ * @return True to prevent future logic */ @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { // Make sure our storage is reachable if (worldIn.getTileEntity(pos) != null && worldIn.getTileEntity(pos) instanceof TileBasicTank) { TileBasicTank fluidStorage = (TileBasicTank) worldIn.getTileEntity(pos); // First interact with fluid handlers IFluidHandler fluidHandler = fluidStorage.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); FluidActionResult result = FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand), fluidHandler, playerIn); if (result.isSuccess()) { playerIn.setHeldItem(hand, result.getResult()); return true; } // We want to display in chat the current levels if (worldIn.isRemote && fluidStorage.tanks[TileBasicTank.TANK].getFluid() != null) { FluidStack fluidStack = fluidStorage.tanks[TileBasicTank.TANK].getFluid(); if (fluidStack.getFluid() != null) { String display = fluidStack.getLocalizedName() + ": " + ClientUtils.formatNumber(fluidStorage.tanks[TileBasicTank.TANK].getFluidAmount()) + " / " + ClientUtils.formatNumber(fluidStorage.tanks[TileBasicTank.TANK].getCapacity()); playerIn.sendMessage(new TextComponentString(display)); } } } return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ); }
From source file:com.teambrmodding.neotech.common.tiles.machines.generators.TileFluidGenerator.java
License:Creative Commons License
/** * Called per tick to manage burn time. You can do nothing here if there is nothing to generate. You should decrease burn time here * You should be handling checks if burnTime is 0 in this method, otherwise the tile won't know what to do * * @return True if able to continue generating *//*from w ww . j av a2 s. c om*/ @Override public boolean manageBurnTime() { if (tanks == null || tanks.length <= 0 || tanks[TANK] == null) return false; // Handle Items ItemStack stackToDrain = getStackInSlot(INPUT_SLOT); if (stackToDrain.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { FluidActionResult result = FluidUtil.tryEmptyContainer(stackToDrain, this, tanks[TANK].getCapacity() - tanks[TANK].getFluidAmount(), null, true); if (result.isSuccess() && FluidUtil.getFluidContained(result.getResult()) == null) { if (getStackInSlot(OUTPUT_SLOT).isEmpty()) { setStackInSlot(OUTPUT_SLOT, result.getResult()); setStackInSlot(INPUT_SLOT, ItemStack.EMPTY); } else if (InventoryUtils.canStacksMerge(result.getResult(), getStackInSlot(OUTPUT_SLOT))) { InventoryUtils.tryMergeStacks(result.getResult(), getStackInSlot(OUTPUT_SLOT)); if (getStackInSlot(INPUT_SLOT).getCount() <= 0) setStackInSlot(INPUT_SLOT, ItemStack.EMPTY); } markForUpdate(6); } else if (result.isSuccess()) { setStackInSlot(INPUT_SLOT, result.getResult()); markForUpdate(6); } } // Do burnTime if (energyStorage.getEnergyStored() < energyStorage.getMaxEnergyStored() && burnTime <= 1) { FluidStack fluidDrained = tanks[TANK].drain(100, false); FluidFuelRecipe recipe = ((FluidFuelRecipeHandler) RecipeManager .getHandler(RecipeManager.RecipeType.FLUID_FUELS)).getRecipe(fluidDrained); if (recipe == null) return false; Pair<Integer, Integer> output = recipe .getOutput(AbstractRecipe.getFluidStackFromString(recipe.fluidStackInput)); if (output == null) return false; fluidDrained = tanks[TANK].drain(AbstractRecipe.getFluidStackFromString(recipe.fluidStackInput).amount, false); if (fluidDrained == null || fluidDrained.getFluid() == null || fluidDrained.amount <= 0) return false; else drain(fluidDrained.amount, true); burnTime = output.getLeft(); currentObjectBurnRate = output.getRight() + (output.getRight() * (getModifierForCategory(IUpgradeItem.ENUM_UPGRADE_CATEGORY.CPU) / 8)); if (burnTime > 0) { currentObjectBurnTime = burnTime; return true; } } burnTime -= Math.max(1, getModifierForCategory(IUpgradeItem.ENUM_UPGRADE_CATEGORY.MEMORY) - (getModifierForCategory(IUpgradeItem.ENUM_UPGRADE_CATEGORY.CPU) / 2)); return burnTime > 0; }
From source file:de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase.java
protected boolean tryUseItemOnTank(EntityPlayer player, EnumHand hand, FluidTank tank) { ItemStack heldItem = player.getHeldItem(hand); if (StackUtil.isValid(heldItem)) { FluidActionResult result = FluidUtil.interactWithFluidHandler(heldItem, tank, player); if (result.isSuccess()) { player.setHeldItem(hand, result.getResult()); return true; }//from w w w . j a va 2 s. c o m } return false; }
From source file:hellfirepvp.astralsorcery.common.block.network.BlockWell.java
License:Open Source License
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote) { ItemStack heldItem = playerIn.getHeldItem(hand); if (!heldItem.isEmpty() && playerIn instanceof EntityPlayerMP) { TileWell tw = MiscUtils.getTileAt(worldIn, pos, TileWell.class, false); if (tw == null) return false; WellLiquefaction.LiquefactionEntry entry = WellLiquefaction.getLiquefactionEntry(heldItem); if (entry != null) { ItemStackHandler handle = tw.getInventoryHandler(); if (!handle.getStackInSlot(0).isEmpty()) return false; if (!worldIn.isAirBlock(pos.up())) { return false; }//from w w w. j a v a 2 s .c o m handle.setStackInSlot(0, ItemUtils.copyStackWithSize(heldItem, 1)); worldIn.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F); if (!MiscUtils.isPlayerFakeMP((EntityPlayerMP) playerIn) && entry.producing instanceof FluidLiquidStarlight) { //Lets assume it starts collecting right away... playerIn.addStat(RegistryAchievements.achvLiqStarlight); } if (!playerIn.isCreative()) { heldItem.shrink(1); } if (heldItem.getCount() <= 0) { playerIn.setHeldItem(hand, ItemStack.EMPTY); } } FluidActionResult far = FluidUtil.tryFillContainerAndStow(heldItem, tw.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN), new InvWrapper(playerIn.inventory), 1000, playerIn); if (far.isSuccess()) { playerIn.setHeldItem(hand, far.getResult()); SoundHelper.playSoundAround(SoundEvents.ITEM_BUCKET_FILL, worldIn, pos, 1F, 1F); tw.markForUpdate(); } } } return true; }