Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Detect Bottle use on fluid


Recommended Posts

I have added and registered a fluid, and I need to detect when the player right clicks the fluid with a bottle, but there is no way to detect that within the class extending FlowingFluid, and if I use onBlockActivated in the class extending FlowingFluidBlock, nothing happens. It seems vanilla Minecraft detects it within the bottle itself, so where would I detect a bottle clicking my fluid at?

Link to post
Share on other sites
5 hours ago, diesieben07 said:

This happens in GlassBottleItem#onItemRightClick, which you can intercept using PlayerInteractEvent.RightClickItem.

Alright, so I have done that, but I cannot use the same rayTrace method that the bottle uses because it is protected, so how do I find the fluid that was clicked?

@SubscribeEvent
    public static void playerRightClickItem(PlayerInteractEvent.RightClickItem event) {
        System.out.println("Player Right Clicked!");
        World worldIn = event.getWorld();
        PlayerEntity playerIn = event.getPlayer();

        if (event.getPlayer().getHeldItem(event.getHand()).getItem() == Items.GLASS_BOTTLE) {
            RayTraceResult raytraceresult = rayTrace(worldIn, playerIn, RayTraceContext.FluidMode.SOURCE_ONLY); //Error: 'rayTrace(net.minecraft.world.World, net.minecraft.entity.player.PlayerEntity, net.minecraft.util.math.RayTraceContext.FluidMode)' has protected access in 'net.minecraft.item.Item'
            if (raytraceresult.getType() == RayTraceResult.Type.MISS) {
            } else {
                if (raytraceresult.getType() == RayTraceResult.Type.BLOCK) {
                    BlockPos blockpos = ((BlockRayTraceResult)raytraceresult).getPos();
                    if (worldIn.getFluidState(blockpos).getFluid() instanceof RedWater) {
                        worldIn.playSound(playerIn, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.NEUTRAL, 1.0F, 1.0F);
                        turnBottleIntoItem(event.getPlayer().getHeldItem(event.getHand()), event.getPlayer(), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTION), Potions.HEALING));
                    }
                }
            }

        }
    }

 

Link to post
Share on other sites

You can use the following ugly hack:

public class UglyHack extends Item {
  public static BlockRayTraceResult rayTraceAccess(World worldIn, PlayerEntity player, RayTraceContext.FluidMode fluidMode) {
    return Item.rayTrace(worldIn, player, fluidMode);
  }        
}

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.