Permalink
Browse files

Merge pull request #196 from cynmod/3.x

Modifyable Driller
  • Loading branch information...
me4502 committed Oct 22, 2016
2 parents 05cce7a + 60371b8 commit d331cfe91d51d6f6c361ea11cb7f8b1647c9de60
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 d331cfe

Please sign in to comment.