Carpet

Carpet

2M Downloads

getReceivedRedstonePower() returns incorrect values

CommandLeo opened this issue ยท 2 comments

commented

getReceivedRedstonePower() is currently used in /info block and Scarpet power() function.

There are 2 issues with how it works:

  1. It should (arguably) not work with blocks that don't have varying signal strengths, as described in the Scarpet docs for power(): Numeric function, returning redstone power level at position. Therefore it makes sense that it works only with redstone dust, comparators, daylight sensors and target blocks.
    image
    In this example running the command /info block <x> <y> <z> grep Redstone power on the powered rail returns Redstone power level: 15 even though rails don't have different signal strengths, they are either powered or unpowered.

  2. This a more serious issue: power() doesn't consider the fact that repeaters and comparators only take an input from behind. So by, for example, placing a redstone block next to a comparator and running /info block on the comparator it will return a power level of 15.
    image

What's even weirder is what happens when you try to search for getReceivedRedstonePower in the mod's code. There are 4 results, including the definition of the function.
But in line 36 of RedstoneWireBlockMixin.java apparently the function always returns 0?

Apart from the issues with how the function works, I've found out that power() is actually slower than block_state(b, 'power'), so in the current state power() is completely useless.

commented

getReceivedRedstonePower is a vanilla method that checks the power that a block in the given position would receive, the block that's doing the call is expected to know where to look at (for example, comparators would look at the block behind IIRC, etc.

The get getReceivedRedstonePower() in the mixin isn't a declaration of how it works, it's just a stub to be able to call it (if you check, you'll see it's annotated with @Shadow, meaning that it will just call the method in the original class (since it's a mixin, java doesn't know that method exists, so that is provided to be able to use it). That class should have been abstract though so it didn't need to declare a body for the method, but whatever, that 0 isn't ever actually returned.

Probably docs would need to be updated. block_state(b, 'power') is not the same, power should give you a number when you power a full block.

commented

power(...) is the redstone power for a block at this position. what the block does with its power its up to the block. As altrisi pointed out, power level is not the same as comparators' property of 'power'.