mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 03:16:41 +00:00
This commit is contained in:
@ -53,7 +53,7 @@ public class HeightBrush implements Brush {
|
||||
try {
|
||||
heightMap = ScalableHeightMap.fromPNG(stream);
|
||||
} catch (IOException e) {
|
||||
throw new FaweException(Caption.of("fawe.worldedit.brush.brush.height.invalid"));
|
||||
throw new FaweException(Caption.of("fawe.worldedit.brush.brush.height.invalid", e.getMessage()));
|
||||
}
|
||||
} else if (clipboard != null) {
|
||||
heightMap = ScalableHeightMap.fromClipboard(clipboard, minY, maxY);
|
||||
|
@ -511,7 +511,7 @@ public class Settings extends Config {
|
||||
" - A larger value will use slightly less CPU time",
|
||||
" - A smaller value will reduce memory usage",
|
||||
" - A value too small may break some operations (deform?)",
|
||||
" - Values smaller than the configurated parallel-threads are not accepted",
|
||||
" - Values smaller than the configured parallel-threads are not accepted",
|
||||
" - It is recommended this option be at least 4x greater than parallel-threads"
|
||||
|
||||
})
|
||||
@ -544,12 +544,6 @@ public class Settings extends Config {
|
||||
})
|
||||
public boolean POOL = true;
|
||||
|
||||
@Comment({
|
||||
"When using fastmode do not bother to tick existing/placed blocks/fluids",
|
||||
"Only works in versions up to 1.17.1"
|
||||
})
|
||||
public boolean NO_TICK_FASTMODE = true;
|
||||
|
||||
public static class PROGRESS {
|
||||
|
||||
@Comment({"Display constant titles about the progress of a user's edit",
|
||||
|
@ -2,7 +2,7 @@ package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.Linear2DBlockPattern;
|
||||
import com.fastasyncworldedit.core.math.random.Linear2DRandom;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
@ -14,7 +14,6 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Linear2DPatternParser extends RichParser<Pattern> {
|
||||
@ -59,9 +58,8 @@ public class Linear2DPatternParser extends RichParser<Pattern> {
|
||||
zScale = Integer.parseInt(arguments[2]);
|
||||
Preconditions.checkArgument(zScale != 0);
|
||||
}
|
||||
if (inner instanceof RandomPattern) {
|
||||
Set<Pattern> patterns = ((RandomPattern) inner).getPatterns();
|
||||
return new Linear2DBlockPattern(patterns.toArray(new Pattern[0]), xScale, zScale);
|
||||
if (inner instanceof RandomPattern rp) {
|
||||
return new RandomPattern(new Linear2DRandom(xScale, zScale), rp);
|
||||
}
|
||||
throw new InputParseException(TextComponent.of("Pattern " + inner.getClass().getSimpleName()
|
||||
+ " cannot be used with " + getPrefix()));
|
||||
|
@ -2,7 +2,7 @@ package com.fastasyncworldedit.core.extension.factory.parser.pattern;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
|
||||
import com.fastasyncworldedit.core.function.pattern.Linear3DBlockPattern;
|
||||
import com.fastasyncworldedit.core.math.random.Linear3DRandom;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.util.SuggestionHelper;
|
||||
@ -14,7 +14,6 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Linear3DPatternParser extends RichParser<Pattern> {
|
||||
@ -64,9 +63,8 @@ public class Linear3DPatternParser extends RichParser<Pattern> {
|
||||
zScale = Integer.parseInt(arguments[3]);
|
||||
Preconditions.checkArgument(zScale != 0);
|
||||
}
|
||||
if (inner instanceof RandomPattern) {
|
||||
Set<Pattern> patterns = ((RandomPattern) inner).getPatterns();
|
||||
return new Linear3DBlockPattern(patterns.toArray(new Pattern[0]), xScale, yScale, zScale);
|
||||
if (inner instanceof RandomPattern rp) {
|
||||
return new RandomPattern(new Linear3DRandom(xScale, yScale, zScale), rp);
|
||||
}
|
||||
throw new InputParseException(TextComponent.of("Pattern " + inner.getClass().getSimpleName()
|
||||
+ " cannot be used with " + getPrefix()));
|
||||
|
@ -9,6 +9,11 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
import static java.lang.Math.floorDiv;
|
||||
|
||||
/**
|
||||
* @deprecated replaced by {@link com.sk89q.worldedit.function.pattern.RandomPattern}
|
||||
* combined with {@link com.fastasyncworldedit.core.math.random.Linear2DRandom}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "TODO")
|
||||
public class Linear2DBlockPattern extends AbstractPattern {
|
||||
|
||||
private final Pattern[] patternsArray;
|
||||
|
@ -9,6 +9,11 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
import static java.lang.Math.floorDiv;
|
||||
|
||||
/**
|
||||
* @deprecated replaced by {@link com.sk89q.worldedit.function.pattern.RandomPattern}
|
||||
* combined with {@link com.fastasyncworldedit.core.math.random.Linear3DRandom}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "TODO")
|
||||
public class Linear3DBlockPattern extends AbstractPattern {
|
||||
|
||||
private final Pattern[] patternsArray;
|
||||
|
@ -0,0 +1,50 @@
|
||||
package com.fastasyncworldedit.core.math.random;
|
||||
|
||||
import static com.fastasyncworldedit.core.math.random.Linear3DRandom.doubleDiv;
|
||||
import static java.lang.Math.floorDiv;
|
||||
|
||||
/**
|
||||
* A {@link SimpleRandom} that deterministically maps coordinates
|
||||
* to values.
|
||||
* @since TODO
|
||||
*/
|
||||
public class Linear2DRandom implements SimpleRandom {
|
||||
private final int xScale;
|
||||
private final int zScale;
|
||||
|
||||
/**
|
||||
* Creates a new {@link Linear2DRandom} instance
|
||||
*
|
||||
* @param xScale the scale applied to the x component of a coordinate
|
||||
* @param zScale the scale applied to the z component of a coordinate
|
||||
*/
|
||||
public Linear2DRandom(final int xScale, final int zScale) {
|
||||
this.xScale = xScale;
|
||||
this.zScale = zScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble(final int x, final int y, final int z) {
|
||||
return nextDouble(x, y, z, 1d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble(final int x, final int y, final int z, double bound) {
|
||||
double index = (doubleDiv(x, this.xScale) + doubleDiv(z, this.zScale)) % bound;
|
||||
if (index < 0) {
|
||||
index += bound;
|
||||
}
|
||||
return index;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt(final int x, final int y, final int z, final int bound) {
|
||||
int index = (floorDiv(x, this.xScale) + floorDiv(z, this.zScale)) % bound;
|
||||
if (index < 0) {
|
||||
index += bound;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.fastasyncworldedit.core.math.random;
|
||||
|
||||
import static java.lang.Math.floorDiv;
|
||||
|
||||
/**
|
||||
* A {@link SimpleRandom} that deterministically maps coordinates
|
||||
* to values.
|
||||
* @since TODO
|
||||
*/
|
||||
public class Linear3DRandom implements SimpleRandom {
|
||||
|
||||
private final int xScale;
|
||||
private final int yScale;
|
||||
private final int zScale;
|
||||
|
||||
/**
|
||||
* Creates a new {@link Linear3DRandom} instance
|
||||
*
|
||||
* @param xScale the scale applied to the x component of a coordinate
|
||||
* @param yScale the scale applied to the y component of a coordinate
|
||||
* @param zScale the scale applied to the z component of a coordinate
|
||||
*/
|
||||
public Linear3DRandom(final int xScale, final int yScale, final int zScale) {
|
||||
this.xScale = xScale;
|
||||
this.yScale = yScale;
|
||||
this.zScale = zScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble(final int x, final int y, final int z) {
|
||||
return nextDouble(x, y, z, 1d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextDouble(final int x, final int y, final int z, double bound) {
|
||||
double index = (doubleDiv(x, this.xScale) + doubleDiv(y, this.yScale) + doubleDiv(z, this.zScale)) % bound;
|
||||
if (index < 0) {
|
||||
index += bound;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
// used to avoid explicit conversion at call site
|
||||
static double doubleDiv(double dividend, double divisor) {
|
||||
// add a minimal value to avoid too many integral values hitting the exact weight of an entry in SimpleRandomCollection
|
||||
return Math.nextUp(dividend) / divisor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextInt(final int x, final int y, final int z, final int bound) {
|
||||
int index = (floorDiv(x, this.xScale) + floorDiv(y, this.yScale) + floorDiv(z, this.zScale)) % bound;
|
||||
if (index < 0) {
|
||||
index += bound;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
@ -13,6 +13,20 @@ public interface SimpleRandom {
|
||||
*/
|
||||
double nextDouble(int x, int y, int z);
|
||||
|
||||
/**
|
||||
* Generate a random double from three integer components.
|
||||
* The generated value is between 0 (inclusive) and {@code bound} (exclusive).
|
||||
*
|
||||
* @param x the first component
|
||||
* @param y the second component
|
||||
* @param z the third component
|
||||
* @param bound upper bound (exclusive)
|
||||
* @return a double between 0 (inclusive) and {@code bound} (exclusive)
|
||||
*/
|
||||
default double nextDouble(int x, int y, int z, double bound) {
|
||||
return nextDouble(x, y, z) * bound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random integer from three integer components.
|
||||
* The generated value is between 0 (inclusive) and 1 (exclusive)
|
||||
@ -24,8 +38,8 @@ public interface SimpleRandom {
|
||||
* @return a random integer between 0 (inclusive) and {@code bound} (exclusive)
|
||||
*/
|
||||
default int nextInt(int x, int y, int z, int bound) {
|
||||
double val = nextDouble(x, y, z);
|
||||
return (int) (val * bound);
|
||||
double val = nextDouble(x, y, z, bound);
|
||||
return (int) val;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,6 +38,8 @@ import org.apache.logging.log4j.Logger;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageReader;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedOutputStream;
|
||||
@ -70,6 +72,7 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@ -519,8 +522,22 @@ public class MainUtil {
|
||||
return destFile;
|
||||
}
|
||||
|
||||
public static BufferedImage readImage(InputStream in) throws IOException {
|
||||
return MainUtil.toRGB(ImageIO.read(in));
|
||||
public static BufferedImage readImage(InputStream stream) throws IOException {
|
||||
Iterator<ImageReader> iter = ImageIO.getImageReaders(stream);
|
||||
if (!iter.hasNext()) {
|
||||
throw new IOException("Could not get image reader from stream.");
|
||||
}
|
||||
ImageReader reader = iter.next();
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
reader.setInput(stream, true, true);
|
||||
BufferedImage bi;
|
||||
try {
|
||||
bi = reader.read(0, param);
|
||||
} finally {
|
||||
reader.dispose();
|
||||
stream.close();
|
||||
}
|
||||
return MainUtil.toRGB(bi);
|
||||
}
|
||||
|
||||
public static BufferedImage readImage(URL url) throws IOException {
|
||||
|
@ -36,7 +36,7 @@ public class SimpleRandomCollection<E> extends RandomCollection<E> {
|
||||
|
||||
@Override
|
||||
public E next(int x, int y, int z) {
|
||||
return map.ceilingEntry(getRandom().nextDouble(x, y, z) * this.total).getValue();
|
||||
return map.ceilingEntry(getRandom().nextDouble(x, y, z, this.total)).getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.sk89q.worldedit.util.gson;
|
||||
package com.fastasyncworldedit.core.util.gson;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
@ -0,0 +1,33 @@
|
||||
package com.fastasyncworldedit.core.util.gson;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.RegionSelectorType;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class RegionSelectorAdapter implements JsonDeserializer<RegionSelector>, JsonSerializer<RegionSelector> {
|
||||
|
||||
@Override
|
||||
public RegionSelector deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
RegionSelectorType regionType = RegionSelectorType.valueOf(json.getAsString());
|
||||
return regionType.createSelector();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(RegionSelector selector, Type type, JsonSerializationContext context) {
|
||||
RegionSelectorType regionType = RegionSelectorType.getForSelector(selector);
|
||||
// Cannot nicely deserialize Fuzzy region type
|
||||
if (regionType == null || regionType == RegionSelectorType.FUZZY) {
|
||||
return null;
|
||||
}
|
||||
return new JsonPrimitive(regionType.toString());
|
||||
}
|
||||
|
||||
}
|
@ -125,7 +125,9 @@ public class LocalSession implements TextureHolder {
|
||||
private transient int cuiVersion = CUI_VERSION_UNINITIALIZED;
|
||||
|
||||
// Session related
|
||||
private transient RegionSelector selector = new CuboidRegionSelector();
|
||||
//FAWE start - allow saving to session store
|
||||
private RegionSelector selector = new CuboidRegionSelector();
|
||||
//FAWE end
|
||||
private transient boolean placeAtPos1 = false;
|
||||
//FAWE start
|
||||
private final transient List<Object> history = Collections.synchronizedList(new LinkedList<>() {
|
||||
@ -771,6 +773,7 @@ public class LocalSession implements TextureHolder {
|
||||
checkNotNull(selector);
|
||||
selector.setWorld(world);
|
||||
this.selector = selector;
|
||||
setDirty();
|
||||
if (hasWorldOverride() && !world.equals(getWorldOverride())) {
|
||||
setWorldOverride(null);
|
||||
}
|
||||
|
@ -755,13 +755,7 @@ public class SelectionCommands {
|
||||
}
|
||||
|
||||
if (setDefaultSelector) {
|
||||
RegionSelectorType found = null;
|
||||
for (RegionSelectorType type : RegionSelectorType.values()) {
|
||||
if (type.getSelectorClass() == newSelector.getClass()) {
|
||||
found = type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
RegionSelectorType found = RegionSelectorType.getForSelector(newSelector);
|
||||
|
||||
if (found != null) {
|
||||
session.setDefaultRegionSelector(found);
|
||||
|
@ -64,6 +64,7 @@ import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
@ -337,9 +338,10 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
return SuggestionHelper.getBlockPropertySuggestions(blockType, props);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private BaseBlock parseLogic(String input, ParserContext context) throws InputParseException {
|
||||
//FAWE start
|
||||
String[] blockAndExtraData = input.trim().split("\\|");
|
||||
String[] blockAndExtraData = input.trim().split("(?<!^)\\|");
|
||||
blockAndExtraData[0] = woolMapper(blockAndExtraData[0]);
|
||||
Map<Property<?>, Object> blockStates = new HashMap<>();
|
||||
//FAWE end
|
||||
|
@ -19,8 +19,14 @@
|
||||
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import com.fastasyncworldedit.core.regions.selector.FuzzyRegionSelector;
|
||||
import com.fastasyncworldedit.core.regions.selector.PolyhedralRegionSelector;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* An enum of default region selector types.
|
||||
*/
|
||||
@ -32,7 +38,21 @@ public enum RegionSelectorType {
|
||||
SPHERE(SphereRegionSelector.class),
|
||||
ELLIPSOID(EllipsoidRegionSelector.class),
|
||||
POLYGON(Polygonal2DRegionSelector.class),
|
||||
CONVEX_POLYHEDRON(ConvexPolyhedralRegionSelector.class);
|
||||
CONVEX_POLYHEDRON(ConvexPolyhedralRegionSelector.class),
|
||||
//FAWE start
|
||||
POLYHEDRAL(PolyhedralRegionSelector.class),
|
||||
FUZZY(FuzzyRegionSelector.class);
|
||||
//FAWE end
|
||||
|
||||
//FAWE start
|
||||
private static final Map<Class<? extends RegionSelector>, RegionSelectorType> VALUE_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (RegionSelectorType type : values()) {
|
||||
VALUE_MAP.put(type.getSelectorClass(), type);
|
||||
}
|
||||
}
|
||||
//FAWE end
|
||||
|
||||
private final Class<? extends RegionSelector> selectorClass;
|
||||
|
||||
@ -40,6 +60,19 @@ public enum RegionSelectorType {
|
||||
this.selectorClass = selectorClass;
|
||||
}
|
||||
|
||||
//FAWE start
|
||||
/**
|
||||
* Get a {@link RegionSelectorType} for the given {@link RegionSelector}
|
||||
*
|
||||
* @param selector Region selector to get type enum for
|
||||
* @since TODO
|
||||
*/
|
||||
@Nullable
|
||||
public static RegionSelectorType getForSelector(RegionSelector selector) {
|
||||
return VALUE_MAP.get(selector.getClass());
|
||||
}
|
||||
//FAWE end
|
||||
|
||||
/**
|
||||
* Get the selector class.
|
||||
*
|
||||
|
@ -19,12 +19,14 @@
|
||||
|
||||
package com.sk89q.worldedit.util.gson;
|
||||
|
||||
import com.fastasyncworldedit.core.util.gson.ItemTypeAdapter;
|
||||
import com.fastasyncworldedit.core.util.gson.RegionSelectorAdapter;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
|
||||
/**
|
||||
* Utility methods for Google's GSON library.
|
||||
@ -43,7 +45,10 @@ public final class GsonUtil {
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
|
||||
gsonBuilder.registerTypeAdapter(BlockVector3.class, new BlockVectorAdapter());
|
||||
//FAWE start
|
||||
gsonBuilder.registerTypeAdapter(RegionSelector.class, new RegionSelectorAdapter());
|
||||
gsonBuilder.registerTypeAdapter(ItemType.class, new ItemTypeAdapter());
|
||||
//FAWE end
|
||||
return gsonBuilder;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user