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;
}
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);
}
}
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);
}
}
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);
}
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();
}
}
Aggregations