Permalink
Browse files

Finished off the base for the mechanics. Actually need to add the mec…

…hanics now.
  • Loading branch information...
me4502 committed Jul 7, 2017
1 parent 9ba615c commit 44d0ea556611b01d0fe24b8b2d989a94f75100f0
@@ -18,7 +18,7 @@
import com.sk89q.craftbook.sponge.CraftBookPlugin;
import com.sk89q.craftbook.sponge.mechanics.ics.IC;
import org.spongepowered.api.block.BlockType;
import com.sk89q.craftbook.sponge.util.BlockUtil;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.event.cause.Cause;
@@ -64,9 +64,8 @@ public boolean getOutput(int outputId, IC ic) {
}
public boolean isValid(int id, IC ic) {
BlockType type = getPinLocation(id, ic).getBlockType();
return type == BlockTypes.REDSTONE_WIRE || type == BlockTypes.LEVER;
// TODO Check directions here to make sure it's actually powering the face
return BlockUtil.isPowerSource(getPinLocation(id, ic));
}
public boolean isTriggered(int id, IC ic) {
@@ -83,8 +83,7 @@ public boolean matches(BlockState blockState) {
*/
public boolean matches(String text) {
return hasSign() && SignUtil.getTextRaw(sign.getTileEntity()
.map(sign -> (Sign) sign).get(), 1).equals(text);
.map(sign -> (Sign) sign).get(), 1).equals('[' + text + ']');
}
/**
@@ -44,7 +44,14 @@ public TernaryState isActive(CartMechanismBlocks blocks) {
public TernaryState isActive(Location<World> block) {
boolean isConnected = false;
for (Direction direction : BlockUtil.getDirectHorizontalFaces()) {
// TODO
switch (BlockUtil.isPowered(block, direction)) {
case TRUE:
return TernaryState.TRUE;
case NONE:
break;
case FALSE:
isConnected = true;
}
}
return isConnected ? TernaryState.FALSE : TernaryState.NONE;
@@ -18,6 +18,7 @@
import com.google.common.collect.Sets;
import com.sk89q.craftbook.core.util.RegexUtil;
import com.sk89q.craftbook.core.util.TernaryState;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.block.BlockType;
@@ -113,6 +114,40 @@ public static Direction getFacing(Location<World> base, Location<World> other) {
return Optional.empty();
}
/**
* Checks whether this block is capable of providing power to nearby blocks.
*
* @param block The block to check
* @return If it's a power source.
*/
public static boolean isPowerSource(Location<World> block) {
// TODO Make this more mod friendly.
return block.getBlockType() == BlockTypes.REDSTONE_WIRE
|| block.getBlockType() == BlockTypes.POWERED_REPEATER
|| block.getBlockType() == BlockTypes.UNPOWERED_REPEATER
|| block.getBlockType() == BlockTypes.UNLIT_REDSTONE_TORCH
|| block.getBlockType() == BlockTypes.REDSTONE_TORCH
|| block.getBlockType() == BlockTypes.WOODEN_PRESSURE_PLATE
|| block.getBlockType() == BlockTypes.STONE_PRESSURE_PLATE
|| block.getBlockType() == BlockTypes.LIGHT_WEIGHTED_PRESSURE_PLATE
|| block.getBlockType() == BlockTypes.HEAVY_WEIGHTED_PRESSURE_PLATE
|| block.getBlockType() == BlockTypes.POWERED_COMPARATOR
|| block.getBlockType() == BlockTypes.UNPOWERED_COMPARATOR
|| block.getBlockType() == BlockTypes.REDSTONE_BLOCK
|| block.getBlockType() == BlockTypes.LEVER;
}
public static TernaryState isPowered(Location<World> block, Direction face) {
Location<World> pow = block.getRelative(face);
if (isPowerSource(block)) {
if (getBlockPowerLevel(pow).orElse(0) > 0
|| getBlockIndirectPowerLevel(pow).orElse(0) > 0) return TernaryState.TRUE;
return TernaryState.FALSE;
}
return TernaryState.NONE;
}
/**
* Gets the combined light level of this block.
*

0 comments on commit 44d0ea5

Please sign in to comment.