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

Dieser Commit ist enthalten in:
dordsor21 2021-09-21 14:59:49 +01:00
Ursprung 23ca345a2e
Commit 57b47d2451
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 1E53E88969FFCF0B
5 geänderte Dateien mit 68 neuen und 34 gelöschten Zeilen

Datei anzeigen

@ -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();
}
}
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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