The bug
You can switch the light mode in adventure mode by holding the light in your hand.
How to reproduce
Place the light
Switch to adventure mode
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
Code analysis
Code analysis by @unknown can be found in this comment.
Linked issues
relates to 1
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.