Skip to content

Commit

Permalink
Make modifyblock take a list of materials
Browse files Browse the repository at this point in the history
Quickly edit large areas in complex manners using this cool new trick!
  • Loading branch information
mcmonkey4eva committed Nov 11, 2014
1 parent 36dcfb6 commit 7ef088e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Expand Up @@ -1706,7 +1706,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name ModifyBlock
// @Syntax modifyblock [<location>|...] [<material>] (radius:<#>) (height:<#>) (depth:<#>) (no_physics/naturally)
// @Syntax modifyblock [<location>|...] [<material>|...] (radius:<#>) (height:<#>) (depth:<#>) (no_physics/naturally)
// @Required 2
// @Stable stable
// @Short Modifies blocks.
Expand All @@ -1724,7 +1724,7 @@ public void registerCoreMembers() {
// TODO: Document Command Details
// -->
registerCoreMember(ModifyBlockCommand.class,
"MODIFYBLOCK", "modifyblock [<location>] [<material>] (radius:<#>) (height:<#>) (depth:<#>) (no_physics/naturally)", 2);
"MODIFYBLOCK", "modifyblock [<location>] [<material>|...] (radius:<#>) (height:<#>) (depth:<#>) (no_physics/naturally)", 2);


// <--[command]
Expand Down
Expand Up @@ -26,7 +26,7 @@
* Modifies blocks based based of single block location.
* Possibility to do faux animations with blocks.
*
* @author Mason Adkins, aufdemrand
* @author Mason Adkins, aufdemrand, mcmonkey
*/

public class ModifyBlockCommand extends AbstractCommand implements Listener {
Expand All @@ -41,9 +41,9 @@ public void parseArgs(ScriptEntry scriptEntry)throws InvalidArgumentsException {
scriptEntry.addObject("locations", arg.asType(dList.class).filter(dLocation.class));
}

else if (!scriptEntry.hasObject("material")
&& arg.matchesArgumentType(dMaterial.class)) {
scriptEntry.addObject("material", arg.asType(dMaterial.class));
else if (!scriptEntry.hasObject("materials")
&& arg.matchesArgumentList(dMaterial.class)) {
scriptEntry.addObject("materials", arg.asType(dList.class));
}

else if (!scriptEntry.hasObject("radius")
Expand Down Expand Up @@ -75,7 +75,7 @@ else if (arg.matches("naturally"))
}

// Must have material
if (!scriptEntry.hasObject("material"))
if (!scriptEntry.hasObject("materials"))
throw new InvalidArgumentsException("Missing material argument!");

// ..and at least one location.
Expand All @@ -95,16 +95,17 @@ else if (arg.matches("naturally"))
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

dMaterial material = (dMaterial) scriptEntry.getObject("material");
dList materials = (dList) scriptEntry.getObject("materials");
List<dObject> locations = (List<dObject>) scriptEntry.getObject("locations");
Element physics = scriptEntry.getElement("physics");
Element natural = scriptEntry.getElement("natural");
Element radiusElement = scriptEntry.getElement("radius");
Element heightElement = scriptEntry.getElement("height");
Element depthElement = scriptEntry.getElement("depth");
List<dMaterial> materialList = materials.filter(dMaterial.class);

dB.report(scriptEntry, getName(), aH.debugList("locations", locations)
+ material.debug()
+ materials.debug()
+ physics.debug()
+ radiusElement.debug()
+ heightElement.debug()
Expand All @@ -125,8 +126,11 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
if (no_physics)
craftWorld.getHandle().isStatic = true;

int index = 0;
for (dObject obj : locations) {

dMaterial material = materialList.get(index % materialList.size());
index++;
dLocation location = (dLocation) obj;
World world = location.getWorld();

Expand Down

0 comments on commit 7ef088e

Please sign in to comment.