Permalink
Browse files

Modifyable Driller

Added to configuration to allow to change the size of the driller and
added to allow over riding the configuration by putting the size on the
3rd line of the sign.
  • Loading branch information...
cynmod committed Oct 22, 2016
1 parent d3fd0e9 commit 60371b868fe9b0a2fec82caf62cd3f34aff5754a
Showing with 22 additions and 32 deletions.
  1. +22 −32 src/main/java/com/sk89q/craftbook/mechanics/ic/gates/world/blocks/Driller.java
@@ -42,8 +42,15 @@ public String getSignTitle () {
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;
@@ -56,38 +63,10 @@ public boolean drill() {
boolean hasHadTrue;
- switch (CraftBookPlugin.inst().getRandom().nextInt(9)) {
- case 0:
- hasHadTrue = drillLine(tool, center.getRelative(-1, 0, -1));
- break;
- case 1:
- hasHadTrue = drillLine(tool, center.getRelative(-1, 0, 0));
- break;
- case 2:
- hasHadTrue = drillLine(tool, center.getRelative(-1, 0, 1));
- break;
- case 3:
- hasHadTrue = drillLine(tool, center.getRelative(0, 0, -1));
- break;
- case 4:
- hasHadTrue = drillLine(tool, center.getRelative(0, 0, 0));
- break;
- case 5:
- hasHadTrue = drillLine(tool, center.getRelative(0, 0, 1));
- break;
- case 6:
- hasHadTrue = drillLine(tool, center.getRelative(1, 0, -1));
- break;
- case 7:
- hasHadTrue = drillLine(tool, center.getRelative(1, 0, 0));
- break;
- case 8:
- hasHadTrue = drillLine(tool, center.getRelative(1, 0, 1));
- break;
- default:
- hasHadTrue = drillLine(tool, center.getRelative(0, 0, 0));
- break;
- }
+ 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;
}
@@ -123,6 +102,7 @@ public void trigger (ChipState chip) {
public static class Factory extends AbstractICFactory implements RestrictedIC, ConfigurableIC {
boolean breakNonNatural;
+ int drillSize;
public Factory(Server server) {
@@ -151,6 +131,16 @@ public String getShortDescription() {
public void addConfiguration(YAMLProcessor config, String path) {
breakNonNatural = config.getBoolean(path + "break-unnatural-blocks", false);
+ drillSize = config.getInt(path + "drill-size", 3);
}
+
+ @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 60371b8

Please sign in to comment.