Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TomyLobo committed Apr 5, 2023
1 parent a7d048d commit 7f88a3e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 17 deletions.
10 changes: 10 additions & 0 deletions worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,16 @@ public World getWorld() {
return world;
}

/**
* Get the actor associated with this EditSession.
*
* @return the actor
*/
@Nullable
public Actor getActor() {
return actor;
}

/**
* Get the underlying {@link ChangeSet}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.annotation.ClipboardMask;
import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.internal.annotation.VertHeight;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.factory.CylinderRegionFactory;
import com.sk89q.worldedit.regions.factory.RegionFactory;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.session.Placement;
import com.sk89q.worldedit.session.request.RequestExtent;
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.TreeGenerator;
Expand Down Expand Up @@ -505,14 +509,35 @@ public void deform(Player player, LocalSession localSession,
boolean usePlacement,
@Switch(name = 'l', desc = "Fetch from the clipboard instead of the world")
boolean useClipboard) throws WorldEditException {
Deform deform = new Deform(expression);
Placement placement = localSession.getPlacement();

// bake placement
switch (placement.getPlacementType()) {
case PLAYER: // Shouldn't be baked, because people can just use "//placement here" instead
case WORLD: // Doesn't need to be baked
break;

case POS1:
case MIN:
case MAX:
placement = placement.bake(localSession.getRegionSelector(player.getWorld()), player);
break;

default:
throw new IllegalStateException("PlacementType " + placement.getPlacementType() + " not implemented");
}

final Deform.Mode mode;
if (useRawCoords) {
deform.setMode(Deform.Mode.RAW_COORD);
mode = Deform.Mode.RAW_COORD;
} else if (usePlacement) {
deform.setMode(Deform.Mode.OFFSET);
deform.setOffset(localSession.getPlacementPosition(player).toVector3());
mode = Deform.Mode.OFFSET;
} else {
mode = Deform.Mode.UNIT_CUBE;
}
deform.setUseClipboard(useClipboard);

final Deform deform = new Deform(placement, expression, mode);

setOperationBasedBrush(player, localSession, radius,
deform, shape, "worldedit.brush.deform");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@
import com.sk89q.worldedit.function.operation.RunContext;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.transform.Identity;
import com.sk89q.worldedit.math.transform.SimpleTransform;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.regions.NullRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.Placement;
import com.sk89q.worldedit.session.PlacementType;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
Expand All @@ -54,7 +57,7 @@ public class Deform implements Contextual<Operation> {
private Region region;
private final Expression expression;
private Mode mode;
private Vector3 offset = Vector3.ZERO;
Placement placement;
private boolean useClipboard;

public Deform(String expression) {
Expand All @@ -81,6 +84,17 @@ public Deform(Extent destination, Region region, String expression, Mode mode) {
this.mode = mode;
}

public Deform(Placement placement, String expression, Mode mode) {
checkNotNull(mode, "mode");
checkNotNull(expression, "expression");

this.placement = placement;
this.expression = Expression.compile(expression, "x", "y", "z");
this.expression.optimize();
this.mode = mode;
}


public Extent getDestination() {
return destination;
}
Expand Down Expand Up @@ -108,21 +122,17 @@ public void setMode(Mode mode) {
this.mode = mode;
}

public boolean getUseClipboard() {
return useClipboard;
}

public void setUseClipboard(boolean useClipboard) {
this.useClipboard = useClipboard;
}

@Deprecated
public Vector3 getOffset() {
return offset;
if (this.placement.getPlacementType() != PlacementType.WORLD) {
throw new IllegalStateException("Deform.getOffset is deprecated and only supported after using setOffset.");
}
return placement.getOffset().toVector3();
}

public void setOffset(Vector3 offset) {
checkNotNull(offset, "offset");
this.offset = offset;
this.placement = new Placement(PlacementType.WORLD, offset.toBlockPoint());
}

@Override
Expand Down Expand Up @@ -176,11 +186,14 @@ public Operation resume(RunContext run) throws WorldEditException {

final Vector3 min = region.getMinimumPoint().toVector3();
final Vector3 max = region.getMaximumPoint().toVector3();
final Transform outputTransform = createTransform(min, max, Deform.this.offset);

final LocalSession session = context.getSession();
final EditSession editSession = (EditSession) context.getDestination();

// TODO: deal with session == null
final BlockVector3 placement = Deform.this.placement.getPlacementPosition(session.getRegionSelector(editSession.getWorld()), editSession.getActor());
final Transform outputTransform = createTransform(min, max, placement.toVector3());

final InputExtent inputExtent;
final Transform inputTransform;
if (Deform.this.useClipboard && session != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ public Component getInfo() {
);
}
}

public Placement bake(RegionSelector selector, Actor actor) throws IncompleteRegionException {
return new Placement(PlacementType.WORLD, getPlacementPosition(selector, actor));
}
}

0 comments on commit 7f88a3e

Please sign in to comment.