Search in sources :

Example 6 with IBucketPickupHandler

use of net.minecraft.block.IBucketPickupHandler in project SophisticatedBackpacks by P3pp3rF1y.

the class PumpUpgradeWrapper method fillFromBlock.

private boolean fillFromBlock(World world, BlockPos pos, IFluidHandler backpackFluidHandler) {
    FluidState fluidState = world.getFluidState(pos);
    if (!fluidState.isEmpty()) {
        BlockState state = world.getBlockState(pos);
        Block block = state.getBlock();
        IFluidHandler targetFluidHandler;
        if (block instanceof IFluidBlock) {
            targetFluidHandler = new FluidBlockWrapper((IFluidBlock) block, world, pos);
        } else if (block instanceof IBucketPickupHandler) {
            targetFluidHandler = new BucketPickupHandlerWrapper((IBucketPickupHandler) block, world, pos);
        } else {
            return false;
        }
        return fillFromFluidHandler(targetFluidHandler, backpackFluidHandler);
    }
    return false;
}
Also used : FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) BucketPickupHandlerWrapper(net.minecraftforge.fluids.capability.wrappers.BucketPickupHandlerWrapper) IBucketPickupHandler(net.minecraft.block.IBucketPickupHandler) BlockState(net.minecraft.block.BlockState) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) FluidState(net.minecraft.fluid.FluidState)

Example 7 with IBucketPickupHandler

use of net.minecraft.block.IBucketPickupHandler in project Enigmatic-Legacy by Aizistral-Studios.

the class Megasponge method absorbWaterBlock.

public static void absorbWaterBlock(BlockPos pos, BlockState state, World world) {
    if (state.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) state.getBlock()).pickupFluid(world, pos, state) != Fluids.EMPTY) {
    // Whatever
    } else if (state.getBlock() instanceof FlowingFluidBlock) {
        world.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
    } else if (state.getMaterial() == Material.OCEAN_PLANT || state.getMaterial() == Material.SEA_GRASS) {
        TileEntity tileentity = state.hasTileEntity() ? world.getTileEntity(pos) : null;
        Block.spawnDrops(state, world, pos, tileentity);
        world.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBucketPickupHandler(net.minecraft.block.IBucketPickupHandler) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock)

Example 8 with IBucketPickupHandler

use of net.minecraft.block.IBucketPickupHandler in project FrostedHeart by TeamMoegMC.

the class CeramicBucket method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
    ItemStack itemstack = playerIn.getHeldItem(handIn);
    Fluid containedFluid = getFluid(itemstack);
    RayTraceResult raytraceresult = rayTrace(worldIn, playerIn, containedFluid == Fluids.EMPTY ? RayTraceContext.FluidMode.SOURCE_ONLY : RayTraceContext.FluidMode.NONE);
    ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onBucketUse(playerIn, worldIn, itemstack, raytraceresult);
    if (ret != null)
        return ret;
    if (raytraceresult.getType() == RayTraceResult.Type.MISS) {
        return ActionResult.resultPass(itemstack);
    } else if (raytraceresult.getType() != RayTraceResult.Type.BLOCK) {
        return ActionResult.resultPass(itemstack);
    } else {
        BlockRayTraceResult blockraytraceresult = (BlockRayTraceResult) raytraceresult;
        BlockPos blockpos = blockraytraceresult.getPos();
        Direction direction = blockraytraceresult.getFace();
        BlockPos blockpos1 = blockpos.offset(direction);
        if (worldIn.isBlockModifiable(playerIn, blockpos) && playerIn.canPlayerEdit(blockpos1, direction, itemstack)) {
            if (containedFluid == Fluids.EMPTY) {
                BlockState blockstate1 = worldIn.getBlockState(blockpos);
                if (blockstate1.getBlock() instanceof IBucketPickupHandler) {
                    Fluid fluid1 = ((IBucketPickupHandler) blockstate1.getBlock()).pickupFluid(worldIn, blockpos, blockstate1);
                    if (fluid1 != Fluids.EMPTY) {
                        SoundEvent soundevent = containedFluid.getAttributes().getFillSound();
                        if (soundevent == null)
                            soundevent = fluid1.isIn(FluidTags.LAVA) ? SoundEvents.ITEM_BUCKET_FILL_LAVA : SoundEvents.ITEM_BUCKET_FILL;
                        playerIn.playSound(soundevent, 1.0F, 1.0F);
                        ItemStack itemstack1 = this.fillBucket(itemstack, playerIn, fluid1);
                        if (!worldIn.isRemote) {
                            CriteriaTriggers.FILLED_BUCKET.trigger((ServerPlayerEntity) playerIn, new ItemStack(fluid1.getFilledBucket()));
                        }
                        return ActionResult.func_233538_a_(itemstack1, worldIn.isRemote());
                    }
                }
                return ActionResult.resultFail(itemstack);
            }
            if (itemstack.getCount() > 1)
                return ActionResult.resultFail(itemstack);
            BlockState blockstate = worldIn.getBlockState(blockpos);
            BlockPos blockpos2 = canBlockContainFluid(worldIn, blockpos, blockstate, containedFluid) ? blockpos : blockpos1;
            if (this.tryPlaceContainedLiquid(playerIn, worldIn, blockpos2, blockraytraceresult, containedFluid)) {
                if (playerIn instanceof ServerPlayerEntity) {
                    CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayerEntity) playerIn, blockpos2, itemstack);
                }
                return ActionResult.func_233538_a_(this.emptyBucket(itemstack, playerIn), worldIn.isRemote());
            }
        }
        return ActionResult.resultFail(itemstack);
    }
}
Also used : SoundEvent(net.minecraft.util.SoundEvent) IBucketPickupHandler(net.minecraft.block.IBucketPickupHandler) BlockState(net.minecraft.block.BlockState) FlowingFluid(net.minecraft.fluid.FlowingFluid) Fluid(net.minecraft.fluid.Fluid) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ItemStack(net.minecraft.item.ItemStack) Direction(net.minecraft.util.Direction)

Example 9 with IBucketPickupHandler

use of net.minecraft.block.IBucketPickupHandler in project LoliServer by Loli-Server.

the class FluidUtil method tryPickUpFluid.

/**
 * Attempts to pick up a fluid in the world and put it in an empty container item.
 *
 * @param emptyContainer The empty container to fill.
 *                       Will not be modified directly, if modifications are necessary a modified copy is returned in the result.
 * @param playerIn       The player filling the container. Optional.
 * @param worldIn        The world the fluid is in.
 * @param pos            The position of the fluid in the world.
 * @param side           The side of the fluid that is being drained.
 * @return a {@link FluidActionResult} holding the result and the resulting container.
 */
@Nonnull
public static FluidActionResult tryPickUpFluid(@Nonnull ItemStack emptyContainer, @Nullable PlayerEntity playerIn, World worldIn, BlockPos pos, Direction side) {
    if (emptyContainer.isEmpty() || worldIn == null || pos == null) {
        return FluidActionResult.FAILURE;
    }
    BlockState state = worldIn.getBlockState(pos);
    Block block = state.getBlock();
    IFluidHandler targetFluidHandler;
    if (block instanceof IFluidBlock) {
        targetFluidHandler = new FluidBlockWrapper((IFluidBlock) block, worldIn, pos);
    } else if (block instanceof IBucketPickupHandler) {
        targetFluidHandler = new BucketPickupHandlerWrapper((IBucketPickupHandler) block, worldIn, pos);
    } else {
        Optional<IFluidHandler> fluidHandler = getFluidHandler(worldIn, pos, side).resolve();
        if (!fluidHandler.isPresent()) {
            return FluidActionResult.FAILURE;
        }
        targetFluidHandler = fluidHandler.get();
    }
    return tryFillContainer(emptyContainer, targetFluidHandler, Integer.MAX_VALUE, playerIn, true);
}
Also used : FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) BucketPickupHandlerWrapper(net.minecraftforge.fluids.capability.wrappers.BucketPickupHandlerWrapper) IBucketPickupHandler(net.minecraft.block.IBucketPickupHandler) BlockState(net.minecraft.block.BlockState) LazyOptional(net.minecraftforge.common.util.LazyOptional) Optional(java.util.Optional) Block(net.minecraft.block.Block) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Nonnull(javax.annotation.Nonnull)

Example 10 with IBucketPickupHandler

use of net.minecraft.block.IBucketPickupHandler in project Arclight by IzzelAliz.

the class BucketItemMixin method arclight$bucketFill.

// @formatter:on
@Inject(method = "onItemRightClick", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/IBucketPickupHandler;pickupFluid(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/fluid/Fluid;"))
private void arclight$bucketFill(World worldIn, PlayerEntity playerIn, Hand handIn, CallbackInfoReturnable<ActionResult<ItemStack>> cir, ItemStack stack, RayTraceResult result) {
    BlockPos pos = ((BlockRayTraceResult) result).getPos();
    BlockState state = worldIn.getBlockState(pos);
    Fluid dummyFluid = ((IBucketPickupHandler) state.getBlock()).pickupFluid(DummyGeneratorAccess.INSTANCE, pos, state);
    PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(worldIn, playerIn, pos, pos, ((BlockRayTraceResult) result).getFace(), stack, dummyFluid.getFilledBucket());
    if (event.isCancelled()) {
        ((ServerPlayerEntity) playerIn).connection.sendPacket(new SChangeBlockPacket(worldIn, pos));
        ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
        cir.setReturnValue(new ActionResult<>(ActionResultType.FAIL, stack));
    } else {
        arclight$captureItem = event.getItemStack();
    }
}
Also used : PlayerBucketFillEvent(org.bukkit.event.player.PlayerBucketFillEvent) IBucketPickupHandler(net.minecraft.block.IBucketPickupHandler) BlockState(net.minecraft.block.BlockState) SChangeBlockPacket(net.minecraft.network.play.server.SChangeBlockPacket) Fluid(net.minecraft.fluid.Fluid) BlockPos(net.minecraft.util.math.BlockPos) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

IBucketPickupHandler (net.minecraft.block.IBucketPickupHandler)13 BlockState (net.minecraft.block.BlockState)11 BlockPos (net.minecraft.util.math.BlockPos)8 Fluid (net.minecraft.fluid.Fluid)7 Block (net.minecraft.block.Block)6 ItemStack (net.minecraft.item.ItemStack)5 Direction (net.minecraft.util.Direction)5 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)5 FluidState (net.minecraft.fluid.FluidState)4 SoundEvent (net.minecraft.util.SoundEvent)4 Nonnull (javax.annotation.Nonnull)3 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 FlowingFluid (net.minecraft.fluid.FlowingFluid)3 RayTraceResult (net.minecraft.util.math.RayTraceResult)3 FluidStack (net.minecraftforge.fluids.FluidStack)3 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)3 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)3 BucketPickupHandlerWrapper (net.minecraftforge.fluids.capability.wrappers.BucketPickupHandlerWrapper)3 FluidBlockWrapper (net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper)3 Optional (java.util.Optional)2