Search in sources :

Example 1 with FluidActionResult

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) TileInfiniteWaterSource(com.cjm721.overloaded.block.tile.TileInfiniteWaterSource) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 2 with FluidActionResult

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;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Random(java.util.Random) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) JsonUtil(stevekung.mods.moreplanets.util.JsonUtil) TileEntityBlackHoleStorage(stevekung.mods.moreplanets.tileentity.TileEntityBlackHoleStorage)

Example 3 with FluidActionResult

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;
}
Also used : ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult)

Example 4 with FluidActionResult

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;
}
Also used : ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult)

Example 5 with FluidActionResult

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);
    }
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) RayTraceResult(net.minecraft.util.math.RayTraceResult) ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult)

Aggregations

FluidActionResult (net.minecraftforge.fluids.FluidActionResult)13 ItemStack (net.minecraft.item.ItemStack)9 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)5 TileEntity (net.minecraft.tileentity.TileEntity)3 RayTraceResult (net.minecraft.util.math.RayTraceResult)3 FluidStack (net.minecraftforge.fluids.FluidStack)3 IBlockState (net.minecraft.block.state.IBlockState)2 ActionResult (net.minecraft.util.ActionResult)2 EnumActionResult (net.minecraft.util.EnumActionResult)2 BlockPos (net.minecraft.util.math.BlockPos)2 IInventorySlots (binnie.core.machines.inventory.IInventorySlots)1 InventorySlot (binnie.core.machines.inventory.InventorySlot)1 ITankMachine (binnie.core.machines.power.ITankMachine)1 TileInfiniteWaterSource (com.cjm721.overloaded.block.tile.TileInfiniteWaterSource)1 TileInfiniteTank (com.cjm721.overloaded.block.tile.infinity.TileInfiniteTank)1 LongFluidStack (com.cjm721.overloaded.storage.LongFluidStack)1 Random (java.util.Random)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 SoundEvent (net.minecraft.util.SoundEvent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1