Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparator update order different from vanilla #1863

Open
2No2Name opened this issue Jan 17, 2025 · 6 comments · May be fixed by #1866
Open

Comparator update order different from vanilla #1863

2No2Name opened this issue Jan 17, 2025 · 6 comments · May be fixed by #1866
Labels
1.21.4 Targeted at Minecraft 1.21.4 bug A bug or error

Comments

@2No2Name
Copy link

Minecraft Version: 1.21.4

NeoForge Version: 21.4.50-beta

Steps to Reproduce:

  1. Place a sunflower (to get the orientation correct)
  2. Build the rest (sticky pistons) as in the screenshots
  3. Put an item into the chest

Description of issue:
With neoforge:
Image
With vanilla:
Image
Neoforge's comparator update order seems to be different from vanilla

@2No2Name 2No2Name added the triage Needs triaging and confirmation label Jan 17, 2025
@2No2Name 2No2Name changed the title Comparator updates order different from vanilla Comparator update order different from vanilla Jan 17, 2025
@2No2Name
Copy link
Author

2No2Name commented Jan 17, 2025

Code analysis: Level.java: updateNeighbourForOutputSignal uses Direction.values() instead of Direction.Plane.HORIZONTAL. These have different iteration order for the horizontal directions

@2No2Name
Copy link
Author

Seems like this is for a vertical comparator implementation

@sciwhiz12
Copy link
Member

After digging through the patch git blame, this change was implemented all the way back in 2016, to fix MinecraftForge/MinecraftForge#2428.

@sciwhiz12 sciwhiz12 added 1.21.4 Targeted at Minecraft 1.21.4 bug A bug or error and removed triage Needs triaging and confirmation labels Jan 17, 2025
@2No2Name
Copy link
Author

2No2Name commented Jan 18, 2025

The issue also includes the vertical updates existing, which is detectable and different from vanilla. I think in some reasonable setups this might occur accidentally, breaking contraptions. (Comparator update detector above or below some other inventories.)

This setup updates the detector with neoforge, but not in vanilla.

Image

For some reason placing the comparator directly on the hopper doesn't trigger the behavior, I don't understand why.

@2No2Name
Copy link
Author

2No2Name commented Jan 18, 2025

For some reason placing the comparator directly on the hopper doesn't trigger the behavior, I don't understand why.

Ah you are implementing pos.getY() == neighbor.getY() in ComparatorBlock for the first update attempt (1 block range) in

ComparatorBlock:
   @Override
    public void onNeighborChange(BlockState state, net.minecraft.world.level.LevelReader levelReader, BlockPos pos, BlockPos neighbor) {
        if (pos.getY() == neighbor.getY() && levelReader instanceof Level level && !levelReader.isClientSide()) {
            // TODO porting: check this still works as expected
            state.handleNeighborChanged(level, pos, levelReader.getBlockState(neighbor).getBlock(), null, false);
        }
    }

But it is not implemented for the 2 block range update. I suggest removing the check above and instead doing something at the point of sending the comparator updates

@2No2Name
Copy link
Author

2No2Name commented Jan 18, 2025

I suggest if you want to keep the vertical updates, reorder them as in the PR and then instead of blockState.is(Blocks.COMPARATOR) do your blockstate.getWeakChanges(this, blockpos) && (direction.isHorizontal || !blockState.is(Blocks.COMPARATOR))

An alternative might be to implement the second update with the same code path as the first update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.4 Targeted at Minecraft 1.21.4 bug A bug or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants