
export class RedstoneDisplayComponent {
    constructor() {
        this.onTick = this.onTick.bind(this);
        this.redstonePowerState = 0;
    }

    onTick(e) {
        const block = e.block;
        const north = block.north();
        const east = block.east();
        const south = block.south();
        const west = block.west();
        const above = block.above();
        const below = block.below();
        const adjacentBlocks = [north, east, south, west, above, below];

        this.redstonePowerState = 0;

        adjacentBlocks.forEach((adjacentBlock) => {
            if (adjacentBlock && adjacentBlock.permutation.matches("minecraft:redstone_wire")) {
                const powerState = adjacentBlock.permutation.getState("redstone_signal");
                if (powerState > this.redstonePowerState) {
                    this.redstonePowerState = powerState;
                }
            }
        });
        if (block.permutation.matches("pb_red:redstone_display"))
            block.setPermutation(block.permutation.withState('pb_red:power_state', this.redstonePowerState));
    }
}