return this.getReceivingPower(block) > 0;
}
public short getReceivingPower(Block block) {
short maxPower = 0;
Block rel, relvert;
BlockMaterial mat;
//detect power from direct neighbouring sources
boolean topIsConductor = false;
for (BlockFace face : BlockFaces.BTEWNS) {
rel = block.translate(face);
mat = rel.getMaterial();
if (mat.equals(this)) {
//handle neighbouring redstone wires
maxPower = (short) Math.max(maxPower, this.getRedstonePower(rel) - 1);
} else if (mat instanceof VanillaBlockMaterial) {
//handle solid blocks and redstone sources
maxPower = (short) Math.max(maxPower, ((VanillaBlockMaterial) mat).getRedstonePower(rel, RedstonePowerMode.ALLEXCEPTWIRE));
if (mat instanceof RedstoneSource) {
maxPower = (short) Math.max(maxPower, ((RedstoneSource) mat).getDirectRedstonePower(rel, face.getOpposite(), RedstonePowerMode.ALL));
}
}
//shortcut just in case the answer is simple
if (maxPower == REDSTONE_POWER_MAX) {
return maxPower;
}
//check relatively up and down faces
if (face == BlockFace.TOP) {
topIsConductor = RedstoneUtil.isConductor(mat);
} else if (face != BlockFace.BOTTOM) {
//check below for wire
if (!RedstoneUtil.isConductor(mat)) {
relvert = rel.translate(BlockFace.BOTTOM);
if (relvert.getMaterial().equals(this)) {
maxPower = (short) Math.max(maxPower, this.getRedstonePower(relvert) - 1);
}
}
//check above for wire
if (!topIsConductor) {
relvert = rel.translate(BlockFace.TOP);
if (relvert.getMaterial().equals(this)) {
maxPower = (short) Math.max(maxPower, this.getRedstonePower(relvert) - 1);
}
}
}