Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

  • Author
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));
                    }
                }
            }

        }
    }

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.