use of org.bukkit.block.data.type.Repeater in project Glowstone by GlowstoneMC.
the class BlockRedstone method updatePhysicsAfterEvent.
@Override
public void updatePhysicsAfterEvent(GlowBlock me) {
super.updatePhysicsAfterEvent(me);
for (BlockFace face : ADJACENT) {
GlowBlock target = me.getRelative(face);
switch(target.getType()) {
case LEVER:
case STONE_BUTTON:
case OAK_BUTTON:
case DARK_OAK_BUTTON:
case ACACIA_BUTTON:
case BIRCH_BUTTON:
case JUNGLE_BUTTON:
case SPRUCE_BUTTON:
case REDSTONE_TORCH:
case REDSTONE_WALL_TORCH:
Redstone state = (Redstone) target.getState().getData();
if (state.isPowered()) {
setFullyPowered(me);
return;
}
break;
case REPEATER:
Diode diode = (Diode) target.getState().getData();
if (diode.isPowered() && face == diode.getFacing().getOppositeFace()) {
setFullyPowered(me);
return;
}
break;
case REDSTONE_BLOCK:
setFullyPowered(me);
return;
case OBSERVER:
boolean powered = BlockObserver.isPowered(target);
BlockFace outputFace = BlockObserver.getFace(target).getOppositeFace();
if (powered && target.getRelative(outputFace).getLocation().equals(me.getLocation())) {
setFullyPowered(me);
return;
}
break;
default:
if (!target.getType().isSolid()) {
continue;
}
GlowBlock underTarget = target.getRelative(BlockFace.DOWN);
if (underTarget.getType() == Material.REDSTONE_TORCH && ((Redstone) (underTarget.getState().getData())).isPowered()) {
setFullyPowered(me);
return;
}
for (BlockFace face2 : ADJACENT) {
GlowBlock target2 = target.getRelative(face2);
if (target2.getType() == Material.REPEATER) {
Repeater data = (Repeater) target2.getBlockData();
if (data.isPowered() && data.getFacing() == target2.getFace(target)) {
setFullyPowered(me);
return;
} else if (Tag.BUTTONS.isTagged(target2.getType())) {
Button button2 = (Button) target2.getState().getData();
if (button2.isPowered() && button2.getAttachedFace() == target2.getFace(target)) {
setFullyPowered(me);
return;
}
} else if (target2.getType() == Material.LEVER) {
Lever lever2 = (Lever) target2.getState().getData();
if (lever2.isPowered() && lever2.getAttachedFace() == target2.getFace(target)) {
setFullyPowered(me);
return;
}
}
} else if (Tag.BUTTONS.isTagged(target2.getType())) {
Button button2 = (Button) target2.getState().getData();
if (button2.isPowered() && button2.getAttachedFace() == target2.getFace(target)) {
setFullyPowered(me);
return;
}
} else if (target2.getType() == Material.LEVER) {
Lever lever2 = (Lever) target2.getState().getData();
if (lever2.isPowered() && lever2.getAttachedFace() == target2.getFace(target)) {
setFullyPowered(me);
return;
}
}
}
}
}
byte power = 0;
for (BlockFace face : calculateConnections(me)) {
if (face == BlockFace.DOWN) {
continue;
}
GlowBlock target = me.getRelative(face);
if (target.getType() != Material.REDSTONE_WIRE) {
if (!target.getType().isSolid()) {
target = target.getRelative(BlockFace.DOWN);
} else if (!me.getRelative(BlockFace.UP).getType().isSolid()) {
target = target.getRelative(BlockFace.UP);
}
if (target.getType() != Material.REDSTONE_WIRE) {
// There is no redstone wire here..
continue;
}
}
if (target.getData() > power) {
power = (byte) (target.getData() - 1);
}
}
if (power != me.getData()) {
BlockRedstoneEvent event = EventFactory.getInstance().callEvent(new BlockRedstoneEvent(me, me.getData(), power));
power = (byte) event.getNewCurrent();
me.setData(power);
updateConnected(me);
new PulseTask(me, true, 1, true).startPulseTask();
}
}
Aggregations