Skip to content

Commit 7fb7887

Browse files
committed
Add tool argument for break_block() (Closes #1342)
1 parent 8d0c206 commit 7fb7887

5 files changed

Lines changed: 29 additions & 16 deletions

File tree

src/main/java/com/laytonsmith/abstraction/MCLocation.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public interface MCLocation extends AbstractionObject {
5757

5858
void setYaw(float y);
5959

60-
void breakBlock();
61-
6260
Vector3D getDirection();
6361

6462
MCLocation clone();

src/main/java/com/laytonsmith/abstraction/blocks/MCBlock.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@ public interface MCBlock extends MCMetadatable {
8282
boolean isEmpty();
8383

8484
boolean applyBoneMeal();
85+
86+
boolean breakNaturally(MCItemStack item);
8587
}

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCLocation.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,6 @@ public int hashCode() {
187187
return l.hashCode();
188188
}
189189

190-
@Override
191-
public void breakBlock() {
192-
l.getBlock().breakNaturally();
193-
}
194-
195190
@Override
196191
public Vector3D getDirection() {
197192
Vector v = l.getDirection();

src/main/java/com/laytonsmith/abstraction/bukkit/blocks/BukkitMCBlock.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,12 @@ public boolean isEmpty() {
241241
public boolean applyBoneMeal() {
242242
return b.applyBoneMeal(BlockFace.UP);
243243
}
244+
245+
@Override
246+
public boolean breakNaturally(MCItemStack item) {
247+
if(item == null) {
248+
return b.breakNaturally(null);
249+
}
250+
return b.breakNaturally((ItemStack) item.getHandle());
251+
}
244252
}

src/main/java/com/laytonsmith/core/functions/Environment.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.laytonsmith.abstraction.MCColor;
66
import com.laytonsmith.abstraction.MCCommandSender;
77
import com.laytonsmith.abstraction.MCEntity;
8+
import com.laytonsmith.abstraction.MCItemStack;
89
import com.laytonsmith.abstraction.MCLocation;
910
import com.laytonsmith.abstraction.MCNote;
1011
import com.laytonsmith.abstraction.MCOfflinePlayer;
@@ -897,17 +898,22 @@ public String getName() {
897898

898899
@Override
899900
public Integer[] numArgs() {
900-
return new Integer[]{1};
901+
return new Integer[]{1, 2};
901902
}
902903

903904
@Override
904905
public String docs() {
905-
return "void {locationArray} Mostly simulates a block break at a location. Does not trigger an event.";
906+
return "boolean {locationArray, [itemArray]} Mostly simulates a block break at a location."
907+
+ " Optional item array to simulate tool used to break block."
908+
+ " Returns true if block was not already air and either no tool was given, a correct tool was given,"
909+
+ " or the block type does not require a specific tool."
910+
+ " Does not trigger an event.";
906911
}
907912

908913
@Override
909914
public Class<? extends CREThrowable>[] thrown() {
910-
return new Class[]{CREFormatException.class};
915+
return new Class[]{CREFormatException.class, CREInvalidWorldException.class, CRECastException.class,
916+
CRERangeException.class};
911917
}
912918

913919
@Override
@@ -927,13 +933,17 @@ public Boolean runAsync() {
927933

928934
@Override
929935
public Mixed exec(Target t, com.laytonsmith.core.environments.Environment environment, Mixed... args) throws ConfigRuntimeException {
930-
MCLocation l;
931-
MCPlayer p;
932-
p = environment.getEnv(CommandHelperEnvironment.class).GetPlayer();
936+
MCPlayer p = environment.getEnv(CommandHelperEnvironment.class).GetPlayer();
933937
MCWorld w = (p != null ? p.getWorld() : null);
934-
l = ObjectGenerator.GetGenerator().location(args[0], w, t);
935-
l.breakBlock();
936-
return CVoid.VOID;
938+
MCBlock b = ObjectGenerator.GetGenerator().location(args[0], w, t).getBlock();
939+
boolean success;
940+
if(args.length == 2) {
941+
MCItemStack item = ObjectGenerator.GetGenerator().item(args[1], t);
942+
success = b.breakNaturally(item);
943+
} else {
944+
success = b.breakNaturally(null);
945+
}
946+
return CBoolean.get(success);
937947
}
938948
}
939949

0 commit comments

Comments
 (0)