Skip to content

Commit

Permalink
Fixed a few IC bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Aug 20, 2018
1 parent 22d8f25 commit 785c083
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/sk89q/craftbook/util/ICUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 785c083

Please sign in to comment.