Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,6 +24,7 @@
import com.sk89q.worldedit.antlr.ExpressionLexer;
import com.sk89q.worldedit.antlr.ExpressionParser;
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.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
Expand Down Expand Up @@ -199,7 +200,9 @@ public void setEnvironment(ExpressionEnvironment environment) {

//FAWE start
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

Expand Down
Expand Up @@ -36,4 +36,5 @@ public interface ExpressionEnvironment {

int getBlockDataRel(double x, double y, double z);

ExpressionEnvironment clone();
MineFact marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Up @@ -28,6 +28,8 @@

public class WorldEditExpressionEnvironment implements ExpressionEnvironment {

private final Vector3 UN_OFFSET = Vector3.at(0.5, 0.5, 0.5);
MineFact marked this conversation as resolved.
Show resolved Hide resolved

private final Vector3 unit;
private final Vector3 zero2;
//FAWE start - MutableVector3
Expand All @@ -42,7 +44,7 @@ public WorldEditExpressionEnvironment(EditSession editSession, Vector3 unit, Vec
public WorldEditExpressionEnvironment(Extent extent, Vector3 unit, Vector3 zero) {
this.extent = extent;
this.unit = unit;
this.zero2 = zero.add(0.5, 0.5, 0.5);
this.zero2 = zero.add(UN_OFFSET);
}

public BlockVector3 toWorld(double x, double y, double z) {
Expand Down Expand Up @@ -94,10 +96,13 @@ public void setCurrentBlock(int x, int y, int z) {
public Vector3 toWorldRel(double x, double y, double z) {
return current.add(x, y, z);
}

public WorldEditExpressionEnvironment clone() {
return new WorldEditExpressionEnvironment(extent, unit, zero2.subtract(UN_OFFSET));
}
//FAWe end

public void setCurrentBlock(Vector3 current) {
this.current = current;
}

}
Expand Up @@ -114,6 +114,11 @@ public int getBlockTypeRel(double x, double y, double z) {
public int getBlockDataRel(double x, double y, double z) {
return (int) y * 100;
}

@Override
public ExpressionEnvironment clone() {
return this;
}
});

return expression.evaluate();
Expand Down