Anvil trimAllAir + Fix elliptic cylinder arguments

This commit is contained in:
Jesse Boyd 2017-08-26 23:07:12 +10:00
parent 0dbb3b2844
commit bc0bc5b705
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
5 changed files with 120 additions and 6 deletions

View File

@ -19,6 +19,7 @@ import com.boydti.fawe.jnbt.anvil.filters.RemapFilter;
import com.boydti.fawe.jnbt.anvil.filters.RemoveLayerFilter;
import com.boydti.fawe.jnbt.anvil.filters.ReplacePatternFilter;
import com.boydti.fawe.jnbt.anvil.filters.ReplaceSimpleFilter;
import com.boydti.fawe.jnbt.anvil.filters.TrimAirFilter;
import com.boydti.fawe.jnbt.anvil.history.IAnvilHistory;
import com.boydti.fawe.jnbt.anvil.history.NullAnvilHistory;
import com.boydti.fawe.object.FawePlayer;
@ -254,6 +255,17 @@ public class AnvilCommands {
if (result != null) player.print(BBC.getPrefix() + BBC.VISITOR_BLOCK.format(result.getTotal()));
}
@Command(
aliases = {"trimallair", },
desc = "Trim all air in the world"
)
@CommandPermissions("worldedit.anvil.trimallair")
public void trimAllAir(Player player, String folder) throws WorldEditException {
TrimAirFilter filter = new TrimAirFilter();
TrimAirFilter result = runWithWorld(player, folder, filter, true);
if (result != null) player.print(BBC.getPrefix() + BBC.VISITOR_BLOCK.format(result.getTotal()));
}
@Command(
aliases = {"replaceallpattern", "reap", "repallpat"},
usage = "<folder> [from-block] <to-pattern>",

View File

@ -240,7 +240,7 @@ public class FawePrimitiveBinding extends BindingHelper {
case 2:
radiusX = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[0]));
radiusZ = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[2]));
radiusZ = Math.max(1, FawePrimitiveBinding.parseNumericInput(radii[1]));
break;
default:

View File

@ -0,0 +1,45 @@
package com.boydti.fawe.jnbt.anvil.filters;
import com.boydti.fawe.jnbt.anvil.MCAChunk;
import com.boydti.fawe.jnbt.anvil.MCAFile;
import com.boydti.fawe.jnbt.anvil.MCAFilterCounter;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.number.MutableLong;
public class TrimAirFilter extends MCAFilterCounter {
@Override
public MCAChunk applyChunk(MCAChunk chunk, MutableLong cache) {
for (int layer = 0; layer < chunk.ids.length; layer++) {
byte[] idLayer = chunk.ids[layer];
if (idLayer == null) continue;
for (int i = 0; i < 4096; i++) {
if (idLayer[i] != 0) {
return null;
}
}
{ // Possibly dead code depending on the generator
chunk.ids[layer] = null;
chunk.data[layer] = null;
chunk.setModified();
}
}
chunk.setDeleted(true);
return null;
}
@Override
public void finishFile(MCAFile file, MutableLong cache) {
boolean[] deleteFile = { true };
file.forEachCachedChunk(new RunnableVal<MCAChunk>() {
@Override
public void run(MCAChunk value) {
if (!value.isDeleted()) {
deleteFile[0] = false;
}
}
});
if (deleteFile[0]) {
file.setDeleted(true);
}
}
}

View File

@ -35,19 +35,19 @@ public class BlobBrush implements Brush {
double modY = 1d/radius.getY();
double modZ = 1d/radius.getZ();
int radiusSqr = (int) (size * size);
int radius = (int) size;
int sizeInt = (int) size * 2;
for (int x = -sizeInt; x <= sizeInt; x++) {
double nx = seedX + x * distort;
double d1 = x * x * modX;
double d1 = Math.abs(x) * modX;
for (int y = -sizeInt; y <= sizeInt; y++) {
double d2 = d1 + y * y * modY;
double d2 = d1 + Math.abs(y) * modY;
double ny = seedY + y * distort;
for (int z = -sizeInt; z <= sizeInt; z++) {
double nz = seedZ + z * distort;
double distance = d2 + z * z * modZ;
double distance = d2 + Math.abs(z) * modZ;
double noise = this.amplitude * SimplexNoise.noise(nx, ny, nz);
if (distance + distance * noise < radiusSqr) {
if (distance + distance * noise < radius) {
editSession.setBlock(px + x, py + y, pz + z, pattern);
}
}

View File

@ -0,0 +1,57 @@
package com.boydti.fawe.object.brush;
import com.boydti.fawe.object.random.SimplexNoise;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.function.pattern.Pattern;
import java.util.concurrent.ThreadLocalRandom;
public class RockBrush implements Brush {
private final double amplitude;
private final double frequency;
private final Vector radius;
public RockBrush(Vector radius, double frequency, double amplitude) {
this.frequency = frequency;
this.amplitude = amplitude;
this.radius = radius;
}
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
double seedX = ThreadLocalRandom.current().nextDouble();
double seedY = ThreadLocalRandom.current().nextDouble();
double seedZ = ThreadLocalRandom.current().nextDouble();
int px = position.getBlockX();
int py = position.getBlockY();
int pz = position.getBlockZ();
double distort = this.frequency / size;
double modX = 1d/radius.getX();
double modY = 1d/radius.getY();
double modZ = 1d/radius.getZ();
int radiusSqr = (int) (size * size);
int sizeInt = (int) size * 2;
for (int x = -sizeInt; x <= sizeInt; x++) {
double nx = seedX + x * distort;
double d1 = x * x * modX;
for (int y = -sizeInt; y <= sizeInt; y++) {
double d2 = d1 + y * y * modY;
double ny = seedY + y * distort;
for (int z = -sizeInt; z <= sizeInt; z++) {
double nz = seedZ + z * distort;
double distance = d2 + z * z * modZ;
double noise = this.amplitude * SimplexNoise.noise(nx, ny, nz);
if (distance + distance * noise < radiusSqr) {
editSession.setBlock(px + x, py + y, pz + z, pattern);
}
}
}
}
}
}