9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-27 19:19:07 +00:00

Auto stash before revert of "Cleanup"

This commit is contained in:
cyberpwn
2021-08-27 00:16:30 -04:00
parent 2aa240337c
commit 8ff5887955
28 changed files with 238 additions and 156 deletions

View File

@@ -24,10 +24,15 @@ import com.volmit.iris.engine.IrisComplex;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.scheduling.ChronoLatch;
import lombok.AllArgsConstructor;
import lombok.Data;
public record IrisContext(Engine engine) {
private static final ChronoLatch cl = new ChronoLatch(60000);
@Data
@AllArgsConstructor
public class IrisContext {
private static ChronoLatch cl = new ChronoLatch(60000);
private static final KMap<Thread, IrisContext> context = new KMap<>();
private final Engine engine;
public static IrisContext get() {
return context.get(Thread.currentThread());

View File

@@ -380,12 +380,13 @@ public class Cuboid implements Iterable<Block>, Cloneable, ConfigurationSerializ
* @return a new Cuboid outset by the given direction and amount
*/
public Cuboid outset(CuboidDirection dir, int amount) {
return switch (dir) {
Cuboid c = switch (dir) {
case Horizontal -> expand(CuboidDirection.North, amount).expand(CuboidDirection.South, amount).expand(CuboidDirection.East, amount).expand(CuboidDirection.West, amount);
case Vertical -> expand(CuboidDirection.Down, amount).expand(CuboidDirection.Up, amount);
case Both -> outset(CuboidDirection.Horizontal, amount).outset(CuboidDirection.Vertical, amount);
default -> throw new IllegalArgumentException("invalid direction " + dir);
};
return c;
}
/**

View File

@@ -68,7 +68,7 @@ public abstract class NibbleDataPalette<T> implements Writable {
data = new NibbleArray(CAPACITY, i);
}
private void expand() {
private final void expand() {
if (bpb < 8) {
changeBitsPerBlock(bpb + 1);
} else {
@@ -90,7 +90,7 @@ public abstract class NibbleDataPalette<T> implements Writable {
changeBitsPerBlock(targetBits);
}
private void changeBitsPerBlock(int bits) {
private final void changeBitsPerBlock(int bits) {
bpb = bits;
data = new NibbleArray(bpb, CAPACITY, data);
}
@@ -103,7 +103,7 @@ public abstract class NibbleDataPalette<T> implements Writable {
return palette.get(data.get(getCoordinateIndex(x, y, z)));
}
private int getPaletteId(T d) {
private final int getPaletteId(T d) {
int index = palette.indexOf(d);
if (index == -1) {
@@ -118,7 +118,7 @@ public abstract class NibbleDataPalette<T> implements Writable {
return index + Byte.MIN_VALUE;
}
private int getCoordinateIndex(int x, int y, int z) {
private final int getCoordinateIndex(int x, int y, int z) {
return y << 8 | z << 4 | x;
}
}

View File

@@ -277,8 +277,10 @@ public class Form {
if (phantom > div) {
phantom /= div;
suffix = "Year";
return Form.fd(phantom, 0) + " " + suffix + ((int) phantom == 1 ? "" : "s");
} else {
return Form.fd(phantom, 0) + " " + suffix + ((int) phantom == 1 ? "" : "s");
}
return Form.fd(phantom, 0) + " " + suffix + ((int) phantom == 1 ? "" : "s");
} else {
return Form.fd(phantom, 0) + " " + suffix + ((int) phantom == 1 ? "" : "s");
}

View File

@@ -196,7 +196,8 @@ public class RandomColor {
int saturation = pickSaturation(color, null, null);
int brightness = pickBrightness(color, saturation, null);
return getColor(hue, saturation, brightness);
int colorValue = getColor(hue, saturation, brightness);
return colorValue;
}
public int[] random(Color color, int count) {
@@ -261,13 +262,18 @@ public class RandomColor {
private int pickSaturation(ColorInfo colorInfo, SaturationType saturationType, Luminosity luminosity) {
if (saturationType != null) {
return switch (saturationType) {
case RANDOM -> randomWithin(new Range(0, 100));
case MONOCHROME -> 0;
case HIGH -> randomWithin(new Range(75, 100));
case MEDIUM -> randomWithin(new Range(55, 75));
case LOW -> randomWithin(new Range(35, 55));
};
switch (saturationType) {
case RANDOM:
return randomWithin(new Range(0, 100));
case MONOCHROME:
return 0;
case HIGH:
return randomWithin(new Range(75, 100));
case MEDIUM:
return randomWithin(new Range(55, 75));
case LOW:
return randomWithin(new Range(35, 55));
}
}
if (colorInfo == null) {
@@ -281,9 +287,15 @@ public class RandomColor {
if (luminosity != null) {
switch (luminosity) {
case LIGHT -> min = 55;
case BRIGHT -> min = max - 10;
case DARK -> max = 55;
case LIGHT:
min = 55;
break;
case BRIGHT:
min = max - 10;
break;
case DARK:
max = 55;
break;
}
}
@@ -308,12 +320,19 @@ public class RandomColor {
if (luminosity != null) {
switch (luminosity) {
case DARK -> max = min + 20;
case LIGHT -> min = (max + min) / 2;
case RANDOM -> {
case DARK:
max = min + 20;
break;
case LIGHT:
min = (max + min) / 2;
break;
case RANDOM:
min = 0;
max = 100;
}
break;
}
}

View File

@@ -361,7 +361,9 @@ public class IrisMathHelper {
var9 = var5;
var10 = var6;
}
default -> throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + var0 + ", " + var1 + ", " + var2);
default -> {
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + var0 + ", " + var1 + ", " + var2);
}
}
final int var11 = clamp((int) (var8 * 255.0f), 0, 255);
final int var12 = clamp((int) (var9 * 255.0f), 0, 255);

View File

@@ -197,15 +197,19 @@ public class KochanekBartelsInterpolation implements PathInterpolation {
* Assumes a < b.
*/
private double arcLengthRecursive(int indexLeft, double remainderLeft, int indexRight, double remainderRight) {
return switch (indexRight - indexLeft) {
case 0 -> arcLengthRecursive(indexLeft, remainderLeft, remainderRight);
case 1 ->
// This case is merely a speed-up for a very common case
arcLengthRecursive(indexLeft, remainderLeft, 1.0)
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
default -> arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0)
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
};
switch (indexRight - indexLeft) {
case 0:
return arcLengthRecursive(indexLeft, remainderLeft, remainderRight);
case 1:
// This case is merely a speed-up for a very common case
return arcLengthRecursive(indexLeft, remainderLeft, 1.0)
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
default:
return arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0)
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
}
}
private double arcLengthRecursive(int index, double remainderLeft, double remainderRight) {

View File

@@ -200,10 +200,11 @@ public class MathHelper {
public static double a(long[] var0) {
long var1 = 0L;
long[] var3 = var0;
int var4 = var0.length;
for (int var5 = 0; var5 < var4; ++var5) {
long var6 = var0[var5];
long var6 = var3[var5];
var1 += var6;
}
@@ -451,7 +452,7 @@ public class MathHelper {
public static double d(double var0, double var2) {
double var4 = var2 * var2 + var0 * var0;
if (Double.isNaN(var4)) {
return Double.NaN;
return 0.0D / 0.0;
} else {
boolean var6 = var0 < 0.0D;
if (var6) {
@@ -535,37 +536,38 @@ public class MathHelper {
float var9;
float var10;
switch (var3) {
case 0 -> {
case 0:
var8 = var2;
var9 = var7;
var10 = var5;
}
case 1 -> {
break;
case 1:
var8 = var6;
var9 = var2;
var10 = var5;
}
case 2 -> {
break;
case 2:
var8 = var5;
var9 = var2;
var10 = var7;
}
case 3 -> {
break;
case 3:
var8 = var5;
var9 = var6;
var10 = var2;
}
case 4 -> {
break;
case 4:
var8 = var7;
var9 = var5;
var10 = var2;
}
case 5 -> {
break;
case 5:
var8 = var2;
var9 = var5;
var10 = var6;
}
default -> throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + var0 + ", " + var1 + ", " + var2);
break;
default:
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + var0 + ", " + var1 + ", " + var2);
}
int var11 = clamp((int) (var8 * 255.0F), 0, 255);
@@ -594,10 +596,11 @@ public class MathHelper {
public static double[] a(double... var0) {
float var1 = 0.0F;
double[] var2f = var0;
int var3 = var0.length;
for (int var4 = 0; var4 < var3; ++var4) {
double var5 = var0[var4];
double var5 = var2f[var4];
var1 = (float) ((double) var1 + var5);
}

View File

@@ -265,71 +265,85 @@ public class VectorMath {
KList<BlockFace> faces = new KList<>();
switch (f) {
case DOWN -> faces.add(BlockFace.DOWN);
case EAST -> faces.add(BlockFace.EAST);
case EAST_NORTH_EAST -> {
case DOWN:
faces.add(BlockFace.DOWN);
break;
case EAST:
faces.add(BlockFace.EAST);
break;
case EAST_NORTH_EAST:
faces.add(BlockFace.EAST);
faces.add(BlockFace.EAST);
faces.add(BlockFace.NORTH);
}
case EAST_SOUTH_EAST -> {
break;
case EAST_SOUTH_EAST:
faces.add(BlockFace.EAST);
faces.add(BlockFace.EAST);
faces.add(BlockFace.SOUTH);
}
case NORTH -> faces.add(BlockFace.NORTH);
case NORTH_EAST -> {
break;
case NORTH:
faces.add(BlockFace.NORTH);
break;
case NORTH_EAST:
faces.add(BlockFace.NORTH);
faces.add(BlockFace.EAST);
}
case NORTH_NORTH_EAST -> {
break;
case NORTH_NORTH_EAST:
faces.add(BlockFace.NORTH);
faces.add(BlockFace.NORTH);
faces.add(BlockFace.EAST);
}
case NORTH_NORTH_WEST -> {
break;
case NORTH_NORTH_WEST:
faces.add(BlockFace.NORTH);
faces.add(BlockFace.NORTH);
faces.add(BlockFace.WEST);
}
case NORTH_WEST -> {
break;
case NORTH_WEST:
faces.add(BlockFace.NORTH);
faces.add(BlockFace.WEST);
}
case SELF -> faces.add(BlockFace.SELF);
case SOUTH -> faces.add(BlockFace.SOUTH);
case SOUTH_EAST -> {
break;
case SELF:
faces.add(BlockFace.SELF);
break;
case SOUTH:
faces.add(BlockFace.SOUTH);
break;
case SOUTH_EAST:
faces.add(BlockFace.SOUTH);
faces.add(BlockFace.EAST);
}
case SOUTH_SOUTH_EAST -> {
break;
case SOUTH_SOUTH_EAST:
faces.add(BlockFace.SOUTH);
faces.add(BlockFace.SOUTH);
faces.add(BlockFace.EAST);
}
case SOUTH_SOUTH_WEST -> {
break;
case SOUTH_SOUTH_WEST:
faces.add(BlockFace.SOUTH);
faces.add(BlockFace.SOUTH);
faces.add(BlockFace.WEST);
}
case SOUTH_WEST -> {
break;
case SOUTH_WEST:
faces.add(BlockFace.SOUTH);
faces.add(BlockFace.WEST);
}
case UP -> faces.add(BlockFace.UP);
case WEST -> faces.add(BlockFace.WEST);
case WEST_NORTH_WEST -> {
break;
case UP:
faces.add(BlockFace.UP);
break;
case WEST:
faces.add(BlockFace.WEST);
break;
case WEST_NORTH_WEST:
faces.add(BlockFace.WEST);
faces.add(BlockFace.WEST);
faces.add(BlockFace.NORTH);
}
case WEST_SOUTH_WEST -> {
break;
case WEST_SOUTH_WEST:
faces.add(BlockFace.WEST);
faces.add(BlockFace.WEST);
faces.add(BlockFace.SOUTH);
}
default -> {
}
break;
default:
break;
}
return faces;

View File

@@ -19,6 +19,14 @@
package com.volmit.iris.util.matter;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import lombok.AllArgsConstructor;
import lombok.Data;
public record MatterEntity(double xOff, double yOff, double zOff, CompoundTag entityData) {
@Data
@AllArgsConstructor
public class MatterEntity {
private final double xOff;
private final double yOff;
private final double zOff;
private final CompoundTag entityData;
}

View File

@@ -19,6 +19,11 @@
package com.volmit.iris.util.matter;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import lombok.AllArgsConstructor;
import lombok.Data;
public record MatterTile(CompoundTag tileData) {
@Data
@AllArgsConstructor
public class MatterTile {
private final CompoundTag tileData;
}

View File

@@ -50,8 +50,8 @@ public class EntityMatter extends RawMatter<MatterEntityGroup> {
super(width, height, depth, MatterEntityGroup.class);
registerWriter(World.class, ((w, d, x, y, z) -> {
for (MatterEntity i : d.getEntities()) {
Location realPosition = new Location(w, x + i.xOff(), y + i.yOff(), z + i.zOff());
INMS.get().deserializeEntity(i.entityData(), realPosition);
Location realPosition = new Location(w, x + i.getXOff(), y + i.getYOff(), z + i.getZOff());
INMS.get().deserializeEntity(i.getEntityData(), realPosition);
}
}));
registerReader(World.class, (w, x, y, z) -> {
@@ -124,10 +124,10 @@ public class EntityMatter extends RawMatter<MatterEntityGroup> {
public void writeNode(MatterEntityGroup b, DataOutputStream dos) throws IOException {
Varint.writeUnsignedVarInt(b.getEntities().size(), dos);
for (MatterEntity i : b.getEntities()) {
dos.writeByte((int) (i.xOff() * 255) + Byte.MIN_VALUE);
dos.writeByte((int) (i.yOff() * 255) + Byte.MIN_VALUE);
dos.writeByte((int) (i.zOff() * 255) + Byte.MIN_VALUE);
NBTUtil.write(i.entityData(), dos, false);
dos.writeByte((int) (i.getXOff() * 255) + Byte.MIN_VALUE);
dos.writeByte((int) (i.getYOff() * 255) + Byte.MIN_VALUE);
dos.writeByte((int) (i.getZOff() * 255) + Byte.MIN_VALUE);
NBTUtil.write(i.getEntityData(), dos, false);
}
}

View File

@@ -38,7 +38,7 @@ public class TileMatter extends RawMatter<MatterTile> {
public TileMatter(int width, int height, int depth) {
super(width, height, depth, MatterTile.class);
registerWriter(World.class, ((w, d, x, y, z) -> INMS.get().deserializeTile(d.tileData(), new Location(w, x, y, z))));
registerWriter(World.class, ((w, d, x, y, z) -> INMS.get().deserializeTile(d.getTileData(), new Location(w, x, y, z))));
registerReader(World.class, (w, x, y, z) -> {
Location l = new Location(w, x, y, z);
if (INMS.get().hasTile(l)) {
@@ -55,7 +55,7 @@ public class TileMatter extends RawMatter<MatterTile> {
@Override
public void writeNode(MatterTile b, DataOutputStream dos) throws IOException {
NBTUtil.write(b.tileData(), dos, false);
NBTUtil.write(b.getTileData(), dos, false);
}
@Override

View File

@@ -494,7 +494,7 @@ public class Mth {
float var6 = var2 * (1.0F - var4 * var1);
float var7 = var2 * (1.0F - (1.0F - var4) * var1);
switch (var3) {
case 0 -> {
case 0:
var8 = var2;
var9 = var7;
var10 = var5;
@@ -502,8 +502,7 @@ public class Mth {
var12 = clamp((int) (var9 * 255.0F), 0, 255);
var13 = clamp((int) (var10 * 255.0F), 0, 255);
return var11 << 16 | var12 << 8 | var13;
}
case 1 -> {
case 1:
var8 = var6;
var9 = var2;
var10 = var5;
@@ -511,8 +510,7 @@ public class Mth {
var12 = clamp((int) (var9 * 255.0F), 0, 255);
var13 = clamp((int) (var10 * 255.0F), 0, 255);
return var11 << 16 | var12 << 8 | var13;
}
case 2 -> {
case 2:
var8 = var5;
var9 = var2;
var10 = var7;
@@ -520,8 +518,7 @@ public class Mth {
var12 = clamp((int) (var9 * 255.0F), 0, 255);
var13 = clamp((int) (var10 * 255.0F), 0, 255);
return var11 << 16 | var12 << 8 | var13;
}
case 3 -> {
case 3:
var8 = var5;
var9 = var6;
var10 = var2;
@@ -529,8 +526,7 @@ public class Mth {
var12 = clamp((int) (var9 * 255.0F), 0, 255);
var13 = clamp((int) (var10 * 255.0F), 0, 255);
return var11 << 16 | var12 << 8 | var13;
}
case 4 -> {
case 4:
var8 = var7;
var9 = var5;
var10 = var2;
@@ -538,8 +534,7 @@ public class Mth {
var12 = clamp((int) (var9 * 255.0F), 0, 255);
var13 = clamp((int) (var10 * 255.0F), 0, 255);
return var11 << 16 | var12 << 8 | var13;
}
case 5 -> {
case 5:
var8 = var2;
var9 = var5;
var10 = var6;
@@ -547,7 +542,6 @@ public class Mth {
var12 = clamp((int) (var9 * 255.0F), 0, 255);
var13 = clamp((int) (var10 * 255.0F), 0, 255);
return var11 << 16 | var12 << 8 | var13;
}
}
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + var0 + ", " + var1 + ", " + var2);
}

View File

@@ -25,23 +25,22 @@ import com.volmit.iris.util.scheduling.ChronoLatch;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.Arrays;
public abstract class DL {
protected final File d;
protected final URL u;
protected final ChronoLatch latch;
protected final KSet<DownloadFlag> flags;
protected File d;
protected URL u;
protected ChronoLatch latch;
protected KSet<DownloadFlag> flags;
protected MeteredOutputStream o;
protected DownloadState state;
protected final int timeout;
protected int timeout;
protected long size;
protected long start;
protected long downloaded;
protected long currentChunk;
protected long lastChunk;
protected long bps;
protected final int bufferSize;
protected int bufferSize;
protected long lastPull;
protected DownloadMonitor m;
@@ -61,7 +60,9 @@ public abstract class DL {
flags = new KSet<>();
latch = new ChronoLatch(500);
flags.addAll(Arrays.asList(downloadFlags));
for (DownloadFlag i : downloadFlags) {
flags.add(i);
}
}
public void monitor(DownloadMonitor m) {

View File

@@ -518,7 +518,9 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
return super.getDataFolder();
}
return new File(getDataFolder(), new KList<>(strings).toString(File.separator));
File f = new File(getDataFolder(), new KList<>(strings).toString(File.separator));
return f;
}
public File getDataFolderList(String pre, String[] strings) {

View File

@@ -206,16 +206,17 @@ public class VolmitSender implements CommandSender {
}
public void sendProgress(double percent, String thing) {
int l = 44;
int g;
if (percent < 0) {
g = (int) (1D * l);
int l = 44;
int g = (int) (1D * l);
sendTitle(C.IRIS + thing + " ", 0, 500, 250);
sendActionNoProcessing("" + "" + pulse("#00ff80", "#00373d", 1D) + "<underlined> " + Form.repeat(" ", g) + "<reset>" + Form.repeat(" ", l - g));
} else {
g = (int) (percent * l);
int l = 44;
int g = (int) (percent * l);
sendTitle(C.IRIS + thing + " " + C.BLUE + "<font:minecraft:uniform>" + Form.pc(percent, 0), 0, 500, 250);
sendActionNoProcessing("" + "" + pulse("#00ff80", "#00373d", 1D) + "<underlined> " + Form.repeat(" ", g) + "<reset>" + Form.repeat(" ", l - g));
}
sendActionNoProcessing("" + "" + pulse("#00ff80", "#00373d", 1D) + "<underlined> " + Form.repeat(" ", g) + "<reset>" + Form.repeat(" ", l - g));
}
public static String pulse(String colorA, String colorB, double speed) {
@@ -387,8 +388,9 @@ public class VolmitSender implements CommandSender {
public void sendHeader(String name, int overrideLength) {
int len = overrideLength;
int h = name.length() + 2;
String s = Form.repeat(" ", overrideLength - h - 4);
String s = Form.repeat(" ", len - h - 4);
String si = Form.repeat("(", 3);
String so = Form.repeat(")", 3);
String sf = "[";

View File

@@ -19,6 +19,7 @@
package com.volmit.iris.util.scheduling.jobs;
import com.volmit.iris.util.network.DL;
import com.volmit.iris.util.network.DownloadMonitor;
import java.io.File;
import java.io.IOException;
@@ -34,12 +35,15 @@ public class DownloadJob implements Job {
tw = 1;
cw = 0;
download = new DL.Download(new URL(url), destination, DL.DownloadFlag.CALCULATE_SIZE);
download.monitor((state, progress, elapsed, estimated, bps, iobps, size, downloaded, buffer, bufferuse) -> {
if (size == -1) {
tw = 1;
} else {
tw = (int) (size / 100);
cw = (int) (downloaded / 100);
download.monitor(new DownloadMonitor() {
@Override
public void onUpdate(DL.DownloadState state, double progress, long elapsed, long estimated, long bps, long iobps, long size, long downloaded, long buffer, double bufferuse) {
if (size == -1) {
tw = 1;
} else {
tw = (int) (size / 100);
cw = (int) (downloaded / 100);
}
}
});
}