wip on FaweQueue

This commit is contained in:
Jesse Boyd
2019-07-19 06:49:29 +10:00
parent 1dcb18ae20
commit e86e4c9c53
91 changed files with 540 additions and 5951 deletions

View File

@ -183,7 +183,7 @@ public class HistoryCommands extends MethodCommands {
// TODO mask the regions bot / top to the bottom and top coord in the allowedRegions
// TODO: then mask the edit to the bot / top
// if (allowedRegions.length != 1 || !allowedRegions[0].isGlobal()) {
// finalQueue = new MaskedFaweQueue(SetQueue.IMP.getNewQueue(fp.getWorld(), true, false), allowedRegions);
// finalQueue = new MaskedIQueueExtent(SetQueue.IMP.getNewQueue(fp.getWorld(), true, false), allowedRegions);
// } else {
// finalQueue = SetQueue.IMP.getNewQueue(fp.getWorld(), true, false);
// }

View File

@ -35,10 +35,10 @@ import com.boydti.fawe.beta.filters.SetFilter;
import com.boydti.fawe.beta.implementation.QueueHandler;
import com.boydti.fawe.beta.filters.DistrFilter;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.example.NMSMappedFaweQueue;
import com.boydti.fawe.example.NMSMappedIQueueExtent;
import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.object.visitor.Fast2DIterator;
import com.boydti.fawe.util.MathMan;
@ -166,7 +166,7 @@ public class RegionCommands {
final int cz = loc.getBlockZ() >> 4;
selection = new CuboidRegion(BlockVector3.at(cx - 8, 0, cz - 8).multiply(16), BlockVector3.at(cx + 8, 0, cz + 8).multiply(16));
}
int count = FaweAPI.fixLighting(player.getWorld(), selection,null, FaweQueue.RelightMode.ALL);
int count = FaweAPI.fixLighting(player.getWorld(), selection,null, IQueueExtent.RelightMode.ALL);
BBC.LIGHTING_PROPOGATE_SELECTION.send(fp, count);
}
@ -178,7 +178,7 @@ public class RegionCommands {
public void getlighting(Player player) throws WorldEditException {
FawePlayer fp = FawePlayer.wrap(player);
final Location loc = player.getLocation();
FaweQueue queue = fp.getFaweQueue(false);
IQueueExtent queue = fp.getIQueueExtent(false);
fp.sendMessage("Light: " + queue.getEmmittedLight(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()) + " | " + queue.getSkyLight(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}
@ -195,7 +195,7 @@ public class RegionCommands {
final int cz = player.getLocation().getBlockZ() >> 4;
selection = new CuboidRegion(BlockVector3.at(cx - 8, 0, cz - 8).multiply(16), BlockVector3.at(cx + 8, 0, cz + 8).multiply(16));
}
int count = FaweAPI.fixLighting(player.getWorld(), selection, null, FaweQueue.RelightMode.NONE);
int count = FaweAPI.fixLighting(player.getWorld(), selection, null, IQueueExtent.RelightMode.NONE);
BBC.UPDATED_LIGHTING_SELECTION.send(fp, count);
}
@ -225,7 +225,7 @@ public class RegionCommands {
@CommandPermissions("worldedit.light.set")
public void setlighting(Player player, @Selection Region region, @Range(min = 0, max = 15) int value) {
FawePlayer fp = FawePlayer.wrap(player);
final NMSMappedFaweQueue queue = (NMSMappedFaweQueue) fp.getFaweQueue(false);
final NMSMappedIQueueExtent queue = (NMSMappedIQueueExtent) fp.getIQueueExtent(false);
for (BlockVector3 pt : region) {
queue.setBlockLight(pt.getX(), pt.getY(), pt.getZ(), value);
}
@ -244,7 +244,7 @@ public class RegionCommands {
@CommandPermissions("worldedit.light.set")
public void setskylighting(Player player, @Selection Region region, @Range(min = 0, max = 15) int value) {
FawePlayer fp = FawePlayer.wrap(player);
final NMSMappedFaweQueue queue = (NMSMappedFaweQueue) fp.getFaweQueue(false);
final NMSMappedIQueueExtent queue = (NMSMappedIQueueExtent) fp.getIQueueExtent(false);
for (BlockVector3 pt : region) {
queue.setSkyLight(pt.getX(), pt.getY(), pt.getZ(), value);
}

View File

@ -21,7 +21,7 @@ package com.sk89q.worldedit.command.composition;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.extent.FaweRegionExtent;
@ -111,7 +111,7 @@ public class SelectionCommand extends SimpleCommand<Operation> {
Pattern pattern = (Pattern) field.get(replace);
if (pattern instanceof BlockStateHolder) {
BlockStateHolder block = ((BlockStateHolder) pattern);
final FaweQueue queue = editSession.getQueue();
final IQueueExtent queue = editSession.getQueue();
final int minY = cuboid.getMinimumY();
final int maxY = cuboid.getMaximumY();

View File

@ -19,11 +19,6 @@
package com.sk89q.worldedit.extent;
import com.boydti.fawe.jnbt.anvil.generator.CavesGen;
import com.boydti.fawe.jnbt.anvil.generator.GenBase;
import com.boydti.fawe.jnbt.anvil.generator.OreGen;
import com.boydti.fawe.jnbt.anvil.generator.Resource;
import com.boydti.fawe.jnbt.anvil.generator.SchemGen;
import com.boydti.fawe.object.clipboard.WorldCopyClipboard;
import com.boydti.fawe.object.exception.FaweException;
import com.sk89q.worldedit.MaxChangedBlocksException;
@ -33,6 +28,11 @@ import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.function.RegionMaskingFilter;
import com.sk89q.worldedit.function.block.BlockReplace;
import com.sk89q.worldedit.function.generator.CavesGen;
import com.sk89q.worldedit.function.generator.GenBase;
import com.sk89q.worldedit.function.generator.OreGen;
import com.sk89q.worldedit.function.generator.Resource;
import com.sk89q.worldedit.function.generator.SchemGen;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask;
@ -535,7 +535,7 @@ public interface Extent extends InputExtent, OutputExtent {
return setBlocks(region, (BlockStateHolder) pattern);
}
BlockReplace replace = new BlockReplace(this, pattern);
RegionVisitor visitor = new RegionVisitor(region, replace, queue instanceof MappedFaweQueue ? (MappedFaweQueue) queue : null);
RegionVisitor visitor = new RegionVisitor(region, replace, queue instanceof MappedIQueueExtent ? (MappedIQueueExtent) queue : null);
Operations.completeBlindly(visitor);
return this.changes = visitor.getAffected();
}

View File

@ -0,0 +1,271 @@
package com.sk89q.worldedit.function.generator;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.world.block.BlockID;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.concurrent.ThreadLocalRandom;
public class CavesGen extends GenBase {
private boolean evenCaveDistribution = false;
private int caveFrequency = 40;
private int caveRarity = 7;
private int caveMinAltitude = 8;
private int caveMaxAltitude = 127;
private int caveSystemFrequency = 1;
private int individualCaveRarity = 25;
private int caveSystemPocketChance = 0;
private int caveSystemPocketMinSize = 0;
private int caveSystemPocketMaxSize = 3;
public CavesGen(int caveSize) {
super(caveSize);
}
public CavesGen(int caveSize, int caveFrequency, int caveRarity, int caveMinAltitude, int caveMaxAltitude, int caveSystemFrequency, int individualCaveRarity, int caveSystemPocketChance, int caveSystemPocketMinSize, int caveSystemPocketMaxSize) {
super(caveSize);
this.caveFrequency = caveFrequency;
this.caveRarity = caveRarity;
this.caveMinAltitude = caveMinAltitude;
this.caveMaxAltitude = caveMaxAltitude;
this.caveSystemFrequency = caveSystemFrequency;
this.individualCaveRarity = individualCaveRarity;
this.caveSystemPocketChance = caveSystemPocketChance;
this.caveSystemPocketMinSize = caveSystemPocketMinSize;
this.caveSystemPocketMaxSize = caveSystemPocketMaxSize;
}
protected void generateLargeCaveNode(long seed, BlockVector2 pos, Extent chunk, double x, double y, double z) throws WorldEditException {
generateCaveNode(seed, pos, chunk, x, y, z, 1.0F + ThreadLocalRandom.current().nextDouble()
* 6.0F, 0.0F, 0.0F, -1, -1, 0.5D);
}
protected void generateCaveNode(long seed, BlockVector2 chunkPos, Extent chunk, double x, double y, double z, double paramdouble1, double paramdouble2, double paramdouble3, int angle, int maxAngle, double paramDouble4) throws WorldEditException {
int bx = (chunkPos.getBlockX() << 4);
int bz = (chunkPos.getBlockZ() << 4);
double real_x = bx + 7;
double real_z = bz + 7;
double f1 = 0.0F;
double f2 = 0.0F;
if (maxAngle <= 0) {
int checkAreaSize = (this.getCheckAreaSize() * 16) - 16;
maxAngle = checkAreaSize - ThreadLocalRandom.current().nextInt(checkAreaSize / 4);
}
boolean isLargeCave = false;
if (angle == -1) {
angle = maxAngle / 2;
isLargeCave = true;
}
int j = ThreadLocalRandom.current().nextInt(maxAngle / 2) + maxAngle / 4;
int k = ThreadLocalRandom.current().nextInt(6) == 0 ? 1 : 0;
for (; angle < maxAngle; angle++) {
double d3 = 1.5D + MathMan.sinInexact(angle * Math.PI / maxAngle) * paramdouble1 * 1.0F;
double d4 = d3 * paramDouble4;
double f3 = MathMan.cosInexact(paramdouble3);
double f4 = MathMan.sinInexact(paramdouble3);
x += MathMan.cosInexact(paramdouble2) * f3;
y += f4;
z += MathMan.sinInexact(paramdouble2) * f3;
if (k != 0)
paramdouble3 *= 0.92F;
else {
paramdouble3 *= 0.7F;
}
paramdouble3 += f2 * 0.1F;
paramdouble2 += f1 * 0.1F;
f2 *= 0.9F;
f1 *= 0.75F;
f2 += (ThreadLocalRandom.current().nextDouble() - ThreadLocalRandom.current()
.nextDouble()) * ThreadLocalRandom.current().nextDouble() * 2.0F;
f1 += (ThreadLocalRandom.current().nextDouble() - ThreadLocalRandom.current()
.nextDouble()) * ThreadLocalRandom.current().nextDouble() * 4.0F;
if ((!isLargeCave) && (angle == j) && (paramdouble1 > 1.0F) && (maxAngle > 0)) {
generateCaveNode(ThreadLocalRandom.current().nextLong(), chunkPos, chunk, x, y, z, ThreadLocalRandom
.current().nextDouble() * 0.5F + 0.5F, paramdouble2 - 1.570796F, paramdouble3 / 3.0F, angle, maxAngle, 1.0D);
generateCaveNode(ThreadLocalRandom.current().nextLong(), chunkPos, chunk, x, y, z, ThreadLocalRandom
.current().nextDouble() * 0.5F + 0.5F, paramdouble2 + 1.570796F, paramdouble3 / 3.0F, angle, maxAngle, 1.0D);
return;
}
if ((!isLargeCave) && (ThreadLocalRandom.current().nextInt(4) == 0)) {
continue;
}
// Check if distance to working point (x and z) too larger than working radius (maybe ??)
double d5 = x - real_x;
double d6 = z - real_z;
double d7 = maxAngle - angle;
double d8 = paramdouble1 + 2.0F + 16.0F;
if (d5 * d5 + d6 * d6 - d7 * d7 > d8 * d8) {
return;
}
//Boundaries check.
if ((x < real_x - 16.0D - d3 * 2.0D) || (z < real_z - 16.0D - d3 * 2.0D) || (x > real_x + 16.0D + d3 * 2.0D) || (z > real_z + 16.0D + d3 * 2.0D))
continue;
int m = (int) (x - d3) - bx - 1;
int n = (int) (x + d3) - bx + 1;
int i1 = (int) (y - d4) - 1;
int i2 = (int) (y + d4) + 1;
int i3 = (int) (z - d3) - bz - 1;
int i4 = (int) (z + d3) - bz + 1;
if (m < 0)
m = 0;
if (n > 16)
n = 16;
if (i1 < 1)
i1 = 1;
if (i2 > 256 - 8) {
i2 = 256 - 8;
}
if (i3 < 0)
i3 = 0;
if (i4 > 16)
i4 = 16;
// Search for water
boolean waterFound = false;
for (int local_x = m; (!waterFound) && (local_x < n); local_x++) {
for (int local_z = i3; (!waterFound) && (local_z < i4); local_z++) {
for (int local_y = i2 + 1; (!waterFound) && (local_y >= i1 - 1); local_y--) {
if (local_y < 255) {
BlockStateHolder material = chunk.getBlock(bx + local_x, local_y, bz + local_z);
if (material.getBlockType() == BlockTypes.WATER) {
waterFound = true;
}
if ((local_y != i1 - 1) && (local_x != m) && (local_x != n - 1) && (local_z != i3) && (local_z != i4 - 1))
local_y = i1;
}
}
}
}
if (waterFound) {
continue;
}
// Generate cave
for (int local_x = m; local_x < n; local_x++) {
double d9 = (local_x + bx + 0.5D - x) / d3;
for (int local_z = i3; local_z < i4; local_z++) {
double d10 = (local_z + bz + 0.5D - z) / d3;
boolean grassFound = false;
if (d9 * d9 + d10 * d10 < 1.0D) {
for (int local_y = i2; local_y > i1; local_y--) {
double d11 = ((local_y - 1) + 0.5D - y) / d4;
if ((d11 > -0.7D) && (d9 * d9 + d11 * d11 + d10 * d10 < 1.0D)) {
BlockStateHolder material = chunk.getBlock(bx + local_x, local_y, bz + local_z);
BlockStateHolder materialAbove = chunk.getBlock(bx + local_x, local_y + 1, bz + local_z);
BlockType blockType = material.getBlockType();
switch (blockType.getInternalId()) {
case BlockID.MYCELIUM:
case BlockID.GRASS:
grassFound = true;
}
if (this.isSuitableBlock(material, materialAbove)) {
if (local_y - 1 < 10) {
chunk.setBlock(bx + local_x, local_y, bz + local_z, BlockTypes.LAVA.getDefaultState());
} else {
chunk.setBlock(bx + local_x, local_y, bz + local_z, BlockTypes.CAVE_AIR.getDefaultState());
// If grass was just deleted, try to
// move it down
if (grassFound) {
BlockStateHolder block = chunk.getBlock(bx + local_x, local_y - 1, bz + local_z);
if (block.getBlockType() == BlockTypes.DIRT) {
chunk.setBlock(bx + local_x, local_y - 1, bz + local_z, BlockTypes.STONE.getDefaultState());
}
}
}
}
}
}
}
}
}
if (isLargeCave)
break;
}
}
protected boolean isSuitableBlock(BlockStateHolder material, BlockStateHolder materialAbove) {
switch (material.getBlockType().getInternalId()) {
case BlockID.AIR:
case BlockID.CAVE_AIR:
case BlockID.VOID_AIR:
case BlockID.WATER:
case BlockID.LAVA:
case BlockID.BEDROCK:
return false;
default:
return true;
}
}
@Override
public void generateChunk(int chunkX, int chunkZ, BlockVector2 originChunk, Extent chunk) throws WorldEditException {
int i = ThreadLocalRandom.current().nextInt(ThreadLocalRandom.current()
.nextInt(ThreadLocalRandom.current().nextInt(this.caveFrequency) + 1) + 1);
if (this.evenCaveDistribution)
i = this.caveFrequency;
if (ThreadLocalRandom.current().nextInt(100) >= this.caveRarity)
i = 0;
for (int j = 0; j < i; j++) {
double x = (chunkX << 4) + ThreadLocalRandom.current().nextInt(16);
double y;
if (this.evenCaveDistribution)
y = ThreadLocalRandom.current().nextInt(this.caveMinAltitude, this.caveMaxAltitude);
else {
y = ThreadLocalRandom.current()
.nextInt(ThreadLocalRandom.current()
.nextInt(this.caveMaxAltitude - this.caveMinAltitude + 1) + 1) + this.caveMinAltitude;
}
double z = (chunkZ << 4) + ThreadLocalRandom.current().nextInt(16);
int count = this.caveSystemFrequency;
boolean largeCaveSpawned = false;
if (ThreadLocalRandom.current().nextInt(100) <= this.individualCaveRarity) {
generateLargeCaveNode(ThreadLocalRandom.current().nextLong(), originChunk, chunk, x, y, z);
largeCaveSpawned = true;
}
if ((largeCaveSpawned) || (ThreadLocalRandom.current().nextInt(100)
<= this.caveSystemPocketChance - 1)) {
count += ThreadLocalRandom.current()
.nextInt(this.caveSystemPocketMinSize, this.caveSystemPocketMaxSize);
}
while (count > 0) {
count--;
double f1 = ThreadLocalRandom.current().nextDouble() * 3.141593F * 2.0F;
double f2 = (ThreadLocalRandom.current().nextDouble() - 0.5F) * 2.0F / 8.0F;
double f3 = ThreadLocalRandom.current().nextDouble() * 2.0F + ThreadLocalRandom
.current().nextDouble();
generateCaveNode(ThreadLocalRandom.current().nextLong(), originChunk, chunk, x, y, z, f3, f1, f2, 0, 0, 1.0D);
}
}
}
}

View File

@ -0,0 +1,38 @@
package com.sk89q.worldedit.function.generator;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector2;
import java.util.concurrent.ThreadLocalRandom;
public abstract class GenBase {
private final int checkAreaSize;
private final long seed;
private final long worldSeed1, worldSeed2;
public GenBase(int area) {
this.checkAreaSize = area;
this.seed = ThreadLocalRandom.current().nextLong();
this.worldSeed1 = ThreadLocalRandom.current().nextLong();
this.worldSeed2 = ThreadLocalRandom.current().nextLong();
}
public int getCheckAreaSize() {
return checkAreaSize;
}
public void generate(BlockVector2 chunkPos, Extent chunk) throws WorldEditException {
int i = this.checkAreaSize;
int chunkX = chunkPos.getBlockX();
int chunkZ = chunkPos.getBlockZ();
for (int x = chunkX - i; x <= chunkX + i; x++) {
for (int z = chunkZ - i; z <= chunkZ + i; z++) {
generateChunk(x, z, chunkPos, chunk);
}
}
}
public abstract void generateChunk(int x, int z, BlockVector2 originChunk, Extent chunk) throws WorldEditException;
}

View File

@ -0,0 +1,116 @@
package com.sk89q.worldedit.function.generator;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.MutableBlockVector3;
import java.util.Random;
public class OreGen implements Resource {
private final int maxSize;
private final double maxSizeO8;
private final double maxSizeO16;
private final double sizeInverse;
private final int minY;
private final int maxY;
private final Pattern pattern;
private final Extent extent;
private final Mask mask;
private MutableBlockVector3 mutable = new MutableBlockVector3();
private final double ONE_2 = 1 / 2F;
private final double ONE_8 = 1 / 8F;
private final double ONE_16 = 1 / 16F;
public int laced = 0;
public OreGen(Extent extent, Mask mask, Pattern pattern, int size, int minY, int maxY) {
this.maxSize = size;
this.maxSizeO8 = size * ONE_8;
this.maxSizeO16 = size * ONE_16;
this.sizeInverse = 1.0 / size;
this.minY = minY;
this.maxY = maxY;
this.mask = mask;
this.pattern = pattern;
this.extent = extent;
}
@Override
public boolean spawn(Random rand, int x, int z) throws WorldEditException {
int y = rand.nextInt(maxY - minY) + minY;
if (!mask.test(mutable.setComponents(x, y, z))) {
return false;
}
double f = rand.nextDouble() * Math.PI;
double so8 = maxSizeO8;
double sf = MathMan.sinInexact(f) * so8;
double cf = MathMan.cosInexact(f) * so8;
double d1 = x + sf;
double d2 = x - sf;
double d3 = z + cf;
double d4 = z - cf;
double d5 = y + rand.nextInt(3) - 2;
double d6 = y + rand.nextInt(3) - 2;
double xd = (d2 - d1);
double yd = (d6 - d5);
double zd = (d4 - d3);
double iFactor = 0;
for (int i = 0; i < maxSize; i++, iFactor += sizeInverse) {
double d7 = d1 + xd * iFactor;
double d8 = d5 + yd * iFactor;
double d9 = d3 + zd * iFactor;
double d10 = rand.nextDouble() * maxSizeO16;
double sif = MathMan.sinInexact(Math.PI * iFactor);
double d11 = (sif + 1.0) * d10 + 1.0;
double d12 = (sif + 1.0) * d10 + 1.0;
double d11o2 = d11 * ONE_2;
double d12o2 = d12 * ONE_2;
int minX = MathMan.floorZero(d7 - d11o2);
int minY = Math.max(1, MathMan.floorZero(d8 - d12o2));
int minZ = MathMan.floorZero(d9 - d11o2);
int maxX = MathMan.floorZero(d7 + d11o2);
int maxY = Math.min(255, MathMan.floorZero(d8 + d12o2));
int maxZ = MathMan.floorZero(d9 + d11o2);
double id11o2 = 1.0 / (d11o2);
double id12o2 = 1.0 / (d12o2);
for (int xx = minX; xx <= maxX; xx++) {
double dx = (xx + 0.5D - d7) * id11o2;
double dx2 = dx * dx;
if (dx2 < 1) {
mutable.mutX(xx);
for (int yy = minY; yy <= maxY; yy++) {
double dy = (yy + 0.5D - d8) * id12o2;
double dxy2 = dx2 + dy * dy;
if (dxy2 < 1) {
mutable.mutY(yy);
for (int zz = minZ; zz <= maxZ; zz++) {
mutable.mutZ(zz);
double dz = (zz + 0.5D - d9) * id11o2;
double dxyz2 = dxy2 + dz * dz;
if ((dxyz2 < 1)) {
if (mask.test(mutable))
pattern.apply(extent, mutable, mutable);
}
}
}
}
}
}
}
return true;
}
}

View File

@ -0,0 +1,10 @@
package com.sk89q.worldedit.function.generator;
import com.sk89q.worldedit.WorldEditException;
import java.util.Random;
public interface Resource {
boolean spawn(Random random, int x, int z) throws WorldEditException;
}

View File

@ -0,0 +1,58 @@
package com.sk89q.worldedit.function.generator;
import com.boydti.fawe.object.schematic.Schematic;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.session.ClipboardHolder;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
public class SchemGen implements Resource {
private final Extent extent;
private final List<ClipboardHolder> clipboards;
private final boolean randomRotate;
private final Mask mask;
private MutableBlockVector3 mutable = new MutableBlockVector3();
public SchemGen(Mask mask, Extent extent, List<ClipboardHolder> clipboards, boolean randomRotate) {
this.mask = mask;
this.extent = extent;
this.clipboards = clipboards;
this.randomRotate = randomRotate;
}
@Override
public boolean spawn(Random random, int x, int z) throws WorldEditException {
mutable.mutX(x);
mutable.mutZ(z);
int y = extent.getNearestSurfaceTerrainBlock(x, z, mutable.getBlockY(), 0, 255);
if (y == -1) return false;
mutable.mutY(y);
if (!mask.test(mutable)) {
return false;
}
mutable.mutY(y + 1);
ClipboardHolder holder = clipboards.get(ThreadLocalRandom.current().nextInt(clipboards.size()));
if (randomRotate) {
holder.setTransform(new AffineTransform().rotateY(ThreadLocalRandom.current().nextInt(4) * 90));
}
Clipboard clipboard = holder.getClipboard();
Schematic schematic = new Schematic(clipboard);
Transform transform = holder.getTransform();
if (transform.isIdentity()) {
schematic.paste(extent, mutable, false);
} else {
schematic.paste(extent, mutable, false, transform);
}
mutable.mutY(y);
return true;
}
}

View File

@ -22,8 +22,8 @@ package com.sk89q.worldedit.function.operation;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.example.MappedFaweQueue;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.example.MappedIQueueExtent;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.object.extent.BlockTranslateExtent;
import com.boydti.fawe.object.extent.PositionTransformExtent;
import com.boydti.fawe.object.function.block.BiomeCopy;
@ -277,7 +277,7 @@ public class ForwardExtentCopy implements Operation {
if (currentTransform == null) {
currentTransform = transform;
}
FaweQueue queue;
IQueueExtent queue;
if (source instanceof EditSession) {
queue = ((EditSession) source).getQueue();
} else if (destination instanceof EditSession) {
@ -368,7 +368,7 @@ public class ForwardExtentCopy implements Operation {
if (copyingBiomes && (!(source instanceof BlockArrayClipboard) || ((BlockArrayClipboard) source).IMP.hasBiomes())) {
copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest));
}
blockCopy = new RegionVisitor(region, copy, queue instanceof MappedFaweQueue ? (MappedFaweQueue) queue : null);
blockCopy = new RegionVisitor(region, copy, queue instanceof MappedIQueueExtent ? (MappedIQueueExtent) queue : null);
}
List<? extends Entity> entities;

View File

@ -22,7 +22,7 @@ package com.sk89q.worldedit.function.visitor;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.example.MappedFaweQueue;
import com.boydti.fawe.example.MappedIQueueExtent;
import com.boydti.fawe.object.collection.BlockVectorSet;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.RegionFunction;

View File

@ -20,9 +20,9 @@
package com.sk89q.worldedit.function.visitor;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.example.MappedFaweQueue;
import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.object.HasFaweQueue;
import com.boydti.fawe.example.MappedIQueueExtent;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.object.HasIQueueExtent;
import com.boydti.fawe.object.visitor.Fast2DIterator;
import static com.google.common.base.Preconditions.checkNotNull;
@ -41,7 +41,7 @@ import java.util.List;
public class FlatRegionVisitor implements Operation {
private final FlatRegionFunction function;
private MappedFaweQueue queue;
private MappedIQueueExtent queue;
private int affected = 0;
private final Iterable<BlockVector2> iterator;
@ -59,13 +59,13 @@ public class FlatRegionVisitor implements Operation {
this.iterator = flatRegion.asFlatRegion();
}
public FlatRegionVisitor(final FlatRegion flatRegion, final FlatRegionFunction function, HasFaweQueue hasFaweQueue) {
public FlatRegionVisitor(final FlatRegion flatRegion, final FlatRegionFunction function, HasIQueueExtent hasIQueueExtent) {
checkNotNull(flatRegion);
checkNotNull(function);
this.function = function;
this.iterator = flatRegion.asFlatRegion();
FaweQueue queue = hasFaweQueue.getQueue();
this.queue = (MappedFaweQueue) (queue instanceof MappedFaweQueue ? queue : null);
IQueueExtent queue = hasIQueueExtent.getQueue();
this.queue = (MappedIQueueExtent) (queue instanceof MappedIQueueExtent ? queue : null);
}
/**

View File

@ -19,7 +19,7 @@
package com.sk89q.worldedit.function.visitor;
import com.boydti.fawe.object.HasFaweQueue;
import com.boydti.fawe.object.HasIQueueExtent;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.mask.Mask;
@ -42,8 +42,8 @@ public class NonRisingVisitor extends RecursiveVisitor {
this(mask, function, Integer.MAX_VALUE, null);
}
public NonRisingVisitor(Mask mask, RegionFunction function, int depth, HasFaweQueue hasFaweQueue) {
super(mask, function, depth, hasFaweQueue);
public NonRisingVisitor(Mask mask, RegionFunction function, int depth, HasIQueueExtent hasIQueueExtent) {
super(mask, function, depth, hasIQueueExtent);
setDirections(
BlockVector3.UNIT_X,
BlockVector3.UNIT_MINUS_X,