Use a MaskTraverser to set extent where it will be a WorldWrapper otherwise

This commit is contained in:
dordsor21 2021-09-21 14:59:49 +01:00
parent 23ca345a2e
commit 57b47d2451
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
5 changed files with 68 additions and 34 deletions

View File

@ -73,4 +73,57 @@ public class MaskTraverser {
} }
} }
public void setNewExtent(Extent newExtent) {
setNewExtent(mask, newExtent);
}
private void setNewExtent(Mask mask, Extent newExtent) {
if (mask == null) {
return;
}
Class<?> current = mask.getClass();
while (current.getSuperclass() != null) {
if (mask instanceof AbstractExtentMask) {
AbstractExtentMask mask1 = (AbstractExtentMask) mask;
mask1.setExtent(newExtent);
} else {
try {
Field field = current.getDeclaredField("extent");
field.setAccessible(true);
field.set(mask, newExtent);
} catch (NoSuchFieldException | IllegalAccessException ignored) {
}
}
if (mask instanceof MaskIntersection) {
MaskIntersection mask1 = (MaskIntersection) mask;
try {
Field field = mask1.getClass().getDeclaredField("masks");
field.setAccessible(true);
Collection<Mask> masks = (Collection<Mask>) field.get(mask);
for (Mask next : masks) {
setNewExtent(next, newExtent);
}
} catch (NoSuchFieldException | IllegalAccessException ignored) {
}
}
try {
Field field = current.getDeclaredField("mask");
field.setAccessible(true);
Mask next = (Mask) field.get(mask);
setNewExtent(next, newExtent);
} catch (NoSuchFieldException | IllegalAccessException ignored) {
}
try {
Field field = current.getDeclaredField("masks");
field.setAccessible(true);
Collection<Mask> masks = (Collection<Mask>) field.get(mask);
for (Mask next : masks) {
setNewExtent(next, newExtent);
}
} catch (NoSuchFieldException | IllegalAccessException ignored) {
}
current = current.getSuperclass();
}
}
} }

View File

@ -23,6 +23,7 @@ import com.fastasyncworldedit.core.Fawe;
import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.function.generator.CavesGen; import com.fastasyncworldedit.core.function.generator.CavesGen;
import com.fastasyncworldedit.core.util.MainUtil; import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.MaskTraverser;
import com.fastasyncworldedit.core.util.MathMan; import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.TextureUtil; import com.fastasyncworldedit.core.util.TextureUtil;
import com.fastasyncworldedit.core.util.image.ImageUtil; import com.fastasyncworldedit.core.util.image.ImageUtil;
@ -37,7 +38,6 @@ 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.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
@ -560,9 +560,7 @@ public class GenerationCommands {
@Selection Region region, @Selection Region region,
@Arg(desc = "Mask") Mask mask @Arg(desc = "Mask") Mask mask
) throws WorldEditException { ) throws WorldEditException {
if (mask instanceof AbstractExtentMask) { new MaskTraverser(mask).setNewExtent(editSession);
((AbstractExtentMask) mask).setExtent(editSession);
}
editSession.addOres(region, mask); editSession.addOres(region, mask);
actor.print(Caption.of("fawe.worldedit.visitor.visitor.block", editSession.getBlockChangeCount())); actor.print(Caption.of("fawe.worldedit.visitor.visitor.block", editSession.getBlockChangeCount()));
} }
@ -633,9 +631,7 @@ public class GenerationCommands {
@Arg(desc = "Ore vein min y", def = "0") int minY, @Arg(desc = "Ore vein min y", def = "0") int minY,
@Arg(desc = "Ore vein max y", def = "63") int maxY @Arg(desc = "Ore vein max y", def = "63") int maxY
) throws WorldEditException { ) throws WorldEditException {
if (mask instanceof AbstractExtentMask) { new MaskTraverser(mask).setNewExtent(editSession);
((AbstractExtentMask) mask).setExtent(editSession);
}
checkCommandArgument(minY >= editSession.getMinY(), Caption.of("fawe.error.outside-range-lower", "miny", checkCommandArgument(minY >= editSession.getMinY(), Caption.of("fawe.error.outside-range-lower", "miny",
editSession.getMinY() editSession.getMinY()
)); ));

View File

@ -24,6 +24,7 @@ import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.extent.processor.lighting.RelightMode; import com.fastasyncworldedit.core.extent.processor.lighting.RelightMode;
import com.fastasyncworldedit.core.object.FaweLimit; import com.fastasyncworldedit.core.object.FaweLimit;
import com.fastasyncworldedit.core.util.MaskTraverser;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
@ -37,7 +38,6 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.GroundFunction; import com.sk89q.worldedit.function.GroundFunction;
import com.sk89q.worldedit.function.generator.FloraGenerator; import com.sk89q.worldedit.function.generator.FloraGenerator;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.MaskIntersection; import com.sk89q.worldedit.function.mask.MaskIntersection;
@ -321,9 +321,8 @@ public class RegionCommands {
if (from == null) { if (from == null) {
from = new ExistingBlockMask(editSession); from = new ExistingBlockMask(editSession);
//FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow //FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow
} else if (from instanceof AbstractExtentMask) { } else {
((AbstractExtentMask) from).setExtent(editSession); new MaskTraverser(from).setNewExtent(editSession);
//FAWE end
} }
int affected = editSession.replaceBlocks(region, from, to); int affected = editSession.replaceBlocks(region, from, to);
actor.print(Caption.of("worldedit.replace.replaced", TextComponent.of(affected))); actor.print(Caption.of("worldedit.replace.replaced", TextComponent.of(affected)));
@ -467,9 +466,7 @@ public class RegionCommands {
Mask mask Mask mask
) throws WorldEditException { ) throws WorldEditException {
//FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow) //FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
if (mask instanceof AbstractExtentMask) { new MaskTraverser(mask).setNewExtent(editSession);
((AbstractExtentMask) mask).setExtent(editSession);
}
//FAWE end //FAWE end
BlockVector3 min = region.getMinimumPoint(); BlockVector3 min = region.getMinimumPoint();
BlockVector3 max = region.getMaximumPoint(); BlockVector3 max = region.getMaximumPoint();
@ -582,9 +579,7 @@ public class RegionCommands {
checkCommandArgument(count >= 1, "Count must be >= 1"); checkCommandArgument(count >= 1, "Count must be >= 1");
//FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow) //FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
if (mask instanceof AbstractExtentMask) { new MaskTraverser(mask).setNewExtent(editSession);
((AbstractExtentMask) mask).setExtent(editSession);
}
//FAWE end //FAWE end
Mask combinedMask; Mask combinedMask;
if (ignoreAirBlocks) { if (ignoreAirBlocks) {
@ -664,9 +659,7 @@ public class RegionCommands {
) throws WorldEditException { ) throws WorldEditException {
//FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow) //FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
if (mask instanceof AbstractExtentMask) { new MaskTraverser(mask).setNewExtent(editSession);
((AbstractExtentMask) mask).setExtent(editSession);
}
//FAWE end //FAWE end
Mask combinedMask; Mask combinedMask;
if (ignoreAirBlocks) { if (ignoreAirBlocks) {
@ -842,9 +835,7 @@ public class RegionCommands {
//FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow) //FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
Mask finalMask; Mask finalMask;
if (mask != null) { if (mask != null) {
if (mask instanceof AbstractExtentMask) { new MaskTraverser(mask).setNewExtent(editSession);
((AbstractExtentMask) mask).setExtent(editSession);
}
finalMask = mask; finalMask = mask;
} else { } else {
finalMask = new SolidBlockMask(editSession); finalMask = new SolidBlockMask(editSession);

View File

@ -24,6 +24,7 @@ import com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder;
import com.fastasyncworldedit.core.function.mask.IdMask; import com.fastasyncworldedit.core.function.mask.IdMask;
import com.fastasyncworldedit.core.regions.selector.FuzzyRegionSelector; import com.fastasyncworldedit.core.regions.selector.FuzzyRegionSelector;
import com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector; import com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector;
import com.fastasyncworldedit.core.util.MaskTraverser;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
@ -42,7 +43,6 @@ import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.block.BlockDistributionCounter; import com.sk89q.worldedit.function.block.BlockDistributionCounter;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.visitor.RegionVisitor; import com.sk89q.worldedit.function.visitor.RegionVisitor;
@ -576,9 +576,7 @@ public class SelectionCommands {
Mask mask Mask mask
) throws WorldEditException { ) throws WorldEditException {
//FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow) //FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
if (mask instanceof AbstractExtentMask) { new MaskTraverser(mask).setNewExtent(editSession);
((AbstractExtentMask) mask).setExtent(editSession);
}
//FAWE end //FAWE end
int count = editSession.countBlocks(session.getSelection(world), mask); int count = editSession.countBlocks(session.getSelection(world), mask);
actor.print(Caption.of("worldedit.count.counted", TextComponent.of(count))); actor.print(Caption.of("worldedit.count.counted", TextComponent.of(count)));

View File

@ -24,6 +24,7 @@ import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.configuration.Settings; import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.function.QuadFunction; import com.fastasyncworldedit.core.function.QuadFunction;
import com.fastasyncworldedit.core.util.MainUtil; import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.MaskTraverser;
import com.fastasyncworldedit.core.util.TaskManager; import com.fastasyncworldedit.core.util.TaskManager;
import com.fastasyncworldedit.core.util.image.ImageUtil; import com.fastasyncworldedit.core.util.image.ImageUtil;
import com.fastasyncworldedit.core.util.task.DelegateConsumer; import com.fastasyncworldedit.core.util.task.DelegateConsumer;
@ -49,7 +50,6 @@ import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.function.EntityFunction; import com.sk89q.worldedit.function.EntityFunction;
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
@ -462,9 +462,7 @@ public class UtilityCommands {
int radius int radius
) throws WorldEditException { ) throws WorldEditException {
//FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow) //FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
if (mask instanceof AbstractExtentMask) { new MaskTraverser(mask).setNewExtent(editSession);
((AbstractExtentMask) mask).setExtent(editSession);
}
//FAWE end //FAWE end
radius = Math.max(1, radius); radius = Math.max(1, radius);
we.checkMaxRadius(radius); we.checkMaxRadius(radius);
@ -491,9 +489,7 @@ public class UtilityCommands {
Pattern to Pattern to
) throws WorldEditException { ) throws WorldEditException {
//FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow) //FAWE start > the mask will have been initialised with a WorldWrapper extent (very bad/slow)
if (from instanceof AbstractExtentMask) { new MaskTraverser(from).setNewExtent(editSession);
((AbstractExtentMask) from).setExtent(editSession);
}
//FAWE end //FAWE end
radius = Math.max(1, radius); radius = Math.max(1, radius);
we.checkMaxRadius(radius); we.checkMaxRadius(radius);