mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-28 11:39:07 +00:00
Cleanup
This commit is contained in:
@@ -31,10 +31,10 @@ import com.volmit.iris.util.data.DoubleArrayUtils;
|
||||
*/
|
||||
public class AtomicAverage {
|
||||
protected final AtomicDoubleArray values;
|
||||
protected int cursor;
|
||||
private double average;
|
||||
private double lastSum;
|
||||
private boolean dirty;
|
||||
protected int cursor;
|
||||
private boolean brandNew;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,14 +47,14 @@ public class AtomicRollingSequence extends AtomicAverage {
|
||||
return f;
|
||||
}
|
||||
|
||||
public void setPrecision(boolean p) {
|
||||
this.precision = p;
|
||||
}
|
||||
|
||||
public boolean isPrecision() {
|
||||
return precision;
|
||||
}
|
||||
|
||||
public void setPrecision(boolean p) {
|
||||
this.precision = p;
|
||||
}
|
||||
|
||||
public double getMin() {
|
||||
if (dirtyExtremes > (isPrecision() ? 0 : values.length())) {
|
||||
resetExtremes();
|
||||
|
||||
@@ -33,15 +33,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class BoardManager {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
|
||||
private BoardSettings boardSettings;
|
||||
|
||||
|
||||
private final Map<UUID, Board> scoreboards;
|
||||
|
||||
|
||||
private final BukkitTask updateTask;
|
||||
private BoardSettings boardSettings;
|
||||
|
||||
|
||||
public BoardManager(JavaPlugin plugin, BoardSettings boardSettings) {
|
||||
|
||||
@@ -23,7 +23,13 @@ import com.volmit.iris.util.json.JSONArray;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -55,6 +61,26 @@ public class KList<T> extends ArrayList<T> implements List<T> {
|
||||
add(e);
|
||||
}
|
||||
|
||||
public static KList<String> fromJSONAny(JSONArray oo) {
|
||||
KList<String> s = new KList<String>();
|
||||
|
||||
for (int i = 0; i < oo.length(); i++) {
|
||||
s.add(oo.get(i).toString());
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public static KList<String> asStringList(List<?> oo) {
|
||||
KList<String> s = new KList<String>();
|
||||
|
||||
for (Object i : oo) {
|
||||
s.add(i.toString());
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public int indexOfAddIfNeeded(T v) {
|
||||
addIfMissing(v);
|
||||
return indexOf(v);
|
||||
@@ -203,7 +229,6 @@ public class KList<T> extends ArrayList<T> implements List<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public KList<T> shuffle(Random rng) {
|
||||
Collections.shuffle(this, rng);
|
||||
return this;
|
||||
@@ -484,16 +509,6 @@ public class KList<T> extends ArrayList<T> implements List<T> {
|
||||
return remove(rng.i(0, last()));
|
||||
}
|
||||
|
||||
public static KList<String> fromJSONAny(JSONArray oo) {
|
||||
KList<String> s = new KList<String>();
|
||||
|
||||
for (int i = 0; i < oo.length(); i++) {
|
||||
s.add(oo.get(i).toString());
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public KList<T> sub(int f, int t) {
|
||||
KList<T> g = new KList<>();
|
||||
|
||||
@@ -514,16 +529,6 @@ public class KList<T> extends ArrayList<T> implements List<T> {
|
||||
return j;
|
||||
}
|
||||
|
||||
public static KList<String> asStringList(List<?> oo) {
|
||||
KList<String> s = new KList<String>();
|
||||
|
||||
for (Object i : oo) {
|
||||
s.add(i.toString());
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public KList<T> forceAdd(Object[] values) {
|
||||
for (Object i : values) {
|
||||
|
||||
@@ -30,8 +30,8 @@ import lombok.Data;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class IrisContext {
|
||||
private static ChronoLatch cl = new ChronoLatch(60000);
|
||||
private static final KMap<Thread, IrisContext> context = new KMap<>();
|
||||
private static ChronoLatch cl = new ChronoLatch(60000);
|
||||
private final Engine engine;
|
||||
|
||||
public static IrisContext get() {
|
||||
|
||||
@@ -22,7 +22,11 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSets;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -32,7 +36,6 @@ import org.bukkit.block.data.type.PointedDripstone;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -434,45 +437,30 @@ public class B {
|
||||
}
|
||||
|
||||
if (bx == null) {
|
||||
try
|
||||
{
|
||||
try {
|
||||
bx = Bukkit.createBlockData(ix.toLowerCase());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(bx == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (bx == null) {
|
||||
try {
|
||||
bx = Bukkit.createBlockData("minecraft:" + ix.toLowerCase());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(bx == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (bx == null) {
|
||||
try {
|
||||
bx = Material.valueOf(ix.toUpperCase()).createBlockData();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(bx == null)
|
||||
{
|
||||
if (bx == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,20 @@ package com.volmit.iris.util.data;
|
||||
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.math.Direction;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Cuboids
|
||||
@@ -58,35 +66,6 @@ public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializ
|
||||
z2 = Math.max(l1.getBlockZ(), l2.getBlockZ());
|
||||
}
|
||||
|
||||
public KList<Entity> getEntities() {
|
||||
KList<Entity> en = new KList<>();
|
||||
|
||||
for (Chunk i : getChunks()) {
|
||||
for (Entity j : i.getEntities()) {
|
||||
if (contains(j.getLocation())) {
|
||||
en.add(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return en;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the locations
|
||||
*
|
||||
* @param l1 a
|
||||
* @param l2 b
|
||||
*/
|
||||
public void set(Location l1, Location l2) {
|
||||
x1 = Math.min(l1.getBlockX(), l2.getBlockX());
|
||||
y1 = Math.min(l1.getBlockY(), l2.getBlockY());
|
||||
z1 = Math.min(l1.getBlockZ(), l2.getBlockZ());
|
||||
x2 = Math.max(l1.getBlockX(), l2.getBlockX());
|
||||
y2 = Math.max(l1.getBlockY(), l2.getBlockY());
|
||||
z2 = Math.max(l1.getBlockZ(), l2.getBlockZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a one-block Cuboid at the given Location of the Cuboid.
|
||||
*
|
||||
@@ -157,6 +136,35 @@ public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializ
|
||||
z2 = (Integer) map.get("z2");
|
||||
}
|
||||
|
||||
public KList<Entity> getEntities() {
|
||||
KList<Entity> en = new KList<>();
|
||||
|
||||
for (Chunk i : getChunks()) {
|
||||
for (Entity j : i.getEntities()) {
|
||||
if (contains(j.getLocation())) {
|
||||
en.add(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return en;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the locations
|
||||
*
|
||||
* @param l1 a
|
||||
* @param l2 b
|
||||
*/
|
||||
public void set(Location l1, Location l2) {
|
||||
x1 = Math.min(l1.getBlockX(), l2.getBlockX());
|
||||
y1 = Math.min(l1.getBlockY(), l2.getBlockY());
|
||||
z1 = Math.min(l1.getBlockZ(), l2.getBlockZ());
|
||||
x2 = Math.max(l1.getBlockX(), l2.getBlockX());
|
||||
y2 = Math.max(l1.getBlockY(), l2.getBlockY());
|
||||
z2 = Math.max(l1.getBlockZ(), l2.getBlockZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
@@ -671,15 +679,44 @@ public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializ
|
||||
return "Cuboid: " + worldName + "," + x1 + "," + y1 + "," + z1 + "=>" + x2 + "," + y2 + "," + z2;
|
||||
}
|
||||
|
||||
public enum CuboidDirection {
|
||||
|
||||
North,
|
||||
East,
|
||||
South,
|
||||
West,
|
||||
Up,
|
||||
Down,
|
||||
Horizontal,
|
||||
Vertical,
|
||||
Both,
|
||||
Unknown;
|
||||
|
||||
public CuboidDirection opposite() {
|
||||
return switch (this) {
|
||||
case North -> South;
|
||||
case East -> West;
|
||||
case South -> North;
|
||||
case West -> East;
|
||||
case Horizontal -> Vertical;
|
||||
case Vertical -> Horizontal;
|
||||
case Up -> Down;
|
||||
case Down -> Up;
|
||||
case Both -> Both;
|
||||
default -> Unknown;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class CuboidIterator implements Iterator<Block> {
|
||||
private final World w;
|
||||
private final int baseX;
|
||||
private final int baseY;
|
||||
private final int baseZ;
|
||||
private int x, y, z;
|
||||
private final int sizeX;
|
||||
private final int sizeY;
|
||||
private final int sizeZ;
|
||||
private int x, y, z;
|
||||
|
||||
public CuboidIterator(World w, int x1, int y1, int z1, int x2, int y2, int z2) {
|
||||
this.w = w;
|
||||
@@ -716,33 +753,4 @@ public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializ
|
||||
}
|
||||
}
|
||||
|
||||
public enum CuboidDirection {
|
||||
|
||||
North,
|
||||
East,
|
||||
South,
|
||||
West,
|
||||
Up,
|
||||
Down,
|
||||
Horizontal,
|
||||
Vertical,
|
||||
Both,
|
||||
Unknown;
|
||||
|
||||
public CuboidDirection opposite() {
|
||||
return switch (this) {
|
||||
case North -> South;
|
||||
case East -> West;
|
||||
case South -> North;
|
||||
case West -> East;
|
||||
case Horizontal -> Vertical;
|
||||
case Vertical -> Horizontal;
|
||||
case Up -> Down;
|
||||
case Down -> Up;
|
||||
case Both -> Both;
|
||||
default -> Unknown;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,9 +24,9 @@ package com.volmit.iris.util.data;
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public class CuboidException extends Exception {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CuboidException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -35,6 +35,17 @@ public class DataPalette<T> {
|
||||
this.palette = palette;
|
||||
}
|
||||
|
||||
public static <T> DataPalette<T> getPalette(IOAdapter<T> adapter, DataInputStream din) throws IOException {
|
||||
KList<T> palette = new KList<>();
|
||||
int s = din.readShort() - Short.MIN_VALUE;
|
||||
|
||||
for (int i = 0; i < s; i++) {
|
||||
palette.add(adapter.read(din));
|
||||
}
|
||||
|
||||
return new DataPalette<>(palette);
|
||||
}
|
||||
|
||||
public KList<T> getPalette() {
|
||||
return palette;
|
||||
}
|
||||
@@ -73,15 +84,4 @@ public class DataPalette<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> DataPalette<T> getPalette(IOAdapter<T> adapter, DataInputStream din) throws IOException {
|
||||
KList<T> palette = new KList<>();
|
||||
int s = din.readShort() - Short.MIN_VALUE;
|
||||
|
||||
for (int i = 0; i < s; i++) {
|
||||
palette.add(adapter.read(din));
|
||||
}
|
||||
|
||||
return new DataPalette<>(palette);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,11 @@ import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class IrisBiomeStorage implements BiomeGrid {
|
||||
private static final int e;
|
||||
private static final int f;
|
||||
public static final int a;
|
||||
public static final int b;
|
||||
public static final int c;
|
||||
private final Biome[] g;
|
||||
private static final int e;
|
||||
private static final int f;
|
||||
|
||||
static {
|
||||
e = (int) Math.round(Math.log(16.0) / Math.log(2.0)) - 2;
|
||||
@@ -39,6 +38,8 @@ public class IrisBiomeStorage implements BiomeGrid {
|
||||
c = (1 << IrisBiomeStorage.f) - 1;
|
||||
}
|
||||
|
||||
private final Biome[] g;
|
||||
|
||||
public IrisBiomeStorage(final Biome[] aBiome) {
|
||||
this.g = aBiome;
|
||||
}
|
||||
|
||||
@@ -26,11 +26,20 @@ import java.util.Arrays;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class NibbleArray implements Writable {
|
||||
private static final int[] MASKS = new int[8];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < MASKS.length; i++) {
|
||||
MASKS[i] = maskFor(i);
|
||||
}
|
||||
}
|
||||
|
||||
private final int size;
|
||||
private final Object lock = new Object();
|
||||
private byte[] data;
|
||||
private int depth;
|
||||
private final int size;
|
||||
private byte mask;
|
||||
private final Object lock = new Object();
|
||||
private transient int bitIndex, byteIndex, bitInByte;
|
||||
|
||||
public NibbleArray(int capacity, DataInputStream in) throws IOException {
|
||||
size = capacity;
|
||||
@@ -66,6 +75,30 @@ public class NibbleArray implements Writable {
|
||||
}
|
||||
}
|
||||
|
||||
public static int maskFor(int amountOfBits) {
|
||||
return powerOfTwo(amountOfBits) - 1;
|
||||
}
|
||||
|
||||
public static int powerOfTwo(int power) {
|
||||
int result = 1;
|
||||
|
||||
for (int i = 0; i < power; i++) {
|
||||
result *= 2;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String binaryString(byte b, ByteOrder byteOrder) {
|
||||
String str = String.format("%8s", Integer.toBinaryString(b & 0xff)).replace(' ', '0');
|
||||
|
||||
return byteOrder.equals(ByteOrder.BIG_ENDIAN) ? str : reverse(str);
|
||||
}
|
||||
|
||||
public static String reverse(String str) {
|
||||
return new StringBuilder(str).reverse().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream o) throws IOException {
|
||||
o.writeByte(depth + Byte.MIN_VALUE);
|
||||
@@ -108,8 +141,6 @@ public class NibbleArray implements Writable {
|
||||
return y << 8 | z << 4 | x;
|
||||
}
|
||||
|
||||
private transient int bitIndex, byteIndex, bitInByte;
|
||||
|
||||
public void set(int x, int y, int z, int nibble) {
|
||||
set(index(x, y, z), nibble);
|
||||
}
|
||||
@@ -160,36 +191,4 @@ public class NibbleArray implements Writable {
|
||||
set(i, (byte) nibble);
|
||||
}
|
||||
}
|
||||
|
||||
public static int maskFor(int amountOfBits) {
|
||||
return powerOfTwo(amountOfBits) - 1;
|
||||
}
|
||||
|
||||
public static int powerOfTwo(int power) {
|
||||
int result = 1;
|
||||
|
||||
for (int i = 0; i < power; i++) {
|
||||
result *= 2;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final int[] MASKS = new int[8];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < MASKS.length; i++) {
|
||||
MASKS[i] = maskFor(i);
|
||||
}
|
||||
}
|
||||
|
||||
public static String binaryString(byte b, ByteOrder byteOrder) {
|
||||
String str = String.format("%8s", Integer.toBinaryString(b & 0xff)).replace(' ', '0');
|
||||
|
||||
return byteOrder.equals(ByteOrder.BIG_ENDIAN) ? str : reverse(str);
|
||||
}
|
||||
|
||||
public static String reverse(String str) {
|
||||
return new StringBuilder(str).reverse().toString();
|
||||
}
|
||||
}
|
||||
@@ -32,38 +32,6 @@ public class VanillaBiomeMap {
|
||||
private static final KMap<Biome, SaturationType> BIOME_SATURATION = new KMap<>();
|
||||
private static final KMap<Biome, Short> BIOME_IDs = new KMap<>();
|
||||
|
||||
private static void add(Biome biome, int color, short id, Color randomColor, Luminosity luminosity, SaturationType saturation) {
|
||||
BIOME_HEX.put(biome, color);
|
||||
BIOME_COLOR.put(biome, randomColor);
|
||||
if (luminosity != null) BIOME_LUMINOSITY.put(biome, luminosity);
|
||||
if (saturation != null) BIOME_SATURATION.put(biome, saturation);
|
||||
BIOME_IDs.put(biome, id);
|
||||
}
|
||||
|
||||
private static void add(Biome biome, int color, short id, Color randomColor, Luminosity luminosity) {
|
||||
add(biome, color, id, randomColor, luminosity, null);
|
||||
}
|
||||
|
||||
public static int getColor(Biome biome) {
|
||||
return BIOME_HEX.get(biome);
|
||||
}
|
||||
|
||||
public static Color getColorType(Biome biome) {
|
||||
return BIOME_COLOR.get(biome);
|
||||
}
|
||||
|
||||
public static Luminosity getColorLuminosity(Biome biome) {
|
||||
return BIOME_LUMINOSITY.get(biome);
|
||||
}
|
||||
|
||||
public static SaturationType getColorSaturatiom(Biome biome) {
|
||||
return BIOME_SATURATION.get(biome);
|
||||
}
|
||||
|
||||
public static short getId(Biome biome) {
|
||||
return BIOME_IDs.get(biome);
|
||||
}
|
||||
|
||||
static {
|
||||
add(Biome.OCEAN, 0x000070, (short) 0, Color.BLUE, Luminosity.BRIGHT, SaturationType.MEDIUM);
|
||||
add(Biome.PLAINS, 0x8DB360, (short) 1, Color.GREEN, Luminosity.LIGHT, SaturationType.MEDIUM);
|
||||
@@ -144,4 +112,36 @@ public class VanillaBiomeMap {
|
||||
add(Biome.WARPED_FOREST, 0x49907B, (short) 172, Color.BLUE, Luminosity.BRIGHT);
|
||||
add(Biome.BASALT_DELTAS, 0x403636, (short) 173, Color.MONOCHROME, Luminosity.DARK);
|
||||
}
|
||||
|
||||
private static void add(Biome biome, int color, short id, Color randomColor, Luminosity luminosity, SaturationType saturation) {
|
||||
BIOME_HEX.put(biome, color);
|
||||
BIOME_COLOR.put(biome, randomColor);
|
||||
if (luminosity != null) BIOME_LUMINOSITY.put(biome, luminosity);
|
||||
if (saturation != null) BIOME_SATURATION.put(biome, saturation);
|
||||
BIOME_IDs.put(biome, id);
|
||||
}
|
||||
|
||||
private static void add(Biome biome, int color, short id, Color randomColor, Luminosity luminosity) {
|
||||
add(biome, color, id, randomColor, luminosity, null);
|
||||
}
|
||||
|
||||
public static int getColor(Biome biome) {
|
||||
return BIOME_HEX.get(biome);
|
||||
}
|
||||
|
||||
public static Color getColorType(Biome biome) {
|
||||
return BIOME_COLOR.get(biome);
|
||||
}
|
||||
|
||||
public static Luminosity getColorLuminosity(Biome biome) {
|
||||
return BIOME_LUMINOSITY.get(biome);
|
||||
}
|
||||
|
||||
public static SaturationType getColorSaturatiom(Biome biome) {
|
||||
return BIOME_SATURATION.get(biome);
|
||||
}
|
||||
|
||||
public static short getId(Biome biome) {
|
||||
return BIOME_IDs.get(biome);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,64 +40,6 @@ import java.util.List;
|
||||
public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
||||
KList<DecreeParameterHandler<?>> handlers = Iris.initialize("com.volmit.iris.util.decree.handlers", null).convert((i) -> (DecreeParameterHandler<?>) i);
|
||||
|
||||
/**
|
||||
* The root class to start command searching from
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
VirtualDecreeCommand getRoot();
|
||||
|
||||
default boolean call(VolmitSender sender, String[] args) {
|
||||
DecreeContext.touch(sender);
|
||||
return getRoot().invoke(sender, enhanceArgs(args));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
default List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
KList<String> enhanced = new KList<>(args);
|
||||
KList<String> v = getRoot().tabComplete(enhanced, enhanced.toString(" "));
|
||||
v.removeDuplicates();
|
||||
|
||||
if (sender instanceof Player) {
|
||||
if (IrisSettings.get().getGeneral().isCommandSounds()) {
|
||||
((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_BLOCK_CHIME, 0.25f, RNG.r.f(0.125f, 1.95f));
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (!sender.hasPermission("iris.all")) {
|
||||
sender.sendMessage("You lack the Permission 'iris.all'");
|
||||
return true;
|
||||
}
|
||||
|
||||
J.aBukkit(() -> {
|
||||
if (!call(new VolmitSender(sender), args)) {
|
||||
|
||||
if (IrisSettings.get().getGeneral().isCommandSounds()) {
|
||||
if (sender instanceof Player) {
|
||||
((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 0.25f);
|
||||
((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.2f, 0.45f);
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(C.RED + "Unknown Iris Command");
|
||||
} else {
|
||||
if (IrisSettings.get().getGeneral().isCommandSounds()) {
|
||||
if (sender instanceof Player) {
|
||||
((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 1.65f);
|
||||
((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 0.125f, 2.99f);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
static KList<String> enhanceArgs(String[] args) {
|
||||
return enhanceArgs(args, true);
|
||||
}
|
||||
@@ -183,4 +125,62 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
||||
Iris.error("Unhandled type in Decree Parameter: " + type.getName() + ". This is bad!");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The root class to start command searching from
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
VirtualDecreeCommand getRoot();
|
||||
|
||||
default boolean call(VolmitSender sender, String[] args) {
|
||||
DecreeContext.touch(sender);
|
||||
return getRoot().invoke(sender, enhanceArgs(args));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
default List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
KList<String> enhanced = new KList<>(args);
|
||||
KList<String> v = getRoot().tabComplete(enhanced, enhanced.toString(" "));
|
||||
v.removeDuplicates();
|
||||
|
||||
if (sender instanceof Player) {
|
||||
if (IrisSettings.get().getGeneral().isCommandSounds()) {
|
||||
((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_BLOCK_CHIME, 0.25f, RNG.r.f(0.125f, 1.95f));
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (!sender.hasPermission("iris.all")) {
|
||||
sender.sendMessage("You lack the Permission 'iris.all'");
|
||||
return true;
|
||||
}
|
||||
|
||||
J.aBukkit(() -> {
|
||||
if (!call(new VolmitSender(sender), args)) {
|
||||
|
||||
if (IrisSettings.get().getGeneral().isCommandSounds()) {
|
||||
if (sender instanceof Player) {
|
||||
((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 0.25f);
|
||||
((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.2f, 0.45f);
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(C.RED + "Unknown Iris Command");
|
||||
} else {
|
||||
if (IrisSettings.get().getGeneral().isCommandSounds()) {
|
||||
if (sender instanceof Player) {
|
||||
((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 1.65f);
|
||||
((Player) sender).playSound(((Player) sender).getLocation(), Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, 0.125f, 2.99f);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,11 @@ import com.volmit.iris.core.service.CommandSVC;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.decree.*;
|
||||
import com.volmit.iris.util.decree.DecreeContext;
|
||||
import com.volmit.iris.util.decree.DecreeContextHandler;
|
||||
import com.volmit.iris.util.decree.DecreeNode;
|
||||
import com.volmit.iris.util.decree.DecreeParameter;
|
||||
import com.volmit.iris.util.decree.DecreeParameterHandler;
|
||||
import com.volmit.iris.util.decree.annotations.Decree;
|
||||
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;
|
||||
import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
||||
@@ -53,6 +57,15 @@ public class VirtualDecreeCommand {
|
||||
private final VirtualDecreeCommand parent;
|
||||
private final KList<VirtualDecreeCommand> nodes;
|
||||
private final DecreeNode node;
|
||||
String[] gradients = new String[]{
|
||||
"<gradient:#f5bc42:#45b32d>",
|
||||
"<gradient:#1ed43f:#1ecbd4>",
|
||||
"<gradient:#1e2ad4:#821ed4>",
|
||||
"<gradient:#d41ea7:#611ed4>",
|
||||
"<gradient:#1ed473:#1e55d4>",
|
||||
"<gradient:#6ad41e:#9a1ed4>"
|
||||
};
|
||||
private ChronoLatch cl = new ChronoLatch(1000);
|
||||
|
||||
private VirtualDecreeCommand(Class<?> type, VirtualDecreeCommand parent, KList<VirtualDecreeCommand> nodes, DecreeNode node) {
|
||||
this.parent = parent;
|
||||
@@ -103,8 +116,6 @@ public class VirtualDecreeCommand {
|
||||
return c;
|
||||
}
|
||||
|
||||
private ChronoLatch cl = new ChronoLatch(1000);
|
||||
|
||||
public void cacheAll() {
|
||||
VolmitSender sender = new VolmitSender(new CommandDummy());
|
||||
|
||||
@@ -504,15 +515,6 @@ public class VirtualDecreeCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] gradients = new String[]{
|
||||
"<gradient:#f5bc42:#45b32d>",
|
||||
"<gradient:#1ed43f:#1ecbd4>",
|
||||
"<gradient:#1e2ad4:#821ed4>",
|
||||
"<gradient:#d41ea7:#611ed4>",
|
||||
"<gradient:#1ed473:#1e55d4>",
|
||||
"<gradient:#6ad41e:#9a1ed4>"
|
||||
};
|
||||
|
||||
private String pickValidOption(VolmitSender sender, KList<?> validOptions, DecreeParameterHandler<?> handler, String name, String type) {
|
||||
sender.sendHeader("Pick a " + name + " (" + type + ")");
|
||||
sender.sendMessageRaw("<gradient:#1ed497:#b39427>This query will expire in 15 seconds.</gradient>");
|
||||
|
||||
@@ -253,14 +253,9 @@ public enum C {
|
||||
* need to dynamically convert colour codes from your custom format.
|
||||
*/
|
||||
public static final char COLOR_CHAR = '\u00A7';
|
||||
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + COLOR_CHAR + "[0-9A-FK-OR]");
|
||||
public final static C[] COLORCYCLE = new C[]{C.GOLD, C.YELLOW, C.GREEN, C.AQUA, C.LIGHT_PURPLE, C.AQUA, C.GREEN, C.YELLOW, C.GOLD, C.RED};
|
||||
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + COLOR_CHAR + "[0-9A-FK-OR]");
|
||||
private final static C[] COLORS = new C[]{C.BLACK, C.DARK_BLUE, C.DARK_GREEN, C.DARK_AQUA, C.DARK_RED, C.DARK_PURPLE, C.GOLD, C.GRAY, C.DARK_GRAY, C.BLUE, C.GREEN, C.AQUA, C.RED, C.LIGHT_PURPLE, C.YELLOW, C.WHITE};
|
||||
private final int intCode;
|
||||
private final char code;
|
||||
private final String token;
|
||||
private final boolean isFormat;
|
||||
private final String toString;
|
||||
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
|
||||
private final static Map<Integer, C> BY_ID = new HashMap<>();
|
||||
private final static Map<Character, C> BY_CHAR = new HashMap<>();
|
||||
@@ -320,6 +315,19 @@ public enum C {
|
||||
dyeHexMap.put(DyeColor.YELLOW, "#c2b51c");
|
||||
}
|
||||
|
||||
static {
|
||||
for (C color : values()) {
|
||||
BY_ID.put(color.intCode, color);
|
||||
BY_CHAR.put(color.code, color);
|
||||
}
|
||||
}
|
||||
|
||||
private final int intCode;
|
||||
private final char code;
|
||||
private final String token;
|
||||
private final boolean isFormat;
|
||||
private final String toString;
|
||||
|
||||
C(char code, int intCode) {
|
||||
this("^", code, intCode, false);
|
||||
}
|
||||
@@ -415,57 +423,6 @@ public enum C {
|
||||
return BaseComponent.toLegacyText(TextComponent.fromLegacyText(c));
|
||||
}
|
||||
|
||||
public net.md_5.bungee.api.ChatColor asBungee() {
|
||||
return net.md_5.bungee.api.ChatColor.RESET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the char value associated with this color
|
||||
*
|
||||
* @return A char value of this color code
|
||||
*/
|
||||
public char getChar() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return intCode == -1 ? token : toString;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the dye color for the chatcolor
|
||||
*/
|
||||
public DyeColor dye() {
|
||||
return chatToDye(chatColor());
|
||||
}
|
||||
|
||||
public String hex() {
|
||||
return chatToHex(this);
|
||||
}
|
||||
|
||||
public java.awt.Color awtColor() {
|
||||
return java.awt.Color.decode(hex());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this code is a format code as opposed to a color code.
|
||||
*
|
||||
* @return whether this ChatColor is a format code
|
||||
*/
|
||||
public boolean isFormat() {
|
||||
return isFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this code is a color code as opposed to a format code.
|
||||
*
|
||||
* @return whether this ChatColor is a color code
|
||||
*/
|
||||
public boolean isColor() {
|
||||
return !isFormat && this != RESET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color represented by the specified color code
|
||||
*
|
||||
@@ -613,13 +570,6 @@ public enum C {
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ChatColor enum instance instead of C
|
||||
*/
|
||||
public ChatColor chatColor() {
|
||||
return ChatColor.getByChar(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a string using an alternate color code character into a string
|
||||
* that uses the internal ChatColor.COLOR_CODE color code character. The
|
||||
@@ -655,6 +605,99 @@ public enum C {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static C randomColor() {
|
||||
return COLORS[(int) (Math.random() * (COLORS.length - 1))];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ChatColors used at the end of the given input string.
|
||||
*
|
||||
* @param input Input string to retrieve the colors from.
|
||||
* @return Any remaining ChatColors to pass onto the next line.
|
||||
*/
|
||||
public static String getLastColors(String input) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
int length = input.length();
|
||||
|
||||
// Search backwards from the end as it is faster
|
||||
for (int index = length - 1; index > -1; index--) {
|
||||
char section = input.charAt(index);
|
||||
if (section == COLOR_CHAR && index < length - 1) {
|
||||
char c = input.charAt(index + 1);
|
||||
C color = getByChar(c);
|
||||
|
||||
if (color != null) {
|
||||
result.insert(0, color);
|
||||
|
||||
// Once we find a color or reset we can stop searching
|
||||
if (color.isColor() || color.equals(RESET)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public net.md_5.bungee.api.ChatColor asBungee() {
|
||||
return net.md_5.bungee.api.ChatColor.RESET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the char value associated with this color
|
||||
*
|
||||
* @return A char value of this color code
|
||||
*/
|
||||
public char getChar() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return intCode == -1 ? token : toString;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the dye color for the chatcolor
|
||||
*/
|
||||
public DyeColor dye() {
|
||||
return chatToDye(chatColor());
|
||||
}
|
||||
|
||||
public String hex() {
|
||||
return chatToHex(this);
|
||||
}
|
||||
|
||||
public java.awt.Color awtColor() {
|
||||
return java.awt.Color.decode(hex());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this code is a format code as opposed to a color code.
|
||||
*
|
||||
* @return whether this ChatColor is a format code
|
||||
*/
|
||||
public boolean isFormat() {
|
||||
return isFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this code is a color code as opposed to a format code.
|
||||
*
|
||||
* @return whether this ChatColor is a color code
|
||||
*/
|
||||
public boolean isColor() {
|
||||
return !isFormat && this != RESET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ChatColor enum instance instead of C
|
||||
*/
|
||||
public ChatColor chatColor() {
|
||||
return ChatColor.getByChar(code);
|
||||
}
|
||||
|
||||
public byte getMeta() {
|
||||
return switch (this) {
|
||||
case AQUA -> (byte) 11;
|
||||
@@ -696,46 +739,4 @@ public enum C {
|
||||
default -> (byte) 15;
|
||||
};
|
||||
}
|
||||
|
||||
public static C randomColor() {
|
||||
return COLORS[(int) (Math.random() * (COLORS.length - 1))];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ChatColors used at the end of the given input string.
|
||||
*
|
||||
* @param input Input string to retrieve the colors from.
|
||||
* @return Any remaining ChatColors to pass onto the next line.
|
||||
*/
|
||||
public static String getLastColors(String input) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
int length = input.length();
|
||||
|
||||
// Search backwards from the end as it is faster
|
||||
for (int index = length - 1; index > -1; index--) {
|
||||
char section = input.charAt(index);
|
||||
if (section == COLOR_CHAR && index < length - 1) {
|
||||
char c = input.charAt(index + 1);
|
||||
C color = getByChar(c);
|
||||
|
||||
if (color != null) {
|
||||
result.insert(0, color);
|
||||
|
||||
// Once we find a color or reset we can stop searching
|
||||
if (color.isColor() || color.equals(RESET)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
static {
|
||||
for (C color : values()) {
|
||||
BY_ID.put(color.intCode, color);
|
||||
BY_CHAR.put(color.code, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,19 +24,31 @@ import com.volmit.iris.util.math.RollingSequence;
|
||||
import java.math.BigInteger;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Form {
|
||||
private static NumberFormat NF;
|
||||
private static DecimalFormat DF;
|
||||
|
||||
private static final String[] NAMES = new String[]{"Thousand", "Million", "Billion", "Trillion", "Quadrillion", "Quintillion", "Sextillion", "Septillion", "Octillion", "Nonillion", "Decillion", "Undecillion", "Duodecillion", "Tredecillion", "Quattuordecillion", "Quindecillion", "Sexdecillion", "Septendecillion", "Octodecillion", "Novemdecillion", "Vigintillion",};
|
||||
private static final BigInteger THOUSAND = BigInteger.valueOf(1000);
|
||||
private static final NavigableMap<BigInteger, String> MAP;
|
||||
private static NumberFormat NF;
|
||||
private static DecimalFormat DF;
|
||||
|
||||
static {
|
||||
MAP = new TreeMap<>();
|
||||
for (int i = 0; i < NAMES.length; i++) {
|
||||
MAP.put(THOUSAND.pow(i + 1), NAMES[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getNumberSuffixThStRd(int day) {
|
||||
if (day >= 11 && day <= 13) {
|
||||
@@ -50,13 +62,6 @@ public class Form {
|
||||
};
|
||||
}
|
||||
|
||||
static {
|
||||
MAP = new TreeMap<>();
|
||||
for (int i = 0; i < NAMES.length; i++) {
|
||||
MAP.put(THOUSAND.pow(i + 1), NAMES[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void instantiate() {
|
||||
if (NF == null) {
|
||||
NF = NumberFormat.getInstance(Locale.US);
|
||||
|
||||
@@ -20,9 +20,37 @@ package com.volmit.iris.util.hunk;
|
||||
|
||||
import com.volmit.iris.engine.object.IrisPosition;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.function.*;
|
||||
import com.volmit.iris.util.hunk.storage.*;
|
||||
import com.volmit.iris.util.hunk.view.*;
|
||||
import com.volmit.iris.util.function.Consumer2;
|
||||
import com.volmit.iris.util.function.Consumer3;
|
||||
import com.volmit.iris.util.function.Consumer4;
|
||||
import com.volmit.iris.util.function.Consumer4IO;
|
||||
import com.volmit.iris.util.function.Consumer5;
|
||||
import com.volmit.iris.util.function.Consumer6;
|
||||
import com.volmit.iris.util.function.Consumer8;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.function.NoiseProvider;
|
||||
import com.volmit.iris.util.function.NoiseProvider3;
|
||||
import com.volmit.iris.util.function.Supplier3R;
|
||||
import com.volmit.iris.util.hunk.storage.ArrayHunk;
|
||||
import com.volmit.iris.util.hunk.storage.AtomicDoubleHunk;
|
||||
import com.volmit.iris.util.hunk.storage.AtomicHunk;
|
||||
import com.volmit.iris.util.hunk.storage.AtomicIntegerHunk;
|
||||
import com.volmit.iris.util.hunk.storage.AtomicLongHunk;
|
||||
import com.volmit.iris.util.hunk.storage.MappedHunk;
|
||||
import com.volmit.iris.util.hunk.storage.SynchronizedArrayHunk;
|
||||
import com.volmit.iris.util.hunk.view.BiomeGridHunkView;
|
||||
import com.volmit.iris.util.hunk.view.ChunkBiomeHunkView;
|
||||
import com.volmit.iris.util.hunk.view.ChunkDataHunkView;
|
||||
import com.volmit.iris.util.hunk.view.ChunkHunkView;
|
||||
import com.volmit.iris.util.hunk.view.DriftHunkView;
|
||||
import com.volmit.iris.util.hunk.view.FringedHunkView;
|
||||
import com.volmit.iris.util.hunk.view.FunctionalHunkView;
|
||||
import com.volmit.iris.util.hunk.view.HunkView;
|
||||
import com.volmit.iris.util.hunk.view.InvertedHunkView;
|
||||
import com.volmit.iris.util.hunk.view.ListeningHunk;
|
||||
import com.volmit.iris.util.hunk.view.ReadOnlyHunk;
|
||||
import com.volmit.iris.util.hunk.view.SynchronizedHunkView;
|
||||
import com.volmit.iris.util.hunk.view.WriteTrackHunk;
|
||||
import com.volmit.iris.util.interpolation.InterpolationMethod;
|
||||
import com.volmit.iris.util.interpolation.InterpolationMethod3D;
|
||||
import com.volmit.iris.util.interpolation.IrisInterpolation;
|
||||
@@ -57,14 +85,6 @@ public interface Hunk<T> {
|
||||
return new HunkView<T>(src);
|
||||
}
|
||||
|
||||
default boolean isMapped() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default int getEntryCount() {
|
||||
return getWidth() * getHeight() * getDepth();
|
||||
}
|
||||
|
||||
static <A, B> Hunk<B> convertedReadView(Hunk<A> src, Function<A, B> reader) {
|
||||
return new FunctionalHunkView<A, B>(src, reader, null);
|
||||
}
|
||||
@@ -106,18 +126,6 @@ public interface Hunk<T> {
|
||||
return newCombinedArrayHunk(hunks);
|
||||
}
|
||||
|
||||
default Hunk<T> listen(Consumer4<Integer, Integer, Integer, T> l) {
|
||||
return new ListeningHunk<>(this, l);
|
||||
}
|
||||
|
||||
default Hunk<T> synchronize() {
|
||||
return new SynchronizedHunkView<>(this);
|
||||
}
|
||||
|
||||
default Hunk<T> trackWrite(AtomicBoolean b) {
|
||||
return new WriteTrackHunk<T>(this, b);
|
||||
}
|
||||
|
||||
static <T> Hunk<T> newArrayHunk(int w, int h, int d) {
|
||||
return new ArrayHunk<>(w, h, d);
|
||||
}
|
||||
@@ -214,6 +222,208 @@ public interface Hunk<T> {
|
||||
return b;
|
||||
}
|
||||
|
||||
static <A, B> void computeDual2D(int parallelism, Hunk<A> a, Hunk<B> b, Consumer5<Integer, Integer, Integer, Hunk<A>, Hunk<B>> v) {
|
||||
if (a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight() || a.getDepth() != b.getDepth()) {
|
||||
throw new RuntimeException("Hunk sizes must match!");
|
||||
}
|
||||
|
||||
if (a.get2DDimension(parallelism) == 1) {
|
||||
v.accept(0, 0, 0, a, b);
|
||||
return;
|
||||
}
|
||||
|
||||
BurstExecutor e = MultiBurst.burst.burst(parallelism);
|
||||
KList<Runnable> rq = new KList<Runnable>(parallelism);
|
||||
getDualSections2D(parallelism, a, b, (xx, yy, zz, ha, hr, r) -> e.queue(() ->
|
||||
{
|
||||
v.accept(xx, yy, zz, ha, hr);
|
||||
|
||||
synchronized (rq) {
|
||||
rq.add(r);
|
||||
}
|
||||
}), (x, y, z, hax, hbx) ->
|
||||
{
|
||||
a.insert(x, y, z, hax);
|
||||
b.insert(x, y, z, hbx);
|
||||
});
|
||||
e.complete();
|
||||
rq.forEach(Runnable::run);
|
||||
return;
|
||||
}
|
||||
|
||||
static <A, B> void getDualSections2D(int sections, Hunk<A> a, Hunk<B> b, Consumer6<Integer, Integer, Integer, Hunk<A>, Hunk<B>, Runnable> v, Consumer5<Integer, Integer, Integer, Hunk<A>, Hunk<B>> inserterAB) {
|
||||
if (a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight() || a.getDepth() != b.getDepth()) {
|
||||
throw new RuntimeException("Hunk sizes must match!");
|
||||
}
|
||||
|
||||
int dim = a.get2DDimension(sections);
|
||||
|
||||
if (sections <= 1) {
|
||||
getDualSection(0, 0, 0, a.getWidth(), a.getHeight(), a.getDepth(), a, b, (ha, hr, r) -> v.accept(0, 0, 0, ha, hr, r), inserterAB);
|
||||
return;
|
||||
}
|
||||
|
||||
int w = a.getWidth() / dim;
|
||||
int wr = a.getWidth() - (w * dim);
|
||||
int d = a.getDepth() / dim;
|
||||
int dr = a.getDepth() - (d * dim);
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < a.getWidth(); i += w) {
|
||||
int ii = i;
|
||||
|
||||
for (j = 0; j < a.getDepth(); j += d) {
|
||||
int jj = j;
|
||||
getDualSection(i, 0, j, i + w + (i == 0 ? wr : 0), a.getHeight(), j + d + (j == 0 ? dr : 0), a, b, (ha, hr, r) -> v.accept(ii, 0, jj, ha, hr, r), inserterAB);
|
||||
i = i == 0 ? i + wr : i;
|
||||
j = j == 0 ? j + dr : j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static <A, B> void getDualSection(int x, int y, int z, int x1, int y1, int z1, Hunk<A> a, Hunk<B> b, Consumer3<Hunk<A>, Hunk<B>, Runnable> v, Consumer5<Integer, Integer, Integer, Hunk<A>, Hunk<B>> inserter) {
|
||||
Hunk<A> copya = a.crop(x, y, z, x1, y1, z1);
|
||||
Hunk<B> copyb = b.crop(x, y, z, x1, y1, z1);
|
||||
v.accept(copya, copyb, () -> inserter.accept(x, y, z, copya, copyb));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a hunk that is optimized for specific uses
|
||||
*
|
||||
* @param w width
|
||||
* @param h height
|
||||
* @param d depth
|
||||
* @param type the class type
|
||||
* @param packed if the hunk is generally more than 50% full (non-null nodes)
|
||||
* @param concurrent if this hunk must be thread safe
|
||||
* @param <T> the type
|
||||
* @return the hunk
|
||||
*/
|
||||
static <T> Hunk<T> newHunk(int w, int h, int d, Class<T> type, boolean packed, boolean concurrent) {
|
||||
if (type.equals(Double.class)) {
|
||||
return concurrent ?
|
||||
packed ? (Hunk<T>) newAtomicDoubleHunk(w, h, d) : newMappedHunk(w, h, d)
|
||||
: packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
|
||||
}
|
||||
|
||||
if (type.equals(Integer.class)) {
|
||||
return concurrent ?
|
||||
packed ? (Hunk<T>) newAtomicIntegerHunk(w, h, d) : newMappedHunk(w, h, d)
|
||||
: packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
|
||||
}
|
||||
|
||||
if (type.equals(Long.class)) {
|
||||
return concurrent ?
|
||||
packed ? (Hunk<T>) newAtomicLongHunk(w, h, d) : newMappedHunk(w, h, d)
|
||||
: packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
|
||||
}
|
||||
|
||||
return concurrent ?
|
||||
packed ? newAtomicHunk(w, h, d) : newMappedHunk(w, h, d)
|
||||
: packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
|
||||
}
|
||||
|
||||
static IrisPosition rotatedBounding(int w, int h, int d, double x, double y, double z) {
|
||||
int[] iii = {0, 0, 0};
|
||||
int[] aaa = {w, h, d};
|
||||
int[] aai = {w, h, 0};
|
||||
int[] iaa = {0, h, d};
|
||||
int[] aia = {w, 0, d};
|
||||
int[] iai = {0, h, 0};
|
||||
int[] iia = {0, 0, d};
|
||||
int[] aii = {w, 0, 0};
|
||||
rotate(x, y, z, iii);
|
||||
rotate(x, y, z, aaa);
|
||||
rotate(x, y, z, aai);
|
||||
rotate(x, y, z, iaa);
|
||||
rotate(x, y, z, aia);
|
||||
rotate(x, y, z, iai);
|
||||
rotate(x, y, z, iia);
|
||||
rotate(x, y, z, aii);
|
||||
int maxX = max(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]);
|
||||
int minX = min(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]);
|
||||
int maxY = max(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]);
|
||||
int minY = min(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]);
|
||||
int maxZ = max(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]);
|
||||
int minZ = min(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]);
|
||||
return new IrisPosition(maxX - minX, maxY - minY, maxZ - minZ);
|
||||
}
|
||||
|
||||
static int max(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) {
|
||||
return Math.max(Math.max(Math.max(a5, a6), Math.max(a7, a8)), Math.max(Math.max(a1, a2), Math.max(a3, a4)));
|
||||
}
|
||||
|
||||
static int min(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) {
|
||||
return Math.min(Math.min(Math.min(a5, a6), Math.min(a7, a8)), Math.min(Math.min(a1, a2), Math.min(a3, a4)));
|
||||
}
|
||||
|
||||
static void rotate(double x, double y, double z, int[] c) {
|
||||
if (x % 360 != 0) {
|
||||
rotateAroundX(Math.toRadians(x), c);
|
||||
}
|
||||
|
||||
if (y % 360 != 0) {
|
||||
rotateAroundY(Math.toRadians(y), c);
|
||||
}
|
||||
|
||||
if (z % 360 != 0) {
|
||||
rotateAroundZ(Math.toRadians(z), c);
|
||||
}
|
||||
}
|
||||
|
||||
static void rotateAroundX(double a, int[] c) {
|
||||
rotateAroundX(Math.cos(a), Math.sin(a), c);
|
||||
}
|
||||
|
||||
static void rotateAroundX(double cos, double sin, int[] c) {
|
||||
int y = (int) Math.floor(cos * (double) (c[1] + 0.5) - sin * (double) (c[2] + 0.5));
|
||||
int z = (int) Math.floor(sin * (double) (c[1] + 0.5) + cos * (double) (c[2] + 0.5));
|
||||
c[1] = y;
|
||||
c[2] = z;
|
||||
}
|
||||
|
||||
static void rotateAroundY(double a, int[] c) {
|
||||
rotateAroundY(Math.cos(a), Math.sin(a), c);
|
||||
}
|
||||
|
||||
static void rotateAroundY(double cos, double sin, int[] c) {
|
||||
int x = (int) Math.floor(cos * (double) (c[0] + 0.5) + sin * (double) (c[2] + 0.5));
|
||||
int z = (int) Math.floor(-sin * (double) (c[0] + 0.5) + cos * (double) (c[2] + 0.5));
|
||||
c[0] = x;
|
||||
c[2] = z;
|
||||
}
|
||||
|
||||
static void rotateAroundZ(double a, int[] c) {
|
||||
rotateAroundZ(Math.cos(a), Math.sin(a), c);
|
||||
}
|
||||
|
||||
static void rotateAroundZ(double cos, double sin, int[] c) {
|
||||
int x = (int) Math.floor(cos * (double) (c[0] + 0.5) - sin * (double) (c[1] + 0.5));
|
||||
int y = (int) Math.floor(sin * (double) (c[0] + 0.5) + cos * (double) (c[1] + 0.5));
|
||||
c[0] = x;
|
||||
c[1] = y;
|
||||
}
|
||||
|
||||
default boolean isMapped() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default int getEntryCount() {
|
||||
return getWidth() * getHeight() * getDepth();
|
||||
}
|
||||
|
||||
default Hunk<T> listen(Consumer4<Integer, Integer, Integer, T> l) {
|
||||
return new ListeningHunk<>(this, l);
|
||||
}
|
||||
|
||||
default Hunk<T> synchronize() {
|
||||
return new SynchronizedHunkView<>(this);
|
||||
}
|
||||
|
||||
default Hunk<T> trackWrite(AtomicBoolean b) {
|
||||
return new WriteTrackHunk<T>(this, b);
|
||||
}
|
||||
|
||||
default Hunk<T> readOnly() {
|
||||
return new ReadOnlyHunk<>(this);
|
||||
}
|
||||
@@ -589,71 +799,6 @@ public interface Hunk<T> {
|
||||
return compute2D(getIdeal2DParallelism(), v);
|
||||
}
|
||||
|
||||
static <A, B> void computeDual2D(int parallelism, Hunk<A> a, Hunk<B> b, Consumer5<Integer, Integer, Integer, Hunk<A>, Hunk<B>> v) {
|
||||
if (a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight() || a.getDepth() != b.getDepth()) {
|
||||
throw new RuntimeException("Hunk sizes must match!");
|
||||
}
|
||||
|
||||
if (a.get2DDimension(parallelism) == 1) {
|
||||
v.accept(0, 0, 0, a, b);
|
||||
return;
|
||||
}
|
||||
|
||||
BurstExecutor e = MultiBurst.burst.burst(parallelism);
|
||||
KList<Runnable> rq = new KList<Runnable>(parallelism);
|
||||
getDualSections2D(parallelism, a, b, (xx, yy, zz, ha, hr, r) -> e.queue(() ->
|
||||
{
|
||||
v.accept(xx, yy, zz, ha, hr);
|
||||
|
||||
synchronized (rq) {
|
||||
rq.add(r);
|
||||
}
|
||||
}), (x, y, z, hax, hbx) ->
|
||||
{
|
||||
a.insert(x, y, z, hax);
|
||||
b.insert(x, y, z, hbx);
|
||||
});
|
||||
e.complete();
|
||||
rq.forEach(Runnable::run);
|
||||
return;
|
||||
}
|
||||
|
||||
static <A, B> void getDualSections2D(int sections, Hunk<A> a, Hunk<B> b, Consumer6<Integer, Integer, Integer, Hunk<A>, Hunk<B>, Runnable> v, Consumer5<Integer, Integer, Integer, Hunk<A>, Hunk<B>> inserterAB) {
|
||||
if (a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight() || a.getDepth() != b.getDepth()) {
|
||||
throw new RuntimeException("Hunk sizes must match!");
|
||||
}
|
||||
|
||||
int dim = a.get2DDimension(sections);
|
||||
|
||||
if (sections <= 1) {
|
||||
getDualSection(0, 0, 0, a.getWidth(), a.getHeight(), a.getDepth(), a, b, (ha, hr, r) -> v.accept(0, 0, 0, ha, hr, r), inserterAB);
|
||||
return;
|
||||
}
|
||||
|
||||
int w = a.getWidth() / dim;
|
||||
int wr = a.getWidth() - (w * dim);
|
||||
int d = a.getDepth() / dim;
|
||||
int dr = a.getDepth() - (d * dim);
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < a.getWidth(); i += w) {
|
||||
int ii = i;
|
||||
|
||||
for (j = 0; j < a.getDepth(); j += d) {
|
||||
int jj = j;
|
||||
getDualSection(i, 0, j, i + w + (i == 0 ? wr : 0), a.getHeight(), j + d + (j == 0 ? dr : 0), a, b, (ha, hr, r) -> v.accept(ii, 0, jj, ha, hr, r), inserterAB);
|
||||
i = i == 0 ? i + wr : i;
|
||||
j = j == 0 ? j + dr : j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static <A, B> void getDualSection(int x, int y, int z, int x1, int y1, int z1, Hunk<A> a, Hunk<B> b, Consumer3<Hunk<A>, Hunk<B>, Runnable> v, Consumer5<Integer, Integer, Integer, Hunk<A>, Hunk<B>> inserter) {
|
||||
Hunk<A> copya = a.crop(x, y, z, x1, y1, z1);
|
||||
Hunk<B> copyb = b.crop(x, y, z, x1, y1, z1);
|
||||
v.accept(copya, copyb, () -> inserter.accept(x, y, z, copya, copyb));
|
||||
}
|
||||
|
||||
default Hunk<T> compute2D(int parallelism, Consumer4<Integer, Integer, Integer, Hunk<T>> v) {
|
||||
if (get2DDimension(parallelism) == 1) {
|
||||
v.accept(0, 0, 0, this);
|
||||
@@ -1051,42 +1196,6 @@ public interface Hunk<T> {
|
||||
setRaw(x, y, z, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a hunk that is optimized for specific uses
|
||||
*
|
||||
* @param w width
|
||||
* @param h height
|
||||
* @param d depth
|
||||
* @param type the class type
|
||||
* @param packed if the hunk is generally more than 50% full (non-null nodes)
|
||||
* @param concurrent if this hunk must be thread safe
|
||||
* @param <T> the type
|
||||
* @return the hunk
|
||||
*/
|
||||
static <T> Hunk<T> newHunk(int w, int h, int d, Class<T> type, boolean packed, boolean concurrent) {
|
||||
if (type.equals(Double.class)) {
|
||||
return concurrent ?
|
||||
packed ? (Hunk<T>) newAtomicDoubleHunk(w, h, d) : newMappedHunk(w, h, d)
|
||||
: packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
|
||||
}
|
||||
|
||||
if (type.equals(Integer.class)) {
|
||||
return concurrent ?
|
||||
packed ? (Hunk<T>) newAtomicIntegerHunk(w, h, d) : newMappedHunk(w, h, d)
|
||||
: packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
|
||||
}
|
||||
|
||||
if (type.equals(Long.class)) {
|
||||
return concurrent ?
|
||||
packed ? (Hunk<T>) newAtomicLongHunk(w, h, d) : newMappedHunk(w, h, d)
|
||||
: packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
|
||||
}
|
||||
|
||||
return concurrent ?
|
||||
packed ? newAtomicHunk(w, h, d) : newMappedHunk(w, h, d)
|
||||
: packed ? newArrayHunk(w, h, d) : newMappedHunkSynced(w, h, d);
|
||||
}
|
||||
|
||||
default void setIfExists(int x, int y, int z, T t) {
|
||||
if (x < 0 || x >= getWidth() || y < 0 || y >= getHeight() || z < 0 || z >= getDepth()) {
|
||||
return;
|
||||
@@ -1297,32 +1406,6 @@ public interface Hunk<T> {
|
||||
return t;
|
||||
}
|
||||
|
||||
static IrisPosition rotatedBounding(int w, int h, int d, double x, double y, double z) {
|
||||
int[] iii = {0, 0, 0};
|
||||
int[] aaa = {w, h, d};
|
||||
int[] aai = {w, h, 0};
|
||||
int[] iaa = {0, h, d};
|
||||
int[] aia = {w, 0, d};
|
||||
int[] iai = {0, h, 0};
|
||||
int[] iia = {0, 0, d};
|
||||
int[] aii = {w, 0, 0};
|
||||
rotate(x, y, z, iii);
|
||||
rotate(x, y, z, aaa);
|
||||
rotate(x, y, z, aai);
|
||||
rotate(x, y, z, iaa);
|
||||
rotate(x, y, z, aia);
|
||||
rotate(x, y, z, iai);
|
||||
rotate(x, y, z, iia);
|
||||
rotate(x, y, z, aii);
|
||||
int maxX = max(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]);
|
||||
int minX = min(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]);
|
||||
int maxY = max(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]);
|
||||
int minY = min(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]);
|
||||
int maxZ = max(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]);
|
||||
int minZ = min(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]);
|
||||
return new IrisPosition(maxX - minX, maxY - minY, maxZ - minZ);
|
||||
}
|
||||
|
||||
default Hunk<T> rotate(double x, double y, double z, Supplier3R<Integer, Integer, Integer, Hunk<T>> builder) {
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
@@ -1375,61 +1458,6 @@ public interface Hunk<T> {
|
||||
return r;
|
||||
}
|
||||
|
||||
static int max(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) {
|
||||
return Math.max(Math.max(Math.max(a5, a6), Math.max(a7, a8)), Math.max(Math.max(a1, a2), Math.max(a3, a4)));
|
||||
}
|
||||
|
||||
static int min(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) {
|
||||
return Math.min(Math.min(Math.min(a5, a6), Math.min(a7, a8)), Math.min(Math.min(a1, a2), Math.min(a3, a4)));
|
||||
}
|
||||
|
||||
static void rotate(double x, double y, double z, int[] c) {
|
||||
if (x % 360 != 0) {
|
||||
rotateAroundX(Math.toRadians(x), c);
|
||||
}
|
||||
|
||||
if (y % 360 != 0) {
|
||||
rotateAroundY(Math.toRadians(y), c);
|
||||
}
|
||||
|
||||
if (z % 360 != 0) {
|
||||
rotateAroundZ(Math.toRadians(z), c);
|
||||
}
|
||||
}
|
||||
|
||||
static void rotateAroundX(double a, int[] c) {
|
||||
rotateAroundX(Math.cos(a), Math.sin(a), c);
|
||||
}
|
||||
|
||||
static void rotateAroundX(double cos, double sin, int[] c) {
|
||||
int y = (int) Math.floor(cos * (double) (c[1] + 0.5) - sin * (double) (c[2] + 0.5));
|
||||
int z = (int) Math.floor(sin * (double) (c[1] + 0.5) + cos * (double) (c[2] + 0.5));
|
||||
c[1] = y;
|
||||
c[2] = z;
|
||||
}
|
||||
|
||||
static void rotateAroundY(double a, int[] c) {
|
||||
rotateAroundY(Math.cos(a), Math.sin(a), c);
|
||||
}
|
||||
|
||||
static void rotateAroundY(double cos, double sin, int[] c) {
|
||||
int x = (int) Math.floor(cos * (double) (c[0] + 0.5) + sin * (double) (c[2] + 0.5));
|
||||
int z = (int) Math.floor(-sin * (double) (c[0] + 0.5) + cos * (double) (c[2] + 0.5));
|
||||
c[0] = x;
|
||||
c[2] = z;
|
||||
}
|
||||
|
||||
static void rotateAroundZ(double a, int[] c) {
|
||||
rotateAroundZ(Math.cos(a), Math.sin(a), c);
|
||||
}
|
||||
|
||||
static void rotateAroundZ(double cos, double sin, int[] c) {
|
||||
int x = (int) Math.floor(cos * (double) (c[0] + 0.5) - sin * (double) (c[1] + 0.5));
|
||||
int y = (int) Math.floor(sin * (double) (c[0] + 0.5) + cos * (double) (c[1] + 0.5));
|
||||
c[0] = x;
|
||||
c[1] = y;
|
||||
}
|
||||
|
||||
default boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ import com.volmit.iris.util.noise.CNG;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class IrisInterpolation {
|
||||
public static CNG cng = NoiseStyle.SIMPLEX.create(new RNG());
|
||||
|
||||
public static double bezier(double t) {
|
||||
return t * t * (3.0d - 2.0d * t);
|
||||
}
|
||||
@@ -278,8 +280,6 @@ public class IrisInterpolation {
|
||||
//@done
|
||||
}
|
||||
|
||||
public static CNG cng = NoiseStyle.SIMPLEX.create(new RNG());
|
||||
|
||||
public static double getBilinearNoise(int x, int z, double rad, NoiseProvider n) {
|
||||
int fx = (int) Math.floor(x / rad);
|
||||
int fz = (int) Math.floor(z / rad);
|
||||
|
||||
@@ -37,24 +37,24 @@ public interface Element {
|
||||
|
||||
String getName();
|
||||
|
||||
Element setProgress(double progress);
|
||||
Element setName(String name);
|
||||
|
||||
double getProgress();
|
||||
|
||||
Element setProgress(double progress);
|
||||
|
||||
short getEffectiveDurability();
|
||||
|
||||
Element setCount(int c);
|
||||
|
||||
int getCount();
|
||||
|
||||
Element setCount(int c);
|
||||
|
||||
ItemStack computeItemStack();
|
||||
|
||||
Element setBackground(boolean bg);
|
||||
|
||||
boolean isBackgrond();
|
||||
|
||||
Element setName(String name);
|
||||
|
||||
Element addLore(String loreLine);
|
||||
|
||||
KList<String> getLore();
|
||||
|
||||
@@ -29,112 +29,7 @@ import java.util.Random;
|
||||
public class RandomColor {
|
||||
|
||||
public static int hueOffset = 0;
|
||||
|
||||
public static class ColorInfo {
|
||||
Range hueRange;
|
||||
Range saturationRange;
|
||||
Range brightnessRange;
|
||||
List<Range> lowerBounds;
|
||||
|
||||
public ColorInfo(Range hueRange, Range saturationRange, Range brightnessRange, List<Range> lowerBounds) {
|
||||
this.hueRange = hueRange;
|
||||
this.saturationRange = saturationRange;
|
||||
this.brightnessRange = brightnessRange;
|
||||
this.lowerBounds = lowerBounds;
|
||||
}
|
||||
|
||||
public Range getHueRange() {
|
||||
return hueRange;
|
||||
}
|
||||
|
||||
public void setHueRange(Range hueRange) {
|
||||
this.hueRange = hueRange;
|
||||
}
|
||||
|
||||
public Range getSaturationRange() {
|
||||
return saturationRange;
|
||||
}
|
||||
|
||||
public void setSaturationRange(Range saturationRange) {
|
||||
this.saturationRange = saturationRange;
|
||||
}
|
||||
|
||||
public Range getBrightnessRange() {
|
||||
return brightnessRange;
|
||||
}
|
||||
|
||||
public void setBrightnessRange(Range brightnessRange) {
|
||||
this.brightnessRange = brightnessRange;
|
||||
}
|
||||
|
||||
public List<Range> getLowerBounds() {
|
||||
return lowerBounds;
|
||||
}
|
||||
|
||||
public void setLowerBounds(List<Range> lowerBounds) {
|
||||
this.lowerBounds = lowerBounds;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Range {
|
||||
int start;
|
||||
int end;
|
||||
|
||||
public Range(int start, int end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public boolean contain(int value) {
|
||||
return value >= start && value <= end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "start: " + start + " end: " + end;
|
||||
}
|
||||
}
|
||||
|
||||
private final Random random;
|
||||
|
||||
public enum SaturationType {
|
||||
RANDOM, MONOCHROME, HIGH, LOW, MEDIUM
|
||||
}
|
||||
|
||||
public enum Luminosity {
|
||||
BRIGHT, LIGHT, DARK, RANDOM
|
||||
}
|
||||
|
||||
public static class Options {
|
||||
int hue;
|
||||
SaturationType saturationType;
|
||||
Luminosity luminosity;
|
||||
|
||||
public int getHue() {
|
||||
return hue;
|
||||
}
|
||||
|
||||
public void setHue(int hue) {
|
||||
this.hue = hue;
|
||||
}
|
||||
|
||||
public SaturationType getSaturationType() {
|
||||
return saturationType;
|
||||
}
|
||||
|
||||
public void setSaturationType(SaturationType saturationType) {
|
||||
this.saturationType = saturationType;
|
||||
}
|
||||
|
||||
public Luminosity getLuminosity() {
|
||||
return luminosity;
|
||||
}
|
||||
|
||||
public void setLuminosity(Luminosity luminosity) {
|
||||
this.luminosity = luminosity;
|
||||
}
|
||||
}
|
||||
|
||||
private final HashMap<String, ColorInfo> colors = new HashMap<>();
|
||||
|
||||
public RandomColor() {
|
||||
@@ -520,10 +415,113 @@ public class RandomColor {
|
||||
);
|
||||
}
|
||||
|
||||
public enum SaturationType {
|
||||
RANDOM, MONOCHROME, HIGH, LOW, MEDIUM
|
||||
}
|
||||
|
||||
public enum Luminosity {
|
||||
BRIGHT, LIGHT, DARK, RANDOM
|
||||
}
|
||||
|
||||
public enum Color {
|
||||
MONOCHROME, RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE, PINK
|
||||
}
|
||||
|
||||
public static class ColorInfo {
|
||||
Range hueRange;
|
||||
Range saturationRange;
|
||||
Range brightnessRange;
|
||||
List<Range> lowerBounds;
|
||||
|
||||
public ColorInfo(Range hueRange, Range saturationRange, Range brightnessRange, List<Range> lowerBounds) {
|
||||
this.hueRange = hueRange;
|
||||
this.saturationRange = saturationRange;
|
||||
this.brightnessRange = brightnessRange;
|
||||
this.lowerBounds = lowerBounds;
|
||||
}
|
||||
|
||||
public Range getHueRange() {
|
||||
return hueRange;
|
||||
}
|
||||
|
||||
public void setHueRange(Range hueRange) {
|
||||
this.hueRange = hueRange;
|
||||
}
|
||||
|
||||
public Range getSaturationRange() {
|
||||
return saturationRange;
|
||||
}
|
||||
|
||||
public void setSaturationRange(Range saturationRange) {
|
||||
this.saturationRange = saturationRange;
|
||||
}
|
||||
|
||||
public Range getBrightnessRange() {
|
||||
return brightnessRange;
|
||||
}
|
||||
|
||||
public void setBrightnessRange(Range brightnessRange) {
|
||||
this.brightnessRange = brightnessRange;
|
||||
}
|
||||
|
||||
public List<Range> getLowerBounds() {
|
||||
return lowerBounds;
|
||||
}
|
||||
|
||||
public void setLowerBounds(List<Range> lowerBounds) {
|
||||
this.lowerBounds = lowerBounds;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Range {
|
||||
int start;
|
||||
int end;
|
||||
|
||||
public Range(int start, int end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public boolean contain(int value) {
|
||||
return value >= start && value <= end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "start: " + start + " end: " + end;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Options {
|
||||
int hue;
|
||||
SaturationType saturationType;
|
||||
Luminosity luminosity;
|
||||
|
||||
public int getHue() {
|
||||
return hue;
|
||||
}
|
||||
|
||||
public void setHue(int hue) {
|
||||
this.hue = hue;
|
||||
}
|
||||
|
||||
public SaturationType getSaturationType() {
|
||||
return saturationType;
|
||||
}
|
||||
|
||||
public void setSaturationType(SaturationType saturationType) {
|
||||
this.saturationType = saturationType;
|
||||
}
|
||||
|
||||
public Luminosity getLuminosity() {
|
||||
return luminosity;
|
||||
}
|
||||
|
||||
public void setLuminosity(Luminosity luminosity) {
|
||||
this.luminosity = luminosity;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,13 +28,13 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class UIElement implements Element {
|
||||
private final String id;
|
||||
private final KList<String> lore;
|
||||
private MaterialBlock material;
|
||||
private boolean enchanted;
|
||||
private final String id;
|
||||
private String name;
|
||||
private double progress;
|
||||
private boolean bg;
|
||||
private final KList<String> lore;
|
||||
private Callback<Element> eLeft;
|
||||
private Callback<Element> eRight;
|
||||
private Callback<Element> eShiftLeft;
|
||||
@@ -56,16 +56,16 @@ public class UIElement implements Element {
|
||||
return material;
|
||||
}
|
||||
|
||||
public Double clip(double value, double min, double max) {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UIElement setMaterial(MaterialBlock material) {
|
||||
this.material = material;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Double clip(double value, double min, double max) {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnchanted() {
|
||||
return enchanted;
|
||||
|
||||
@@ -35,11 +35,11 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class UIWindow implements Window, Listener {
|
||||
private WindowDecorator decorator;
|
||||
private final Player viewer;
|
||||
private final KMap<Integer, Element> elements;
|
||||
private WindowDecorator decorator;
|
||||
private Callback<Window> eClose;
|
||||
private WindowResolution resolution;
|
||||
private final KMap<Integer, Element> elements;
|
||||
private String title;
|
||||
private boolean visible;
|
||||
private int viewportPosition;
|
||||
@@ -195,14 +195,14 @@ public class UIWindow implements Window, Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UIWindow setDecorator(WindowDecorator decorator) {
|
||||
this.decorator = decorator;
|
||||
return this;
|
||||
public WindowDecorator getDecorator() {
|
||||
return decorator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WindowDecorator getDecorator() {
|
||||
return decorator;
|
||||
public UIWindow setDecorator(WindowDecorator decorator) {
|
||||
this.decorator = decorator;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,6 +217,11 @@ public class UIWindow implements Window, Listener {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UIWindow setVisible(boolean visible) {
|
||||
if (isVisible() == visible) {
|
||||
@@ -245,11 +250,6 @@ public class UIWindow implements Window, Listener {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewportPosition() {
|
||||
return viewportPosition;
|
||||
|
||||
@@ -23,10 +23,10 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface Window {
|
||||
Window setDecorator(WindowDecorator decorator);
|
||||
|
||||
WindowDecorator getDecorator();
|
||||
|
||||
Window setDecorator(WindowDecorator decorator);
|
||||
|
||||
WindowResolution getResolution();
|
||||
|
||||
Window setResolution(WindowResolution resolution);
|
||||
@@ -41,8 +41,6 @@ public interface Window {
|
||||
|
||||
Window updateInventory();
|
||||
|
||||
Window setVisible(boolean visible);
|
||||
|
||||
ItemStack computeItemStack(int viewportSlot);
|
||||
|
||||
int getLayoutRow(int viewportSlottedPosition);
|
||||
@@ -59,12 +57,14 @@ public interface Window {
|
||||
|
||||
boolean isVisible();
|
||||
|
||||
Window setVisible(boolean visible);
|
||||
|
||||
int getViewportPosition();
|
||||
|
||||
int getViewportSlots();
|
||||
|
||||
Window setViewportPosition(int position);
|
||||
|
||||
int getViewportSlots();
|
||||
|
||||
int getMaxViewportPosition();
|
||||
|
||||
Window scroll(int direction);
|
||||
|
||||
@@ -20,12 +20,36 @@ package com.volmit.iris.util.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.CharArrayWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
@@ -64,6 +88,14 @@ public class IO {
|
||||
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
|
||||
private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
static {
|
||||
// avoid security issues
|
||||
StringWriter buf = new StringWriter(4);
|
||||
PrintWriter out = new PrintWriter(buf);
|
||||
out.println();
|
||||
LINE_SEPARATOR = buf.toString();
|
||||
}
|
||||
|
||||
public static String decompress(String gz) throws IOException {
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(Base64.getUrlDecoder().decode(gz));
|
||||
GZIPInputStream gzi = new GZIPInputStream(bin);
|
||||
@@ -451,6 +483,8 @@ public class IO {
|
||||
doCopyFile(srcFile, destFile, preserveFileDate);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Internal copy file method.
|
||||
*
|
||||
@@ -484,8 +518,6 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Unconditionally close an <code>Reader</code>.
|
||||
* <p>
|
||||
@@ -543,6 +575,9 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// read toByteArray
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Unconditionally close an <code>OutputStream</code>.
|
||||
* <p>
|
||||
@@ -562,9 +597,6 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// read toByteArray
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
|
||||
* <p>
|
||||
@@ -623,6 +655,9 @@ public class IO {
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
// read char[]
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the contents of a <code>String</code> as a <code>byte[]</code> using the
|
||||
* default character encoding of the platform.
|
||||
@@ -638,9 +673,6 @@ public class IO {
|
||||
return input.getBytes();
|
||||
}
|
||||
|
||||
// read char[]
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the contents of an <code>InputStream</code> as a character array using
|
||||
* the default character encoding of the platform.
|
||||
@@ -683,6 +715,9 @@ public class IO {
|
||||
return output.toCharArray();
|
||||
}
|
||||
|
||||
// read toString
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the contents of a <code>Reader</code> as a character array.
|
||||
* <p>
|
||||
@@ -701,9 +736,6 @@ public class IO {
|
||||
return sw.toCharArray();
|
||||
}
|
||||
|
||||
// read toString
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the contents of an <code>InputStream</code> as a String using the default
|
||||
* character encoding of the platform.
|
||||
@@ -774,6 +806,9 @@ public class IO {
|
||||
return new String(input);
|
||||
}
|
||||
|
||||
// readLines
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the contents of a <code>byte[]</code> as a String using the specified
|
||||
* character encoding.
|
||||
@@ -797,9 +832,6 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// readLines
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the contents of an <code>InputStream</code> as a list of Strings, one
|
||||
* entry per line, using the default character encoding of the platform.
|
||||
@@ -844,6 +876,8 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the contents of a <code>Reader</code> as a list of Strings, one entry per
|
||||
* line.
|
||||
@@ -868,8 +902,6 @@ public class IO {
|
||||
return list;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Convert the specified string to an input stream, encoded as bytes using the
|
||||
* default character encoding of the platform.
|
||||
@@ -883,6 +915,9 @@ public class IO {
|
||||
return new ByteArrayInputStream(bytes);
|
||||
}
|
||||
|
||||
// write byte[]
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Convert the specified string to an input stream, encoded as bytes using the
|
||||
* specified character encoding.
|
||||
@@ -901,9 +936,6 @@ public class IO {
|
||||
return new ByteArrayInputStream(bytes);
|
||||
}
|
||||
|
||||
// write byte[]
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Writes bytes from a <code>byte[]</code> to an <code>OutputStream</code>.
|
||||
*
|
||||
@@ -937,6 +969,9 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// write char[]
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Writes bytes from a <code>byte[]</code> to chars on a <code>Writer</code>
|
||||
* using the specified character encoding.
|
||||
@@ -963,9 +998,6 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// write char[]
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Writes chars from a <code>char[]</code> to a <code>Writer</code> using the
|
||||
* default character encoding of the platform.
|
||||
@@ -1000,6 +1032,9 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// write String
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Writes chars from a <code>char[]</code> to bytes on an
|
||||
* <code>OutputStream</code> using the specified character encoding.
|
||||
@@ -1027,9 +1062,6 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// write String
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Writes chars from a <code>String</code> to a <code>Writer</code>.
|
||||
*
|
||||
@@ -1064,6 +1096,9 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// write StringBuffer
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Writes chars from a <code>String</code> to bytes on an
|
||||
* <code>OutputStream</code> using the specified character encoding.
|
||||
@@ -1090,9 +1125,6 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// write StringBuffer
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Writes chars from a <code>StringBuffer</code> to a <code>Writer</code>.
|
||||
*
|
||||
@@ -1127,6 +1159,9 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// writeLines
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Writes chars from a <code>StringBuffer</code> to bytes on an
|
||||
* <code>OutputStream</code> using the specified character encoding.
|
||||
@@ -1153,9 +1188,6 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// writeLines
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Writes the <code>toString()</code> value of each item in a collection to an
|
||||
* <code>OutputStream</code> line by line, using the default character encoding
|
||||
@@ -1220,6 +1252,9 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// copy from InputStream
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Writes the <code>toString()</code> value of each item in a collection to a
|
||||
* <code>Writer</code> line by line, using the specified line ending.
|
||||
@@ -1247,9 +1282,6 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// copy from InputStream
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
|
||||
* <p>
|
||||
@@ -1322,6 +1354,9 @@ public class IO {
|
||||
copy(in, output);
|
||||
}
|
||||
|
||||
// copy from Reader
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Copy bytes from an <code>InputStream</code> to chars on a <code>Writer</code>
|
||||
* using the specified character encoding.
|
||||
@@ -1350,9 +1385,6 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// copy from Reader
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Copy chars from a <code>Reader</code> to a <code>Writer</code>.
|
||||
* <p>
|
||||
@@ -1431,6 +1463,9 @@ public class IO {
|
||||
out.flush();
|
||||
}
|
||||
|
||||
// content equals
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Copy chars from a <code>Reader</code> to bytes on an
|
||||
* <code>OutputStream</code> using the specified character encoding, and calling
|
||||
@@ -1465,9 +1500,6 @@ public class IO {
|
||||
}
|
||||
}
|
||||
|
||||
// content equals
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Compare the contents of two Streams to determine if they are equal or not.
|
||||
* <p>
|
||||
@@ -1536,12 +1568,4 @@ public class IO {
|
||||
int ch2 = input2.read();
|
||||
return (ch2 == -1);
|
||||
}
|
||||
|
||||
static {
|
||||
// avoid security issues
|
||||
StringWriter buf = new StringWriter(4);
|
||||
PrintWriter out = new PrintWriter(buf);
|
||||
out.println();
|
||||
LINE_SEPARATOR = buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,15 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A JSONObject is an unordered collection of name/value pairs. Its external
|
||||
@@ -83,51 +90,6 @@ import java.util.Map.Entry;
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
public class JSONObject {
|
||||
/**
|
||||
* JSONObject.NULL is equivalent to the value that JavaScript calls null,
|
||||
* whilst Java's null is equivalent to the value that JavaScript calls
|
||||
* undefined.
|
||||
*/
|
||||
private static final class Null {
|
||||
|
||||
/**
|
||||
* There is only intended to be a single instance of the NULL object, so
|
||||
* the clone method returns itself.
|
||||
*
|
||||
* @return NULL.
|
||||
*/
|
||||
@Override
|
||||
protected final Object clone() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Null object is equal to the null value and to itself.
|
||||
*
|
||||
* @param object An object to test for nullness.
|
||||
* @return true if the object parameter is the JSONObject.NULL object or
|
||||
* null.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
return object == null || object == this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "null" string value.
|
||||
*
|
||||
* @return The string "null".
|
||||
*/
|
||||
public String toString() {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The map where the JSONObject's properties are kept.
|
||||
*/
|
||||
private final LinkedHashMap<String, Object> map;
|
||||
|
||||
/**
|
||||
* It is sometimes more convenient and less ambiguous to have a
|
||||
* <code>NULL</code> object than to use Java's <code>null</code> value.
|
||||
@@ -135,6 +97,10 @@ public class JSONObject {
|
||||
* <code>JSONObject.NULL.toString()</code> returns <code>"null"</code>.
|
||||
*/
|
||||
public static final Object NULL = new Null();
|
||||
/**
|
||||
* The map where the JSONObject's properties are kept.
|
||||
*/
|
||||
private final LinkedHashMap<String, Object> map;
|
||||
|
||||
/**
|
||||
* Construct an empty JSONObject.
|
||||
@@ -344,6 +310,401 @@ public class JSONObject {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a string from a double. The string "null" will be returned if the
|
||||
* number is not finite.
|
||||
*
|
||||
* @param d A double.
|
||||
* @return A String.
|
||||
*/
|
||||
public static String doubleToString(double d) {
|
||||
if (Double.isInfinite(d) || Double.isNaN(d)) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
// Shave off trailing zeros and decimal point, if possible.
|
||||
|
||||
String string = Double.toString(d);
|
||||
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
|
||||
while (string.endsWith("0")) {
|
||||
string = string.substring(0, string.length() - 1);
|
||||
}
|
||||
if (string.endsWith(".")) {
|
||||
string = string.substring(0, string.length() - 1);
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of field names from a JSONObject.
|
||||
*
|
||||
* @return An array of field names, or null if there are no names.
|
||||
*/
|
||||
public static String[] getNames(JSONObject jo) {
|
||||
int length = jo.length();
|
||||
if (length == 0) {
|
||||
return null;
|
||||
}
|
||||
Iterator<String> iterator = jo.keys();
|
||||
String[] names = new String[length];
|
||||
int i = 0;
|
||||
while (iterator.hasNext()) {
|
||||
names[i] = iterator.next();
|
||||
i += 1;
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of field names from an Object.
|
||||
*
|
||||
* @return An array of field names, or null if there are no names.
|
||||
*/
|
||||
public static String[] getNames(Object object) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
Class<?> klass = object.getClass();
|
||||
Field[] fields = klass.getFields();
|
||||
int length = fields.length;
|
||||
if (length == 0) {
|
||||
return null;
|
||||
}
|
||||
String[] names = new String[length];
|
||||
for (int i = 0; i < length; i += 1) {
|
||||
names[i] = fields[i].getName();
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a string from a Number.
|
||||
*
|
||||
* @param number A Number
|
||||
* @return A String.
|
||||
* @throws JSONException If n is a non-finite number.
|
||||
*/
|
||||
public static String numberToString(Number number) throws JSONException {
|
||||
if (number == null) {
|
||||
throw new JSONException("Null pointer");
|
||||
}
|
||||
testValidity(number);
|
||||
|
||||
// Shave off trailing zeros and decimal point, if possible.
|
||||
|
||||
String string = number.toString();
|
||||
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
|
||||
while (string.endsWith("0")) {
|
||||
string = string.substring(0, string.length() - 1);
|
||||
}
|
||||
if (string.endsWith(".")) {
|
||||
string = string.substring(0, string.length() - 1);
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a string in double quotes with backslash sequences in all the
|
||||
* right places. A backslash will be inserted within </, producing <\/,
|
||||
* allowing JSON text to be delivered in HTML. In JSON text, a string cannot
|
||||
* contain a control character or an unescaped quote or backslash.
|
||||
*
|
||||
* @param string A String
|
||||
* @return A String correctly formatted for insertion in a JSON text.
|
||||
*/
|
||||
public static String quote(String string) {
|
||||
StringWriter sw = new StringWriter();
|
||||
synchronized (sw.getBuffer()) {
|
||||
try {
|
||||
return quote(string, sw).toString();
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
// will never happen - we are writing to a string writer
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Writer quote(String string, Writer w) throws IOException {
|
||||
if (string == null || string.length() == 0) {
|
||||
w.write("\"\"");
|
||||
return w;
|
||||
}
|
||||
|
||||
char b;
|
||||
char c = 0;
|
||||
String hhhh;
|
||||
int i;
|
||||
int len = string.length();
|
||||
|
||||
w.write('"');
|
||||
for (i = 0; i < len; i += 1) {
|
||||
b = c;
|
||||
c = string.charAt(i);
|
||||
switch (c) {
|
||||
case '\\':
|
||||
case '"':
|
||||
w.write('\\');
|
||||
w.write(c);
|
||||
break;
|
||||
case '/':
|
||||
if (b == '<') {
|
||||
w.write('\\');
|
||||
}
|
||||
w.write(c);
|
||||
break;
|
||||
case '\b':
|
||||
w.write("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
w.write("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
w.write("\\n");
|
||||
break;
|
||||
case '\f':
|
||||
w.write("\\f");
|
||||
break;
|
||||
case '\r':
|
||||
w.write("\\r");
|
||||
break;
|
||||
default:
|
||||
if (c < ' ' || (c >= '\u0080' && c < '\u00a0') || (c >= '\u2000' && c < '\u2100')) {
|
||||
w.write("\\u");
|
||||
hhhh = Integer.toHexString(c);
|
||||
w.write("0000", 0, 4 - hhhh.length());
|
||||
w.write(hhhh);
|
||||
} else {
|
||||
w.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
w.write('"');
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to convert a string into a number, boolean, or null. If the string
|
||||
* can't be converted, return the string.
|
||||
*
|
||||
* @param string A String.
|
||||
* @return A simple JSON value.
|
||||
*/
|
||||
public static Object stringToValue(String string) {
|
||||
Double d;
|
||||
if (string.equals("")) {
|
||||
return string;
|
||||
}
|
||||
if (string.equalsIgnoreCase("true")) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
if (string.equalsIgnoreCase("false")) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
if (string.equalsIgnoreCase("null")) {
|
||||
return JSONObject.NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* If it might be a number, try converting it. If a number cannot be
|
||||
* produced, then the value will just be a string.
|
||||
*/
|
||||
|
||||
char b = string.charAt(0);
|
||||
if ((b >= '0' && b <= '9') || b == '-') {
|
||||
try {
|
||||
if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) {
|
||||
d = Double.valueOf(string);
|
||||
if (!d.isInfinite() && !d.isNaN()) {
|
||||
return d;
|
||||
}
|
||||
} else {
|
||||
Long myLong = Long.valueOf(string);
|
||||
if (string.equals(myLong.toString())) {
|
||||
if (myLong == myLong.intValue()) {
|
||||
return myLong.intValue();
|
||||
} else {
|
||||
return myLong;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw an exception if the object is a NaN or infinite number.
|
||||
*
|
||||
* @param o The object to test.
|
||||
* @throws JSONException If o is a non-finite number.
|
||||
*/
|
||||
public static void testValidity(Object o) throws JSONException {
|
||||
if (o != null) {
|
||||
if (o instanceof Double) {
|
||||
if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
|
||||
throw new JSONException("JSON does not allow non-finite numbers.");
|
||||
}
|
||||
} else if (o instanceof Float) {
|
||||
if (((Float) o).isInfinite() || ((Float) o).isNaN()) {
|
||||
throw new JSONException("JSON does not allow non-finite numbers.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a JSON text of an Object value. If the object has an
|
||||
* value.toJSONString() method, then that method will be used to produce the
|
||||
* JSON text. The method is required to produce a strictly conforming text.
|
||||
* If the object does not contain a toJSONString method (which is the most
|
||||
* common case), then a text will be produced by other means. If the value
|
||||
* is an array or Collection, then a JSONArray will be made from it and its
|
||||
* toJSONString method will be called. If the value is a MAP, then a
|
||||
* JSONObject will be made from it and its toJSONString method will be
|
||||
* called. Otherwise, the value's toString method will be called, and the
|
||||
* result will be quoted.
|
||||
*
|
||||
* <p>
|
||||
* Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @param value The value to be serialized.
|
||||
* @return a printable, displayable, transmittable representation of the
|
||||
* object, beginning with <code>{</code> <small>(left
|
||||
* brace)</small> and ending with <code>}</code> <small>(right
|
||||
* brace)</small>.
|
||||
* @throws JSONException If the value is or contains an invalid number.
|
||||
*/
|
||||
public static String valueToString(Object value) throws JSONException {
|
||||
if (value == null || value.equals(null)) {
|
||||
return "null";
|
||||
}
|
||||
if (value instanceof JSONString) {
|
||||
Object object;
|
||||
try {
|
||||
object = ((JSONString) value).toJSONString();
|
||||
} catch (Exception e) {
|
||||
Iris.reportError(e);
|
||||
throw new JSONException(e);
|
||||
}
|
||||
if (object instanceof String) {
|
||||
return (String) object;
|
||||
}
|
||||
throw new JSONException("Bad value from toJSONString: " + object);
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return numberToString((Number) value);
|
||||
}
|
||||
if (value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray) {
|
||||
return value.toString();
|
||||
}
|
||||
if (value instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) value;
|
||||
return new JSONObject(map).toString();
|
||||
}
|
||||
if (value instanceof Collection) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Object> coll = (Collection<Object>) value;
|
||||
return new JSONArray(coll).toString();
|
||||
}
|
||||
if (value.getClass().isArray()) {
|
||||
return new JSONArray(value).toString();
|
||||
}
|
||||
return quote(value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap an object, if necessary. If the object is null, return the NULL
|
||||
* object. If it is an array or collection, wrap it in a JSONArray. If it is
|
||||
* a map, wrap it in a JSONObject. If it is a standard property (Double,
|
||||
* String, et al) then it is already wrapped. Otherwise, if it comes from
|
||||
* one of the java packages, turn it into a string. And if it doesn't, try
|
||||
* to wrap it in a JSONObject. If the wrapping fails, then null is returned.
|
||||
*
|
||||
* @param object The object to wrap
|
||||
* @return The wrapped value
|
||||
*/
|
||||
public static Object wrap(Object object) {
|
||||
try {
|
||||
if (object == null) {
|
||||
return NULL;
|
||||
}
|
||||
if (object instanceof JSONObject || object instanceof JSONArray || NULL.equals(object) || object instanceof JSONString || object instanceof Byte || object instanceof Character || object instanceof Short || object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Float || object instanceof Double || object instanceof String || object instanceof BigInteger || object instanceof BigDecimal) {
|
||||
return object;
|
||||
}
|
||||
|
||||
if (object instanceof Collection) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Object> coll = (Collection<Object>) object;
|
||||
return new JSONArray(coll);
|
||||
}
|
||||
if (object.getClass().isArray()) {
|
||||
return new JSONArray(object);
|
||||
}
|
||||
if (object instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) object;
|
||||
return new JSONObject(map);
|
||||
}
|
||||
Package objectPackage = object.getClass().getPackage();
|
||||
String objectPackageName = objectPackage != null ? objectPackage.getName() : "";
|
||||
if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || object.getClass().getClassLoader() == null) {
|
||||
return object.toString();
|
||||
}
|
||||
return new JSONObject(object);
|
||||
} catch (Exception e) {
|
||||
Iris.reportError(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent) throws JSONException, IOException {
|
||||
if (value == null || value.equals(null)) {
|
||||
writer.write("null");
|
||||
} else if (value instanceof JSONObject) {
|
||||
((JSONObject) value).write(writer, indentFactor, indent);
|
||||
} else if (value instanceof JSONArray) {
|
||||
((JSONArray) value).write(writer, indentFactor, indent);
|
||||
} else if (value instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) value;
|
||||
new JSONObject(map).write(writer, indentFactor, indent);
|
||||
} else if (value instanceof Collection) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Object> coll = (Collection<Object>) value;
|
||||
new JSONArray(coll).write(writer, indentFactor, indent);
|
||||
} else if (value.getClass().isArray()) {
|
||||
new JSONArray(value).write(writer, indentFactor, indent);
|
||||
} else if (value instanceof Number) {
|
||||
writer.write(numberToString((Number) value));
|
||||
} else if (value instanceof Boolean) {
|
||||
writer.write(value.toString());
|
||||
} else if (value instanceof JSONString) {
|
||||
Object o;
|
||||
try {
|
||||
o = ((JSONString) value).toJSONString();
|
||||
} catch (Exception e) {
|
||||
Iris.reportError(e);
|
||||
throw new JSONException(e);
|
||||
}
|
||||
writer.write(o != null ? o.toString() : quote(value.toString()));
|
||||
} else {
|
||||
quote(value.toString(), writer);
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
|
||||
static final void indent(Writer writer, int indent) throws IOException {
|
||||
for (int i = 0; i < indent; i += 1) {
|
||||
writer.write(' ');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accumulate values under a key. It is similar to the put method except
|
||||
* that if there is already an object stored under the key then a JSONArray
|
||||
@@ -398,32 +759,6 @@ public class JSONObject {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a string from a double. The string "null" will be returned if the
|
||||
* number is not finite.
|
||||
*
|
||||
* @param d A double.
|
||||
* @return A String.
|
||||
*/
|
||||
public static String doubleToString(double d) {
|
||||
if (Double.isInfinite(d) || Double.isNaN(d)) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
// Shave off trailing zeros and decimal point, if possible.
|
||||
|
||||
String string = Double.toString(d);
|
||||
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
|
||||
while (string.endsWith("0")) {
|
||||
string = string.substring(0, string.length() - 1);
|
||||
}
|
||||
if (string.endsWith(".")) {
|
||||
string = string.substring(0, string.length() - 1);
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value object associated with a key.
|
||||
*
|
||||
@@ -600,48 +935,6 @@ public class JSONObject {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of field names from a JSONObject.
|
||||
*
|
||||
* @return An array of field names, or null if there are no names.
|
||||
*/
|
||||
public static String[] getNames(JSONObject jo) {
|
||||
int length = jo.length();
|
||||
if (length == 0) {
|
||||
return null;
|
||||
}
|
||||
Iterator<String> iterator = jo.keys();
|
||||
String[] names = new String[length];
|
||||
int i = 0;
|
||||
while (iterator.hasNext()) {
|
||||
names[i] = iterator.next();
|
||||
i += 1;
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of field names from an Object.
|
||||
*
|
||||
* @return An array of field names, or null if there are no names.
|
||||
*/
|
||||
public static String[] getNames(Object object) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
Class<?> klass = object.getClass();
|
||||
Field[] fields = klass.getFields();
|
||||
int length = fields.length;
|
||||
if (length == 0) {
|
||||
return null;
|
||||
}
|
||||
String[] names = new String[length];
|
||||
for (int i = 0; i < length; i += 1) {
|
||||
names[i] = fields[i].getName();
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string associated with a key.
|
||||
*
|
||||
@@ -754,33 +1047,6 @@ public class JSONObject {
|
||||
return ja.length() == 0 ? null : ja;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a string from a Number.
|
||||
*
|
||||
* @param number A Number
|
||||
* @return A String.
|
||||
* @throws JSONException If n is a non-finite number.
|
||||
*/
|
||||
public static String numberToString(Number number) throws JSONException {
|
||||
if (number == null) {
|
||||
throw new JSONException("Null pointer");
|
||||
}
|
||||
testValidity(number);
|
||||
|
||||
// Shave off trailing zeros and decimal point, if possible.
|
||||
|
||||
String string = number.toString();
|
||||
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
|
||||
while (string.endsWith("0")) {
|
||||
string = string.substring(0, string.length() - 1);
|
||||
}
|
||||
if (string.endsWith(".")) {
|
||||
string = string.substring(0, string.length() - 1);
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an optional value associated with a key.
|
||||
*
|
||||
@@ -1221,86 +1487,6 @@ public class JSONObject {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a string in double quotes with backslash sequences in all the
|
||||
* right places. A backslash will be inserted within </, producing <\/,
|
||||
* allowing JSON text to be delivered in HTML. In JSON text, a string cannot
|
||||
* contain a control character or an unescaped quote or backslash.
|
||||
*
|
||||
* @param string A String
|
||||
* @return A String correctly formatted for insertion in a JSON text.
|
||||
*/
|
||||
public static String quote(String string) {
|
||||
StringWriter sw = new StringWriter();
|
||||
synchronized (sw.getBuffer()) {
|
||||
try {
|
||||
return quote(string, sw).toString();
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
// will never happen - we are writing to a string writer
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Writer quote(String string, Writer w) throws IOException {
|
||||
if (string == null || string.length() == 0) {
|
||||
w.write("\"\"");
|
||||
return w;
|
||||
}
|
||||
|
||||
char b;
|
||||
char c = 0;
|
||||
String hhhh;
|
||||
int i;
|
||||
int len = string.length();
|
||||
|
||||
w.write('"');
|
||||
for (i = 0; i < len; i += 1) {
|
||||
b = c;
|
||||
c = string.charAt(i);
|
||||
switch (c) {
|
||||
case '\\':
|
||||
case '"':
|
||||
w.write('\\');
|
||||
w.write(c);
|
||||
break;
|
||||
case '/':
|
||||
if (b == '<') {
|
||||
w.write('\\');
|
||||
}
|
||||
w.write(c);
|
||||
break;
|
||||
case '\b':
|
||||
w.write("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
w.write("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
w.write("\\n");
|
||||
break;
|
||||
case '\f':
|
||||
w.write("\\f");
|
||||
break;
|
||||
case '\r':
|
||||
w.write("\\r");
|
||||
break;
|
||||
default:
|
||||
if (c < ' ' || (c >= '\u0080' && c < '\u00a0') || (c >= '\u2000' && c < '\u2100')) {
|
||||
w.write("\\u");
|
||||
hhhh = Integer.toHexString(c);
|
||||
w.write("0000", 0, 4 - hhhh.length());
|
||||
w.write(hhhh);
|
||||
} else {
|
||||
w.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
w.write('"');
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a name and its value, if present.
|
||||
*
|
||||
@@ -1353,78 +1539,6 @@ public class JSONObject {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to convert a string into a number, boolean, or null. If the string
|
||||
* can't be converted, return the string.
|
||||
*
|
||||
* @param string A String.
|
||||
* @return A simple JSON value.
|
||||
*/
|
||||
public static Object stringToValue(String string) {
|
||||
Double d;
|
||||
if (string.equals("")) {
|
||||
return string;
|
||||
}
|
||||
if (string.equalsIgnoreCase("true")) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
if (string.equalsIgnoreCase("false")) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
if (string.equalsIgnoreCase("null")) {
|
||||
return JSONObject.NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* If it might be a number, try converting it. If a number cannot be
|
||||
* produced, then the value will just be a string.
|
||||
*/
|
||||
|
||||
char b = string.charAt(0);
|
||||
if ((b >= '0' && b <= '9') || b == '-') {
|
||||
try {
|
||||
if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) {
|
||||
d = Double.valueOf(string);
|
||||
if (!d.isInfinite() && !d.isNaN()) {
|
||||
return d;
|
||||
}
|
||||
} else {
|
||||
Long myLong = Long.valueOf(string);
|
||||
if (string.equals(myLong.toString())) {
|
||||
if (myLong == myLong.intValue()) {
|
||||
return myLong.intValue();
|
||||
} else {
|
||||
return myLong;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw an exception if the object is a NaN or infinite number.
|
||||
*
|
||||
* @param o The object to test.
|
||||
* @throws JSONException If o is a non-finite number.
|
||||
*/
|
||||
public static void testValidity(Object o) throws JSONException {
|
||||
if (o != null) {
|
||||
if (o instanceof Double) {
|
||||
if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
|
||||
throw new JSONException("JSON does not allow non-finite numbers.");
|
||||
}
|
||||
} else if (o instanceof Float) {
|
||||
if (((Float) o).isInfinite() || ((Float) o).isNaN()) {
|
||||
throw new JSONException("JSON does not allow non-finite numbers.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a JSONArray containing the values of the members of this
|
||||
* JSONObject.
|
||||
@@ -1485,112 +1599,6 @@ public class JSONObject {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a JSON text of an Object value. If the object has an
|
||||
* value.toJSONString() method, then that method will be used to produce the
|
||||
* JSON text. The method is required to produce a strictly conforming text.
|
||||
* If the object does not contain a toJSONString method (which is the most
|
||||
* common case), then a text will be produced by other means. If the value
|
||||
* is an array or Collection, then a JSONArray will be made from it and its
|
||||
* toJSONString method will be called. If the value is a MAP, then a
|
||||
* JSONObject will be made from it and its toJSONString method will be
|
||||
* called. Otherwise, the value's toString method will be called, and the
|
||||
* result will be quoted.
|
||||
*
|
||||
* <p>
|
||||
* Warning: This method assumes that the data structure is acyclical.
|
||||
*
|
||||
* @param value The value to be serialized.
|
||||
* @return a printable, displayable, transmittable representation of the
|
||||
* object, beginning with <code>{</code> <small>(left
|
||||
* brace)</small> and ending with <code>}</code> <small>(right
|
||||
* brace)</small>.
|
||||
* @throws JSONException If the value is or contains an invalid number.
|
||||
*/
|
||||
public static String valueToString(Object value) throws JSONException {
|
||||
if (value == null || value.equals(null)) {
|
||||
return "null";
|
||||
}
|
||||
if (value instanceof JSONString) {
|
||||
Object object;
|
||||
try {
|
||||
object = ((JSONString) value).toJSONString();
|
||||
} catch (Exception e) {
|
||||
Iris.reportError(e);
|
||||
throw new JSONException(e);
|
||||
}
|
||||
if (object instanceof String) {
|
||||
return (String) object;
|
||||
}
|
||||
throw new JSONException("Bad value from toJSONString: " + object);
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return numberToString((Number) value);
|
||||
}
|
||||
if (value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray) {
|
||||
return value.toString();
|
||||
}
|
||||
if (value instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) value;
|
||||
return new JSONObject(map).toString();
|
||||
}
|
||||
if (value instanceof Collection) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Object> coll = (Collection<Object>) value;
|
||||
return new JSONArray(coll).toString();
|
||||
}
|
||||
if (value.getClass().isArray()) {
|
||||
return new JSONArray(value).toString();
|
||||
}
|
||||
return quote(value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap an object, if necessary. If the object is null, return the NULL
|
||||
* object. If it is an array or collection, wrap it in a JSONArray. If it is
|
||||
* a map, wrap it in a JSONObject. If it is a standard property (Double,
|
||||
* String, et al) then it is already wrapped. Otherwise, if it comes from
|
||||
* one of the java packages, turn it into a string. And if it doesn't, try
|
||||
* to wrap it in a JSONObject. If the wrapping fails, then null is returned.
|
||||
*
|
||||
* @param object The object to wrap
|
||||
* @return The wrapped value
|
||||
*/
|
||||
public static Object wrap(Object object) {
|
||||
try {
|
||||
if (object == null) {
|
||||
return NULL;
|
||||
}
|
||||
if (object instanceof JSONObject || object instanceof JSONArray || NULL.equals(object) || object instanceof JSONString || object instanceof Byte || object instanceof Character || object instanceof Short || object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Float || object instanceof Double || object instanceof String || object instanceof BigInteger || object instanceof BigDecimal) {
|
||||
return object;
|
||||
}
|
||||
|
||||
if (object instanceof Collection) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Object> coll = (Collection<Object>) object;
|
||||
return new JSONArray(coll);
|
||||
}
|
||||
if (object.getClass().isArray()) {
|
||||
return new JSONArray(object);
|
||||
}
|
||||
if (object instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) object;
|
||||
return new JSONObject(map);
|
||||
}
|
||||
Package objectPackage = object.getClass().getPackage();
|
||||
String objectPackageName = objectPackage != null ? objectPackage.getName() : "";
|
||||
if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || object.getClass().getClassLoader() == null) {
|
||||
return object.toString();
|
||||
}
|
||||
return new JSONObject(object);
|
||||
} catch (Exception e) {
|
||||
Iris.reportError(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the contents of the JSONObject as JSON text to a writer. For
|
||||
* compactness, no whitespace is added.
|
||||
@@ -1604,48 +1612,6 @@ public class JSONObject {
|
||||
return this.write(writer, 0, 0);
|
||||
}
|
||||
|
||||
static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent) throws JSONException, IOException {
|
||||
if (value == null || value.equals(null)) {
|
||||
writer.write("null");
|
||||
} else if (value instanceof JSONObject) {
|
||||
((JSONObject) value).write(writer, indentFactor, indent);
|
||||
} else if (value instanceof JSONArray) {
|
||||
((JSONArray) value).write(writer, indentFactor, indent);
|
||||
} else if (value instanceof Map) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) value;
|
||||
new JSONObject(map).write(writer, indentFactor, indent);
|
||||
} else if (value instanceof Collection) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Object> coll = (Collection<Object>) value;
|
||||
new JSONArray(coll).write(writer, indentFactor, indent);
|
||||
} else if (value.getClass().isArray()) {
|
||||
new JSONArray(value).write(writer, indentFactor, indent);
|
||||
} else if (value instanceof Number) {
|
||||
writer.write(numberToString((Number) value));
|
||||
} else if (value instanceof Boolean) {
|
||||
writer.write(value.toString());
|
||||
} else if (value instanceof JSONString) {
|
||||
Object o;
|
||||
try {
|
||||
o = ((JSONString) value).toJSONString();
|
||||
} catch (Exception e) {
|
||||
Iris.reportError(e);
|
||||
throw new JSONException(e);
|
||||
}
|
||||
writer.write(o != null ? o.toString() : quote(value.toString()));
|
||||
} else {
|
||||
quote(value.toString(), writer);
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
|
||||
static final void indent(Writer writer, int indent) throws IOException {
|
||||
for (int i = 0; i < indent; i += 1) {
|
||||
writer.write(' ');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the contents of the JSONObject as JSON text to a writer. For
|
||||
* compactness, no whitespace is added.
|
||||
@@ -1701,4 +1667,44 @@ public class JSONObject {
|
||||
throw new JSONException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* JSONObject.NULL is equivalent to the value that JavaScript calls null,
|
||||
* whilst Java's null is equivalent to the value that JavaScript calls
|
||||
* undefined.
|
||||
*/
|
||||
private static final class Null {
|
||||
|
||||
/**
|
||||
* There is only intended to be a single instance of the NULL object, so
|
||||
* the clone method returns itself.
|
||||
*
|
||||
* @return NULL.
|
||||
*/
|
||||
@Override
|
||||
protected final Object clone() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Null object is equal to the null value and to itself.
|
||||
*
|
||||
* @param object An object to test for nullness.
|
||||
* @return true if the object parameter is the JSONObject.NULL object or
|
||||
* null.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
return object == null || object == this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "null" string value.
|
||||
*
|
||||
* @return The string "null".
|
||||
*/
|
||||
public String toString() {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,12 @@ package com.volmit.iris.util.json;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
||||
/**
|
||||
* A JSONTokener takes a source string and extracts characters and tokens from
|
||||
@@ -34,12 +39,12 @@ import java.io.*;
|
||||
@SuppressWarnings("ALL")
|
||||
public class JSONTokener {
|
||||
|
||||
private final Reader reader;
|
||||
private long character;
|
||||
private boolean eof;
|
||||
private long index;
|
||||
private long line;
|
||||
private char previous;
|
||||
private final Reader reader;
|
||||
private boolean usePrevious;
|
||||
|
||||
/**
|
||||
@@ -75,21 +80,6 @@ public class JSONTokener {
|
||||
this(new StringReader(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* Back up one character. This provides a sort of lookahead capability, so
|
||||
* that you can test for a digit or letter before attempting to parse the
|
||||
* next number or identifier.
|
||||
*/
|
||||
public void back() throws JSONException {
|
||||
if (this.usePrevious || this.index <= 0) {
|
||||
throw new JSONException("Stepping back two steps is not supported");
|
||||
}
|
||||
this.index -= 1;
|
||||
this.character -= 1;
|
||||
this.usePrevious = true;
|
||||
this.eof = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hex value of a character (base16).
|
||||
*
|
||||
@@ -110,6 +100,21 @@ public class JSONTokener {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Back up one character. This provides a sort of lookahead capability, so
|
||||
* that you can test for a digit or letter before attempting to parse the
|
||||
* next number or identifier.
|
||||
*/
|
||||
public void back() throws JSONException {
|
||||
if (this.usePrevious || this.index <= 0) {
|
||||
throw new JSONException("Stepping back two steps is not supported");
|
||||
}
|
||||
this.index -= 1;
|
||||
this.character -= 1;
|
||||
this.usePrevious = true;
|
||||
this.eof = false;
|
||||
}
|
||||
|
||||
public boolean end() {
|
||||
return this.eof && !this.usePrevious;
|
||||
}
|
||||
|
||||
@@ -59,34 +59,29 @@ import java.io.Writer;
|
||||
*/
|
||||
public class JSONWriter {
|
||||
private static final int maxdepth = 200;
|
||||
|
||||
/**
|
||||
* The comma flag determines if a comma should be output before the next
|
||||
* value.
|
||||
* The writer that will receive the output.
|
||||
*/
|
||||
private boolean comma;
|
||||
|
||||
protected final Writer writer;
|
||||
/**
|
||||
* The object/array stack.
|
||||
*/
|
||||
private final JSONObject[] stack;
|
||||
/**
|
||||
* The current mode. Values: 'a' (array), 'd' (done), 'i' (initial), 'k'
|
||||
* (key), 'o' (object).
|
||||
*/
|
||||
protected char mode;
|
||||
|
||||
/**
|
||||
* The object/array stack.
|
||||
* The comma flag determines if a comma should be output before the next
|
||||
* value.
|
||||
*/
|
||||
private final JSONObject[] stack;
|
||||
|
||||
private boolean comma;
|
||||
/**
|
||||
* The stack top index. A value of 0 indicates that the stack is empty.
|
||||
*/
|
||||
private int top;
|
||||
|
||||
/**
|
||||
* The writer that will receive the output.
|
||||
*/
|
||||
protected final Writer writer;
|
||||
|
||||
/**
|
||||
* Make a fresh JSONWriter. It can be used to build one JSON text.
|
||||
*/
|
||||
|
||||
@@ -82,6 +82,44 @@ public class Mantle {
|
||||
Iris.debug("Opened The Mantle " + C.DARK_AQUA + dataFolder.getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file for a region
|
||||
*
|
||||
* @param folder the folder
|
||||
* @param x the x coord
|
||||
* @param z the z coord
|
||||
* @return the file
|
||||
*/
|
||||
public static File fileForRegion(File folder, int x, int z) {
|
||||
return fileForRegion(folder, key(x, z));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file for the given region
|
||||
*
|
||||
* @param folder the data folder
|
||||
* @param key the region key
|
||||
* @return the file
|
||||
*/
|
||||
public static File fileForRegion(File folder, Long key) {
|
||||
File f = new File(folder, "p." + key + ".ttp");
|
||||
if (!f.getParentFile().exists()) {
|
||||
f.getParentFile().mkdirs();
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the long value representing a chunk or region coordinate
|
||||
*
|
||||
* @param x the x
|
||||
* @param z the z
|
||||
* @return the value
|
||||
*/
|
||||
public static Long key(int x, int z) {
|
||||
return Cache.key(x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise a flag if it is lowered currently, If the flag was raised, execute the runnable
|
||||
*
|
||||
@@ -391,7 +429,6 @@ public class Mantle {
|
||||
return get(x, z);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This retreives a future of the Tectonic Plate at the given coordinates.
|
||||
* All methods accessing tectonic plates should go through this method
|
||||
@@ -449,44 +486,6 @@ public class Mantle {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file for a region
|
||||
*
|
||||
* @param folder the folder
|
||||
* @param x the x coord
|
||||
* @param z the z coord
|
||||
* @return the file
|
||||
*/
|
||||
public static File fileForRegion(File folder, int x, int z) {
|
||||
return fileForRegion(folder, key(x, z));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file for the given region
|
||||
*
|
||||
* @param folder the data folder
|
||||
* @param key the region key
|
||||
* @return the file
|
||||
*/
|
||||
public static File fileForRegion(File folder, Long key) {
|
||||
File f = new File(folder, "p." + key + ".ttp");
|
||||
if (!f.getParentFile().exists()) {
|
||||
f.getParentFile().mkdirs();
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the long value representing a chunk or region coordinate
|
||||
*
|
||||
* @param x the x
|
||||
* @param z the z
|
||||
* @return the value
|
||||
*/
|
||||
public static Long key(int x, int z) {
|
||||
return Cache.key(x, z);
|
||||
}
|
||||
|
||||
public void saveAll() {
|
||||
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
* Mantle Chunks are fully atomic & thread safe
|
||||
*/
|
||||
public class MantleChunk {
|
||||
private static final ZoneMatter zm = new ZoneMatter();
|
||||
@Getter
|
||||
private final int x;
|
||||
@Getter
|
||||
private final int z;
|
||||
private static final ZoneMatter zm = new ZoneMatter();
|
||||
private final AtomicIntegerArray flags;
|
||||
private final AtomicReferenceArray<Matter> sections;
|
||||
private final CopyOnWriteArrayList<IrisFeaturePositional> features;
|
||||
|
||||
@@ -26,7 +26,12 @@ import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
@@ -29,10 +29,10 @@ import com.volmit.iris.util.data.DoubleArrayUtils;
|
||||
*/
|
||||
public class Average {
|
||||
protected final double[] values;
|
||||
protected int cursor;
|
||||
private double average;
|
||||
private double lastSum;
|
||||
private boolean dirty;
|
||||
protected int cursor;
|
||||
private boolean brandNew;
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,14 +40,6 @@ public class AxisAlignedBB {
|
||||
this.zb = zb;
|
||||
}
|
||||
|
||||
public AxisAlignedBB shifted(IrisPosition p) {
|
||||
return shifted(p.getX(), p.getY(), p.getZ());
|
||||
}
|
||||
|
||||
public AxisAlignedBB shifted(double x, double y, double z) {
|
||||
return new AxisAlignedBB(min().add(new IrisPosition((int) x, (int) y, (int) z)), max().add(new IrisPosition((int) x, (int) y, (int) z)));
|
||||
}
|
||||
|
||||
public AxisAlignedBB(AlignedPoint a, AlignedPoint b) {
|
||||
this(a.getX(), b.getX(), a.getY(), b.getY(), a.getZ(), b.getZ());
|
||||
}
|
||||
@@ -56,6 +48,14 @@ public class AxisAlignedBB {
|
||||
this(a.getX(), b.getX(), a.getY(), b.getY(), a.getZ(), b.getZ());
|
||||
}
|
||||
|
||||
public AxisAlignedBB shifted(IrisPosition p) {
|
||||
return shifted(p.getX(), p.getY(), p.getZ());
|
||||
}
|
||||
|
||||
public AxisAlignedBB shifted(double x, double y, double z) {
|
||||
return new AxisAlignedBB(min().add(new IrisPosition((int) x, (int) y, (int) z)), max().add(new IrisPosition((int) x, (int) y, (int) z)));
|
||||
}
|
||||
|
||||
public boolean contains(AlignedPoint p) {
|
||||
return p.getX() >= xa && p.getX() <= xb && p.getY() >= ya && p.getZ() <= yb && p.getZ() >= za && p.getZ() <= zb;
|
||||
}
|
||||
|
||||
@@ -26,17 +26,16 @@ import java.util.Objects;
|
||||
|
||||
@Data
|
||||
public class BlockPosition {
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
//Magic numbers
|
||||
private static final int m1 = 1 + MathHelper.f(MathHelper.c(30000000));
|
||||
private static final int m2 = 64 - (m1 * 2);
|
||||
private static final long m3 = m1 + m2;
|
||||
private static final long m4 = (1L << m1) - 1L;
|
||||
private static final long m5 = (1L << m2) - 1L;
|
||||
private static final long m4 = (1L << m1) - 1L;
|
||||
private static final long m6 = (1L << m1) - 1L;
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
public BlockPosition(int x, int y, int z) {
|
||||
this.x = x;
|
||||
@@ -44,6 +43,14 @@ public class BlockPosition {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public static long toLong(int x, int y, int z) {
|
||||
long var3 = 0L;
|
||||
var3 |= (x & m4) << m3;
|
||||
var3 |= (y & m5);
|
||||
var3 |= (z & m6) << m2;
|
||||
return var3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
@@ -82,14 +89,6 @@ public class BlockPosition {
|
||||
return toLong(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public static long toLong(int x, int y, int z) {
|
||||
long var3 = 0L;
|
||||
var3 |= (x & m4) << m3;
|
||||
var3 |= (y & m5);
|
||||
var3 |= (z & m6) << m2;
|
||||
return var3;
|
||||
}
|
||||
|
||||
public Block toBlock(World world) {
|
||||
return world.getBlockAt(x, y, z);
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ package com.volmit.iris.util.math;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
public class CDou {
|
||||
private double number;
|
||||
private final double max;
|
||||
private double number;
|
||||
|
||||
public CDou(double max) {
|
||||
number = 0;
|
||||
|
||||
@@ -48,6 +48,13 @@ public enum Direction {
|
||||
private final int z;
|
||||
private final CuboidDirection f;
|
||||
|
||||
Direction(int x, int y, int z, CuboidDirection f) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
public static Direction getDirection(BlockFace f) {
|
||||
return switch (f) {
|
||||
case DOWN -> D;
|
||||
@@ -60,23 +67,6 @@ public enum Direction {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return switch (this) {
|
||||
case D -> "Down";
|
||||
case E -> "East";
|
||||
case N -> "North";
|
||||
case S -> "South";
|
||||
case U -> "Up";
|
||||
case W -> "West";
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public boolean isVertical() {
|
||||
return equals(D) || equals(U);
|
||||
}
|
||||
|
||||
public static Direction closest(Vector v) {
|
||||
double m = Double.MAX_VALUE;
|
||||
Direction s = null;
|
||||
@@ -128,75 +118,6 @@ public enum Direction {
|
||||
return s;
|
||||
}
|
||||
|
||||
public Vector toVector() {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
public boolean isCrooked(Direction to) {
|
||||
if (equals(to.reverse())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !equals(to);
|
||||
}
|
||||
|
||||
Direction(int x, int y, int z, CuboidDirection f) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
public Vector angle(Vector initial, Direction d) {
|
||||
calculatePermutations();
|
||||
|
||||
for (Map.Entry<GBiset<Direction, Direction>, DOP> entry : permute.entrySet()) {
|
||||
GBiset<Direction, Direction> i = entry.getKey();
|
||||
if (i.getA().equals(this) && i.getB().equals(d)) {
|
||||
return entry.getValue().op(initial);
|
||||
}
|
||||
}
|
||||
|
||||
return initial;
|
||||
}
|
||||
|
||||
public Direction reverse() {
|
||||
switch (this) {
|
||||
case D:
|
||||
return U;
|
||||
case E:
|
||||
return W;
|
||||
case N:
|
||||
return S;
|
||||
case S:
|
||||
return N;
|
||||
case U:
|
||||
return D;
|
||||
case W:
|
||||
return E;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int z() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public CuboidDirection f() {
|
||||
return f;
|
||||
}
|
||||
|
||||
public static KList<Direction> news() {
|
||||
return new KList<Direction>().add(N, E, W, S);
|
||||
}
|
||||
@@ -245,32 +166,6 @@ public enum Direction {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the byte value represented in some directional blocks
|
||||
*
|
||||
* @return the byte value
|
||||
*/
|
||||
public byte byteValue() {
|
||||
switch (this) {
|
||||
case D:
|
||||
return 0;
|
||||
case E:
|
||||
return 5;
|
||||
case N:
|
||||
return 2;
|
||||
case S:
|
||||
return 3;
|
||||
case U:
|
||||
return 1;
|
||||
case W:
|
||||
return 4;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void calculatePermutations() {
|
||||
if (permute != null) {
|
||||
return;
|
||||
@@ -359,6 +254,111 @@ public enum Direction {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return switch (this) {
|
||||
case D -> "Down";
|
||||
case E -> "East";
|
||||
case N -> "North";
|
||||
case S -> "South";
|
||||
case U -> "Up";
|
||||
case W -> "West";
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public boolean isVertical() {
|
||||
return equals(D) || equals(U);
|
||||
}
|
||||
|
||||
public Vector toVector() {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
public boolean isCrooked(Direction to) {
|
||||
if (equals(to.reverse())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !equals(to);
|
||||
}
|
||||
|
||||
public Vector angle(Vector initial, Direction d) {
|
||||
calculatePermutations();
|
||||
|
||||
for (Map.Entry<GBiset<Direction, Direction>, DOP> entry : permute.entrySet()) {
|
||||
GBiset<Direction, Direction> i = entry.getKey();
|
||||
if (i.getA().equals(this) && i.getB().equals(d)) {
|
||||
return entry.getValue().op(initial);
|
||||
}
|
||||
}
|
||||
|
||||
return initial;
|
||||
}
|
||||
|
||||
public Direction reverse() {
|
||||
switch (this) {
|
||||
case D:
|
||||
return U;
|
||||
case E:
|
||||
return W;
|
||||
case N:
|
||||
return S;
|
||||
case S:
|
||||
return N;
|
||||
case U:
|
||||
return D;
|
||||
case W:
|
||||
return E;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int z() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public CuboidDirection f() {
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the byte value represented in some directional blocks
|
||||
*
|
||||
* @return the byte value
|
||||
*/
|
||||
public byte byteValue() {
|
||||
switch (this) {
|
||||
case D:
|
||||
return 0;
|
||||
case E:
|
||||
return 5;
|
||||
case N:
|
||||
return 2;
|
||||
case S:
|
||||
return 3;
|
||||
case U:
|
||||
return 1;
|
||||
case W:
|
||||
return 4;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public BlockFace getFace() {
|
||||
return switch (this) {
|
||||
case D -> BlockFace.DOWN;
|
||||
|
||||
@@ -30,6 +30,21 @@ public class IrisMathHelper {
|
||||
private static final double[] f;
|
||||
private static final double[] g;
|
||||
|
||||
static {
|
||||
a = c(2.0f);
|
||||
c = new Random();
|
||||
d = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
|
||||
e = Double.longBitsToDouble(4805340802404319232L);
|
||||
f = new double[257];
|
||||
g = new double[257];
|
||||
for (int var2 = 0; var2 < 257; ++var2) {
|
||||
final double var3 = var2 / 256.0;
|
||||
final double var4 = Math.asin(var3);
|
||||
IrisMathHelper.g[var2] = Math.cos(var4);
|
||||
IrisMathHelper.f[var2] = var4;
|
||||
}
|
||||
}
|
||||
|
||||
public static float c(final float var0) {
|
||||
return (float) Math.sqrt(var0);
|
||||
}
|
||||
@@ -436,19 +451,4 @@ public class IrisMathHelper {
|
||||
public static float k(final float var0) {
|
||||
return var0 * var0;
|
||||
}
|
||||
|
||||
static {
|
||||
a = c(2.0f);
|
||||
c = new Random();
|
||||
d = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
|
||||
e = Double.longBitsToDouble(4805340802404319232L);
|
||||
f = new double[257];
|
||||
g = new double[257];
|
||||
for (int var2 = 0; var2 < 257; ++var2) {
|
||||
final double var3 = var2 / 256.0;
|
||||
final double var4 = Math.asin(var3);
|
||||
IrisMathHelper.g[var2] = Math.cos(var4);
|
||||
IrisMathHelper.f[var2] = var4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,12 @@ public class M {
|
||||
private static final float[] sin = new float[modulus];
|
||||
public static int tick = 0;
|
||||
|
||||
static {
|
||||
for (int i = 0; i < sin.length; i++) {
|
||||
sin[i] = (float) Math.sin((i * Math.PI) / (precision * 180));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales B by an external range change so that <br/>
|
||||
* <br/>
|
||||
@@ -355,12 +361,6 @@ public class M {
|
||||
return ms / 1000 / 60 / 60 / 24;
|
||||
}
|
||||
|
||||
static {
|
||||
for (int i = 0; i < sin.length; i++) {
|
||||
sin[i] = (float) Math.sin((i * Math.PI) / (precision * 180));
|
||||
}
|
||||
}
|
||||
|
||||
private static float sinLookup(int a) {
|
||||
return a >= 0 ? sin[a % (modulus)] : -sin[-a % (modulus)];
|
||||
}
|
||||
|
||||
@@ -29,12 +29,6 @@ import java.util.UUID;
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
public class MathHelper {
|
||||
private static final int h = 1024;
|
||||
private static final float i = 1024.0F;
|
||||
private static final long j = 61440L;
|
||||
private static final long k = 16384L;
|
||||
private static final long l = -4611686018427387904L;
|
||||
private static final long m = -9223372036854775808L;
|
||||
public static final float a = 3.1415927F;
|
||||
public static final float b = 1.5707964F;
|
||||
public static final float c = 6.2831855F;
|
||||
@@ -42,6 +36,12 @@ public class MathHelper {
|
||||
public static final float e = 57.295776F;
|
||||
public static final float f = 1.0E-5F;
|
||||
public static final float g = c(2.0F);
|
||||
private static final int h = 1024;
|
||||
private static final float i = 1024.0F;
|
||||
private static final long j = 61440L;
|
||||
private static final long k = 16384L;
|
||||
private static final long l = -4611686018427387904L;
|
||||
private static final long m = -9223372036854775808L;
|
||||
private static final float n = 10430.378F;
|
||||
private static final float[] o = SystemUtils.a(new float[65536], (var0x) -> {
|
||||
for (int var1 = 0; var1 < var0x.length; ++var1) {
|
||||
@@ -58,6 +58,16 @@ public class MathHelper {
|
||||
private static final double[] v = new double[257];
|
||||
private static final double[] w = new double[257];
|
||||
|
||||
static {
|
||||
for (int var0 = 0; var0 < 257; ++var0) {
|
||||
double var1 = (double) var0 / 256.0D;
|
||||
double var3 = Math.asin(var1);
|
||||
w[var0] = Math.cos(var3);
|
||||
v[var0] = var3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public MathHelper() {
|
||||
}
|
||||
|
||||
@@ -794,14 +804,4 @@ public class MathHelper {
|
||||
public static double a(int var0, double var1, int var3) {
|
||||
return Math.sqrt((double) (var0 * var0) + var1 * var1 + (double) (var3 * var3));
|
||||
}
|
||||
|
||||
static {
|
||||
for (int var0 = 0; var0 < 257; ++var0) {
|
||||
double var1 = (double) var0 / 256.0D;
|
||||
double var3 = Math.asin(var1);
|
||||
w[var0] = Math.cos(var3);
|
||||
v[var0] = var3;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,9 @@ import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RNG extends Random {
|
||||
public static final RNG r = new RNG();
|
||||
private static final char[] CHARGEN = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-=!@#$%^&*()_+`~[];',./<>?:\\\"{}|\\\\".toCharArray();
|
||||
private static final long serialVersionUID = 5222938581174415179L;
|
||||
public static final RNG r = new RNG();
|
||||
private final long sx;
|
||||
|
||||
public RNG() {
|
||||
|
||||
@@ -46,14 +46,14 @@ public class RollingSequence extends Average {
|
||||
return f;
|
||||
}
|
||||
|
||||
public void setPrecision(boolean p) {
|
||||
this.precision = p;
|
||||
}
|
||||
|
||||
public boolean isPrecision() {
|
||||
return precision;
|
||||
}
|
||||
|
||||
public void setPrecision(boolean p) {
|
||||
this.precision = p;
|
||||
}
|
||||
|
||||
public double getMin() {
|
||||
if (dirtyExtremes > (isPrecision() ? 0 : values.length)) {
|
||||
resetExtremes();
|
||||
|
||||
@@ -20,9 +20,9 @@ package com.volmit.iris.util.math;
|
||||
|
||||
@SuppressWarnings("EmptyMethod")
|
||||
public class Spiraler {
|
||||
private final Spiraled spiraled;
|
||||
int x, z, dx, dz, sizeX, sizeZ, t, maxI, i;
|
||||
int ox, oz;
|
||||
private final Spiraled spiraled;
|
||||
|
||||
public Spiraler(int sizeX, int sizeZ, Spiraled spiraled) {
|
||||
ox = 0;
|
||||
@@ -31,16 +31,16 @@ public class Spiraler {
|
||||
retarget(sizeX, sizeZ);
|
||||
}
|
||||
|
||||
static void Spiral(int X, int Y) {
|
||||
|
||||
}
|
||||
|
||||
public void drain() {
|
||||
while (hasNext()) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
static void Spiral(int X, int Y) {
|
||||
|
||||
}
|
||||
|
||||
public Spiraler setOffset(int ox, int oz) {
|
||||
this.ox = ox;
|
||||
this.oz = oz;
|
||||
|
||||
@@ -23,6 +23,12 @@ package com.volmit.iris.util.math;
|
||||
* objects containing float or double values. This fixes Issue 36.
|
||||
*/
|
||||
class VecMathUtil {
|
||||
/**
|
||||
* Do not construct an instance of this class.
|
||||
*/
|
||||
private VecMathUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the representation of the specified floating-point
|
||||
* value according to the IEEE 754 floating-point "single format"
|
||||
@@ -78,11 +84,4 @@ class VecMathUtil {
|
||||
return Double.doubleToLongBits(d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Do not construct an instance of this class.
|
||||
*/
|
||||
private VecMathUtil() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,16 @@ public class IrisMatter implements Matter {
|
||||
this.sliceMap = new KMap<>();
|
||||
}
|
||||
|
||||
private static KMap<Class<?>, MatterSlice<?>> buildSlicers() {
|
||||
KMap<Class<?>, MatterSlice<?>> c = new KMap<>();
|
||||
for (Object i : Iris.initialize("com.volmit.iris.util.matter.slices", Sliced.class)) {
|
||||
MatterSlice<?> s = (MatterSlice<?>) i;
|
||||
c.put(s.getType(), s);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> MatterSlice<T> createSlice(Class<T> type, Matter m) {
|
||||
MatterSlice<?> slice = slicers.get(type);
|
||||
@@ -64,14 +74,4 @@ public class IrisMatter implements Matter {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static KMap<Class<?>, MatterSlice<?>> buildSlicers() {
|
||||
KMap<Class<?>, MatterSlice<?>> c = new KMap<>();
|
||||
for (Object i : Iris.initialize("com.volmit.iris.util.matter.slices", Sliced.class)) {
|
||||
MatterSlice<?> s = (MatterSlice<?>) i;
|
||||
c.put(s.getType(), s);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,14 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
@@ -50,6 +57,51 @@ import java.util.function.Function;
|
||||
public interface Matter {
|
||||
int VERSION = 1;
|
||||
|
||||
static Matter read(File f) throws IOException, ClassNotFoundException {
|
||||
FileInputStream in = new FileInputStream(f);
|
||||
Matter m = read(in);
|
||||
in.close();
|
||||
return m;
|
||||
}
|
||||
|
||||
static Matter read(InputStream in) throws IOException, ClassNotFoundException {
|
||||
return read(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the input stream into a matter object using a matter factory.
|
||||
* Does not close the input stream. Be a man, close it yourself.
|
||||
*
|
||||
* @param in the input stream
|
||||
* @param matterFactory the matter factory (size) -> new MatterImpl(size);
|
||||
* @return the matter object
|
||||
* @throws IOException shit happens yo
|
||||
*/
|
||||
static Matter read(InputStream in, Function<BlockPosition, Matter> matterFactory) throws IOException, ClassNotFoundException {
|
||||
DataInputStream din = new DataInputStream(in);
|
||||
Matter matter = matterFactory.apply(new BlockPosition(
|
||||
Varint.readUnsignedVarInt(din),
|
||||
Varint.readUnsignedVarInt(din),
|
||||
Varint.readUnsignedVarInt(din)));
|
||||
int sliceCount = din.readByte();
|
||||
matter.getHeader().read(din);
|
||||
|
||||
while (sliceCount-- > 0) {
|
||||
String cn = din.readUTF();
|
||||
try {
|
||||
Class<?> type = Class.forName(cn);
|
||||
MatterSlice<?> slice = matter.createSlice(type, matter);
|
||||
slice.read(din);
|
||||
matter.putSlice(type, slice);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new IOException("Can't read class '" + cn + "' (slice count reverse at " + sliceCount + ")");
|
||||
}
|
||||
}
|
||||
|
||||
return matter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the header information
|
||||
*
|
||||
@@ -313,51 +365,6 @@ public interface Matter {
|
||||
}
|
||||
}
|
||||
|
||||
static Matter read(File f) throws IOException, ClassNotFoundException {
|
||||
FileInputStream in = new FileInputStream(f);
|
||||
Matter m = read(in);
|
||||
in.close();
|
||||
return m;
|
||||
}
|
||||
|
||||
static Matter read(InputStream in) throws IOException, ClassNotFoundException {
|
||||
return read(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the input stream into a matter object using a matter factory.
|
||||
* Does not close the input stream. Be a man, close it yourself.
|
||||
*
|
||||
* @param in the input stream
|
||||
* @param matterFactory the matter factory (size) -> new MatterImpl(size);
|
||||
* @return the matter object
|
||||
* @throws IOException shit happens yo
|
||||
*/
|
||||
static Matter read(InputStream in, Function<BlockPosition, Matter> matterFactory) throws IOException, ClassNotFoundException {
|
||||
DataInputStream din = new DataInputStream(in);
|
||||
Matter matter = matterFactory.apply(new BlockPosition(
|
||||
Varint.readUnsignedVarInt(din),
|
||||
Varint.readUnsignedVarInt(din),
|
||||
Varint.readUnsignedVarInt(din)));
|
||||
int sliceCount = din.readByte();
|
||||
matter.getHeader().read(din);
|
||||
|
||||
while (sliceCount-- > 0) {
|
||||
String cn = din.readUTF();
|
||||
try {
|
||||
Class<?> type = Class.forName(cn);
|
||||
MatterSlice<?> slice = matter.createSlice(type, matter);
|
||||
slice.read(din);
|
||||
matter.putSlice(type, slice);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new IOException("Can't read class '" + cn + "' (slice count reverse at " + sliceCount + ")");
|
||||
}
|
||||
}
|
||||
|
||||
return matter;
|
||||
}
|
||||
|
||||
default int getTotalCount() {
|
||||
int m = 0;
|
||||
|
||||
|
||||
@@ -27,10 +27,6 @@ import java.io.IOException;
|
||||
|
||||
@Sliced
|
||||
public class CavernMatter extends RawMatter<MatterCavern> {
|
||||
public static MatterCavern get(String customBiome, int liquid) {
|
||||
return new MatterCavern(true, customBiome, (byte) liquid);
|
||||
}
|
||||
|
||||
public CavernMatter() {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
@@ -39,6 +35,10 @@ public class CavernMatter extends RawMatter<MatterCavern> {
|
||||
super(width, height, depth, MatterCavern.class);
|
||||
}
|
||||
|
||||
public static MatterCavern get(String customBiome, int liquid) {
|
||||
return new MatterCavern(true, customBiome, (byte) liquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNode(MatterCavern b, DataOutputStream dos) throws IOException {
|
||||
dos.writeBoolean(b.isCavern());
|
||||
|
||||
@@ -27,10 +27,6 @@ import java.io.IOException;
|
||||
|
||||
@Sliced
|
||||
public class FluidBodyMatter extends RawMatter<MatterFluidBody> {
|
||||
public static MatterFluidBody get(String customBiome, boolean lava) {
|
||||
return new MatterFluidBody(true, customBiome, lava);
|
||||
}
|
||||
|
||||
public FluidBodyMatter() {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
@@ -39,6 +35,10 @@ public class FluidBodyMatter extends RawMatter<MatterFluidBody> {
|
||||
super(width, height, depth, MatterFluidBody.class);
|
||||
}
|
||||
|
||||
public static MatterFluidBody get(String customBiome, boolean lava) {
|
||||
return new MatterFluidBody(true, customBiome, lava);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNode(MatterFluidBody b, DataOutputStream dos) throws IOException {
|
||||
dos.writeBoolean(b.isBody());
|
||||
|
||||
@@ -28,9 +28,9 @@ import java.io.IOException;
|
||||
|
||||
@Sliced
|
||||
public class MarkerMatter extends RawMatter<MatterMarker> {
|
||||
private static final KMap<String, MatterMarker> markers = new KMap<>();
|
||||
public static final MatterMarker CAVE_FLOOR = new MatterMarker("cave_floor");
|
||||
public static final MatterMarker CAVE_CEILING = new MatterMarker("cave_ceiling");
|
||||
private static final KMap<String, MatterMarker> markers = new KMap<>();
|
||||
|
||||
public MarkerMatter() {
|
||||
this(1, 1, 1);
|
||||
|
||||
@@ -30,10 +30,10 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class RawMatter<T> extends MappedHunk<T> implements MatterSlice<T> {
|
||||
@Getter
|
||||
private final Class<T> type;
|
||||
protected final KMap<Class<?>, MatterWriter<?, T>> writers;
|
||||
protected final KMap<Class<?>, MatterReader<?, T>> readers;
|
||||
@Getter
|
||||
private final Class<T> type;
|
||||
|
||||
public RawMatter(int width, int height, int depth, Class<T> type) {
|
||||
super(width, height, depth);
|
||||
|
||||
@@ -20,7 +20,20 @@ package com.volmit.iris.util.nbt.io;
|
||||
|
||||
import com.volmit.iris.engine.data.io.ExceptionBiFunction;
|
||||
import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.nbt.tag.*;
|
||||
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.ByteTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.DoubleTag;
|
||||
import com.volmit.iris.util.nbt.tag.EndTag;
|
||||
import com.volmit.iris.util.nbt.tag.FloatTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongTag;
|
||||
import com.volmit.iris.util.nbt.tag.ShortTag;
|
||||
import com.volmit.iris.util.nbt.tag.StringTag;
|
||||
import com.volmit.iris.util.nbt.tag.Tag;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -49,31 +62,13 @@ public class NBTInputStream extends DataInputStream implements MaxDepthIO {
|
||||
put(LongArrayTag.ID, (i, d) -> readLongArray(i), LongArrayTag.class);
|
||||
}
|
||||
|
||||
private static void put(byte id, ExceptionBiFunction<NBTInputStream, Integer, ? extends Tag<?>, IOException> reader, Class<?> clazz) {
|
||||
readers.put(id, reader);
|
||||
idClassMapping.put(id, clazz);
|
||||
}
|
||||
|
||||
public NBTInputStream(InputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
public NamedTag readTag(int maxDepth) throws IOException {
|
||||
byte id = readByte();
|
||||
return new NamedTag(readUTF(), readTag(id, maxDepth));
|
||||
}
|
||||
|
||||
public Tag<?> readRawTag(int maxDepth) throws IOException {
|
||||
byte id = readByte();
|
||||
return readTag(id, maxDepth);
|
||||
}
|
||||
|
||||
private Tag<?> readTag(byte type, int maxDepth) throws IOException {
|
||||
ExceptionBiFunction<NBTInputStream, Integer, ? extends Tag<?>, IOException> f;
|
||||
if ((f = readers.get(type)) == null) {
|
||||
throw new IOException("invalid tag id \"" + type + "\"");
|
||||
}
|
||||
return f.accept(this, maxDepth);
|
||||
private static void put(byte id, ExceptionBiFunction<NBTInputStream, Integer, ? extends Tag<?>, IOException> reader, Class<?> clazz) {
|
||||
readers.put(id, reader);
|
||||
idClassMapping.put(id, clazz);
|
||||
}
|
||||
|
||||
private static ByteTag readByte(NBTInputStream in) throws IOException {
|
||||
@@ -152,4 +147,22 @@ public class NBTInputStream extends DataInputStream implements MaxDepthIO {
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
||||
public NamedTag readTag(int maxDepth) throws IOException {
|
||||
byte id = readByte();
|
||||
return new NamedTag(readUTF(), readTag(id, maxDepth));
|
||||
}
|
||||
|
||||
public Tag<?> readRawTag(int maxDepth) throws IOException {
|
||||
byte id = readByte();
|
||||
return readTag(id, maxDepth);
|
||||
}
|
||||
|
||||
private Tag<?> readTag(byte type, int maxDepth) throws IOException {
|
||||
ExceptionBiFunction<NBTInputStream, Integer, ? extends Tag<?>, IOException> f;
|
||||
if ((f = readers.get(type)) == null) {
|
||||
throw new IOException("invalid tag id \"" + type + "\"");
|
||||
}
|
||||
return f.accept(this, maxDepth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,20 @@ package com.volmit.iris.util.nbt.io;
|
||||
|
||||
import com.volmit.iris.engine.data.io.ExceptionTriConsumer;
|
||||
import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.nbt.tag.*;
|
||||
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.ByteTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.DoubleTag;
|
||||
import com.volmit.iris.util.nbt.tag.EndTag;
|
||||
import com.volmit.iris.util.nbt.tag.FloatTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongTag;
|
||||
import com.volmit.iris.util.nbt.tag.ShortTag;
|
||||
import com.volmit.iris.util.nbt.tag.StringTag;
|
||||
import com.volmit.iris.util.nbt.tag.Tag;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -50,37 +63,13 @@ public class NBTOutputStream extends DataOutputStream implements MaxDepthIO {
|
||||
put(LongArrayTag.ID, (o, t, d) -> writeLongArray(o, t), LongArrayTag.class);
|
||||
}
|
||||
|
||||
private static void put(byte id, ExceptionTriConsumer<NBTOutputStream, Tag<?>, Integer, IOException> f, Class<?> clazz) {
|
||||
writers.put(id, f);
|
||||
classIdMapping.put(clazz, id);
|
||||
}
|
||||
|
||||
public NBTOutputStream(OutputStream out) {
|
||||
super(out);
|
||||
}
|
||||
|
||||
public void writeTag(NamedTag tag, int maxDepth) throws IOException {
|
||||
writeByte(tag.getTag().getID());
|
||||
if (tag.getTag().getID() != 0) {
|
||||
writeUTF(tag.getName() == null ? "" : tag.getName());
|
||||
}
|
||||
writeRawTag(tag.getTag(), maxDepth);
|
||||
}
|
||||
|
||||
public void writeTag(Tag<?> tag, int maxDepth) throws IOException {
|
||||
writeByte(tag.getID());
|
||||
if (tag.getID() != 0) {
|
||||
writeUTF("");
|
||||
}
|
||||
writeRawTag(tag, maxDepth);
|
||||
}
|
||||
|
||||
public void writeRawTag(Tag<?> tag, int maxDepth) throws IOException {
|
||||
ExceptionTriConsumer<NBTOutputStream, Tag<?>, Integer, IOException> f;
|
||||
if ((f = writers.get(tag.getID())) == null) {
|
||||
throw new IOException("invalid tag \"" + tag.getID() + "\"");
|
||||
}
|
||||
f.accept(this, tag, maxDepth);
|
||||
private static void put(byte id, ExceptionTriConsumer<NBTOutputStream, Tag<?>, Integer, IOException> f, Class<?> clazz) {
|
||||
writers.put(id, f);
|
||||
classIdMapping.put(clazz, id);
|
||||
}
|
||||
|
||||
static byte idFromClass(Class<?> clazz) {
|
||||
@@ -157,4 +146,28 @@ public class NBTOutputStream extends DataOutputStream implements MaxDepthIO {
|
||||
}
|
||||
out.writeByte(0);
|
||||
}
|
||||
|
||||
public void writeTag(NamedTag tag, int maxDepth) throws IOException {
|
||||
writeByte(tag.getTag().getID());
|
||||
if (tag.getTag().getID() != 0) {
|
||||
writeUTF(tag.getName() == null ? "" : tag.getName());
|
||||
}
|
||||
writeRawTag(tag.getTag(), maxDepth);
|
||||
}
|
||||
|
||||
public void writeTag(Tag<?> tag, int maxDepth) throws IOException {
|
||||
writeByte(tag.getID());
|
||||
if (tag.getID() != 0) {
|
||||
writeUTF("");
|
||||
}
|
||||
writeRawTag(tag, maxDepth);
|
||||
}
|
||||
|
||||
public void writeRawTag(Tag<?> tag, int maxDepth) throws IOException {
|
||||
ExceptionTriConsumer<NBTOutputStream, Tag<?>, Integer, IOException> f;
|
||||
if ((f = writers.get(tag.getID())) == null) {
|
||||
throw new IOException("invalid tag \"" + tag.getID() + "\"");
|
||||
}
|
||||
f.accept(this, tag, maxDepth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,13 @@ package com.volmit.iris.util.nbt.io;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.Tag;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PushbackInputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public final class NBTUtil {
|
||||
|
||||
@@ -30,19 +30,19 @@ public class NamedTag {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setTag(Tag<?> tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Tag<?> getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(Tag<?> tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,21 @@ package com.volmit.iris.util.nbt.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.nbt.tag.*;
|
||||
import com.volmit.iris.util.nbt.tag.ArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.ByteTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.DoubleTag;
|
||||
import com.volmit.iris.util.nbt.tag.EndTag;
|
||||
import com.volmit.iris.util.nbt.tag.FloatTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongTag;
|
||||
import com.volmit.iris.util.nbt.tag.ShortTag;
|
||||
import com.volmit.iris.util.nbt.tag.StringTag;
|
||||
import com.volmit.iris.util.nbt.tag.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,7 +19,20 @@
|
||||
package com.volmit.iris.util.nbt.io;
|
||||
|
||||
import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.nbt.tag.*;
|
||||
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.ByteTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.DoubleTag;
|
||||
import com.volmit.iris.util.nbt.tag.EndTag;
|
||||
import com.volmit.iris.util.nbt.tag.FloatTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.IntTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongTag;
|
||||
import com.volmit.iris.util.nbt.tag.ShortTag;
|
||||
import com.volmit.iris.util.nbt.tag.StringTag;
|
||||
import com.volmit.iris.util.nbt.tag.Tag;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
@@ -49,6 +62,23 @@ public final class SNBTWriter implements MaxDepthIO {
|
||||
write(tag, writer, Tag.DEFAULT_MAX_DEPTH);
|
||||
}
|
||||
|
||||
public static String escapeString(String s) {
|
||||
if (!NON_QUOTE_PATTERN.matcher(s).matches()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('"');
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '\\' || c == '"') {
|
||||
sb.append('\\');
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
sb.append('"');
|
||||
return sb.toString();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private void writeAnything(Tag<?> tag, int maxDepth) throws IOException {
|
||||
switch (tag.getID()) {
|
||||
case EndTag.ID:
|
||||
@@ -115,21 +145,4 @@ public final class SNBTWriter implements MaxDepthIO {
|
||||
}
|
||||
writer.write(']');
|
||||
}
|
||||
|
||||
public static String escapeString(String s) {
|
||||
if (!NON_QUOTE_PATTERN.matcher(s).matches()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('"');
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '\\' || c == '"') {
|
||||
sb.append('\\');
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
sb.append('"');
|
||||
return sb.toString();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,16 @@ public class StringPointer {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private static boolean isSimpleChar(char c) {
|
||||
return c >= 'a' && c <= 'z'
|
||||
|| c >= 'A' && c <= 'Z'
|
||||
|| c >= '0' && c <= '9'
|
||||
|| c == '-'
|
||||
|| c == '+'
|
||||
|| c == '.'
|
||||
|| c == '_';
|
||||
}
|
||||
|
||||
public String parseSimpleString() {
|
||||
int oldIndex = index;
|
||||
while (hasNext() && isSimpleChar(currentChar())) {
|
||||
@@ -117,16 +127,6 @@ public class StringPointer {
|
||||
return value.charAt(index + offset);
|
||||
}
|
||||
|
||||
private static boolean isSimpleChar(char c) {
|
||||
return c >= 'a' && c <= 'z'
|
||||
|| c >= 'A' && c <= 'Z'
|
||||
|| c >= '0' && c <= '9'
|
||||
|| c == '-'
|
||||
|| c == '+'
|
||||
|| c == '.'
|
||||
|| c == '_';
|
||||
}
|
||||
|
||||
public ParseException parseException(String msg) {
|
||||
return new ParseException(msg, value, index);
|
||||
}
|
||||
|
||||
@@ -27,13 +27,19 @@ import com.volmit.iris.util.nbt.mca.palette.BiomeContainer;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
import static com.volmit.iris.util.nbt.mca.LoadFlags.*;
|
||||
|
||||
public class Chunk {
|
||||
public static final int DEFAULT_DATA_VERSION = 2730;
|
||||
private final AtomicReferenceArray<Section> sections = new AtomicReferenceArray<>(16);
|
||||
private boolean partial;
|
||||
private int lastMCAUpdate;
|
||||
private CompoundTag data;
|
||||
@@ -43,7 +49,6 @@ public class Chunk {
|
||||
private BiomeContainer biomes;
|
||||
private CompoundTag heightMaps;
|
||||
private CompoundTag carvingMasks;
|
||||
private final AtomicReferenceArray<Section> sections = new AtomicReferenceArray<>(16);
|
||||
private ListTag<CompoundTag> entities;
|
||||
private ListTag<CompoundTag> tileEntities;
|
||||
private ListTag<CompoundTag> tileTicks;
|
||||
@@ -70,6 +75,23 @@ public class Chunk {
|
||||
setStatus("full");
|
||||
}
|
||||
|
||||
public static Chunk newChunk() {
|
||||
Chunk c = new Chunk(0);
|
||||
c.dataVersion = DEFAULT_DATA_VERSION;
|
||||
c.data = new CompoundTag();
|
||||
c.biomes = INMS.get().newBiomeContainer(0, 256);
|
||||
c.data.put("Level", defaultLevel());
|
||||
c.status = "full";
|
||||
return c;
|
||||
}
|
||||
|
||||
private static CompoundTag defaultLevel() {
|
||||
CompoundTag level = new CompoundTag();
|
||||
level.putString("Status", "full");
|
||||
level.putString("Generator", "Iris Headless " + Iris.instance.getDescription().getVersion());
|
||||
return level;
|
||||
}
|
||||
|
||||
private void initReferences(long loadFlags) {
|
||||
if (data == null) {
|
||||
throw new NullPointerException("data cannot be null");
|
||||
@@ -550,23 +572,6 @@ public class Chunk {
|
||||
}
|
||||
}
|
||||
|
||||
public static Chunk newChunk() {
|
||||
Chunk c = new Chunk(0);
|
||||
c.dataVersion = DEFAULT_DATA_VERSION;
|
||||
c.data = new CompoundTag();
|
||||
c.biomes = INMS.get().newBiomeContainer(0, 256);
|
||||
c.data.put("Level", defaultLevel());
|
||||
c.status = "full";
|
||||
return c;
|
||||
}
|
||||
|
||||
private static CompoundTag defaultLevel() {
|
||||
CompoundTag level = new CompoundTag();
|
||||
level.putString("Status", "full");
|
||||
level.putString("Generator", "Iris Headless " + Iris.instance.getDescription().getVersion());
|
||||
return level;
|
||||
}
|
||||
|
||||
public CompoundTag updateHandle(int xPos, int zPos) {
|
||||
data.putInt("DataVersion", dataVersion);
|
||||
CompoundTag level = data.getCompoundTag("Level");
|
||||
|
||||
@@ -44,6 +44,15 @@ public enum CompressionType {
|
||||
this.decompressor = decompressor;
|
||||
}
|
||||
|
||||
public static CompressionType getFromID(byte id) {
|
||||
for (CompressionType c : CompressionType.values()) {
|
||||
if (c.id == id) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte getID() {
|
||||
return id;
|
||||
}
|
||||
@@ -55,13 +64,4 @@ public enum CompressionType {
|
||||
public InputStream decompress(InputStream in) throws IOException {
|
||||
return decompressor.accept(in);
|
||||
}
|
||||
|
||||
public static CompressionType getFromID(byte id) {
|
||||
for (CompressionType c : CompressionType.values()) {
|
||||
if (c.id == id) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,18 @@ public class MCAFile {
|
||||
this.regionZ = regionZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the index of a chunk from its x- and z-coordinates in this region.
|
||||
* This works with absolute and relative coordinates.
|
||||
*
|
||||
* @param chunkX The x-coordinate of the chunk.
|
||||
* @param chunkZ The z-coordinate of the chunk.
|
||||
* @return The index of this chunk.
|
||||
*/
|
||||
public static int getChunkIndex(int chunkX, int chunkZ) {
|
||||
return (chunkX & 0x1F) + (chunkZ & 0x1F) * 32;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an .mca file from a {@code RandomAccessFile} into this object.
|
||||
* This method does not perform any cleanups on the data.
|
||||
@@ -245,18 +257,6 @@ public class MCAFile {
|
||||
return getChunk(chunkX, chunkZ) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the index of a chunk from its x- and z-coordinates in this region.
|
||||
* This works with absolute and relative coordinates.
|
||||
*
|
||||
* @param chunkX The x-coordinate of the chunk.
|
||||
* @param chunkZ The z-coordinate of the chunk.
|
||||
* @return The index of this chunk.
|
||||
*/
|
||||
public static int getChunkIndex(int chunkX, int chunkZ) {
|
||||
return (chunkX & 0x1F) + (chunkZ & 0x1F) * 32;
|
||||
}
|
||||
|
||||
private int checkIndex(int index) {
|
||||
if (index < 0 || index > 1023) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
|
||||
@@ -35,6 +35,8 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public final class MCAUtil {
|
||||
|
||||
private static final Pattern mcaFilePattern = Pattern.compile("^.*r\\.(?<regionX>-?\\d+)\\.(?<regionZ>-?\\d+)\\.mca$");
|
||||
|
||||
private MCAUtil() {
|
||||
}
|
||||
|
||||
@@ -259,8 +261,6 @@ public final class MCAUtil {
|
||||
return chunk << 4;
|
||||
}
|
||||
|
||||
private static final Pattern mcaFilePattern = Pattern.compile("^.*r\\.(?<regionX>-?\\d+)\\.(?<regionZ>-?\\d+)\\.mca$");
|
||||
|
||||
public static MCAFile newMCAFile(File file) {
|
||||
Matcher m = mcaFilePattern.matcher(file.getName());
|
||||
if (m.find()) {
|
||||
|
||||
@@ -89,6 +89,49 @@ public class NBTWorld {
|
||||
});
|
||||
}
|
||||
|
||||
public static BlockData getBlockData(CompoundTag tag) {
|
||||
if (tag == null) {
|
||||
return B.getAir();
|
||||
}
|
||||
|
||||
StringBuilder p = new StringBuilder(tag.getString("Name"));
|
||||
|
||||
if (tag.containsKey("Properties")) {
|
||||
CompoundTag props = tag.getCompoundTag("Properties");
|
||||
p.append('[');
|
||||
|
||||
for (String i : props.keySet()) {
|
||||
p.append(i).append('=').append(props.getString(i)).append(',');
|
||||
}
|
||||
|
||||
p.deleteCharAt(p.length() - 1).append(']');
|
||||
}
|
||||
|
||||
BlockData b = B.getOrNull(p.toString());
|
||||
|
||||
if (b == null) {
|
||||
return B.getAir();
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public static CompoundTag getCompound(BlockData bd) {
|
||||
return blockDataCache.computeIfAbsent(bd, BLOCK_DATA_COMPUTE).clone();
|
||||
}
|
||||
|
||||
private static Map<Biome, Integer> computeBiomeIDs() {
|
||||
Map<Biome, Integer> biomeIds = new KMap<>();
|
||||
|
||||
for (Biome biome : Biome.values()) {
|
||||
if (!biome.name().equals("CUSTOM")) {
|
||||
biomeIds.put(biome, INMS.get().getBiomeId(biome));
|
||||
}
|
||||
}
|
||||
|
||||
return biomeIds;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
||||
for (Long i : loadedRegions.k()) {
|
||||
@@ -184,37 +227,6 @@ public class NBTWorld {
|
||||
return new File(worldFolder, "region/r." + x + "." + z + ".mca");
|
||||
}
|
||||
|
||||
public static BlockData getBlockData(CompoundTag tag) {
|
||||
if (tag == null) {
|
||||
return B.getAir();
|
||||
}
|
||||
|
||||
StringBuilder p = new StringBuilder(tag.getString("Name"));
|
||||
|
||||
if (tag.containsKey("Properties")) {
|
||||
CompoundTag props = tag.getCompoundTag("Properties");
|
||||
p.append('[');
|
||||
|
||||
for (String i : props.keySet()) {
|
||||
p.append(i).append('=').append(props.getString(i)).append(',');
|
||||
}
|
||||
|
||||
p.deleteCharAt(p.length() - 1).append(']');
|
||||
}
|
||||
|
||||
BlockData b = B.getOrNull(p.toString());
|
||||
|
||||
if (b == null) {
|
||||
return B.getAir();
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public static CompoundTag getCompound(BlockData bd) {
|
||||
return blockDataCache.computeIfAbsent(bd, BLOCK_DATA_COMPUTE).clone();
|
||||
}
|
||||
|
||||
public BlockData getBlockData(int x, int y, int z) {
|
||||
try {
|
||||
CompoundTag tag = getChunkSection(x >> 4, y >> 4, z >> 4).getBlockStateAt(x & 15, y & 15, z & 15);
|
||||
@@ -317,16 +329,4 @@ public class NBTWorld {
|
||||
public int size() {
|
||||
return loadedRegions.size();
|
||||
}
|
||||
|
||||
private static Map<Biome, Integer> computeBiomeIDs() {
|
||||
Map<Biome, Integer> biomeIds = new KMap<>();
|
||||
|
||||
for (Biome biome : Biome.values()) {
|
||||
if (!biome.name().equals("CUSTOM")) {
|
||||
biomeIds.put(biome, INMS.get().getBiomeId(biome));
|
||||
}
|
||||
}
|
||||
|
||||
return biomeIds;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,18 @@ public class Section {
|
||||
Section() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty Section with base values.
|
||||
*
|
||||
* @return An empty Section
|
||||
*/
|
||||
public static Section newSection() {
|
||||
Section s = new Section();
|
||||
s.data = new CompoundTag();
|
||||
s.palette = INMS.get().createPalette();
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the data of this Section is empty.
|
||||
*
|
||||
@@ -141,18 +153,6 @@ public class Section {
|
||||
this.skyLight = skyLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty Section with base values.
|
||||
*
|
||||
* @return An empty Section
|
||||
*/
|
||||
public static Section newSection() {
|
||||
Section s = new Section();
|
||||
s.data = new CompoundTag();
|
||||
s.palette = INMS.get().createPalette();
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the raw CompoundTag that this Section is based on.
|
||||
* This must be called before saving a Section to disk if the Section was manually created
|
||||
|
||||
@@ -28,12 +28,9 @@ import java.util.List;
|
||||
|
||||
public class IdMapper<T> implements IdMap<T> {
|
||||
public static final int DEFAULT = -1;
|
||||
|
||||
private int nextId;
|
||||
|
||||
private final IdentityHashMap<T, Integer> tToId;
|
||||
|
||||
private final List<T> idToT;
|
||||
private int nextId;
|
||||
|
||||
public IdMapper(IdentityHashMap<T, Integer> tToId, List<T> idToT, int nextId) {
|
||||
this.tToId = tToId;
|
||||
|
||||
@@ -24,35 +24,34 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Mth {
|
||||
private static final int BIG_ENOUGH_INT = 1024;
|
||||
|
||||
private static final float BIG_ENOUGH_FLOAT = 1024.0F;
|
||||
|
||||
private static final long UUID_VERSION = 61440L;
|
||||
|
||||
private static final long UUID_VERSION_TYPE_4 = 16384L;
|
||||
|
||||
private static final long UUID_VARIANT = -4611686018427387904L;
|
||||
|
||||
private static final long UUID_VARIANT_2 = -9223372036854775808L;
|
||||
|
||||
public static final float PI = 3.1415927F;
|
||||
|
||||
public static final float HALF_PI = 1.5707964F;
|
||||
|
||||
public static final float TWO_PI = 6.2831855F;
|
||||
|
||||
public static final float DEG_TO_RAD = 0.017453292F;
|
||||
|
||||
public static final float RAD_TO_DEG = 57.295776F;
|
||||
|
||||
public static final float EPSILON = 1.0E-5F;
|
||||
|
||||
public static final float SQRT_OF_TWO = sqrt(2.0F);
|
||||
|
||||
private static final int BIG_ENOUGH_INT = 1024;
|
||||
private static final float BIG_ENOUGH_FLOAT = 1024.0F;
|
||||
private static final long UUID_VERSION = 61440L;
|
||||
private static final long UUID_VERSION_TYPE_4 = 16384L;
|
||||
private static final long UUID_VARIANT = -4611686018427387904L;
|
||||
private static final long UUID_VARIANT_2 = -9223372036854775808L;
|
||||
private static final float SIN_SCALE = 10430.378F;
|
||||
|
||||
private static final float[] SIN;
|
||||
private static final Random RANDOM = new Random();
|
||||
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{
|
||||
0, 1, 28, 2, 29, 14, 24, 3, 30, 22,
|
||||
20, 15, 25, 17, 4, 8, 31, 27, 13, 23,
|
||||
21, 19, 16, 7, 26, 12, 18, 6, 11, 5,
|
||||
10, 9};
|
||||
private static final double ONE_SIXTH = 0.16666666666666666D;
|
||||
private static final int FRAC_EXP = 8;
|
||||
private static final int LUT_SIZE = 257;
|
||||
private static final double FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L);
|
||||
private static final double[] ASIN_TAB = new double[257];
|
||||
private static final double[] COS_TAB = new double[257];
|
||||
|
||||
static {
|
||||
SIN = make(new float[65536], var0 -> {
|
||||
@@ -61,6 +60,15 @@ public class Mth {
|
||||
});
|
||||
}
|
||||
|
||||
static {
|
||||
for (int var0 = 0; var0 < 257; var0++) {
|
||||
double var1 = var0 / 256.0D;
|
||||
double var3 = Math.asin(var1);
|
||||
COS_TAB[var0] = Math.cos(var3);
|
||||
ASIN_TAB[var0] = var3;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T make(Supplier<T> var0) {
|
||||
return var0.get();
|
||||
}
|
||||
@@ -70,8 +78,6 @@ public class Mth {
|
||||
return var0;
|
||||
}
|
||||
|
||||
private static final Random RANDOM = new Random();
|
||||
|
||||
public static float sin(float var0) {
|
||||
return SIN[(int) (var0 * 10430.378F) & 0xFFFF];
|
||||
}
|
||||
@@ -325,18 +331,6 @@ public class Mth {
|
||||
return (var0 != 0 && (var0 & var0 - 1) == 0);
|
||||
}
|
||||
|
||||
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{
|
||||
0, 1, 28, 2, 29, 14, 24, 3, 30, 22,
|
||||
20, 15, 25, 17, 4, 8, 31, 27, 13, 23,
|
||||
21, 19, 16, 7, 26, 12, 18, 6, 11, 5,
|
||||
10, 9};
|
||||
|
||||
private static final double ONE_SIXTH = 0.16666666666666666D;
|
||||
|
||||
private static final int FRAC_EXP = 8;
|
||||
|
||||
private static final int LUT_SIZE = 257;
|
||||
|
||||
public static int ceillog2(int var0) {
|
||||
var0 = isPowerOfTwo(var0) ? var0 : smallestEncompassingPowerOfTwo(var0);
|
||||
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int) (var0 * 125613361L >> 27L) & 0x1F];
|
||||
@@ -471,21 +465,6 @@ public class Mth {
|
||||
return var2;
|
||||
}
|
||||
|
||||
private static final double FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L);
|
||||
|
||||
private static final double[] ASIN_TAB = new double[257];
|
||||
|
||||
private static final double[] COS_TAB = new double[257];
|
||||
|
||||
static {
|
||||
for (int var0 = 0; var0 < 257; var0++) {
|
||||
double var1 = var0 / 256.0D;
|
||||
double var3 = Math.asin(var1);
|
||||
COS_TAB[var0] = Math.cos(var3);
|
||||
ASIN_TAB[var0] = var3;
|
||||
}
|
||||
}
|
||||
|
||||
public static int hsvToRgb(float var0, float var1, float var2) {
|
||||
float var8, var9, var10;
|
||||
int var11, var12, var13, var3 = (int) (var0 * 6.0F) % 6;
|
||||
|
||||
@@ -26,12 +26,9 @@ import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
private static final int SIZE = 4096;
|
||||
|
||||
public static final int GLOBAL_PALETTE_BITS = 9;
|
||||
|
||||
public static final int MIN_PALETTE_SIZE = 4;
|
||||
|
||||
private static final int SIZE = 4096;
|
||||
private final Palette<T> globalPalette;
|
||||
|
||||
private final PaletteResize<T> dummyPaletteResize = (var0, var1) -> 0;
|
||||
|
||||
@@ -21,7 +21,11 @@ package com.volmit.iris.util.nbt.tag;
|
||||
import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@@ -33,15 +37,15 @@ public class CompoundTag extends Tag<Map<String, Tag<?>>> implements Iterable<Ma
|
||||
super(createEmptyValue());
|
||||
}
|
||||
|
||||
private static Map<String, Tag<?>> createEmptyValue() {
|
||||
return new KMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
private static Map<String, Tag<?>> createEmptyValue() {
|
||||
return new KMap<>();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return getValue().size();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,11 @@ package com.volmit.iris.util.nbt.tag;
|
||||
import com.volmit.iris.engine.data.io.MaxDepthIO;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -43,14 +47,17 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
|
||||
super(createEmptyValue(3));
|
||||
}
|
||||
|
||||
public ListTag<T> makeAtomic() {
|
||||
setValue(new CopyOnWriteArrayList<>(getValue()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getID() {
|
||||
return ID;
|
||||
/**
|
||||
* @param typeClass The exact class of the elements
|
||||
* @throws IllegalArgumentException When {@code typeClass} is {@link EndTag}{@code .class}
|
||||
* @throws NullPointerException When {@code typeClass} is {@code null}
|
||||
*/
|
||||
public ListTag(Class<? super T> typeClass) throws IllegalArgumentException, NullPointerException {
|
||||
super(createEmptyValue(3));
|
||||
if (typeClass == EndTag.class) {
|
||||
throw new IllegalArgumentException("cannot create ListTag with EndTag elements");
|
||||
}
|
||||
this.typeClass = Objects.requireNonNull(typeClass);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,17 +86,14 @@ public class ListTag<T extends Tag<?>> extends Tag<List<T>> implements Iterable<
|
||||
return new KList<>(initialCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param typeClass The exact class of the elements
|
||||
* @throws IllegalArgumentException When {@code typeClass} is {@link EndTag}{@code .class}
|
||||
* @throws NullPointerException When {@code typeClass} is {@code null}
|
||||
*/
|
||||
public ListTag(Class<? super T> typeClass) throws IllegalArgumentException, NullPointerException {
|
||||
super(createEmptyValue(3));
|
||||
if (typeClass == EndTag.class) {
|
||||
throw new IllegalArgumentException("cannot create ListTag with EndTag elements");
|
||||
}
|
||||
this.typeClass = Objects.requireNonNull(typeClass);
|
||||
public ListTag<T> makeAtomic() {
|
||||
setValue(new CopyOnWriteArrayList<>(getValue()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public Class<?> getTypeClass() {
|
||||
|
||||
@@ -59,6 +59,8 @@ public abstract class Tag<T> implements Cloneable {
|
||||
public static final int DEFAULT_MAX_DEPTH = 512;
|
||||
|
||||
private static final Map<String, String> ESCAPE_CHARACTERS;
|
||||
private static final Pattern ESCAPE_PATTERN = Pattern.compile("[\\\\\n\t\r\"]");
|
||||
private static final Pattern NON_QUOTE_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-+]+");
|
||||
|
||||
static {
|
||||
final Map<String, String> temp = new HashMap<>();
|
||||
@@ -71,9 +73,6 @@ public abstract class Tag<T> implements Cloneable {
|
||||
ESCAPE_CHARACTERS = Collections.unmodifiableMap(temp);
|
||||
}
|
||||
|
||||
private static final Pattern ESCAPE_PATTERN = Pattern.compile("[\\\\\n\t\r\"]");
|
||||
private static final Pattern NON_QUOTE_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-+]+");
|
||||
|
||||
private T value;
|
||||
|
||||
/**
|
||||
@@ -86,6 +85,30 @@ public abstract class Tag<T> implements Cloneable {
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a string to fit into a JSON-like string representation for Minecraft
|
||||
* or to create the JSON string representation of a Tag returned from {@link Tag#toString()}
|
||||
*
|
||||
* @param s The string to be escaped.
|
||||
* @param lenient {@code true} if it should force double quotes ({@code "}) at the start and
|
||||
* the end of the string.
|
||||
* @return The escaped string.
|
||||
*/
|
||||
@SuppressWarnings("StringBufferMayBeStringBuilder")
|
||||
protected static String escapeString(String s, @SuppressWarnings("SameParameterValue") boolean lenient) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Matcher m = ESCAPE_PATTERN.matcher(s);
|
||||
while (m.find()) {
|
||||
m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group()));
|
||||
}
|
||||
m.appendTail(sb);
|
||||
m = NON_QUOTE_PATTERN.matcher(s);
|
||||
if (!lenient || !m.matches()) {
|
||||
sb.insert(0, "\"").append("\"");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return This Tag's ID, usually used for serialization and deserialization.
|
||||
*/
|
||||
@@ -192,28 +215,4 @@ public abstract class Tag<T> implements Cloneable {
|
||||
* @return A clone of this Tag.
|
||||
*/
|
||||
public abstract Tag<T> clone();
|
||||
|
||||
/**
|
||||
* Escapes a string to fit into a JSON-like string representation for Minecraft
|
||||
* or to create the JSON string representation of a Tag returned from {@link Tag#toString()}
|
||||
*
|
||||
* @param s The string to be escaped.
|
||||
* @param lenient {@code true} if it should force double quotes ({@code "}) at the start and
|
||||
* the end of the string.
|
||||
* @return The escaped string.
|
||||
*/
|
||||
@SuppressWarnings("StringBufferMayBeStringBuilder")
|
||||
protected static String escapeString(String s, @SuppressWarnings("SameParameterValue") boolean lenient) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Matcher m = ESCAPE_PATTERN.matcher(s);
|
||||
while (m.find()) {
|
||||
m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group()));
|
||||
}
|
||||
m.appendTail(sb);
|
||||
m = NON_QUOTE_PATTERN.matcher(s);
|
||||
if (!lenient || !m.matches()) {
|
||||
sb.insert(0, "\"").append("\"");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,12 @@ import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
|
||||
@@ -33,8 +33,6 @@ import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CNG {
|
||||
public static long hits = 0;
|
||||
public static long creates = 0;
|
||||
public static final NoiseInjector ADD = (s, v) -> new double[]{s + v, 1};
|
||||
public static final NoiseInjector SRC_SUBTRACT = (s, v) -> new double[]{s - v < 0 ? 0 : s - v, -1};
|
||||
public static final NoiseInjector DST_SUBTRACT = (s, v) -> new double[]{v - s < 0 ? 0 : s - v, -1};
|
||||
@@ -45,6 +43,9 @@ public class CNG {
|
||||
public static final NoiseInjector SRC_POW = (s, v) -> new double[]{Math.pow(s, v), 0};
|
||||
public static final NoiseInjector DST_MOD = (s, v) -> new double[]{v % s, 0};
|
||||
public static final NoiseInjector DST_POW = (s, v) -> new double[]{Math.pow(v, s), 0};
|
||||
public static long hits = 0;
|
||||
public static long creates = 0;
|
||||
private final double opacity;
|
||||
private double scale;
|
||||
private double bakedScale;
|
||||
private double fscale;
|
||||
@@ -52,7 +53,6 @@ public class CNG {
|
||||
private KList<CNG> children;
|
||||
private CNG fracture;
|
||||
private NoiseGenerator generator;
|
||||
private final double opacity;
|
||||
private NoiseInjector injector;
|
||||
private RNG rng;
|
||||
private boolean noscale;
|
||||
@@ -63,16 +63,43 @@ public class CNG {
|
||||
private double power;
|
||||
private ProceduralStream<Double> customGenerator;
|
||||
|
||||
public NoiseGenerator getGen() {
|
||||
return generator;
|
||||
public CNG(RNG random) {
|
||||
this(random, 1);
|
||||
}
|
||||
|
||||
public ProceduralStream<Double> stream() {
|
||||
return new CNGStream(this);
|
||||
public CNG(RNG random, int octaves) {
|
||||
this(random, 1D, octaves);
|
||||
}
|
||||
|
||||
public ProceduralStream<Double> stream(double min, double max) {
|
||||
return new FittedStream<>(stream(), min, max);
|
||||
public CNG(RNG random, double opacity, int octaves) {
|
||||
this(random, NoiseType.SIMPLEX, opacity, octaves);
|
||||
}
|
||||
|
||||
public CNG(RNG random, NoiseType type, double opacity, int octaves) {
|
||||
this(random, type.create(random.nextParallelRNG((long) ((1113334944L * opacity) + 12922 + octaves)).lmax()), opacity, octaves);
|
||||
}
|
||||
|
||||
public CNG(RNG random, NoiseGenerator generator, double opacity, int octaves) {
|
||||
customGenerator = null;
|
||||
creates++;
|
||||
noscale = generator.isNoScale();
|
||||
this.oct = octaves;
|
||||
this.rng = random;
|
||||
power = 1;
|
||||
scale = 1;
|
||||
patch = 1;
|
||||
bakedScale = 1;
|
||||
fscale = 1;
|
||||
down = 0;
|
||||
up = 0;
|
||||
fracture = null;
|
||||
this.generator = generator;
|
||||
this.opacity = opacity;
|
||||
this.injector = ADD;
|
||||
|
||||
if (generator instanceof OctaveNoise) {
|
||||
((OctaveNoise) generator).setOctaves(octaves);
|
||||
}
|
||||
}
|
||||
|
||||
public static CNG signature(RNG rng) {
|
||||
@@ -95,7 +122,6 @@ public class CNG {
|
||||
return signatureThick(rng, t).fractureWith(signature(rng.nextParallelRNG(4956)), 93);
|
||||
}
|
||||
|
||||
|
||||
public static CNG signatureDoubleFast(RNG rng, NoiseType t, NoiseType f) {
|
||||
return signatureThickFast(rng, t, f)
|
||||
.fractureWith(signatureFast(rng.nextParallelRNG(4956), t, f), 93);
|
||||
@@ -162,43 +188,16 @@ public class CNG {
|
||||
// @done
|
||||
}
|
||||
|
||||
public CNG(RNG random) {
|
||||
this(random, 1);
|
||||
public NoiseGenerator getGen() {
|
||||
return generator;
|
||||
}
|
||||
|
||||
public CNG(RNG random, int octaves) {
|
||||
this(random, 1D, octaves);
|
||||
public ProceduralStream<Double> stream() {
|
||||
return new CNGStream(this);
|
||||
}
|
||||
|
||||
public CNG(RNG random, double opacity, int octaves) {
|
||||
this(random, NoiseType.SIMPLEX, opacity, octaves);
|
||||
}
|
||||
|
||||
public CNG(RNG random, NoiseType type, double opacity, int octaves) {
|
||||
this(random, type.create(random.nextParallelRNG((long) ((1113334944L * opacity) + 12922 + octaves)).lmax()), opacity, octaves);
|
||||
}
|
||||
|
||||
public CNG(RNG random, NoiseGenerator generator, double opacity, int octaves) {
|
||||
customGenerator = null;
|
||||
creates++;
|
||||
noscale = generator.isNoScale();
|
||||
this.oct = octaves;
|
||||
this.rng = random;
|
||||
power = 1;
|
||||
scale = 1;
|
||||
patch = 1;
|
||||
bakedScale = 1;
|
||||
fscale = 1;
|
||||
down = 0;
|
||||
up = 0;
|
||||
fracture = null;
|
||||
this.generator = generator;
|
||||
this.opacity = opacity;
|
||||
this.injector = ADD;
|
||||
|
||||
if (generator instanceof OctaveNoise) {
|
||||
((OctaveNoise) generator).setOctaves(octaves);
|
||||
}
|
||||
public ProceduralStream<Double> stream(double min, double max) {
|
||||
return new FittedStream<>(stream(), min, max);
|
||||
}
|
||||
|
||||
public CNG bake() {
|
||||
|
||||
@@ -50,6 +50,11 @@ public class CloverNoise implements NoiseGenerator {
|
||||
* Java implementation of 2D Clover Noise. See https://github.com/ValgoBoi/clover-noise
|
||||
*/
|
||||
public static class Noise2D {
|
||||
private static final long HASH_A = 25214903917L;
|
||||
private static final long HASH_C = 11L;
|
||||
private static final long HASH_M = 0x1000000000000L;
|
||||
private static final double POINT_SPREAD = 0.3;
|
||||
private static final double CURL_DX = 0.0001;
|
||||
private final long seed;
|
||||
|
||||
/**
|
||||
@@ -68,10 +73,6 @@ public class CloverNoise implements NoiseGenerator {
|
||||
this(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
private static final long HASH_A = 25214903917L;
|
||||
private static final long HASH_C = 11L;
|
||||
private static final long HASH_M = 0x1000000000000L;
|
||||
|
||||
private long doHash(long input, long seed) {
|
||||
input += seed;
|
||||
|
||||
@@ -97,8 +98,6 @@ public class CloverNoise implements NoiseGenerator {
|
||||
return (double) hash / HASH_M;
|
||||
}
|
||||
|
||||
private static final double POINT_SPREAD = 0.3;
|
||||
|
||||
private Vector2 offset(Vector2 position) {
|
||||
double hash = hash(position);
|
||||
double scale = Math.floor(hash * 50 + 1) / 100;
|
||||
@@ -248,8 +247,6 @@ public class CloverNoise implements NoiseGenerator {
|
||||
return fractalNoise(new Vector2(x, y), iterations);
|
||||
}
|
||||
|
||||
private static final double CURL_DX = 0.0001;
|
||||
|
||||
/**
|
||||
* Generates curl 2D Clover Noise at a specific point.
|
||||
*
|
||||
@@ -366,6 +363,11 @@ public class CloverNoise implements NoiseGenerator {
|
||||
}
|
||||
|
||||
public static class Noise3D {
|
||||
private static final long HASH_A = 25214903917L;
|
||||
private static final long HASH_C = 11L;
|
||||
private static final long HASH_M = 0x1000000000000L;
|
||||
private static final double POINT_SPREAD = 0.2;
|
||||
private static final double CURL_DX = 0.0001;
|
||||
private final long seed;
|
||||
|
||||
public Noise3D(long seed) {
|
||||
@@ -376,10 +378,6 @@ public class CloverNoise implements NoiseGenerator {
|
||||
this(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
private static final long HASH_A = 25214903917L;
|
||||
private static final long HASH_C = 11L;
|
||||
private static final long HASH_M = 0x1000000000000L;
|
||||
|
||||
private long doHash(long input, long seed) {
|
||||
input += seed;
|
||||
|
||||
@@ -406,8 +404,6 @@ public class CloverNoise implements NoiseGenerator {
|
||||
return (double) hash / HASH_M;
|
||||
}
|
||||
|
||||
private static final double POINT_SPREAD = 0.2;
|
||||
|
||||
private Vector3 offset(Vector3 position) {
|
||||
double hash = hash(position);
|
||||
double theta = hash * Math.PI * 2000;
|
||||
@@ -720,8 +716,6 @@ public class CloverNoise implements NoiseGenerator {
|
||||
return fractalNoise(new Vector3(x, y, z), iterations);
|
||||
}
|
||||
|
||||
private static final double CURL_DX = 0.0001;
|
||||
|
||||
/**
|
||||
* Generates curl 3D Clover Noise at a specific point.
|
||||
*
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -25,15 +25,20 @@ import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.math.M;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class MultiBurst {
|
||||
public static final MultiBurst burst = new MultiBurst();
|
||||
private ExecutorService service;
|
||||
private final AtomicLong last;
|
||||
private final String name;
|
||||
private final int priority;
|
||||
private ExecutorService service;
|
||||
|
||||
public MultiBurst() {
|
||||
this("Iris", Thread.MIN_PRIORITY);
|
||||
|
||||
@@ -142,6 +142,24 @@ public enum ParticleType {
|
||||
this.minimumVersion = minimumVersion;
|
||||
}
|
||||
|
||||
public static ParticleType getParticle(String particleName) {
|
||||
try {
|
||||
return ParticleType.valueOf(particleName.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
Iris.reportError(e);
|
||||
for (ParticleType particle : values()) {
|
||||
if (particle.getName().equalsIgnoreCase(particleName)) {
|
||||
return particle;
|
||||
}
|
||||
|
||||
if (particle.hasLegacyName() && particle.getLegacyName().equalsIgnoreCase(particleName)) {
|
||||
return particle;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasLegacyName() {
|
||||
return legacyName != null;
|
||||
}
|
||||
@@ -171,22 +189,4 @@ public enum ParticleType {
|
||||
default -> Void.class;
|
||||
};
|
||||
}
|
||||
|
||||
public static ParticleType getParticle(String particleName) {
|
||||
try {
|
||||
return ParticleType.valueOf(particleName.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
Iris.reportError(e);
|
||||
for (ParticleType particle : values()) {
|
||||
if (particle.getName().equalsIgnoreCase(particleName)) {
|
||||
return particle;
|
||||
}
|
||||
|
||||
if (particle.hasLegacyName() && particle.getLegacyName().equalsIgnoreCase(particleName)) {
|
||||
return particle;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ package com.volmit.iris.util.plugin;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(FIELD)
|
||||
|
||||
@@ -21,8 +21,8 @@ package com.volmit.iris.util.plugin;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(FIELD)
|
||||
|
||||
@@ -21,8 +21,8 @@ package com.volmit.iris.util.plugin;
|
||||
import com.volmit.iris.Iris;
|
||||
|
||||
public abstract class Controller implements IController {
|
||||
private int tickRate;
|
||||
private final String name;
|
||||
private int tickRate;
|
||||
|
||||
public Controller() {
|
||||
name = getClass().getSimpleName().replaceAll("Controller", "") + " Controller";
|
||||
|
||||
@@ -21,8 +21,8 @@ package com.volmit.iris.util.plugin;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(FIELD)
|
||||
|
||||
@@ -31,12 +31,23 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
@@ -49,6 +60,19 @@ import java.util.zip.GZIPOutputStream;
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
public class Metrics {
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
// The url to which the data is sent
|
||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
||||
// Should failed requests be logged?
|
||||
private static boolean logFailedRequests;
|
||||
// Should the sent data be logged?
|
||||
private static boolean logSentData;
|
||||
// Should the response text be logged?
|
||||
private static boolean logResponseStatusText;
|
||||
// The uuid of the server
|
||||
private static String serverUUID;
|
||||
|
||||
static {
|
||||
// You can use the property to disable the check in your test environment
|
||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||
@@ -63,27 +87,8 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
|
||||
// The url to which the data is sent
|
||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
||||
|
||||
// Is bStats enabled on this server?
|
||||
private final boolean enabled;
|
||||
|
||||
// Should failed requests be logged?
|
||||
private static boolean logFailedRequests;
|
||||
|
||||
// Should the sent data be logged?
|
||||
private static boolean logSentData;
|
||||
|
||||
// Should the response text be logged?
|
||||
private static boolean logResponseStatusText;
|
||||
|
||||
// The uuid of the server
|
||||
private static String serverUUID;
|
||||
|
||||
// The plugin
|
||||
private final Plugin plugin;
|
||||
|
||||
@@ -169,6 +174,74 @@ public class Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data);
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
|
||||
// Add headers
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
connection.setDoOutput(true);
|
||||
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||
outputStream.write(compressedData);
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (logResponseStatusText) {
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if bStats is enabled.
|
||||
*
|
||||
@@ -351,74 +424,6 @@ public class Metrics {
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data);
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
|
||||
// Add headers
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
connection.setDoOutput(true);
|
||||
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||
outputStream.write(compressedData);
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (logResponseStatusText) {
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a custom chart.
|
||||
*/
|
||||
|
||||
@@ -30,7 +30,12 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
@@ -49,6 +54,19 @@ import java.util.zip.GZIPOutputStream;
|
||||
*/
|
||||
public class MetricsLite {
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
// The url to which the data is sent
|
||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
||||
// Should failed requests be logged?
|
||||
private static boolean logFailedRequests;
|
||||
// Should the sent data be logged?
|
||||
private static boolean logSentData;
|
||||
// Should the response text be logged?
|
||||
private static boolean logResponseStatusText;
|
||||
// The uuid of the server
|
||||
private static String serverUUID;
|
||||
|
||||
static {
|
||||
// You can use the property to disable the check in your test environment
|
||||
if (System.getProperty("bstats.relocatecheck") == null || !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||
@@ -64,27 +82,8 @@ public class MetricsLite {
|
||||
}
|
||||
}
|
||||
|
||||
// The version of this bStats class
|
||||
public static final int B_STATS_VERSION = 1;
|
||||
|
||||
// The url to which the data is sent
|
||||
private static final String URL = "https://bStats.org/submitData/bukkit";
|
||||
|
||||
// Is bStats enabled on this server?
|
||||
private final boolean enabled;
|
||||
|
||||
// Should failed requests be logged?
|
||||
private static boolean logFailedRequests;
|
||||
|
||||
// Should the sent data be logged?
|
||||
private static boolean logSentData;
|
||||
|
||||
// Should the response text be logged?
|
||||
private static boolean logResponseStatusText;
|
||||
|
||||
// The uuid of the server
|
||||
private static String serverUUID;
|
||||
|
||||
// The plugin
|
||||
private final Plugin plugin;
|
||||
|
||||
@@ -165,6 +164,74 @@ public class MetricsLite {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data);
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
|
||||
// Add headers
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
connection.setDoOutput(true);
|
||||
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||
outputStream.write(compressedData);
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (logResponseStatusText) {
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if bStats is enabled.
|
||||
*
|
||||
@@ -328,72 +395,4 @@ public class MetricsLite {
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the bStats server.
|
||||
*
|
||||
* @param plugin Any plugin. It's just used to get a logger instance.
|
||||
* @param data The data to send.
|
||||
* @throws Exception If the request failed.
|
||||
*/
|
||||
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
|
||||
if (data == null) {
|
||||
throw new IllegalArgumentException("Data cannot be null!");
|
||||
}
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
throw new IllegalAccessException("This method must not be called from the main thread!");
|
||||
}
|
||||
if (logSentData) {
|
||||
plugin.getLogger().info("Sending data to bStats: " + data);
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
|
||||
|
||||
// Compress the data to save bandwidth
|
||||
byte[] compressedData = compress(data.toString());
|
||||
|
||||
// Add headers
|
||||
connection.setRequestMethod("POST");
|
||||
connection.addRequestProperty("Accept", "application/json");
|
||||
connection.addRequestProperty("Connection", "close");
|
||||
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
|
||||
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
|
||||
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
|
||||
|
||||
// Send data
|
||||
connection.setDoOutput(true);
|
||||
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||
outputStream.write(compressedData);
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (logResponseStatusText) {
|
||||
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gzips the given String.
|
||||
*
|
||||
* @param str The string to gzip.
|
||||
* @return The gzipped String.
|
||||
* @throws IOException If the compression failed.
|
||||
*/
|
||||
private static byte[] compress(final String str) throws IOException {
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return outputStream.toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,8 +21,8 @@ package com.volmit.iris.util.plugin;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(FIELD)
|
||||
|
||||
@@ -27,7 +27,10 @@ import com.volmit.iris.util.reflect.V;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@@ -37,7 +37,6 @@ import net.kyori.adventure.title.Title;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
@@ -59,9 +58,10 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
* @author cyberpwn
|
||||
*/
|
||||
public class VolmitSender implements CommandSender {
|
||||
@Getter
|
||||
private static final KMap<String, String> helpCache = new KMap<>();
|
||||
private final CommandSender s;
|
||||
private String tag;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String command;
|
||||
@@ -81,13 +81,33 @@ public class VolmitSender implements CommandSender {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a command tag (prefix for sendMessage)
|
||||
*
|
||||
* @param tag the tag
|
||||
*/
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
public static long getTick() {
|
||||
return M.ms() / 16;
|
||||
}
|
||||
|
||||
public static String pulse(String colorA, String colorB, double speed) {
|
||||
return "<gradient:" + colorA + ":" + colorB + ":" + pulse(speed) + ">";
|
||||
}
|
||||
|
||||
public static String pulse(double speed) {
|
||||
return Form.f(invertSpread((((getTick() * 15D * speed) % 1000D) / 1000D)), 3).replaceAll("\\Q,\\E", ".").replaceAll("\\Q?\\E", "-");
|
||||
}
|
||||
|
||||
public static double invertSpread(double v) {
|
||||
return ((1D - v) * 2D) - 1D;
|
||||
}
|
||||
|
||||
public static <T> KList<T> paginate(KList<T> all, int linesPerPage, int page, AtomicBoolean hasNext) {
|
||||
int totalPages = (int) Math.ceil((double) all.size() / linesPerPage);
|
||||
page = page < 0 ? 0 : page >= totalPages ? totalPages - 1 : page;
|
||||
hasNext.set(page < totalPages - 1);
|
||||
KList<T> d = new KList<>();
|
||||
|
||||
for (int i = linesPerPage * page; i < Math.min(all.size(), linesPerPage * (page + 1)); i++) {
|
||||
d.add(all.get(i));
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,6 +119,15 @@ public class VolmitSender implements CommandSender {
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a command tag (prefix for sendMessage)
|
||||
*
|
||||
* @param tag the tag
|
||||
*/
|
||||
public void setTag(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this sender a player?
|
||||
*
|
||||
@@ -146,13 +175,11 @@ public class VolmitSender implements CommandSender {
|
||||
return s.hasPermission(perm);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
||||
return s.addAttachment(plugin, name, value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin) {
|
||||
return s.addAttachment(plugin);
|
||||
@@ -178,7 +205,6 @@ public class VolmitSender implements CommandSender {
|
||||
s.recalculatePermissions();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
return s.getEffectivePermissions();
|
||||
@@ -205,10 +231,6 @@ public class VolmitSender implements CommandSender {
|
||||
Title.Times.of(Duration.ofMillis(i), Duration.ofMillis(s), Duration.ofMillis(o))));
|
||||
}
|
||||
|
||||
public static long getTick() {
|
||||
return M.ms() / 16;
|
||||
}
|
||||
|
||||
public void sendProgress(double percent, String thing) {
|
||||
if (percent < 0) {
|
||||
int l = 44;
|
||||
@@ -223,18 +245,6 @@ public class VolmitSender implements CommandSender {
|
||||
}
|
||||
}
|
||||
|
||||
public static String pulse(String colorA, String colorB, double speed) {
|
||||
return "<gradient:" + colorA + ":" + colorB + ":" + pulse(speed) + ">";
|
||||
}
|
||||
|
||||
public static String pulse(double speed) {
|
||||
return Form.f(invertSpread((((getTick() * 15D * speed) % 1000D) / 1000D)), 3).replaceAll("\\Q,\\E", ".").replaceAll("\\Q?\\E", "-");
|
||||
}
|
||||
|
||||
public static double invertSpread(double v) {
|
||||
return ((1D - v) * 2D) - 1D;
|
||||
}
|
||||
|
||||
public void sendAction(String action) {
|
||||
Iris.audiences.player(player()).sendActionBar(createNoPrefixComponent(action));
|
||||
}
|
||||
@@ -316,8 +326,7 @@ public class VolmitSender implements CommandSender {
|
||||
return;
|
||||
}
|
||||
|
||||
if((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors())
|
||||
{
|
||||
if ((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors()) {
|
||||
s.sendMessage(C.translateAlternateColorCodes('&', getTag() + message));
|
||||
return;
|
||||
}
|
||||
@@ -347,8 +356,7 @@ public class VolmitSender implements CommandSender {
|
||||
return;
|
||||
}
|
||||
|
||||
if((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors())
|
||||
{
|
||||
if ((!IrisSettings.get().getGeneral().isUseCustomColorsIngame() && s instanceof Player) || !IrisSettings.get().getGeneral().isUseConsoleCustomColors()) {
|
||||
s.sendMessage(C.translateAlternateColorCodes('&', message));
|
||||
return;
|
||||
}
|
||||
@@ -385,19 +393,16 @@ public class VolmitSender implements CommandSender {
|
||||
sendMessage(messages);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Server getServer() {
|
||||
return s.getServer();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return s.getName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Spigot spigot() {
|
||||
return s.spigot();
|
||||
@@ -425,7 +430,6 @@ public class VolmitSender implements CommandSender {
|
||||
return m.removeDuplicates().convert((iff) -> iff.replaceAll("\\Q \\E", " ")).toString("\n");
|
||||
}
|
||||
|
||||
|
||||
public void sendHeader(String name, int overrideLength) {
|
||||
int len = overrideLength;
|
||||
int h = name.length() + 2;
|
||||
@@ -446,25 +450,10 @@ public class VolmitSender implements CommandSender {
|
||||
sendHeader(name, 44);
|
||||
}
|
||||
|
||||
|
||||
public void sendDecreeHelp(VirtualDecreeCommand v) {
|
||||
sendDecreeHelp(v, 0);
|
||||
}
|
||||
|
||||
|
||||
public static <T> KList<T> paginate(KList<T> all, int linesPerPage, int page, AtomicBoolean hasNext) {
|
||||
int totalPages = (int) Math.ceil((double) all.size() / linesPerPage);
|
||||
page = page < 0 ? 0 : page >= totalPages ? totalPages - 1 : page;
|
||||
hasNext.set(page < totalPages - 1);
|
||||
KList<T> d = new KList<>();
|
||||
|
||||
for (int i = linesPerPage * page; i < Math.min(all.size(), linesPerPage * (page + 1)); i++) {
|
||||
d.add(all.get(i));
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
public void sendDecreeHelp(VirtualDecreeCommand v, int page) {
|
||||
if (!isPlayer()) {
|
||||
for (VirtualDecreeCommand i : v.getNodes()) {
|
||||
@@ -508,9 +497,6 @@ public class VolmitSender implements CommandSender {
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
private static final KMap<String, String> helpCache = new KMap<>();
|
||||
|
||||
public void sendDecreeHelpNode(VirtualDecreeCommand i) {
|
||||
if (isPlayer() || s instanceof CommandDummy) {
|
||||
sendMessageRaw(helpCache.compute(i.getPath(), (k, v) -> {
|
||||
|
||||
@@ -29,9 +29,9 @@ import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
|
||||
public class GroupedExecutor {
|
||||
private int xc;
|
||||
private final ExecutorService service;
|
||||
private final KMap<String, Integer> mirror;
|
||||
private int xc;
|
||||
|
||||
public GroupedExecutor(int threadLimit, int priority, String name) {
|
||||
xc = 1;
|
||||
|
||||
@@ -38,6 +38,9 @@ import java.util.function.Supplier;
|
||||
@SuppressWarnings("ALL")
|
||||
public class J {
|
||||
private static int tid = 0;
|
||||
private static KList<Runnable> afterStartup = new KList<>();
|
||||
private static KList<Runnable> afterStartupAsync = new KList<>();
|
||||
private static boolean started = false;
|
||||
|
||||
public static void dofor(int a, Function<Integer, Boolean> c, int ch, Consumer<Integer> d) {
|
||||
for (int i = a; c.apply(i); i += ch) {
|
||||
@@ -153,10 +156,6 @@ public class J {
|
||||
}
|
||||
}
|
||||
|
||||
private static KList<Runnable> afterStartup = new KList<>();
|
||||
private static KList<Runnable> afterStartupAsync = new KList<>();
|
||||
private static boolean started = false;
|
||||
|
||||
/**
|
||||
* Dont call this unless you know what you are doing!
|
||||
*/
|
||||
|
||||
@@ -26,6 +26,11 @@ public class PrecisionStopwatch {
|
||||
private double time;
|
||||
private boolean profiling;
|
||||
|
||||
public PrecisionStopwatch() {
|
||||
reset();
|
||||
profiling = false;
|
||||
}
|
||||
|
||||
public static PrecisionStopwatch start() {
|
||||
PrecisionStopwatch p = new PrecisionStopwatch();
|
||||
p.begin();
|
||||
@@ -33,11 +38,6 @@ public class PrecisionStopwatch {
|
||||
return p;
|
||||
}
|
||||
|
||||
public PrecisionStopwatch() {
|
||||
reset();
|
||||
profiling = false;
|
||||
}
|
||||
|
||||
public void begin() {
|
||||
profiling = true;
|
||||
startNano = System.nanoTime();
|
||||
|
||||
@@ -22,6 +22,15 @@ import com.volmit.iris.util.collection.KList;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
public interface Queue<T> {
|
||||
static <T> Queue<T> create(KList<T> t) {
|
||||
return new ShurikenQueue<T>().queue(t);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> Queue<T> create(T... t) {
|
||||
return new ShurikenQueue<T>().queue(new KList<T>().add(t));
|
||||
}
|
||||
|
||||
Queue<T> queue(T t);
|
||||
|
||||
Queue<T> queue(KList<T> t);
|
||||
@@ -38,14 +47,5 @@ public interface Queue<T> {
|
||||
|
||||
int size();
|
||||
|
||||
static <T> Queue<T> create(KList<T> t) {
|
||||
return new ShurikenQueue<T>().queue(t);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> Queue<T> create(T... t) {
|
||||
return new ShurikenQueue<T>().queue(new KList<T>().add(t));
|
||||
}
|
||||
|
||||
boolean contains(T p);
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory;
|
||||
import java.util.concurrent.ForkJoinWorkerThread;
|
||||
|
||||
public class TaskExecutor {
|
||||
private int xc;
|
||||
private final ExecutorService service;
|
||||
private int xc;
|
||||
|
||||
public TaskExecutor(int threadLimit, int priority, String name) {
|
||||
xc = 1;
|
||||
@@ -85,6 +85,13 @@ public class TaskExecutor {
|
||||
service.shutdown();
|
||||
}
|
||||
|
||||
public enum TaskState {
|
||||
QUEUED,
|
||||
RUNNING,
|
||||
COMPLETED,
|
||||
FAILED
|
||||
}
|
||||
|
||||
public static class TaskGroup {
|
||||
private final KList<AssignedTask> tasks;
|
||||
private final TaskExecutor e;
|
||||
@@ -155,34 +162,25 @@ public class TaskExecutor {
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
@ToString
|
||||
public static class TaskResult {
|
||||
public final double timeElapsed;
|
||||
public final int tasksExecuted;
|
||||
public final int tasksFailed;
|
||||
public final int tasksCompleted;
|
||||
public TaskResult(double timeElapsed, int tasksExecuted, int tasksFailed, int tasksCompleted) {
|
||||
this.timeElapsed = timeElapsed;
|
||||
this.tasksExecuted = tasksExecuted;
|
||||
this.tasksFailed = tasksFailed;
|
||||
this.tasksCompleted = tasksCompleted;
|
||||
}
|
||||
|
||||
public final double timeElapsed;
|
||||
public final int tasksExecuted;
|
||||
public final int tasksFailed;
|
||||
public final int tasksCompleted;
|
||||
}
|
||||
|
||||
public enum TaskState {
|
||||
QUEUED,
|
||||
RUNNING,
|
||||
COMPLETED,
|
||||
FAILED
|
||||
}
|
||||
|
||||
public static class AssignedTask {
|
||||
@Getter
|
||||
private final NastyRunnable task;
|
||||
@Getter
|
||||
@Setter
|
||||
private TaskState state;
|
||||
|
||||
@Getter
|
||||
private final NastyRunnable task;
|
||||
|
||||
public AssignedTask(NastyRunnable task) {
|
||||
this.task = task;
|
||||
state = TaskState.QUEUED;
|
||||
|
||||
@@ -30,12 +30,12 @@ import com.volmit.iris.util.math.RollingSequence;
|
||||
*/
|
||||
public class ThreadMonitor extends Thread {
|
||||
private final Thread monitor;
|
||||
private final ChronoLatch cl;
|
||||
private final RollingSequence sq = new RollingSequence(3);
|
||||
int cycles = 0;
|
||||
private boolean running;
|
||||
private State lastState;
|
||||
private final ChronoLatch cl;
|
||||
private PrecisionStopwatch st;
|
||||
int cycles = 0;
|
||||
private final RollingSequence sq = new RollingSequence(3);
|
||||
|
||||
private ThreadMonitor(Thread monitor) {
|
||||
running = true;
|
||||
@@ -46,6 +46,10 @@ public class ThreadMonitor extends Thread {
|
||||
start();
|
||||
}
|
||||
|
||||
public static ThreadMonitor bind(Thread monitor) {
|
||||
return new ThreadMonitor(monitor);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (running) {
|
||||
try {
|
||||
@@ -84,8 +88,4 @@ public class ThreadMonitor extends Thread {
|
||||
public void unbind() {
|
||||
running = false;
|
||||
}
|
||||
|
||||
public static ThreadMonitor bind(Thread monitor) {
|
||||
return new ThreadMonitor(monitor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import com.volmit.iris.util.collection.KList;
|
||||
|
||||
public class JobCollection implements Job {
|
||||
private final String name;
|
||||
private String status;
|
||||
private final KList<Job> jobs;
|
||||
private String status;
|
||||
|
||||
public JobCollection(String name, Job... jobs) {
|
||||
this(name, new KList<>(jobs));
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public abstract class QueueJob<T> implements Job {
|
||||
final KList<T> queue;
|
||||
protected int totalWork;
|
||||
private final AtomicInteger completed;
|
||||
protected int totalWork;
|
||||
|
||||
public QueueJob() {
|
||||
totalWork = 0;
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
package com.volmit.iris.util.scheduling.jobs;
|
||||
|
||||
public class SingleJob implements Job {
|
||||
private boolean done;
|
||||
private final String name;
|
||||
private final Runnable runnable;
|
||||
private boolean done;
|
||||
|
||||
public SingleJob(String name, Runnable runnable) {
|
||||
this.name = name;
|
||||
|
||||
@@ -28,11 +28,39 @@ import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.function.Function4;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.stream.arithmetic.*;
|
||||
import com.volmit.iris.util.stream.convert.*;
|
||||
import com.volmit.iris.util.stream.arithmetic.AddingStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.ClampedStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.CoordinateBitShiftLeftStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.CoordinateBitShiftRightStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.DividingStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.FittedStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.MaxingStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.MinningStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.ModuloStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.MultiplyingStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.OffsetStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.RadialStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.RoundingDoubleStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.SlopeStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.SubtractingStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.ZoomStream;
|
||||
import com.volmit.iris.util.stream.convert.AwareConversionStream2D;
|
||||
import com.volmit.iris.util.stream.convert.AwareConversionStream3D;
|
||||
import com.volmit.iris.util.stream.convert.CachedConversionStream;
|
||||
import com.volmit.iris.util.stream.convert.ConversionStream;
|
||||
import com.volmit.iris.util.stream.convert.ForceDoubleStream;
|
||||
import com.volmit.iris.util.stream.convert.RoundingStream;
|
||||
import com.volmit.iris.util.stream.convert.SelectionStream;
|
||||
import com.volmit.iris.util.stream.convert.SignificanceStream;
|
||||
import com.volmit.iris.util.stream.convert.To3DStream;
|
||||
import com.volmit.iris.util.stream.interpolation.Interpolated;
|
||||
import com.volmit.iris.util.stream.sources.FunctionStream;
|
||||
import com.volmit.iris.util.stream.utility.*;
|
||||
import com.volmit.iris.util.stream.utility.CachedStream2D;
|
||||
import com.volmit.iris.util.stream.utility.CachedStream3D;
|
||||
import com.volmit.iris.util.stream.utility.NullSafeStream;
|
||||
import com.volmit.iris.util.stream.utility.ProfiledStream;
|
||||
import com.volmit.iris.util.stream.utility.SemaphoreStream;
|
||||
import com.volmit.iris.util.stream.utility.SynchronizedStream;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -38,18 +38,6 @@ public interface Interpolated<T> {
|
||||
Interpolated<Long> LONG = of(Double::valueOf, Double::longValue);
|
||||
Interpolated<UUID> UUID = of((i) -> Double.longBitsToDouble(i.getMostSignificantBits()), (i) -> new UUID(Double.doubleToLongBits(i), i.longValue()));
|
||||
|
||||
double toDouble(T t);
|
||||
|
||||
T fromDouble(double d);
|
||||
|
||||
default InterpolatorFactory<T> interpolate() {
|
||||
if (this instanceof ProceduralStream) {
|
||||
return new InterpolatorFactory<>((ProceduralStream<T>) this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static <T> Interpolated<T> of(Function<T, Double> a, Function<Double, T> b) {
|
||||
return new Interpolated<>() {
|
||||
@Override
|
||||
@@ -63,4 +51,16 @@ public interface Interpolated<T> {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
double toDouble(T t);
|
||||
|
||||
T fromDouble(double d);
|
||||
|
||||
default InterpolatorFactory<T> interpolate() {
|
||||
if (this instanceof ProceduralStream) {
|
||||
return new InterpolatorFactory<>((ProceduralStream<T>) this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,50 +41,6 @@ public class ProfiledStream<T> extends BasicStream<T> {
|
||||
this.id = ids.getAndAdd(1);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double toDouble(T t) {
|
||||
return getTypedSource().toDouble(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T fromDouble(double d) {
|
||||
return getTypedSource().fromDouble(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(double x, double z) {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
T t = getTypedSource().get(x, z);
|
||||
try {
|
||||
metrics.put(p.getMilliseconds());
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(double x, double y, double z) {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
T t = getTypedSource().get(x, y, z);
|
||||
try {
|
||||
metrics.put(p.getMilliseconds());
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public RollingSequence getMetrics() {
|
||||
return metrics;
|
||||
}
|
||||
|
||||
public static void print(Consumer<String> printer, ProceduralStream<?> stream) {
|
||||
KList<ProfiledTail> tails = getTails(stream);
|
||||
int ind = tails.size();
|
||||
@@ -154,12 +110,56 @@ public class ProfiledStream<T> extends BasicStream<T> {
|
||||
return tailx;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double toDouble(T t) {
|
||||
return getTypedSource().toDouble(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T fromDouble(double d) {
|
||||
return getTypedSource().fromDouble(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(double x, double z) {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
T t = getTypedSource().get(x, z);
|
||||
try {
|
||||
metrics.put(p.getMilliseconds());
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(double x, double y, double z) {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
T t = getTypedSource().get(x, y, z);
|
||||
try {
|
||||
metrics.put(p.getMilliseconds());
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public RollingSequence getMetrics() {
|
||||
return metrics;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class ProfiledTail {
|
||||
private final int id;
|
||||
private final RollingSequence metrics;
|
||||
private ProfiledTail child;
|
||||
private final String name;
|
||||
private ProfiledTail child;
|
||||
|
||||
public ProfiledTail(int id, RollingSequence metrics, String name) {
|
||||
this.id = id;
|
||||
|
||||
Reference in New Issue
Block a user