mojira.dev
MC-234702

In adventure mode, you can interact with light blocks

The bug

You can switch the light mode in adventure mode by holding the light in your hand.

How to reproduce

  1. Place the light

  2. Switch to adventure mode

  3. With the light in hand, aim at the spot where you placed the light and try switching the light mode

Observed results

You can switch the light mode in adventure mode.

Expected results

In adventure mode, you cannot interact with the light.

Video demonstrating the issue

[media]

Code analysis

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 4

I can confirm this behavior in 1.18.1.

Here's a code analysis along with a potential fix regarding this issue.

Code Analysis:

The following is based on a decompiled version of Minecraft 1.18.1 using MCP-Reborn.

net.minecraft.world.level.block.LightBlock.java

public class LightBlock extends Block implements SimpleWaterloggedBlock {
   ...
   public InteractionResult use(BlockState $bs, Level $l, BlockPos $bp, Player $p, InteractionHand $ih, BlockHitResult $bhr) {
      if (!$l.isClientSide) {
         $l.setBlock($bp, $bs.cycle(LEVEL), 2);
         return InteractionResult.SUCCESS;
      } else {
         return InteractionResult.CONSUME;
      }
   }
   ...

If we look at the above class, we can see that no checks are carried out to see what abilities the player possesses when interacting with a light block. The only check that is in place is to see whether or not the action wasn't client-side. This is evident through the following line of code:

if (!$l.isClientSide)

Potential Fix:

Simply adding a line of code that checks what abilities the player possesses before interacting with a light block, should resolve this problem. The following line of code could be used in order to fix this:

!$p.getAbilities().mayBuild

Can confirm in 1.18.2 and 22w12a.

Fixed in 1.19.3 pre-release 3, as modifying light blocks requires creative mode and level two operator (LightBlock#onUse method in Yarn mappings)

[Mod] EVGENSYPERPRO

(Unassigned)

Confirmed

Items

1.17.1, 21w39a, 21w42a, 21w43a, 21w44a, , 1.18 Pre-release 4, 1.18.1, 22w03a, 1.18.2, 22w12a

1.19.3 Pre-release 3

Retrieved