Permalink
Browse files

Added max depth option to Driller.

  • Loading branch information...
me4502 committed Oct 22, 2016
1 parent d331cfe commit a737ce3ef81d7664d4dc58b73afdd4b460ff9b87
Showing with 48 additions and 27 deletions.
  1. +48 −27 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/blocks/Driller.java
@@ -40,17 +40,30 @@ public String getSignTitle () {
return "DRILLER";
}
+ private int signDrillSize;
+ private int signMaxDepth;
+
+ @Override
+ public void load() {
+ super.load();
+
+ signDrillSize = ((Factory) getFactory()).drillSize;
+
+ if (!getSign().getLine(2).isEmpty()) {
+ signDrillSize = Math.min(signDrillSize, Integer.parseInt(getSign().getLine(2)));
+ }
+
+ signMaxDepth = ((Factory) getFactory()).maxDrillDepth;
+
+ if (!getSign().getLine(3).isEmpty()) {
+ signMaxDepth = Math.min(signMaxDepth, Integer.parseInt(getSign().getLine(3)));
+ }
+ }
+
public boolean drill() {
- int signDrillSize;
-
if (CraftBookPlugin.inst().getRandom().nextInt(100) < 60) return false;
- signDrillSize = ((Factory) getFactory()).drillSize;
- if (!getSign().getLine(2).isEmpty()) {
- signDrillSize = Math.min(signDrillSize, Integer.parseInt(getSign().getLine(2)));
- }
-
Block center = getBackBlock().getRelative(0, -1, 0);
ItemStack tool = null;
@@ -61,23 +74,22 @@ public boolean drill() {
}
}
- boolean hasHadTrue;
+ int random = CraftBookPlugin.inst().getRandom().nextInt(signDrillSize*signDrillSize);
+ int x = random / signDrillSize;
+ int y = random % signDrillSize;
- int random = CraftBookPlugin.inst().getRandom().nextInt(signDrillSize*signDrillSize);
- int x = random / signDrillSize;
- int y = random % signDrillSize;
- hasHadTrue = drillLine(tool, center.getRelative(signDrillSize/2 - x, 0, signDrillSize/2 - y));
-
- return hasHadTrue;
+ return drillLine(tool, center.getRelative(signDrillSize/2 - x, 0, signDrillSize/2 - y));
}
public boolean drillLine(ItemStack tool, Block blockToBreak) {
Material brokenType = Material.AIR;
+ int depth = 0;
while (brokenType == Material.AIR) {
- if (blockToBreak.getLocation().getBlockY() == 0) return false;
+ if (blockToBreak.getLocation().getBlockY() == 0 || depth > signMaxDepth) return false;
blockToBreak = blockToBreak.getRelative(0, -1, 0);
+ depth += 1;
brokenType = blockToBreak.getType();
if (brokenType == Material.BEDROCK) return false;
if (!((Factory)getFactory()).breakNonNatural)
@@ -102,7 +114,8 @@ public void trigger (ChipState chip) {
public static class Factory extends AbstractICFactory implements RestrictedIC, ConfigurableIC {
boolean breakNonNatural;
- int drillSize;
+ int drillSize;
+ int maxDrillDepth;
public Factory(Server server) {
@@ -124,23 +137,31 @@ public String getShortDescription() {
@Override
public String[] getLineHelp() {
- return new String[] {null, null};
+ return new String[] {"+odrill size", "+omax depth"};
}
@Override
public void addConfiguration(YAMLProcessor config, String path) {
breakNonNatural = config.getBoolean(path + "break-unnatural-blocks", false);
- drillSize = config.getInt(path + "drill-size", 3);
+ drillSize = config.getInt(path + "drill-size", 3);
+ maxDrillDepth = config.getInt(path + "max-drill-depth", 256);
+ }
+
+ @Override
+ public void verify(ChangedSign sign) throws ICVerificationException {
+
+ try {
+ if (!sign.getLine(2).isEmpty()) {
+ sign.setLine(2, String.valueOf(Math.min(drillSize, Integer.parseInt(sign.getLine(2)))));
+ }
+ if (!sign.getLine(3).isEmpty()) {
+ sign.setLine(3, String.valueOf(Math.min(maxDrillDepth, Integer.parseInt(sign.getLine(3)))));
+ }
+ } catch (Exception e) {
+ throw new ICVerificationException("Failed to parse numbers.");
+ }
}
-
- @Override
- public void verify(ChangedSign sign) throws ICVerificationException {
-
- if (!sign.getLine(2).isEmpty()) {
- sign.setLine(2, String.valueOf(Math.min(drillSize,Integer.parseInt(sign.getLine(2)))));
- }
- }
-
+
}
}

0 comments on commit a737ce3

Please sign in to comment.