use of net.minecraftforge.fluids.FluidActionResult in project Overloaded by CJ-MC-Mods.
the class BlockInfiniteWaterSource method onBlockActivated.
@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 && hand == EnumHand.MAIN_HAND) {
TileEntity te = worldIn.getTileEntity(pos);
if (te != null && te instanceof TileInfiniteWaterSource) {
IFluidHandler handler = te.getCapability(FLUID_HANDLER_CAPABILITY, facing);
// FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand), te.getCapability(FLUID_HANDLER_CAPABILITY, facing), playerIn);
FluidActionResult result = FluidUtil.tryFillContainerAndStow(playerIn.getHeldItem(hand), handler, null, Integer.MAX_VALUE, playerIn);
if (result.isSuccess())
playerIn.setHeldItem(hand, result.getResult());
}
}
return true;
}
use of net.minecraftforge.fluids.FluidActionResult in project MorePlanets by SteveKunG.
the class BlockBlackHoleStorage method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
} else {
TileEntity tile = world.getTileEntity(pos);
int slot = player.inventory.currentItem;
if (tile instanceof TileEntityBlackHoleStorage) {
TileEntityBlackHoleStorage storage = (TileEntityBlackHoleStorage) tile;
FluidActionResult result = FluidUtil.interactWithFluidHandler(player.inventory.getCurrentItem(), storage.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null), player);
if (result.isSuccess()) {
player.inventory.setInventorySlotContents(slot, result.result);
if (player.inventoryContainer != null) {
player.inventoryContainer.detectAndSendChanges();
}
return true;
} else {
if (player.getGameProfile().getId().toString().equals(storage.ownerUUID)) {
if (player.isSneaking() && storage.fluidTank.getFluidAmount() > 0) {
Random rand = world.rand;
storage.drainExp(player);
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 0.1F, 0.5F * ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.8F));
} else {
player.openGui(MorePlanetsCore.MOD_ID, -1, world, pos.getX(), pos.getY(), pos.getZ());
}
} else {
JsonUtil json = new JsonUtil();
player.sendMessage(json.text(GCCoreUtil.translate("gui.bh_storage_not_owner.message")).setStyle(json.red()));
}
}
}
return true;
}
}
use of net.minecraftforge.fluids.FluidActionResult in project ForestryMC by ForestryMC.
the class FluidHelper method drainContainers.
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot) {
ItemStack input = inv.getStackInSlot(inputSlot);
if (input.isEmpty()) {
return false;
}
FluidActionResult fluidActionSimulated = FluidUtil.tryEmptyContainer(input, fluidHandler, Fluid.BUCKET_VOLUME, null, false);
if (!fluidActionSimulated.isSuccess()) {
return false;
}
ItemStack drainedItemSimulated = fluidActionSimulated.getResult();
if (input.getCount() == 1 || drainedItemSimulated.isEmpty()) {
FluidActionResult fluidActionResult = FluidUtil.tryEmptyContainer(input, fluidHandler, Fluid.BUCKET_VOLUME, null, true);
if (fluidActionResult.isSuccess()) {
ItemStack drainedItem = fluidActionResult.getResult();
if (!drainedItem.isEmpty()) {
inv.setInventorySlotContents(inputSlot, drainedItem);
} else {
inv.decrStackSize(inputSlot, 1);
}
return true;
}
}
return false;
}
use of net.minecraftforge.fluids.FluidActionResult in project ForestryMC by ForestryMC.
the class FluidHelper method drainContainers.
public static FillStatus drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, boolean doDrain) {
ItemStack input = inv.getStackInSlot(inputSlot);
if (input.isEmpty()) {
return FillStatus.INVALID_INPUT;
}
ItemStack outputStack = inv.getStackInSlot(outputSlot);
FluidActionResult drainedResultSimulated = FluidUtil.tryEmptyContainer(input, fluidHandler, Fluid.BUCKET_VOLUME, null, false);
if (!drainedResultSimulated.isSuccess()) {
return FillStatus.INVALID_INPUT;
}
ItemStack drainedItemSimulated = drainedResultSimulated.getResult();
if (outputStack.isEmpty() || drainedItemSimulated.isEmpty() || ItemStackUtil.isIdenticalItem(outputStack, drainedItemSimulated) && outputStack.getCount() + drainedItemSimulated.getCount() < outputStack.getMaxStackSize()) {
if (doDrain) {
FluidActionResult drainedResult = FluidUtil.tryEmptyContainer(input, fluidHandler, Fluid.BUCKET_VOLUME, null, true);
if (drainedResult.isSuccess()) {
ItemStack drainedItem = drainedResult.getResult();
if (!drainedItem.isEmpty()) {
ItemStack newStack = drainedItem.copy();
if (!outputStack.isEmpty()) {
newStack.grow(outputStack.getCount());
}
if (!isFillableContainer(newStack) || isFillableContainerAndEmpty(newStack)) {
inv.setInventorySlotContents(outputSlot, newStack);
inv.decrStackSize(inputSlot, 1);
}
} else {
inv.decrStackSize(inputSlot, 1);
}
return FillStatus.SUCCESS;
}
}
return FillStatus.SUCCESS;
}
return FillStatus.NO_SPACE;
}
use of net.minecraftforge.fluids.FluidActionResult in project ForestryMC by ForestryMC.
the class ItemFluidContainerForestry method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand handIn) {
ItemStack heldItem = player.getHeldItem(handIn);
DrinkProperties drinkProperties = getDrinkProperties(heldItem);
if (drinkProperties != null) {
if (player.canEat(false)) {
player.setActiveHand(handIn);
return new ActionResult<>(EnumActionResult.SUCCESS, heldItem);
} else {
return new ActionResult<>(EnumActionResult.FAIL, heldItem);
}
} else {
if (Config.CapsuleFluidPickup) {
RayTraceResult target = this.rayTrace(world, player, true);
if (target.typeOfHit != RayTraceResult.Type.BLOCK) {
return ActionResult.newResult(EnumActionResult.PASS, heldItem);
}
ItemStack singleBucket = heldItem.copy();
singleBucket.setCount(1);
FluidActionResult filledResult = FluidUtil.tryPickUpFluid(singleBucket, player, world, target.getBlockPos(), target.sideHit);
if (filledResult.isSuccess()) {
ItemHandlerHelper.giveItemToPlayer(player, filledResult.result);
if (!player.capabilities.isCreativeMode) {
// Remove consumed empty container
heldItem.shrink(1);
}
return ActionResult.newResult(EnumActionResult.SUCCESS, heldItem);
}
}
return super.onItemRightClick(world, player, handIn);
}
}
Aggregations