geforkt von Mirrors/FastAsyncWorldEdit
fix compile + use mutable vector for affine transform + fix bstats package
Dieser Commit ist enthalten in:
Ursprung
1529c187d2
Commit
093542c337
@ -1,6 +1,7 @@
|
||||
package org.bstats.bukkit;
|
||||
package com.boydti.fawe.bukkit;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
@ -41,7 +41,6 @@ import com.boydti.fawe.util.TaskManager;
|
||||
import com.boydti.fawe.util.cui.CUI;
|
||||
import com.boydti.fawe.util.image.ImageViewer;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.bstats.bukkit.BStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
@ -269,7 +268,7 @@ public class FaweBukkit implements IFawe, Listener {
|
||||
}
|
||||
|
||||
@Override public void startMetrics() {
|
||||
BStats bStats = new BStats(plugin);
|
||||
new BStats(plugin);
|
||||
}
|
||||
|
||||
public ItemUtil getItemUtil() {
|
||||
|
@ -79,22 +79,22 @@ public class TransformExtent extends BlockTransformExtent {
|
||||
|
||||
@Override
|
||||
public BlockState getLazyBlock(int x, int y, int z) {
|
||||
return transformBlock(super.getLazyBlock(getPos(x, y, z)), false).toImmutableState();
|
||||
return transform(super.getLazyBlock(getPos(x, y, z)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getLazyBlock(BlockVector3 position) {
|
||||
return transformBlock(super.getLazyBlock(getPos(position)), false).toImmutableState();
|
||||
return transform(super.getLazyBlock(getPos(position)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(BlockVector3 position) {
|
||||
return transformBlock(super.getBlock(getPos(position)), false).toImmutableState();
|
||||
return transform(super.getBlock(getPos(position)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(BlockVector3 position) {
|
||||
return transformBlock(super.getFullBlock(getPos(position)), false);
|
||||
return transform(super.getFullBlock(getPos(position)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -106,14 +106,16 @@ public class TransformExtent extends BlockTransformExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
|
||||
return super.setBlock(getPos(x, y, z), transformBlock((BlockState)block, false));
|
||||
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
|
||||
System.out.println("Set block transform");
|
||||
return super.setBlock(getPos(x, y, z), transformInverse(block));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
return super.setBlock(getPos(location), transformBlock((BlockState)block, false));
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
System.out.println("Set block transform2");
|
||||
return super.setBlock(getPos(location), transformInverse(block));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,9 +55,9 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
|
||||
|
||||
private long combine(Direction... directions) {
|
||||
int mask = 0;
|
||||
long mask = 0;
|
||||
for (Direction dir : directions) {
|
||||
mask = mask | (1 << dir.ordinal());
|
||||
mask = mask | (1L << dir.ordinal());
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
@ -65,7 +65,7 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
private long[] adapt(Direction... dirs) {
|
||||
long[] arr = new long[dirs.length];
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
arr[i] = 1 << dirs[i].ordinal();
|
||||
arr[i] = 1L << dirs[i].ordinal();
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
@ -121,16 +121,16 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
result.add(combine(NORTH, EAST, SOUTH, WEST));
|
||||
continue;
|
||||
case "inner_left":
|
||||
result.add(notIndex(combine(NORTHEAST, SOUTHWEST), property.getIndexFor("outer_right")));
|
||||
result.add(notIndex(combine(NORTHEAST, NORTHWEST, SOUTHWEST, SOUTHEAST), property.getIndexFor("outer_right"), property.getIndexFor("outer_left")));
|
||||
continue;
|
||||
case "inner_right":
|
||||
result.add(notIndex(combine(NORTHWEST, SOUTHEAST), property.getIndexFor("outer_left")));
|
||||
result.add(notIndex(combine(NORTHEAST, NORTHWEST, SOUTHWEST, SOUTHEAST), property.getIndexFor("outer_right"), property.getIndexFor("outer_left")));
|
||||
continue;
|
||||
case "outer_left":
|
||||
result.add(notIndex(combine(NORTHEAST, SOUTHWEST), property.getIndexFor("inner_right")));
|
||||
result.add(notIndex(combine(NORTHEAST, NORTHWEST, SOUTHWEST, SOUTHEAST), property.getIndexFor("inner_left"), property.getIndexFor("inner_right")));
|
||||
continue;
|
||||
case "outer_right":
|
||||
result.add(notIndex(combine(NORTHWEST, SOUTHEAST), property.getIndexFor("inner_left")));
|
||||
result.add(notIndex(combine(NORTHEAST, NORTHWEST, SOUTHWEST, SOUTHEAST), property.getIndexFor("inner_left"), property.getIndexFor("inner_right")));
|
||||
continue;
|
||||
default:
|
||||
System.out.println("Unknown direction " + value);
|
||||
@ -184,21 +184,15 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Direction getFirst(long mask) {
|
||||
for (Direction dir : Direction.values()) {
|
||||
if (hasDirection(mask, dir)) {
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean hasDirection(long mask, Direction dir) {
|
||||
return (mask & (1L << dir.ordinal())) != 0;
|
||||
}
|
||||
|
||||
private static long notIndex(long mask, int index) {
|
||||
return mask | (1L << (index + values().length));
|
||||
private static long notIndex(long mask, int... indexes) {
|
||||
for (int index : indexes) {
|
||||
mask = mask | (1L << (index + values().length));
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
private static boolean hasIndex(long mask, int index) {
|
||||
@ -209,39 +203,49 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
private static Integer getNewStateIndex(Transform transform, long[] directions, int oldIndex) {
|
||||
long oldDirMask = directions[oldIndex];
|
||||
if (oldDirMask == 0) {
|
||||
return oldIndex;
|
||||
return null;
|
||||
}
|
||||
Integer newIndex = null;
|
||||
|
||||
for (Direction oldDirection : values()) {
|
||||
if (!hasDirection(oldDirMask, oldDirection)) continue;
|
||||
if (oldDirection == null) {
|
||||
System.out.println(oldDirMask);
|
||||
if (!hasDirection(oldDirMask, oldDirection)) {
|
||||
continue;
|
||||
}
|
||||
Vector3 oldVector = oldDirection.toVector();
|
||||
Vector3 newVector = transform.apply(oldVector).subtract(transform.apply(Vector3.ZERO)).normalize();
|
||||
int newIndex = oldIndex;
|
||||
boolean flip = false;
|
||||
|
||||
if (transform instanceof AffineTransform) {
|
||||
flip = ((AffineTransform) transform).isScaled(oldVector);
|
||||
}
|
||||
|
||||
if (oldVector.equals(newVector)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double closest = oldVector.normalize().dot(newVector);
|
||||
boolean found = false;
|
||||
for (int i = 0; i < directions.length; i++) {
|
||||
int j = (oldIndex + i) % directions.length;
|
||||
long newDirMask = directions[j];
|
||||
if (!hasIndex(oldDirMask, j)) continue;
|
||||
if (!hasIndex(oldDirMask, j)) {
|
||||
continue;
|
||||
}
|
||||
for (Direction v : Direction.values()) {
|
||||
// Check if it's one of the current directions
|
||||
if (!hasDirection(newDirMask, v)) continue;
|
||||
if (!hasDirection(newDirMask, v)) {
|
||||
continue;
|
||||
}
|
||||
// Check if the old mask excludes it
|
||||
double dot = v.toVector().normalize().dot(newVector);
|
||||
if (dot > closest) {
|
||||
if (dot > closest || (flip && dot >= closest)) { //
|
||||
closest = dot;
|
||||
newIndex = j;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
return newIndex;
|
||||
}
|
||||
if (newIndex != null) return newIndex;
|
||||
}
|
||||
return null;
|
||||
return newIndex != null ? newIndex : null;
|
||||
}
|
||||
|
||||
private boolean isDirectional(Property property) {
|
||||
@ -348,11 +352,13 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
}
|
||||
|
||||
for (AbstractProperty property : (Collection<AbstractProperty>) (Collection) type.getProperties()) {
|
||||
long[] directions = getDirections(property);
|
||||
if (directions != null) {
|
||||
Integer newIndex = getNewStateIndex(transform, directions, property.getIndex(state.getInternalId()));
|
||||
if (newIndex != null) {
|
||||
newMaskedId = property.modifyIndex(newMaskedId, newIndex);
|
||||
if (isDirectional(property)) {
|
||||
long[] directions = getDirections(property);
|
||||
if (directions != null) {
|
||||
Integer newIndex = getNewStateIndex(transform, directions, property.getIndex(state.getInternalId()));
|
||||
if (newIndex != null) {
|
||||
newMaskedId = property.modifyIndex(newMaskedId, newIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -364,18 +370,18 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
}
|
||||
}
|
||||
|
||||
public final BaseBlock transformInverse(BlockStateHolder block) {
|
||||
public final BaseBlock transform(BlockStateHolder block) {
|
||||
BlockState transformed = transform(block.toImmutableState());
|
||||
if (block.hasNbtData()) {
|
||||
return transformFastWith(transformed, block.getNbtData(), transformInverse);
|
||||
return transformFastWith(transformed, block.getNbtData(), transform);
|
||||
}
|
||||
return transformed.toBaseBlock();
|
||||
}
|
||||
|
||||
public final BlockStateHolder transform(BlockStateHolder block) {
|
||||
BlockState transformed = transform(block.toImmutableState());
|
||||
public final BlockStateHolder transformInverse(BlockStateHolder block) {
|
||||
BlockState transformed = transformInverse(block.toImmutableState());
|
||||
if (block.hasNbtData()) {
|
||||
return transformFastWith(transformed, block.getNbtData(), transform);
|
||||
return transformFastWith(transformed, block.getNbtData(), transformInverse);
|
||||
}
|
||||
return transformed;
|
||||
}
|
||||
@ -407,32 +413,32 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
return transformed.toBaseBlock();
|
||||
}
|
||||
|
||||
public final BlockState transformInverse(BlockState block) {
|
||||
return transform(block, BLOCK_TRANSFORM, transformInverse);
|
||||
public final BlockState transform(BlockState block) {
|
||||
return transform(block, BLOCK_TRANSFORM, transform);
|
||||
}
|
||||
|
||||
public final BlockState transform(BlockState block) {
|
||||
return transform(block, BLOCK_TRANSFORM_INVERSE, transform);
|
||||
public final BlockState transformInverse(BlockState block) {
|
||||
return transform(block, BLOCK_TRANSFORM_INVERSE, transformInverse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getLazyBlock(int x, int y, int z) {
|
||||
return transformInverse(super.getLazyBlock(x, y, z));
|
||||
return transform(super.getLazyBlock(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(BlockVector3 position) {
|
||||
return transformInverse(super.getFullBlock(position));
|
||||
return transform(super.getFullBlock(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getLazyBlock(BlockVector3 position) {
|
||||
return transformInverse(super.getLazyBlock(position));
|
||||
return transform(super.getLazyBlock(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(BlockVector3 position) {
|
||||
return transformInverse(super.getBlock(position));
|
||||
return transform(super.getBlock(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -442,13 +448,13 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
|
||||
@Override
|
||||
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException {
|
||||
return super.setBlock(x, y, z, transform(block));
|
||||
return super.setBlock(x, y, z, transformInverse(block));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
return super.setBlock(location, transform(block));
|
||||
return super.setBlock(location, transformInverse(block));
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@ import java.io.Serializable;
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MathUtils;
|
||||
import com.sk89q.worldedit.math.MutableVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
/**
|
||||
@ -17,7 +18,7 @@ import com.sk89q.worldedit.math.Vector3;
|
||||
*/
|
||||
public class AffineTransform implements Transform, Serializable {
|
||||
|
||||
private transient MutableBlockVector3 mutable = new MutableBlockVector3();
|
||||
private AffineTransform inverse;
|
||||
|
||||
/**
|
||||
* coefficients for x coordinate.
|
||||
@ -162,8 +163,9 @@ public class AffineTransform implements Transform, Serializable {
|
||||
*/
|
||||
@Override
|
||||
public AffineTransform inverse() {
|
||||
if (inverse != null) return inverse;
|
||||
double det = this.determinant();
|
||||
return new AffineTransform(
|
||||
return inverse = new AffineTransform(
|
||||
(m11 * m22 - m21 * m12) / det,
|
||||
(m02 * m21 - m22 * m01) / det,
|
||||
(m01 * m12 - m11 * m02) / det,
|
||||
@ -290,16 +292,23 @@ public class AffineTransform implements Transform, Serializable {
|
||||
return scale(vec.getX(), vec.getY(), vec.getZ());
|
||||
}
|
||||
|
||||
public boolean isScaled(Vector3 vector) {
|
||||
boolean flip = false;
|
||||
if (vector.getX() != 0 && m00 < 0) flip = !flip;
|
||||
if (vector.getY() != 0 && m11 < 0) flip = !flip;
|
||||
if (vector.getZ() != 0 && m22 < 0) flip = !flip;
|
||||
return flip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 apply(Vector3 vector) {
|
||||
return Vector3.at(
|
||||
vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03,
|
||||
vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13,
|
||||
vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23);
|
||||
// mutable.mutX((vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03));
|
||||
// mutable.mutY((vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13));
|
||||
// mutable.mutZ((vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23));
|
||||
// return mutable;
|
||||
double x = (vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03);
|
||||
double y = (vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13);
|
||||
double z = (vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23);
|
||||
vector = vector.mutX(x);
|
||||
vector = vector.mutY(y);
|
||||
vector = vector.mutZ(z);
|
||||
return vector;
|
||||
}
|
||||
|
||||
public AffineTransform combine(AffineTransform other) {
|
||||
@ -324,7 +333,6 @@ public class AffineTransform implements Transform, Serializable {
|
||||
|
||||
private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
|
||||
stream.defaultReadObject();
|
||||
mutable = new MutableBlockVector3();
|
||||
}
|
||||
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren