Skip to content

Commit

Permalink
Added //regen to regenerate an area.
Browse files Browse the repository at this point in the history
  • Loading branch information
sk89q committed Mar 13, 2011
1 parent 0fa675c commit 1b670a1
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 66 deletions.
133 changes: 68 additions & 65 deletions plugin.yml
Expand Up @@ -11,6 +11,9 @@ commands:
delchunks:
description: Delete chunks that your selection includes
usage: /<command>
clearclipboard:
description: Clear your clipboard
usage: /<command>
/load:
description: Load a schematic into your clipboard
usage: /<command> <filename>
Expand All @@ -32,12 +35,6 @@ commands:
/paste:
description: Paste the clipboard's contents
usage: /<command> [-ao]
clearclipboard:
description: Clear your clipboard
usage: /<command>
/limit:
description: Modify block change limit
usage: /<command> <limit>
we:
description: WorldEdit commands
usage: /<command>
Expand All @@ -49,6 +46,9 @@ commands:
description: Search for an item
usage: /<command> [-bi] <query>
aliases: ['/l', 'search']
/limit:
description: Modify block change limit
usage: /<command> <limit>
/hcyl:
description: Generate a hollow cylinder
usage: /<command> <block> <radius> [height]
Expand All @@ -67,17 +67,17 @@ commands:
pumpkins:
description: Generate pumpkin patches
usage: /<command> [size]
/undo:
description: Undoes the last action
usage: /<command> [times]
aliases: ['undo']
clearhistory:
description: Clear your history
usage: /<command>
/redo:
description: Redoes the last action (from history)
usage: /<command> [times]
aliases: ['redo']
clearhistory:
description: Clear your history
usage: /<command>
/undo:
description: Undoes the last action
usage: /<command> [times]
aliases: ['undo']
unstuck:
description: Escape from being stuck inside a block
usage: /<command>
Expand All @@ -87,27 +87,18 @@ commands:
descend:
description: Go down a floor
usage: /<command>
ceil:
description: Go to the celing
usage: /<command> [clearance]
thru:
description: Passthrough walls
usage: /<command>
jumpto:
description: Teleport to a location
usage: /<command>
ceil:
description: Go to the celing
usage: /<command> [clearance]
up:
description: Go upwards some distance
usage: /<command> <block>
/replace:
description: Replace all blocks in the selection with another
usage: /<command> [from-block] <to-block>
/stack:
description: Repeat the contents of the selection
usage: /<command> [-a] [count] [direction]
/set:
description: Set all the blocks inside the selection to a block
usage: /<command> <block>
/overlay:
description: Set a block on top of blocks in the region
usage: /<command> <block>
Expand All @@ -121,24 +112,27 @@ commands:
/smooth:
description: Smooth the elevation in the selection
usage: /<command> [iterations]
/regen:
description: Regenerates the contents of the selection
usage: /<command>
/replace:
description: Replace all blocks in the selection with another
usage: /<command> [from-block] <to-block>
/stack:
description: Repeat the contents of the selection
usage: /<command> [-a] [count] [direction]
/set:
description: Set all the blocks inside the selection to a block
usage: /<command> <block>
/move:
description: Move the contents of the selection
usage: /<command> [count] [direction] [leave-id]
cs:
description: Execute a CraftScript
usage: /<command> <filename> [args...]
.s:
description: Execute last CraftScript
usage: /<command> [args...]
/count:
description: Counts the number of a certain type of block
usage: /<command> <block>
/size:
description: Get information about the selection
usage: /<command>
/shift:
description: Shift the selection area
usage: /<command> <amount> [direction]
cs:
description: Execute a CraftScript
usage: /<command> <filename> [args...]
/chunk:
description: Set the selection to your current chunk
usage: /<command>
Expand All @@ -160,25 +154,34 @@ commands:
toggleeditwand:
description: Toggle functionality of the edit wand
usage: /<command>
/expand:
description: Expand the selection area
usage: /<command> <amount> [reverse-amount] <direction>
/contract:
description: Contract the selection area
usage: /<command> <amount> [reverse-amount] [direction]
/outset:
description: Outset the selection area
usage: /<command> [-hv] <amount>
/inset:
description: Inset the selection area
usage: /<command> [-hv] <amount>
/distr:
description: Get the distribution of blocks in the selection
usage: /<command> [-c]
/count:
description: Counts the number of a certain type of block
usage: /<command> <block>
/size:
description: Get information about the selection
usage: /<command>
/shift:
description: Shift the selection area
usage: /<command> <amount> [direction]
/expand:
description: Expand the selection area
usage: /<command> <amount> [reverse-amount] <direction>
/sel:
description: Choose a region selector
usage: /<command> [type]
aliases: [',']
/inset:
description: Inset the selection area
usage: /<command> [-hv] <amount>
snapshot:
description: Snapshot commands
usage: /<command>
Expand All @@ -187,12 +190,6 @@ commands:
description: Restore the selection from a snapshot
usage: /<command> [snapshot]
aliases: ['/restore']
size:
description: Set the brush size
usage: /<command> [pattern]
mask:
description: Set the brush mask
usage: /<command> [mask]
/:
description: Toggle the super pickaxe pickaxe function
usage: /<command>
Expand All @@ -208,15 +205,15 @@ commands:
description: Set the brush material
usage: /<command> [pattern]
aliases: ['material', 'fill']
info:
description: Block information tool
usage: /<command>
size:
description: Set the brush size
usage: /<command> [pattern]
mask:
description: Set the brush mask
usage: /<command> [mask]
none:
description: Turn off all superpickaxe alternate modes
usage: /<command>
tree:
description: Tree generator tool
usage: /<command> [type]
repl:
description: Block replacer tool
usage: /<command> <block>
Expand All @@ -227,19 +224,15 @@ commands:
description: Brush tool
usage: /<command>
aliases: ['br']
remove:
description: Remove all entities of a type
usage: /<command> <type> <radius>
aliases: ['rem', 'rement']
/fill:
description: Fill a hole
usage: /<command> <block> <radius> [depth]
info:
description: Block information tool
usage: /<command>
tree:
description: Tree generator tool
usage: /<command> [type]
/fillr:
description: Fill a hole recursively
usage: /<command> <block> <radius> [depth]
/drain:
description: Drain a pool
usage: /<command> <radius>
fixlava:
description: Fix lava to be stationary
usage: /<command> <radius>
Expand Down Expand Up @@ -271,3 +264,13 @@ commands:
butcher:
description: Kill all or nearby mobs
usage: /<command> [radius]
remove:
description: Remove all entities of a type
usage: /<command> <type> <radius>
aliases: ['rem', 'rement']
/fill:
description: Fill a hole
usage: /<command> <block> <radius> [depth]
/drain:
description: Drain a pool
usage: /<command> <radius>
16 changes: 15 additions & 1 deletion src/com/sk89q/worldedit/EditSession.java
Expand Up @@ -249,6 +249,20 @@ public boolean setBlock(Vector pt, BaseBlock block)
return smartSetBlock(pt, block);
}

/**
* Insert a contrived block change into the history.
*
* @param pt
* @param existing
* @param block
*/
public void rememberChange(Vector pt, BaseBlock existing, BaseBlock block) {
BlockVector blockPt = pt.toBlockVector();

original.put(blockPt, existing);
current.put(pt.toBlockVector(), block);
}

/**
* Set a block with a pattern.
*
Expand Down Expand Up @@ -286,7 +300,7 @@ public boolean setBlockIfAir(Vector pt, BaseBlock block)
* @param block
* @return
*/
private boolean smartSetBlock(Vector pt, BaseBlock block) {
public boolean smartSetBlock(Vector pt, BaseBlock block) {
if (queued) {
// Place torches, etc. last
if (BlockType.shouldPlaceLast(block.getType())) {
Expand Down
10 changes: 10 additions & 0 deletions src/com/sk89q/worldedit/LocalWorld.java
Expand Up @@ -22,6 +22,7 @@
import java.util.Random;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.regions.Region;

/**
* Represents a world.
Expand Down Expand Up @@ -78,6 +79,15 @@ public enum EntityType {
* @return
*/
public abstract int getBlockData(Vector pt);

/**
* Regenerate an area.
*
* @param region
* @param editSession
* @return
*/
public abstract boolean regenerate(Region region, EditSession editSession);

/**
* Attempts to accurately copy a BaseBlock's extra data to the world.
Expand Down
56 changes: 56 additions & 0 deletions src/com/sk89q/worldedit/bukkit/BukkitWorld.java
Expand Up @@ -43,7 +43,9 @@
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.blocks.*;
import com.sk89q.worldedit.regions.Region;

public class BukkitWorld extends LocalWorld {
private World world;
Expand Down Expand Up @@ -111,6 +113,60 @@ public int getBlockData(Vector pt) {
return world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getData();
}

/**
* Regenerate an area.
*
* @param region
* @param editSession
* @return
*/
@Override
public boolean regenerate(Region region, EditSession editSession) {
BaseBlock[] history = new BaseBlock[16 * 16 * 128];

for (Vector2D chunk : region.getChunks()) {
Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16);
Vector max = min.add(15, 127, 15);

// First save all the blocks inside
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 128; y++) {
for (int z = 0; z < 16; z++) {
Vector pt = min.add(x, y, z);
int index = y * 16 * 16 + z * 16 + x;
history[index] = editSession.getBlock(pt);
}
}
}

try {
world.regenerateChunk(chunk.getBlockX(), chunk.getBlockZ());
} catch (Throwable t) {
t.printStackTrace();
}

// Then restore
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 128; y++) {
for (int z = 0; z < 16; z++) {
Vector pt = min.add(x, y, z);
int index = y * 16 * 16 + z * 16 + x;

// We have to restore the block if it was outside
if (!region.contains(pt)) {
editSession.smartSetBlock(pt, history[index]);
} else { // Otherwise fool with history
editSession.rememberChange(pt, history[index],
editSession.rawGetBlock(pt));
}
}
}
}
}

return true;
}

/**
* Attempts to accurately copy a BaseBlock's extra data to the world.
*
Expand Down
1 change: 1 addition & 0 deletions src/com/sk89q/worldedit/commands/ChunkCommands.java
Expand Up @@ -26,6 +26,7 @@
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.data.LegacyChunkStore;
import com.sk89q.worldedit.regions.Region;

/**
* Chunk tools.
Expand Down
17 changes: 17 additions & 0 deletions src/com/sk89q/worldedit/commands/RegionCommands.java
Expand Up @@ -230,4 +230,21 @@ public static void stack(CommandContext args, WorldEdit we,
dir, count, !args.hasFlag('a'));
player.print(affected + " blocks changed. Undo with //undo");
}

@Command(
aliases = {"/regen"},
usage = "",
desc = "Regenerates the contents of the selection",
min = 0,
max = 0
)
@CommandPermissions({"worldedit.regen"})
public static void regenerateChunk(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {

Region region = session.getSelection(player.getWorld());
player.getWorld().regenerate(region, editSession);
player.print("Region regenerated.");
}
}

1 comment on commit 1b670a1

@mickael9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great !

Please sign in to comment.