feat: add switch to allow removal of entities on paste (#2525)

- closes #2395
Dieser Commit ist enthalten in:
Jordan 2023-12-18 15:33:02 +00:00 committet von GitHub
Ursprung 6caf4640ea
Commit 2f92626433
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -47,6 +47,7 @@ import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.command.util.annotation.Confirm; import com.sk89q.worldedit.command.util.annotation.Confirm;
import com.sk89q.worldedit.command.util.annotation.Preload; import com.sk89q.worldedit.command.util.annotation.Preload;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -70,6 +71,7 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.NullRegion; import com.sk89q.worldedit.regions.NullRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionIntersection; import com.sk89q.worldedit.regions.RegionIntersection;
@ -453,7 +455,9 @@ public class ClipboardCommands {
@Switch(name = 'e', desc = "Paste entities if available") @Switch(name = 'e', desc = "Paste entities if available")
boolean pasteEntities, boolean pasteEntities,
@Switch(name = 'b', desc = "Paste biomes if available") @Switch(name = 'b', desc = "Paste biomes if available")
boolean pasteBiomes boolean pasteBiomes,
@Switch(name = 'x', desc = "Remove existing entities in the affected region")
boolean removeEntities
) throws WorldEditException { ) throws WorldEditException {
ClipboardHolder holder = session.getClipboard(); ClipboardHolder holder = session.getClipboard();
final Clipboard clipboard = holder.getClipboard(); final Clipboard clipboard = holder.getClipboard();
@ -466,18 +470,23 @@ public class ClipboardCommands {
} }
Region region = clipboard.getRegion().clone(); Region region = clipboard.getRegion().clone();
if (selectPasted || onlySelect) { if (selectPasted || onlySelect || removeEntities) {
BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
BlockVector3 realTo = to.add(holder.getTransform().apply(clipboardOffset.toVector3()).toBlockPoint()); BlockVector3 realTo = to.add(holder.getTransform().apply(clipboardOffset.toVector3()).toBlockPoint());
BlockVector3 max = realTo.add(holder BlockVector3 max = realTo.add(holder
.getTransform() .getTransform()
.apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3()) .apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3())
.toBlockPoint()); .toBlockPoint());
if (removeEntities) {
editSession.getEntities(new CuboidRegion(realTo, max)).forEach(Entity::remove);
}
if (selectPasted || onlySelect) {
RegionSelector selector = new CuboidRegionSelector(world, realTo, max); RegionSelector selector = new CuboidRegionSelector(world, realTo, max);
session.setRegionSelector(world, selector); session.setRegionSelector(world, selector);
selector.learnChanges(); selector.learnChanges();
selector.explainRegionAdjust(actor, session); selector.explainRegionAdjust(actor, session);
} }
}
if (onlySelect) { if (onlySelect) {
actor.print(Caption.of("worldedit.paste.selected")); actor.print(Caption.of("worldedit.paste.selected"));
} else { } else {
@ -513,14 +522,19 @@ public class ClipboardCommands {
boolean pasteBiomes, boolean pasteBiomes,
@ArgFlag(name = 'm', desc = "Only paste blocks matching this mask") @ArgFlag(name = 'm', desc = "Only paste blocks matching this mask")
@ClipboardMask @ClipboardMask
Mask sourceMask Mask sourceMask,
//FAWE start - entity removal
@Switch(name = 'x', desc = "Remove existing entities in the affected region")
boolean removeEntities
//FAWE end
) throws WorldEditException { ) throws WorldEditException {
ClipboardHolder holder = session.getClipboard(); ClipboardHolder holder = session.getClipboard();
//FAWE start - use place //FAWE start - use place
if (holder.getTransform().isIdentity() && sourceMask == null) { if (holder.getTransform().isIdentity() && sourceMask == null) {
place(actor, world, session, editSession, ignoreAirBlocks, atOrigin, selectPasted, onlySelect, place(actor, world, session, editSession, ignoreAirBlocks, atOrigin, selectPasted, onlySelect,
pasteEntities, pasteBiomes pasteEntities, pasteBiomes, removeEntities
); );
return; return;
} }
@ -547,12 +561,19 @@ public class ClipboardCommands {
messages.addAll(Lists.newArrayList(operation.getStatusMessages())); messages.addAll(Lists.newArrayList(operation.getStatusMessages()));
} }
if (selectPasted || onlySelect) { if (selectPasted || onlySelect || removeEntities) {
BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
Vector3 realTo = to.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3())); Vector3 realTo = to.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3()));
Vector3 max = realTo.add(holder Vector3 max = realTo.add(holder
.getTransform() .getTransform()
.apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3())); .apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3()));
// FAWE start - entity remova;l
if (removeEntities) {
editSession.getEntities(new CuboidRegion(realTo.toBlockPoint(), max.toBlockPoint())).forEach(Entity::remove);
}
if (selectPasted || onlySelect) {
//FAWE end
final CuboidRegionSelector selector; final CuboidRegionSelector selector;
if (session.getRegionSelector(world) instanceof ExtendingCuboidRegionSelector) { if (session.getRegionSelector(world) instanceof ExtendingCuboidRegionSelector) {
selector = new ExtendingCuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint()); selector = new ExtendingCuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint());
@ -563,6 +584,7 @@ public class ClipboardCommands {
selector.learnChanges(); selector.learnChanges();
selector.explainRegionAdjust(actor, session); selector.explainRegionAdjust(actor, session);
} }
}
if (onlySelect) { if (onlySelect) {
actor.print(Caption.of("worldedit.paste.selected")); actor.print(Caption.of("worldedit.paste.selected"));