optimize repeating extent pattern

Dieser Commit ist enthalten in:
Jesse Boyd 2019-04-06 01:05:48 +11:00
Ursprung 9e2832c273
Commit 99db2d557a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F

Datei anzeigen

@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.MutableBlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
/** /**
@ -31,6 +32,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
public class RepeatingExtentPattern extends AbstractExtentPattern { public class RepeatingExtentPattern extends AbstractExtentPattern {
private final BlockVector3 size; private final BlockVector3 size;
private final MutableBlockVector3 mutable;
private BlockVector3 origin; private BlockVector3 origin;
private BlockVector3 offset; private BlockVector3 offset;
@ -45,6 +47,7 @@ public class RepeatingExtentPattern extends AbstractExtentPattern {
setOrigin(origin); setOrigin(origin);
setOffset(offset); setOffset(offset);
size = extent.getMaximumPoint().subtract(extent.getMinimumPoint()).add(1, 1, 1); size = extent.getMaximumPoint().subtract(extent.getMinimumPoint()).add(1, 1, 1);
this.mutable = new MutableBlockVector3();
} }
/** /**
@ -86,11 +89,10 @@ public class RepeatingExtentPattern extends AbstractExtentPattern {
} }
@Override @Override
public BaseBlock apply(BlockVector3 position) { public BaseBlock apply(BlockVector3 p) {
BlockVector3 base = position.add(offset); int x = (Math.abs((p.getX() + offset.getX())) % size.getBlockX()) + origin.getX();
int x = Math.abs(base.getBlockX()) % size.getBlockX(); int y = (Math.abs((p.getY() + offset.getY())) % size.getBlockY()) + origin.getY();
int y = Math.abs(base.getBlockY()) % size.getBlockY(); int z = (Math.abs((p.getZ() + offset.getZ())) % size.getBlockZ()) + origin.getZ();
int z = Math.abs(base.getBlockZ()) % size.getBlockZ(); return getExtent().getFullBlock(mutable.setComponents(x, y, z));
return getExtent().getFullBlock(BlockVector3.at(x, y, z).add(origin));
} }
} }