Permalink
Browse files

Fixed a few IC bugs

  • Loading branch information...
me4502 committed Aug 20, 2018
1 parent 22d8f25 commit 785c08320ad5359f5a84093fca18e3cf4c9752c4
@@ -169,10 +169,13 @@ private static void toggleSwitches(Block sign, BlockFace direction) {
if (checkBlock.getType() == Material.LEVER) {
Powerable powerable = (Powerable) checkBlock.getBlockData();
powerable.setPowered(!powerable.isPowered());
checkBlock.setBlockData(powerable);
} else if (Tag.BUTTONS.getValues().contains(checkBlock.getType())) {
Powerable powerable = (Powerable) checkBlock.getBlockData();
powerable.setPowered(true);
Runnable turnOff = () -> powerable.setPowered(false);
checkBlock.setBlockData(powerable);
powerable.setPowered(false);
Runnable turnOff = () -> checkBlock.setBlockData(powerable);
Bukkit.getScheduler().runTaskLater(CraftBookPlugin.inst(), turnOff, Tag.WOODEN_BUTTONS.getValues().contains(checkBlock.getType()) ? 30L : 20L);
}
}
@@ -9,6 +9,8 @@
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.AnaloguePowerable;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Powerable;
/**
@@ -37,8 +39,12 @@ protected AbstractChipState(Location source, ChangedSign sign, boolean selfTrigg
public boolean get(int pin) {
Block block = getBlock(pin);
if(block == null) return false;
if(block.getBlockData() instanceof Powerable) {
return ((Powerable) block.getBlockData()).isPowered();
BlockData data = block.getBlockData();
if (data instanceof AnaloguePowerable) {
return ((AnaloguePowerable) data).getPower() > 0;
}
if (data instanceof Powerable) {
return ((Powerable) data).isPowered();
}
return block.isBlockIndirectlyPowered();
}
@@ -47,7 +47,9 @@ public String getSignTitle() {
@Override
public void trigger(ChipState chip) {
chip.setOutput(0, chip.getInput(0));
if (chip.getOutput(0) != chip.getInput(0)) {
chip.setOutput(0, chip.getInput(0));
}
}
public static class Factory extends AbstractICFactory {
@@ -70,7 +70,7 @@ public static boolean setState(Block block, boolean state, Block source) {
// return if the lever is not attached to our IC block
Switch lever = (Switch) block.getBlockData();
if (!block.getRelative(lever.getFacing()).equals(source))
if (!block.getRelative(lever.getFacing().getOppositeFace()).equals(source))
return false;
// check if the lever was toggled on

0 comments on commit 785c083

Please sign in to comment.