use of net.minecraftforge.fluids.FluidActionResult in project Overloaded by CJ-MC-Mods.
the class BlockInfiniteTank method onBlockActivated.
@Override
public boolean onBlockActivated(@Nonnull World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!worldIn.isRemote) {
ItemStack heldItem = playerIn.getHeldItem(hand);
if (heldItem.isEmpty() && hand == EnumHand.MAIN_HAND) {
LongFluidStack storedFluid = ((TileInfiniteTank) worldIn.getTileEntity(pos)).getStorage().getFluidStack();
if (storedFluid == null || storedFluid.fluidStack == null) {
playerIn.sendStatusMessage(new TextComponentString("Fluid: EMPTY"), false);
} else {
playerIn.sendStatusMessage(new TextComponentString(String.format("Fluid: %s Amount %,d", storedFluid.fluidStack.getLocalizedName(), storedFluid.amount)), false);
}
} else {
TileEntity te = worldIn.getTileEntity(pos);
if (te != null && te instanceof TileInfiniteTank) {
IFluidHandler handler = te.getCapability(FLUID_HANDLER_CAPABILITY, side);
// FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand), te.getCapability(FLUID_HANDLER_CAPABILITY, facing), playerIn);
FluidActionResult result = FluidUtil.interactWithFluidHandler(heldItem, handler, playerIn);
if (result.isSuccess())
playerIn.setHeldItem(hand, result.getResult());
}
}
}
return true;
}
use of net.minecraftforge.fluids.FluidActionResult in project GregTech by GregTechCE.
the class MetaTileEntity method fillInternalTankFromFluidContainer.
public boolean fillInternalTankFromFluidContainer(IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, int inputSlot, int outputSlot) {
ItemStack inputContainerStack = importItems.extractItem(inputSlot, 1, true);
FluidActionResult result = FluidUtil.tryEmptyContainer(inputContainerStack, importFluids, Integer.MAX_VALUE, null, false);
if (result.isSuccess()) {
ItemStack remainingItem = result.getResult();
if (ItemStack.areItemStacksEqual(inputContainerStack, remainingItem))
// do not fill if item stacks match
return false;
if (!remainingItem.isEmpty() && !exportItems.insertItem(outputSlot, remainingItem, true).isEmpty())
// do not fill if can't put remaining item
return false;
FluidUtil.tryEmptyContainer(inputContainerStack, importFluids, Integer.MAX_VALUE, null, true);
importItems.extractItem(inputSlot, 1, false);
exportItems.insertItem(outputSlot, remainingItem, false);
return true;
}
return false;
}
use of net.minecraftforge.fluids.FluidActionResult in project MorePlanets by SteveKunG.
the class BlockNuclearWasteTank method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack itemStack = player.getHeldItem(hand);
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityNuclearWasteTank) {
TileEntityNuclearWasteTank tank = (TileEntityNuclearWasteTank) tile;
if (!itemStack.isEmpty()) {
if (tank.hasRod && !tank.createRod) {
if (itemStack.getItem() == MPItems.WASTE_ROD_PICKER) {
if (!player.capabilities.isCreativeMode) {
itemStack.damageItem(1, player);
}
Block.spawnAsEntity(world, pos, new ItemStack(MPItems.NUCLEAR_WASTE_ROD));
tank.hasRod = false;
tank.createRod = false;
return true;
}
} else {
int slot = player.inventory.currentItem;
FluidActionResult result = FluidUtil.interactWithFluidHandler(player.inventory.getCurrentItem(), tank.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null), player);
if (result.isSuccess()) {
tank.createRod = true;
tank.setTime();
player.inventory.setInventorySlotContents(slot, result.result);
if (player.inventoryContainer != null) {
player.inventoryContainer.detectAndSendChanges();
}
return true;
}
}
}
}
return false;
}
use of net.minecraftforge.fluids.FluidActionResult in project pnc-repressurized by TeamPneumatic.
the class FluidUtils method tryFluidInsertion.
/**
* 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;
}
}
use of net.minecraftforge.fluids.FluidActionResult in project pnc-repressurized by TeamPneumatic.
the class FluidUtils method doFluidInteraction.
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;
}
Aggregations