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

Hi, I'm trying to detect if a block is water or not however I'm getting results for the block that is highlighted in the crosshair, not the water blocks on top/around it. Here is the method I'm testing this out in so far: is there a method or function that I can use that will treat water as a solid block instead of allowing it to be clicked through? Thanks!

public static void onKeyInput(InputEvent.Key event) {
            if (KeyBinding.DRINK.consumeClick()) {
                double x = Minecraft.getInstance().player.getViewVector(1.0F).x() + Minecraft.getInstance().player.blockPosition().getX();
                double y = Minecraft.getInstance().player.getViewVector(1.0F).y() + Minecraft.getInstance().player.blockPosition().getY();
                double z = Minecraft.getInstance().player.getViewVector(1.0F).z() + Minecraft.getInstance().player.blockPosition().getZ();

                Minecraft.getInstance().player.sendSystemMessage(Component.literal("X: " + x + ", Y: " + y + ", Z: " + z));

                BlockPos blockpos = new BlockPos((int) Math.round(x), (int) Math.round(y), (int) Math.round(z));
                FluidState isWater = Minecraft.getInstance().level.getFluidState(blockpos);

                Minecraft.getInstance().player.sendSystemMessage(Component.literal(isWater.toString()));
	}
}

Update: I've also had a look at the vanilla bucket item class, but I can't seem to figure out where I'm supposed to be looking. The BlockHitResult function only returns MISS, ENTITY or BLOCK. I'm guessing interaction result pass means to do nothing if the his result is a miss or not a block, but where in the final else statement does it determine that there is water?

Edited by Capricocious
solved the issue, reflected in post name and comment.

I'm the CEO of breaking things 

  • Author
public static void onKeyInput(InputEvent.Key event) {
            if (KeyBinding.DRINK.consumeClick()) {

                Player player = Minecraft.getInstance().player;
                Level level = Minecraft.getInstance().level;

                final Vec3 vec3 = player.getEyePosition(1.0F);
                final Vec3 vec31 = player.getViewVector(1.0F);
                final int reach = (int) Math.round(player.getBlockReach());

                for (int i = 1; i <= reach; i++)
                {
                    Vec3 vec32 = vec3.add(vec31.x * i, vec31.y * i, vec31.z * i);
                    BlockPos blockpos = new BlockPos((int) vec32.x, (int) vec32.y, (int) vec32.z);
                    FluidState blockstate = level.getBlockState(blockpos).getFluidState();
                    if (blockstate.getType() == Fluids.WATER) {
                        player.sendSystemMessage(Component.literal(blockstate.toString()));
                    }
                }
            }
 }

This solution appears to be working for now, I receive a message when I click on water. Help from the final comment on this post, and also looking and the vanilla lilypad block net.minecraft.world.level.block.waterlilyblock.

I'm the CEO of breaking things 

  • Capricocious changed the title to [SOLVED] [1.20] detecting player click on water

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.