mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
feat: add switch to allow removal of entities on paste (#2525)
- closes #2395
This commit is contained in:
parent
6caf4640ea
commit
2f92626433
@ -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,17 +470,22 @@ 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());
|
||||||
RegionSelector selector = new CuboidRegionSelector(world, realTo, max);
|
if (removeEntities) {
|
||||||
session.setRegionSelector(world, selector);
|
editSession.getEntities(new CuboidRegion(realTo, max)).forEach(Entity::remove);
|
||||||
selector.learnChanges();
|
}
|
||||||
selector.explainRegionAdjust(actor, session);
|
if (selectPasted || onlySelect) {
|
||||||
|
RegionSelector selector = new CuboidRegionSelector(world, realTo, max);
|
||||||
|
session.setRegionSelector(world, selector);
|
||||||
|
selector.learnChanges();
|
||||||
|
selector.explainRegionAdjust(actor, session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (onlySelect) {
|
if (onlySelect) {
|
||||||
actor.print(Caption.of("worldedit.paste.selected"));
|
actor.print(Caption.of("worldedit.paste.selected"));
|
||||||
@ -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,21 +561,29 @@ 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()));
|
||||||
final CuboidRegionSelector selector;
|
|
||||||
if (session.getRegionSelector(world) instanceof ExtendingCuboidRegionSelector) {
|
// FAWE start - entity remova;l
|
||||||
selector = new ExtendingCuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint());
|
if (removeEntities) {
|
||||||
} else {
|
editSession.getEntities(new CuboidRegion(realTo.toBlockPoint(), max.toBlockPoint())).forEach(Entity::remove);
|
||||||
selector = new CuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint());
|
}
|
||||||
|
if (selectPasted || onlySelect) {
|
||||||
|
//FAWE end
|
||||||
|
final CuboidRegionSelector selector;
|
||||||
|
if (session.getRegionSelector(world) instanceof ExtendingCuboidRegionSelector) {
|
||||||
|
selector = new ExtendingCuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint());
|
||||||
|
} else {
|
||||||
|
selector = new CuboidRegionSelector(world, realTo.toBlockPoint(), max.toBlockPoint());
|
||||||
|
}
|
||||||
|
session.setRegionSelector(world, selector);
|
||||||
|
selector.learnChanges();
|
||||||
|
selector.explainRegionAdjust(actor, session);
|
||||||
}
|
}
|
||||||
session.setRegionSelector(world, selector);
|
|
||||||
selector.learnChanges();
|
|
||||||
selector.explainRegionAdjust(actor, session);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onlySelect) {
|
if (onlySelect) {
|
||||||
|
Loading…
Reference in New Issue
Block a user