fix: set and clone Expression Environment after Expression cloning (#2617)

- Fixes #2616
Dieser Commit ist enthalten in:
MineFact 2024-03-15 11:27:25 +01:00 committet von GitHub
Ursprung facd31ce31
Commit df9527b0b7
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
4 geänderte Dateien mit 20 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -24,6 +24,7 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.antlr.ExpressionLexer; import com.sk89q.worldedit.antlr.ExpressionLexer;
import com.sk89q.worldedit.antlr.ExpressionParser; import com.sk89q.worldedit.antlr.ExpressionParser;
import com.sk89q.worldedit.internal.expression.invoke.ExpressionCompiler; import com.sk89q.worldedit.internal.expression.invoke.ExpressionCompiler;
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.CommonTokenStream;
@ -199,7 +200,9 @@ public class Expression implements Cloneable {
//FAWE start //FAWE start
public Expression clone() { public Expression clone() {
return new Expression(initialExpression, new HashSet<>(providedSlots)); Expression expression = new Expression(initialExpression, new HashSet<>(providedSlots));
expression.setEnvironment(getEnvironment().clone());
return expression;
} }
//FAWE end //FAWE end

Datei anzeigen

@ -22,7 +22,7 @@ package com.sk89q.worldedit.internal.expression;
/** /**
* Represents a way to access blocks in a world. Has to accept non-rounded coordinates. * Represents a way to access blocks in a world. Has to accept non-rounded coordinates.
*/ */
public interface ExpressionEnvironment { public interface ExpressionEnvironment extends Cloneable {
int getBlockType(double x, double y, double z); int getBlockType(double x, double y, double z);
@ -36,4 +36,7 @@ public interface ExpressionEnvironment {
int getBlockDataRel(double x, double y, double z); int getBlockDataRel(double x, double y, double z);
// FAWE start
ExpressionEnvironment clone();
// FAWE end
} }

Datei anzeigen

@ -28,6 +28,8 @@ import com.sk89q.worldedit.math.Vector3;
public class WorldEditExpressionEnvironment implements ExpressionEnvironment { public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
private static final Vector3 BLOCK_CENTER_OFFSET = Vector3.at(0.5, 0.5, 0.5);
private final Vector3 unit; private final Vector3 unit;
private final Vector3 zero2; private final Vector3 zero2;
//FAWE start - MutableVector3 //FAWE start - MutableVector3
@ -42,7 +44,7 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
public WorldEditExpressionEnvironment(Extent extent, Vector3 unit, Vector3 zero) { public WorldEditExpressionEnvironment(Extent extent, Vector3 unit, Vector3 zero) {
this.extent = extent; this.extent = extent;
this.unit = unit; this.unit = unit;
this.zero2 = zero.add(0.5, 0.5, 0.5); this.zero2 = zero.add(BLOCK_CENTER_OFFSET);
} }
public BlockVector3 toWorld(double x, double y, double z) { public BlockVector3 toWorld(double x, double y, double z) {
@ -94,10 +96,13 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
public Vector3 toWorldRel(double x, double y, double z) { public Vector3 toWorldRel(double x, double y, double z) {
return current.add(x, y, z); return current.add(x, y, z);
} }
public WorldEditExpressionEnvironment clone() {
return new WorldEditExpressionEnvironment(extent, unit, zero2.subtract(BLOCK_CENTER_OFFSET));
}
//FAWe end //FAWe end
public void setCurrentBlock(Vector3 current) { public void setCurrentBlock(Vector3 current) {
this.current = current; this.current = current;
} }
} }

Datei anzeigen

@ -114,6 +114,11 @@ class BaseExpressionTest {
public int getBlockDataRel(double x, double y, double z) { public int getBlockDataRel(double x, double y, double z) {
return (int) y * 100; return (int) y * 100;
} }
@Override
public ExpressionEnvironment clone() {
return this;
}
}); });
return expression.evaluate(); return expression.evaluate();