mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Merge branch 't3/port-studio-v4' into feat/zed-editor-support
This commit is contained in:
commit
2455359550
207 files changed
+4308
-1820
No files matched your search
+64
@@ -28,6 +28,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -35,6 +36,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -196,6 +198,68 @@ public class CraftEngineDataProviderTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decayingCustomLeavesAreMadePersistentAndKeepTheirCustomIdentity() {
|
||||
BooleanProperty persistent = BooleanProperty.create("persistent", false);
|
||||
BlockDefinition definition = mock(BlockDefinition.class);
|
||||
ImmutableBlockState decaying = blockState(definition, "test:leaves[persistent=false]");
|
||||
ImmutableBlockState kept = blockState(definition, "test:leaves[persistent=true]");
|
||||
BlockData base = mock(BlockData.class);
|
||||
BlockData keptBase = mock(BlockData.class);
|
||||
doReturn(persistent).when(decaying).getProperty("persistent");
|
||||
doReturn(false).when(decaying).get(persistent);
|
||||
when(decaying.with(persistent, true)).thenReturn(kept);
|
||||
try (MockedStatic<CraftEngineBlocks> blocks = mockStatic(CraftEngineBlocks.class)) {
|
||||
blocks.when(() -> CraftEngineBlocks.getCustomBlockState(base)).thenReturn(decaying);
|
||||
blocks.when(() -> CraftEngineBlocks.getBukkitBlockData(kept)).thenReturn(keptBase);
|
||||
|
||||
IrisCustomData result = (IrisCustomData) new CraftEngineDataProvider()
|
||||
.withoutDecay(IrisCustomData.of(base, new Identifier("craftengine", "test/leaves[persistent=false]")));
|
||||
|
||||
assertSame(keptBase, result.getBase());
|
||||
assertEquals(new Identifier("test", "leaves[persistent=true]"), result.getCustom());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void persistentOrDecaylessCustomBlocksAreKeptAsTheyAre() {
|
||||
BooleanProperty persistent = BooleanProperty.create("persistent", false);
|
||||
BlockDefinition definition = mock(BlockDefinition.class);
|
||||
ImmutableBlockState alreadyPersistent = blockState(definition, "test:leaves[persistent=true]");
|
||||
ImmutableBlockState withoutProperty = blockState(definition, "test:log");
|
||||
BlockData persistentData = mock(BlockData.class);
|
||||
BlockData logData = mock(BlockData.class);
|
||||
BlockData vanilla = mock(BlockData.class);
|
||||
doReturn(persistent).when(alreadyPersistent).getProperty("persistent");
|
||||
doReturn(true).when(alreadyPersistent).get(persistent);
|
||||
try (MockedStatic<CraftEngineBlocks> blocks = mockStatic(CraftEngineBlocks.class)) {
|
||||
blocks.when(() -> CraftEngineBlocks.getCustomBlockState(persistentData)).thenReturn(alreadyPersistent);
|
||||
blocks.when(() -> CraftEngineBlocks.getCustomBlockState(logData)).thenReturn(withoutProperty);
|
||||
CraftEngineDataProvider provider = new CraftEngineDataProvider();
|
||||
|
||||
assertSame(persistentData, provider.withoutDecay(persistentData));
|
||||
assertSame(logData, provider.withoutDecay(logData));
|
||||
assertSame(vanilla, provider.withoutDecay(vanilla));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customBlocksCarryTheTagsTheirSettingsListEvenWhenWrapped() {
|
||||
ImmutableBlockState state = mock(ImmutableBlockState.class, Mockito.RETURNS_DEEP_STUBS);
|
||||
BlockData base = mock(BlockData.class);
|
||||
BlockData vanilla = mock(BlockData.class);
|
||||
when(state.settings().tags()).thenReturn(Set.of(Key.of("minecraft:logs")));
|
||||
try (MockedStatic<CraftEngineBlocks> blocks = mockStatic(CraftEngineBlocks.class)) {
|
||||
blocks.when(() -> CraftEngineBlocks.getCustomBlockState(base)).thenReturn(state);
|
||||
CraftEngineDataProvider provider = new CraftEngineDataProvider();
|
||||
BlockData wrapped = IrisCustomData.of(base, new Identifier("craftengine", "test/log"));
|
||||
|
||||
assertTrue(provider.hasBlockTag(wrapped, NamespacedKey.minecraft("logs")));
|
||||
assertFalse(provider.hasBlockTag(wrapped, NamespacedKey.minecraft("leaves")));
|
||||
assertFalse(provider.hasBlockTag(vanilla, NamespacedKey.minecraft("logs")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknownOrInvalidBlockPropertiesFailBeforeNativeConversion() {
|
||||
Identifier id = new Identifier("test", "lamp");
|
||||
|
||||
@@ -417,6 +417,7 @@ public class IrisSettings {
|
||||
public boolean disableTimeAndWeather = true;
|
||||
public boolean entitySpawning = true;
|
||||
public boolean autoStartDefaultStudio = false;
|
||||
public boolean downloadApp = true;
|
||||
public String studioApp = "";
|
||||
public String electron = "electron";
|
||||
|
||||
|
||||
@@ -84,6 +84,14 @@ public class B {
|
||||
return state != null && state.isTreeBlock();
|
||||
}
|
||||
|
||||
public static boolean isLog(NativeBlockState state) {
|
||||
return state != null && state.isLog();
|
||||
}
|
||||
|
||||
public static boolean isLeaves(NativeBlockState state) {
|
||||
return state != null && state.isLeaves();
|
||||
}
|
||||
|
||||
public static boolean isFoliagePlantable(NativeBlockState state) {
|
||||
return state != null && state.isFoliagePlantable();
|
||||
}
|
||||
|
||||
@@ -62,6 +62,9 @@ public class IrisNoiseGenerator {
|
||||
private static final long GENERATOR_SEED_SALT = 33_955_677L;
|
||||
private static final int MINIMUM_FRACTURE_DEPTH = 4;
|
||||
private static final int MAXIMUM_FRACTURE_NODES = 32;
|
||||
// Fracture axes as CNG.reseededForAxis numbers them for a 2D read: x is axis 0, z is axis 1.
|
||||
static final int X_AXIS = 0;
|
||||
static final int Z_AXIS = 1;
|
||||
private static final ThreadLocal<FractureSamples> FRACTURE_SAMPLES = ThreadLocal.withInitial(FractureSamples::new);
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
@@ -144,6 +147,14 @@ public class IrisNoiseGenerator {
|
||||
}
|
||||
|
||||
double getNoise(long superSeed, double xv, double zv, IrisData data, Engine engine) {
|
||||
return getNoiseForAxis(superSeed, xv, zv, data, engine, X_AXIS);
|
||||
}
|
||||
|
||||
/**
|
||||
* This layer read as the fracture of one axis. Each axis samples this layer's generator reseeded for that axis at
|
||||
* the same coordinates, so the x and z warps are uncorrelated instead of mirror images of each other.
|
||||
*/
|
||||
private double getNoiseForAxis(long superSeed, double xv, double zv, IrisData data, Engine engine, int axis) {
|
||||
if (!enabled) {
|
||||
return offsetY;
|
||||
}
|
||||
@@ -154,7 +165,7 @@ public class IrisNoiseGenerator {
|
||||
samples.active = true;
|
||||
try {
|
||||
if (samples.prepare(this, superSeed, data, engine)) {
|
||||
return samples.sample(xv, zv);
|
||||
return samples.sample(xv, zv, axis);
|
||||
}
|
||||
} finally {
|
||||
samples.clear();
|
||||
@@ -169,13 +180,13 @@ public class IrisNoiseGenerator {
|
||||
for (IrisNoiseGenerator i : fracture) {
|
||||
if (i.isEnabled()) {
|
||||
double fractureOffset = i.getOpacity() / 2D;
|
||||
x += i.getNoise(superSeed + seed + g, xv, zv, data, engine) - fractureOffset;
|
||||
z += i.getNoise(superSeed + seed + g, zv, xv, data, engine) - fractureOffset;
|
||||
x += i.getNoiseForAxis(superSeed + seed + g, xv, zv, data, engine, X_AXIS) - fractureOffset;
|
||||
z += i.getNoiseForAxis(superSeed + seed + g, xv, zv, data, engine, Z_AXIS) - fractureOffset;
|
||||
}
|
||||
g += 819;
|
||||
}
|
||||
|
||||
return sample(getGenerator(superSeed, data, engine), x, z);
|
||||
return sample(getGenerator(superSeed, data, engine).reseededForAxis(axis), x, z);
|
||||
}
|
||||
|
||||
boolean supportsBatch() {
|
||||
@@ -200,6 +211,10 @@ public class IrisNoiseGenerator {
|
||||
}
|
||||
|
||||
NoiseLayerProgram compileProgram(long superSeed, IrisData data, Engine engine) {
|
||||
return compileProgram(superSeed, data, engine, false);
|
||||
}
|
||||
|
||||
private NoiseLayerProgram compileProgram(long superSeed, IrisData data, Engine engine, boolean readAsFracture) {
|
||||
if (!enabled) {
|
||||
return NoiseLayerProgram.disabled(this);
|
||||
}
|
||||
@@ -215,13 +230,14 @@ public class IrisNoiseGenerator {
|
||||
int compiled = 0;
|
||||
for (IrisNoiseGenerator child : fracture) {
|
||||
if (child.isEnabled()) {
|
||||
children[compiled] = child.compileProgram(superSeed + seed + salt, data, engine);
|
||||
children[compiled] = child.compileProgram(superSeed + seed + salt, data, engine, true);
|
||||
offsets[compiled++] = child.getOpacity() / 2D;
|
||||
}
|
||||
salt += 819;
|
||||
}
|
||||
CNG generator = Objects.requireNonNull(getGenerator(superSeed, data, engine), "Noise layer generator");
|
||||
return NoiseLayerProgram.of(this, NoiseProgram.compile2D(generator), children, offsets);
|
||||
NoiseProgram zAxisProgram = readAsFracture ? NoiseProgram.compile2D(generator.reseededForAxis(Z_AXIS)) : null;
|
||||
return NoiseLayerProgram.of(this, NoiseProgram.compile2D(generator), zAxisProgram, children, offsets);
|
||||
}
|
||||
|
||||
public KList<IrisNoiseGenerator> getAllComposites() {
|
||||
@@ -357,20 +373,26 @@ public class IrisNoiseGenerator {
|
||||
return false;
|
||||
}
|
||||
|
||||
private double sample(double x, double z) {
|
||||
/**
|
||||
* Both axes of a fracture node read the same warped coordinates, since a reseeded generator shares the
|
||||
* node's own fracture, so each level samples its generator once per axis.
|
||||
*/
|
||||
private double sample(double x, double z, int rootAxis) {
|
||||
int leaf = size - 1;
|
||||
double forward = nodes[leaf].sample(generators[leaf], x, z);
|
||||
double reverse = nodes[leaf].sample(generators[leaf], z, x);
|
||||
for (int index = leaf - 1; index >= 0; index--) {
|
||||
double offset = nodes[index + 1].opacity / 2D;
|
||||
double forwardX = x + (forward - offset);
|
||||
double forwardZ = z + (reverse - offset);
|
||||
forward = nodes[index].sample(generators[index], forwardX, forwardZ);
|
||||
if (index > 0) {
|
||||
reverse = nodes[index].sample(generators[index], forwardZ, forwardX);
|
||||
}
|
||||
if (leaf == 0) {
|
||||
return nodes[0].sample(generators[0].reseededForAxis(rootAxis), x, z);
|
||||
}
|
||||
return forward;
|
||||
double warpX = nodes[leaf].sample(generators[leaf], x, z);
|
||||
double warpZ = nodes[leaf].sample(generators[leaf].reseededForAxis(Z_AXIS), x, z);
|
||||
for (int index = leaf - 1; index > 0; index--) {
|
||||
double offset = nodes[index + 1].opacity / 2D;
|
||||
double warpedX = x + (warpX - offset);
|
||||
double warpedZ = z + (warpZ - offset);
|
||||
warpX = nodes[index].sample(generators[index], warpedX, warpedZ);
|
||||
warpZ = nodes[index].sample(generators[index].reseededForAxis(Z_AXIS), warpedX, warpedZ);
|
||||
}
|
||||
double offset = nodes[1].opacity / 2D;
|
||||
return nodes[0].sample(generators[0].reseededForAxis(rootAxis), x + (warpX - offset), z + (warpZ - offset));
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
|
||||
@@ -9,6 +9,7 @@ public final class NoiseLayerProgram {
|
||||
private final boolean enabled;
|
||||
private final double offsetY;
|
||||
private final NoiseProgram program;
|
||||
private final NoiseProgram zAxisProgram;
|
||||
private final double zoom;
|
||||
private final double opacity;
|
||||
private final double offsetX;
|
||||
@@ -21,10 +22,12 @@ public final class NoiseLayerProgram {
|
||||
private final NoiseLayerProgram[] children;
|
||||
private final double[] childOffsets;
|
||||
|
||||
private NoiseLayerProgram(IrisNoiseGenerator layer, NoiseProgram program, NoiseLayerProgram[] children, double[] childOffsets) {
|
||||
private NoiseLayerProgram(IrisNoiseGenerator layer, NoiseProgram program, NoiseProgram zAxisProgram,
|
||||
NoiseLayerProgram[] children, double[] childOffsets) {
|
||||
this.enabled = program != null;
|
||||
this.offsetY = layer.getOffsetY();
|
||||
this.program = program;
|
||||
this.zAxisProgram = zAxisProgram;
|
||||
this.zoom = layer.getZoom();
|
||||
this.opacity = layer.getOpacity();
|
||||
this.offsetX = layer.getOffsetX();
|
||||
@@ -39,11 +42,16 @@ public final class NoiseLayerProgram {
|
||||
}
|
||||
|
||||
static NoiseLayerProgram disabled(IrisNoiseGenerator layer) {
|
||||
return new NoiseLayerProgram(layer, null, new NoiseLayerProgram[0], new double[0]);
|
||||
return new NoiseLayerProgram(layer, null, null, new NoiseLayerProgram[0], new double[0]);
|
||||
}
|
||||
|
||||
static NoiseLayerProgram of(IrisNoiseGenerator layer, NoiseProgram program, NoiseLayerProgram[] children, double[] childOffsets) {
|
||||
return new NoiseLayerProgram(layer, program, children, childOffsets);
|
||||
/**
|
||||
* zAxisProgram is the layer's generator reseeded for the z axis; only a layer read as a fracture needs it, and the
|
||||
* root layer passes null.
|
||||
*/
|
||||
static NoiseLayerProgram of(IrisNoiseGenerator layer, NoiseProgram program, NoiseProgram zAxisProgram,
|
||||
NoiseLayerProgram[] children, double[] childOffsets) {
|
||||
return new NoiseLayerProgram(layer, program, zAxisProgram, children, childOffsets);
|
||||
}
|
||||
|
||||
public void evaluate(TerrainBatchScratch scratch, double[] xs, double[] zs, int count, double[] out) {
|
||||
@@ -53,143 +61,110 @@ public final class NoiseLayerProgram {
|
||||
}
|
||||
int mark = scratch.mark();
|
||||
try {
|
||||
fill(scratch, xs, zs, count, out);
|
||||
double[] sampleX = scratch.buffer(count);
|
||||
double[] sampleZ = scratch.buffer(count);
|
||||
warpedSampleCoordinates(scratch, xs, zs, count, sampleX, sampleZ);
|
||||
program.fill2D(scratch.noise(), sampleX, sampleZ, count, out);
|
||||
applyPost(out, count);
|
||||
} finally {
|
||||
scratch.reset(mark);
|
||||
}
|
||||
}
|
||||
|
||||
private void fill(TerrainBatchScratch scratch, double[] xs, double[] zs, int count, double[] out) {
|
||||
double[] sampleX = scratch.buffer(count);
|
||||
double[] sampleZ = scratch.buffer(count);
|
||||
if (children.length == 0) {
|
||||
for (int index = 0; index < count; index++) {
|
||||
sampleX[index] = (xs[index] / zoom) + offsetX;
|
||||
sampleZ[index] = (zs[index] / zoom) + offsetZ;
|
||||
}
|
||||
} else {
|
||||
System.arraycopy(xs, 0, sampleX, 0, count);
|
||||
System.arraycopy(zs, 0, sampleZ, 0, count);
|
||||
double[] forward = scratch.buffer(count);
|
||||
double[] reverse = scratch.buffer(count);
|
||||
for (int child = 0; child < children.length; child++) {
|
||||
children[child].evaluatePair(scratch, xs, zs, count, forward, reverse);
|
||||
double offset = childOffsets[child];
|
||||
for (int index = 0; index < count; index++) {
|
||||
sampleX[index] += forward[index] - offset;
|
||||
sampleZ[index] += reverse[index] - offset;
|
||||
}
|
||||
}
|
||||
for (int index = 0; index < count; index++) {
|
||||
sampleX[index] = (sampleX[index] / zoom) + offsetX;
|
||||
sampleZ[index] = (sampleZ[index] / zoom) + offsetZ;
|
||||
}
|
||||
}
|
||||
program.fill2D(scratch.noise(), sampleX, sampleZ, count, out);
|
||||
for (int index = 0; index < count; index++) {
|
||||
out[index] = post(out[index]);
|
||||
}
|
||||
}
|
||||
|
||||
void evaluatePair(TerrainBatchScratch scratch, double[] xs, double[] zs, int count, double[] forward, double[] reverse) {
|
||||
/** Fills this layer read as a fracture: the x warp from its generator, the z warp from its z-axis generator. */
|
||||
void evaluateAxes(TerrainBatchScratch scratch, double[] xs, double[] zs, int count, double[] xWarp, double[] zWarp) {
|
||||
if (!enabled) {
|
||||
Arrays.fill(forward, 0, count, offsetY);
|
||||
Arrays.fill(reverse, 0, count, offsetY);
|
||||
Arrays.fill(xWarp, 0, count, offsetY);
|
||||
Arrays.fill(zWarp, 0, count, offsetY);
|
||||
return;
|
||||
}
|
||||
int mark = scratch.mark();
|
||||
try {
|
||||
fillPair(scratch, xs, zs, count, forward, reverse);
|
||||
double[] sampleX = scratch.buffer(count);
|
||||
double[] sampleZ = scratch.buffer(count);
|
||||
warpedSampleCoordinates(scratch, xs, zs, count, sampleX, sampleZ);
|
||||
program.fill2D(scratch.noise(), sampleX, sampleZ, count, xWarp);
|
||||
zAxisProgram.fill2D(scratch.noise(), sampleX, sampleZ, count, zWarp);
|
||||
applyPost(xWarp, count);
|
||||
applyPost(zWarp, count);
|
||||
} finally {
|
||||
scratch.reset(mark);
|
||||
}
|
||||
}
|
||||
|
||||
private void fillPair(TerrainBatchScratch scratch, double[] xs, double[] zs, int count, double[] forward, double[] reverse) {
|
||||
int pairs = count * 2;
|
||||
double[] sampleX = scratch.buffer(pairs);
|
||||
double[] sampleZ = scratch.buffer(pairs);
|
||||
private void warpedSampleCoordinates(TerrainBatchScratch scratch, double[] xs, double[] zs, int count,
|
||||
double[] sampleX, double[] sampleZ) {
|
||||
System.arraycopy(xs, 0, sampleX, 0, count);
|
||||
System.arraycopy(zs, 0, sampleZ, 0, count);
|
||||
System.arraycopy(zs, 0, sampleX, count, count);
|
||||
System.arraycopy(xs, 0, sampleZ, count, count);
|
||||
if (children.length > 0) {
|
||||
double[] childForward = scratch.buffer(count);
|
||||
double[] childReverse = scratch.buffer(count);
|
||||
double[] childX = scratch.buffer(count);
|
||||
double[] childZ = scratch.buffer(count);
|
||||
for (int child = 0; child < children.length; child++) {
|
||||
children[child].evaluatePair(scratch, xs, zs, count, childForward, childReverse);
|
||||
children[child].evaluateAxes(scratch, xs, zs, count, childX, childZ);
|
||||
double offset = childOffsets[child];
|
||||
for (int index = 0; index < count; index++) {
|
||||
sampleX[index] += childForward[index] - offset;
|
||||
sampleZ[index] += childReverse[index] - offset;
|
||||
sampleX[count + index] += childReverse[index] - offset;
|
||||
sampleZ[count + index] += childForward[index] - offset;
|
||||
sampleX[index] += childX[index] - offset;
|
||||
sampleZ[index] += childZ[index] - offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int index = 0; index < pairs; index++) {
|
||||
for (int index = 0; index < count; index++) {
|
||||
sampleX[index] = (sampleX[index] / zoom) + offsetX;
|
||||
sampleZ[index] = (sampleZ[index] / zoom) + offsetZ;
|
||||
}
|
||||
double[] values = scratch.buffer(pairs);
|
||||
program.fill2D(scratch.noise(), sampleX, sampleZ, pairs, values);
|
||||
for (int index = 0; index < count; index++) {
|
||||
forward[index] = post(values[index]);
|
||||
reverse[index] = post(values[count + index]);
|
||||
}
|
||||
}
|
||||
|
||||
public double sample(TerrainBatchScratch scratch, double x, double z) {
|
||||
if (!enabled) {
|
||||
return offsetY;
|
||||
}
|
||||
double sampleX = x;
|
||||
double sampleZ = z;
|
||||
if (children.length > 0) {
|
||||
int mark = scratch.mark();
|
||||
try {
|
||||
double[] pair = scratch.buffer(2);
|
||||
for (int child = 0; child < children.length; child++) {
|
||||
children[child].samplePair(scratch, x, z, pair);
|
||||
double offset = childOffsets[child];
|
||||
sampleX += pair[0] - offset;
|
||||
sampleZ += pair[1] - offset;
|
||||
}
|
||||
} finally {
|
||||
scratch.reset(mark);
|
||||
}
|
||||
int mark = scratch.mark();
|
||||
try {
|
||||
double[] sampleCoordinates = scratch.buffer(2);
|
||||
warpedSampleCoordinate(scratch, x, z, sampleCoordinates);
|
||||
return post(program.sample2D(sampleCoordinates[0], sampleCoordinates[1]));
|
||||
} finally {
|
||||
scratch.reset(mark);
|
||||
}
|
||||
return post(program.sample2D((sampleX / zoom) + offsetX, (sampleZ / zoom) + offsetZ));
|
||||
}
|
||||
|
||||
private void samplePair(TerrainBatchScratch scratch, double x, double z, double[] out) {
|
||||
private void sampleAxes(TerrainBatchScratch scratch, double x, double z, double[] out) {
|
||||
if (!enabled) {
|
||||
out[0] = offsetY;
|
||||
out[1] = offsetY;
|
||||
return;
|
||||
}
|
||||
double forwardX = x;
|
||||
double forwardZ = z;
|
||||
double reverseX = z;
|
||||
double reverseZ = x;
|
||||
int mark = scratch.mark();
|
||||
try {
|
||||
double[] sampleCoordinates = scratch.buffer(2);
|
||||
warpedSampleCoordinate(scratch, x, z, sampleCoordinates);
|
||||
out[0] = post(program.sample2D(sampleCoordinates[0], sampleCoordinates[1]));
|
||||
out[1] = post(zAxisProgram.sample2D(sampleCoordinates[0], sampleCoordinates[1]));
|
||||
} finally {
|
||||
scratch.reset(mark);
|
||||
}
|
||||
}
|
||||
|
||||
private void warpedSampleCoordinate(TerrainBatchScratch scratch, double x, double z, double[] out) {
|
||||
double sampleX = x;
|
||||
double sampleZ = z;
|
||||
if (children.length > 0) {
|
||||
int mark = scratch.mark();
|
||||
try {
|
||||
double[] pair = scratch.buffer(2);
|
||||
for (int child = 0; child < children.length; child++) {
|
||||
children[child].samplePair(scratch, x, z, pair);
|
||||
double offset = childOffsets[child];
|
||||
forwardX += pair[0] - offset;
|
||||
forwardZ += pair[1] - offset;
|
||||
reverseX += pair[1] - offset;
|
||||
reverseZ += pair[0] - offset;
|
||||
}
|
||||
} finally {
|
||||
scratch.reset(mark);
|
||||
double[] warp = scratch.buffer(2);
|
||||
for (int child = 0; child < children.length; child++) {
|
||||
children[child].sampleAxes(scratch, x, z, warp);
|
||||
double offset = childOffsets[child];
|
||||
sampleX += warp[0] - offset;
|
||||
sampleZ += warp[1] - offset;
|
||||
}
|
||||
}
|
||||
out[0] = post(program.sample2D((forwardX / zoom) + offsetX, (forwardZ / zoom) + offsetZ));
|
||||
out[1] = post(program.sample2D((reverseX / zoom) + offsetX, (reverseZ / zoom) + offsetZ));
|
||||
out[0] = (sampleX / zoom) + offsetX;
|
||||
out[1] = (sampleZ / zoom) + offsetZ;
|
||||
}
|
||||
|
||||
private void applyPost(double[] values, int count) {
|
||||
for (int index = 0; index < count; index++) {
|
||||
values[index] = post(values[index]);
|
||||
}
|
||||
}
|
||||
|
||||
private double post(double raw) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -128,6 +129,25 @@ public abstract class ExternalDataProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data The block to keep, possibly an {@link IrisCustomData} this provider returned from {@link #getBlockData}
|
||||
* @return The block made to never decay, like custom leaves, or {@code data} itself when it is not one of the
|
||||
* provider's decaying blocks
|
||||
*/
|
||||
@NotNull
|
||||
public BlockData withoutDecay(@NotNull BlockData data) {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data The block to check, possibly an {@link IrisCustomData} this provider returned from {@link #getBlockData}
|
||||
* @param tag A block tag, like {@code minecraft:logs}
|
||||
* @return Whether the block is one of the provider's blocks and carries that tag
|
||||
*/
|
||||
public boolean hasBlockTag(@NotNull BlockData data, @NotNull NamespacedKey tag) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawns a mob in the specified location using the given engine and entity identifier.
|
||||
*
|
||||
|
||||
@@ -30,6 +30,7 @@ import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.iris.platform.bukkit.plugin.IrisService;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -193,6 +194,26 @@ public class ExternalDataSVC implements IrisService {
|
||||
return blockData;
|
||||
}
|
||||
|
||||
/** The block made to never decay by the provider it belongs to, or {@code data} itself. */
|
||||
public BlockData withoutDecay(BlockData data) {
|
||||
for (ExternalDataProvider provider : activeProviders) {
|
||||
BlockData kept = provider.withoutDecay(data);
|
||||
if (kept == data) {
|
||||
continue;
|
||||
}
|
||||
if (kept instanceof IrisCustomData custom && data instanceof IrisCustomData) {
|
||||
return IrisCustomData.of(custom.getBase(), qualifyBlockId(provider, custom.getCustom()));
|
||||
}
|
||||
return kept;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/** Whether {@code data} is a provider's block carrying {@code tag}. */
|
||||
public boolean hasBlockTag(BlockData data, NamespacedKey tag) {
|
||||
return activeProviders.stream().anyMatch(provider -> provider.hasBlockTag(data, tag));
|
||||
}
|
||||
|
||||
public Optional<BlockData> getBlockData(final Identifier key) {
|
||||
Pair<Identifier, KMap<String, String>> pair;
|
||||
try {
|
||||
|
||||
@@ -30,6 +30,7 @@ import net.momirealms.craftengine.core.util.Key;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -57,6 +58,7 @@ public class CraftEngineDataProvider extends ExternalDataProvider implements Lis
|
||||
BlockProperty.ofBoolean("randomPitch", false),
|
||||
BlockProperty.ofDouble("pitch", 0, 0, 360f, false, true)
|
||||
);
|
||||
private static final String PERSISTENT_PROPERTY = "persistent";
|
||||
private static final ContentRegistry EMPTY_CONTENT = new ContentRegistry(Set.of(), Set.of(), false);
|
||||
|
||||
private volatile ContentRegistry content = EMPTY_CONTENT;
|
||||
@@ -131,6 +133,32 @@ public class CraftEngineDataProvider extends ExternalDataProvider implements Lis
|
||||
return state == null || state.isEmpty() ? Optional.empty() : Optional.of(Identifier.fromString(state.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BlockData withoutDecay(@NotNull BlockData data) {
|
||||
ImmutableBlockState state = customStateOf(data);
|
||||
if (state == null) {
|
||||
return data;
|
||||
}
|
||||
Property<Boolean> persistent = state.getProperty(PERSISTENT_PROPERTY);
|
||||
if (persistent == null || persistent.valueClass() != Boolean.class || state.get(persistent)) {
|
||||
return data;
|
||||
}
|
||||
ImmutableBlockState kept = state.with(persistent, true);
|
||||
return IrisCustomData.of(CraftEngineBlocks.getBukkitBlockData(kept), Identifier.fromString(kept.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBlockTag(@NotNull BlockData data, @NotNull NamespacedKey tag) {
|
||||
ImmutableBlockState state = customStateOf(data);
|
||||
return state != null && state.settings().tags().contains(Key.of(tag.getNamespace(), tag.getKey()));
|
||||
}
|
||||
|
||||
private static ImmutableBlockState customStateOf(BlockData data) {
|
||||
BlockData nativeData = data instanceof IrisCustomData custom ? custom.getBase() : data;
|
||||
ImmutableBlockState state = CraftEngineBlocks.getCustomBlockState(nativeData);
|
||||
return state == null || state.isEmpty() ? null : state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(@NotNull Block block, @NotNull Identifier blockId) {
|
||||
Pair<Identifier, KMap<String, String>> parsed = ExternalDataSVC.parseState(blockId);
|
||||
|
||||
@@ -78,6 +78,14 @@ public final class RuntimeUiMessages {
|
||||
public static final TextKey DUST_OBJECTS_IN_CHUNK = TextKey.of("iris.runtime.dust.objects_in_chunk", "Objects in chunk: {objects}");
|
||||
public static final TextKey DUST_COPY_BUTTON = TextKey.of("iris.runtime.dust.copy_button", "[Click to copy these stats]");
|
||||
public static final TextKey DUST_COPY_HOVER = TextKey.of("iris.runtime.dust.copy_hover", "Copy block stats to clipboard");
|
||||
public static final TextKey STUDIO_APP_DOWNLOAD_OFF = TextKey.of("iris.runtime.studio.app_download_off", "Studio app download is off: set studio.downloadApp to true in iris.json.");
|
||||
public static final TextKey STUDIO_APP_NO_DISPLAY = TextKey.of("iris.runtime.studio.app_no_display", "This server has no display to open the studio app on.");
|
||||
public static final TextKey STUDIO_APP_DOWNLOADING = TextKey.of("iris.runtime.studio.app_downloading", "Studio app is still downloading; try again in a moment.");
|
||||
public static final TextKey STUDIO_APP_UNAVAILABLE = TextKey.of("iris.runtime.studio.app_unavailable", "Studio app unavailable; see the console.");
|
||||
public static final TextKey STUDIO_APP_NOT_BUILT = TextKey.of("iris.runtime.studio.app_not_built", "Studio app not built: run npm run build in its folder.");
|
||||
public static final TextKey STUDIO_APP_FAILED_TO_START = TextKey.of("iris.runtime.studio.app_failed_to_start", "Studio app failed to start; see the console.");
|
||||
public static final TextKey STUDIO_LINK_COPY_BUTTON = TextKey.of("iris.runtime.studio.link_copy_button", "[Copy studio link]");
|
||||
public static final TextKey STUDIO_LINK_COPY_HOVER = TextKey.of("iris.runtime.studio.link_copy_hover", "Paste it into the studio app's connect screen");
|
||||
public static final TextKey DUST_REVEAL_FAILED = TextKey.of("iris.runtime.dust.reveal_failed", "Object reveal failed; see the console for details.");
|
||||
public static final TextKey DUST_BIOME_LOADING = TextKey.of("iris.runtime.dust.biome_loading", "Saved biome information is loading. Try revealing this block again shortly.");
|
||||
public static final TextKey WHAT_MATERIAL = TextKey.of("iris.runtime.what.material", "Material: {material}");
|
||||
@@ -196,6 +204,14 @@ public final class RuntimeUiMessages {
|
||||
DUST_OBJECTS_IN_CHUNK,
|
||||
DUST_COPY_BUTTON,
|
||||
DUST_COPY_HOVER,
|
||||
STUDIO_APP_DOWNLOAD_OFF,
|
||||
STUDIO_APP_NO_DISPLAY,
|
||||
STUDIO_APP_DOWNLOADING,
|
||||
STUDIO_APP_UNAVAILABLE,
|
||||
STUDIO_APP_NOT_BUILT,
|
||||
STUDIO_APP_FAILED_TO_START,
|
||||
STUDIO_LINK_COPY_BUTTON,
|
||||
STUDIO_LINK_COPY_HOVER,
|
||||
DUST_REVEAL_FAILED,
|
||||
DUST_BIOME_LOADING,
|
||||
WHAT_MATERIAL,
|
||||
|
||||
+2
-10
@@ -143,7 +143,7 @@ public final class NoiseStyleCompiler implements StyleCompiler {
|
||||
Field center = new Field.Const(-child.getOpacity() / 2.0);
|
||||
String childPath = path + "/f" + index + "_" + child.getSeed();
|
||||
warpX = sum(warpX, binary(Field.BinaryOp.ADD, layer(child, domain, emit, childPath + "x"), center));
|
||||
warpZ = sum(warpZ, binary(Field.BinaryOp.ADD, layer(child, domain.swapped(), emit, childPath + "z"), center));
|
||||
warpZ = sum(warpZ, binary(Field.BinaryOp.ADD, layer(child, domain, emit, childPath + "z"), center));
|
||||
}
|
||||
Domain sampled = domain.layer(positive(layer.getZoom(), "layer zoom"), layer.getOffsetX(), layer.getOffsetZ(), warpX, warpZ);
|
||||
Field value = style(layer.getStyle(), layer.getOctaves(), sampled, emit, path);
|
||||
@@ -208,7 +208,7 @@ public final class NoiseStyleCompiler implements StyleCompiler {
|
||||
Displacement leafDisplacement = displacement;
|
||||
if (warped(cng)) {
|
||||
Field warpX = displacement(node(cng.getFracture(), displacement, emit, path + "/x"), cng.getFscale());
|
||||
Field warpZ = displacement(node(cng.getFracture(), displacement.swapped(), emit, path + "/z"), cng.getFscale());
|
||||
Field warpZ = displacement(node(cng.getFracture(), displacement, emit, path + "/z"), cng.getFscale());
|
||||
leafDisplacement = displacement.warped(warpX, warpZ);
|
||||
}
|
||||
value = leaf(type, cng.getOct(), cng.getEffectiveScale() * multiplier, leafDisplacement, emit, path);
|
||||
@@ -483,19 +483,11 @@ public final class NoiseStyleCompiler implements StyleCompiler {
|
||||
sum(warpX, layerWarpX == null ? null : scaled(layerWarpX, zoom)),
|
||||
sum(warpZ, layerWarpZ == null ? null : scaled(layerWarpZ, zoom)));
|
||||
}
|
||||
|
||||
private Domain swapped() {
|
||||
return new Domain(zoom, offsetZ, offsetX, warpZ, warpX);
|
||||
}
|
||||
}
|
||||
|
||||
private record Displacement(double offsetX, double offsetZ, Field warpX, Field warpZ) {
|
||||
private static final Displacement NONE = new Displacement(0.0, 0.0, null, null);
|
||||
|
||||
private Displacement swapped() {
|
||||
return new Displacement(offsetZ, offsetX, warpZ, warpX);
|
||||
}
|
||||
|
||||
private Displacement warped(Field addedX, Field addedZ) {
|
||||
return new Displacement(offsetX, offsetZ, sum(warpX, addedX), sum(warpZ, addedZ));
|
||||
}
|
||||
|
||||
@@ -129,6 +129,16 @@ public final class MissingBlockState implements NativeBlockState {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoliagePlantable() {
|
||||
return false;
|
||||
|
||||
@@ -100,8 +100,12 @@ public final class BukkitBlockResolution {
|
||||
}
|
||||
|
||||
Identifier key = Identifier.fromString(ix);
|
||||
Optional<BlockData> bd = IrisServices.get(ExternalDataSVC.class).getBlockData(key);
|
||||
ExternalDataSVC external = IrisServices.get(ExternalDataSVC.class);
|
||||
Optional<BlockData> bd = external.getBlockData(key);
|
||||
debug("Loading block data " + key);
|
||||
if (bd.isPresent() && shouldPreventLeafDecay()) {
|
||||
return external.withoutDecay(bd.get());
|
||||
}
|
||||
return bd.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,11 @@ import art.arcane.volmlib.nativelib.terrain.BlockStateKey;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.iris.generation.block.IrisCustomData;
|
||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -75,6 +77,8 @@ public final class BukkitBlockState implements NativeBlockState {
|
||||
private byte updatable;
|
||||
private byte foliage;
|
||||
private byte treeBlock;
|
||||
private byte log;
|
||||
private byte leaves;
|
||||
private byte foliagePlantable;
|
||||
private byte decorant;
|
||||
private byte storage;
|
||||
@@ -318,12 +322,41 @@ public final class BukkitBlockState implements NativeBlockState {
|
||||
public boolean isTreeBlock() {
|
||||
byte cached = treeBlock;
|
||||
if (cached == UNKNOWN) {
|
||||
cached = flag(Tag.LOGS.isTagged(data.getMaterial()) || Tag.LEAVES.isTagged(data.getMaterial()));
|
||||
cached = flag(isLog() || isLeaves());
|
||||
treeBlock = cached;
|
||||
}
|
||||
return cached == TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLog() {
|
||||
byte cached = log;
|
||||
if (cached == UNKNOWN) {
|
||||
cached = flag(hasTag(Tag.LOGS));
|
||||
log = cached;
|
||||
}
|
||||
return cached == TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
byte cached = leaves;
|
||||
if (cached == UNKNOWN) {
|
||||
cached = flag(hasTag(Tag.LEAVES));
|
||||
leaves = cached;
|
||||
}
|
||||
return cached == TRUE;
|
||||
}
|
||||
|
||||
// A plugin's custom block shows up as some other material, so the plugin is asked for its own tags too.
|
||||
private boolean hasTag(Tag<Material> tag) {
|
||||
if (tag.isTagged(data.getMaterial())) {
|
||||
return true;
|
||||
}
|
||||
ExternalDataSVC external = IrisServices.getOrNull(ExternalDataSVC.class);
|
||||
return external != null && external.hasBlockTag(data, tag.getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoliagePlantable() {
|
||||
byte cached = foliagePlantable;
|
||||
|
||||
@@ -32,6 +32,9 @@ import art.arcane.volmlib.util.math.M;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Sound;
|
||||
@@ -326,6 +329,17 @@ public class VolmitSender implements CommandSender {
|
||||
deliver(ComponentText.component(component));
|
||||
}
|
||||
|
||||
/** A green line that copies {@code payload} to a player's clipboard when clicked; a console gets nothing. */
|
||||
public void sendCopyButton(String label, String hover, String payload) {
|
||||
if (!isPlayer()) {
|
||||
return;
|
||||
}
|
||||
sendComponent(Component.text(label)
|
||||
.color(NamedTextColor.GREEN)
|
||||
.clickEvent(ClickEvent.copyToClipboard(payload))
|
||||
.hoverEvent(HoverEvent.showText(Component.text(hover))));
|
||||
}
|
||||
|
||||
private void deliver(ComponentText message) {
|
||||
ComponentMessenger.send(s, message);
|
||||
}
|
||||
|
||||
@@ -141,8 +141,9 @@ final class ObjectBlockPass {
|
||||
|
||||
private boolean handleCustomData(NativeBlockState data, boolean air, TileData tile, String marker, int xx, int yy, int zz) {
|
||||
// Short-circuit order matters for cost only: the mantle read is paid solely
|
||||
// for vine blocks. Both operands are pure, so the value is unchanged.
|
||||
boolean wouldReplace = !is(ObjectPlaceMode.STRUCTURE_PIECE) && B.isVineBlock(data) && B.isSolid(state.placer.get(xx, yy, zz));
|
||||
// for vine blocks and leaves. Both operands are pure, so the value is unchanged.
|
||||
boolean wouldReplace = !is(ObjectPlaceMode.STRUCTURE_PIECE) && readsExistingBlock(data)
|
||||
&& keepsExisting(data, state.placer.get(xx, yy, zz));
|
||||
boolean place = shouldPlaceObjectBlock(is(ObjectPlaceMode.STRUCTURE_PIECE), air, wouldReplace);
|
||||
if (data.isCustom() || place) {
|
||||
state.placer.set(xx, yy, zz, data);
|
||||
@@ -160,6 +161,15 @@ final class ObjectBlockPass {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean readsExistingBlock(NativeBlockState data) {
|
||||
return B.isVineBlock(data) || B.isLeaves(data);
|
||||
}
|
||||
|
||||
/** Vines never replace solid blocks, and leaves never cut a log: the trunk above the cut would float. */
|
||||
static boolean keepsExisting(NativeBlockState data, NativeBlockState existing) {
|
||||
return B.isVineBlock(data) ? B.isSolid(existing) : B.isLeaves(data) && B.isLog(existing);
|
||||
}
|
||||
|
||||
private EditResult applyEdits(double[] exact, int index, NativeBlockState data, TileData tile) {
|
||||
double exactX = exact[index * 3];
|
||||
double exactY = exact[index * 3 + 1];
|
||||
|
||||
@@ -70,8 +70,7 @@ final class PlacementPalette {
|
||||
NativeBlockState resolved = decayed[entry];
|
||||
if (resolved == null) {
|
||||
NativeBlockState data = source(entry);
|
||||
resolved = preventingDecay && IrisProceduralBlocks.hasProperty(data, "distance")
|
||||
&& "false".equals(IrisProceduralBlocks.propertyValue(data, "persistent"))
|
||||
resolved = preventingDecay && "false".equals(IrisProceduralBlocks.propertyValue(data, "persistent"))
|
||||
? data.withProperty("persistent", "true") : data;
|
||||
decayed[entry] = resolved;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
/** The studio app the jar carries, unpacked into a folder named by its checksum so each build gets its own copy. */
|
||||
final class BundledStudioApp {
|
||||
static final String RESOURCE = "META-INF/iris/studio-app.zip";
|
||||
private static final String FOLDER_PREFIX = "app-";
|
||||
private static final int FOLDER_CHECKSUM_LENGTH = 12;
|
||||
|
||||
private BundledStudioApp() {
|
||||
}
|
||||
|
||||
static Path install(Path root, ClassLoader resources) throws IOException {
|
||||
Path archive = root.resolve("studio-app.zip.part");
|
||||
try {
|
||||
copyResource(resources, archive);
|
||||
Path folder = root.resolve(FOLDER_PREFIX + ElectronRuntime.sha256(archive).substring(0, FOLDER_CHECKSUM_LENGTH));
|
||||
if (!Files.isRegularFile(folder.resolve("package.json"))) {
|
||||
ZipArchives.extract(archive, folder);
|
||||
}
|
||||
return folder;
|
||||
} finally {
|
||||
Files.deleteIfExists(archive);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isAppFolder(Path folder) {
|
||||
return folder.getFileName().toString().startsWith(FOLDER_PREFIX);
|
||||
}
|
||||
|
||||
private static void copyResource(ClassLoader resources, Path archive) throws IOException {
|
||||
try (InputStream input = resources.getResourceAsStream(RESOURCE)) {
|
||||
if (input == null) {
|
||||
throw new IOException("this build does not bundle the studio app; point studio.studioApp at a studio checkout");
|
||||
}
|
||||
Files.createDirectories(archive.getParent());
|
||||
Files.copy(input, archive, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.Duration;
|
||||
import java.util.HexFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* The Electron build the studio app runs on. The build pins its version and each platform's SHA-256 in the studio app
|
||||
* manifest; the archive comes from Electron's own GitHub release and is unpacked once into the studio folder.
|
||||
*/
|
||||
final class ElectronRuntime {
|
||||
private static final String RELEASE_ROOT = "https://github.com/electron/electron/releases/download/";
|
||||
private static final String VERSION_KEY = "electron.version";
|
||||
private static final String CHECKSUM_SUFFIX = ".sha256";
|
||||
private static final Duration CONNECT_TIMEOUT = Duration.ofSeconds(10);
|
||||
private static final Duration DOWNLOAD_TIMEOUT = Duration.ofMinutes(15);
|
||||
|
||||
private final String version;
|
||||
private final Platform platform;
|
||||
private final String sha256;
|
||||
|
||||
private ElectronRuntime(String version, Platform platform, String sha256) {
|
||||
this.version = version;
|
||||
this.platform = platform;
|
||||
this.sha256 = sha256;
|
||||
}
|
||||
|
||||
static ElectronRuntime pinned(Properties manifest, Platform platform) throws IOException {
|
||||
String version = manifest.getProperty(VERSION_KEY);
|
||||
String sha256 = manifest.getProperty(platform.name() + CHECKSUM_SUFFIX);
|
||||
if (version == null || sha256 == null) {
|
||||
throw new IOException("no Electron build is pinned for " + platform.name());
|
||||
}
|
||||
return new ElectronRuntime(version, platform, sha256.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
String folderName() {
|
||||
return "electron-v" + version + "-" + platform.name();
|
||||
}
|
||||
|
||||
URI source() {
|
||||
return URI.create(RELEASE_ROOT + "v" + version + "/" + folderName() + ".zip");
|
||||
}
|
||||
|
||||
/** The Electron executable under {@code root}, downloaded, checked and unpacked first when it is not there yet. */
|
||||
Path install(Path root, Downloader downloader) throws IOException {
|
||||
Path executable = root.resolve(folderName()).resolve(platform.executable());
|
||||
if (Files.isRegularFile(executable)) {
|
||||
return executable;
|
||||
}
|
||||
Path archive = root.resolve(folderName() + ".zip.part");
|
||||
try {
|
||||
downloader.download(source(), archive);
|
||||
requireChecksum(archive);
|
||||
if (platform.macOS()) {
|
||||
ZipArchives.extractWithDitto(archive, root.resolve(folderName()));
|
||||
} else {
|
||||
ZipArchives.extract(archive, root.resolve(folderName()));
|
||||
}
|
||||
} finally {
|
||||
Files.deleteIfExists(archive);
|
||||
}
|
||||
if (!Files.isRegularFile(executable)) {
|
||||
throw new IOException(source() + " has no " + platform.executable());
|
||||
}
|
||||
return executable;
|
||||
}
|
||||
|
||||
private void requireChecksum(Path archive) throws IOException {
|
||||
String actual = sha256(archive);
|
||||
if (!actual.equals(sha256)) {
|
||||
throw new IOException(source() + " failed its checksum (expected " + sha256 + ", got " + actual + ")");
|
||||
}
|
||||
}
|
||||
|
||||
static String sha256(Path file) throws IOException {
|
||||
try (InputStream input = Files.newInputStream(file)) {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
byte[] buffer = new byte[1 << 16];
|
||||
int read;
|
||||
while ((read = input.read(buffer)) >= 0) {
|
||||
digest.update(buffer, 0, read);
|
||||
}
|
||||
return HexFormat.of().formatHex(digest.digest());
|
||||
} catch (NoSuchAlgorithmException missing) {
|
||||
throw new IllegalStateException(missing);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface Downloader {
|
||||
void download(URI source, Path target) throws IOException;
|
||||
|
||||
static Downloader http() {
|
||||
return (source, target) -> {
|
||||
HttpClient client = HttpClient.newBuilder()
|
||||
.connectTimeout(CONNECT_TIMEOUT)
|
||||
.followRedirects(HttpClient.Redirect.NORMAL)
|
||||
.build();
|
||||
HttpRequest request = HttpRequest.newBuilder(source)
|
||||
.timeout(DOWNLOAD_TIMEOUT)
|
||||
.header("User-Agent", "Iris")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<Path> response = client.send(request, HttpResponse.BodyHandlers.ofFile(target));
|
||||
if (response.statusCode() != 200) {
|
||||
throw new IOException(source + " answered HTTP " + response.statusCode());
|
||||
}
|
||||
} catch (InterruptedException interrupted) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IOException("download of " + source + " was interrupted", interrupted);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** An Electron release platform, named as its archives are, and where the executable sits inside them. */
|
||||
record Platform(String name, String executable) {
|
||||
static Platform current() {
|
||||
return of(System.getProperty("os.name", ""), System.getProperty("os.arch", ""));
|
||||
}
|
||||
|
||||
/** Null for a system Electron publishes no build for. */
|
||||
static Platform of(String operatingSystem, String architecture) {
|
||||
String os = operatingSystem.toLowerCase(Locale.ROOT);
|
||||
String arch = switch (architecture) {
|
||||
case "aarch64", "arm64" -> "arm64";
|
||||
case "amd64", "x86_64" -> "x64";
|
||||
default -> null;
|
||||
};
|
||||
if (arch == null) {
|
||||
return null;
|
||||
}
|
||||
if (os.contains("linux")) {
|
||||
return new Platform("linux-" + arch, "electron");
|
||||
}
|
||||
if (os.contains("win")) {
|
||||
return new Platform("win32-" + arch, "electron.exe");
|
||||
}
|
||||
if (os.contains("mac")) {
|
||||
return new Platform("darwin-" + arch, "Electron.app/Contents/MacOS/Electron");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean macOS() {
|
||||
return name.startsWith("darwin");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
/** A studio app ready to start: the Electron executable and the app folder it runs. */
|
||||
public record StudioAppInstall(Path electron, Path app) {
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.studio.view.GuiHost;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Installs the studio app into the Iris data folder in the background at startup: the app from the jar, and the
|
||||
* Electron build it runs on from Electron's release. Servers without a display skip it, since the window could not
|
||||
* open there anyway.
|
||||
*/
|
||||
public final class StudioAppInstaller {
|
||||
static final String MANIFEST = "META-INF/iris/studio-app.properties";
|
||||
private static final String DATA_FOLDER = "studio";
|
||||
private static final String STAGING_SUFFIX = ".part";
|
||||
|
||||
private static StudioAppState state = StudioAppState.NOT_STARTED;
|
||||
private static StudioAppInstall installed;
|
||||
private static String unavailableReason = "";
|
||||
|
||||
private StudioAppInstaller() {
|
||||
}
|
||||
|
||||
/** Starts the install unless it is done, running, or off; the state it leaves, for a caller about to open the app. */
|
||||
public static synchronized StudioAppState installInBackground() {
|
||||
if (state == StudioAppState.DOWNLOADING || state == StudioAppState.READY || state == StudioAppState.UNAVAILABLE) {
|
||||
return state;
|
||||
}
|
||||
state = blockedState();
|
||||
if (state != StudioAppState.DOWNLOADING) {
|
||||
return state;
|
||||
}
|
||||
Thread.ofPlatform().daemon().name("Iris Studio install").start(StudioAppInstaller::install);
|
||||
return state;
|
||||
}
|
||||
|
||||
public static synchronized StudioAppInstall installed() {
|
||||
return installed;
|
||||
}
|
||||
|
||||
public static synchronized String unavailableReason() {
|
||||
return unavailableReason;
|
||||
}
|
||||
|
||||
static boolean hasDisplay(String operatingSystem, Map<String, String> environment) {
|
||||
String os = operatingSystem.toLowerCase(Locale.ROOT);
|
||||
if (os.contains("win") || os.contains("mac")) {
|
||||
return true;
|
||||
}
|
||||
return isSet(environment.get("DISPLAY")) || isSet(environment.get("WAYLAND_DISPLAY"));
|
||||
}
|
||||
|
||||
private static StudioAppState blockedState() {
|
||||
if (!IrisSettings.get().getStudio().isDownloadApp()) {
|
||||
return StudioAppState.DOWNLOAD_OFF;
|
||||
}
|
||||
if (GuiHost.isDesktopSuppressed() || !hasDisplay(System.getProperty("os.name", ""), System.getenv())) {
|
||||
return StudioAppState.NO_DISPLAY;
|
||||
}
|
||||
return StudioAppState.DOWNLOADING;
|
||||
}
|
||||
|
||||
private static void install() {
|
||||
long startedNanos = System.nanoTime();
|
||||
try {
|
||||
ElectronRuntime.Platform platform = ElectronRuntime.Platform.current();
|
||||
if (platform == null) {
|
||||
throw new IOException("Electron has no build for " + System.getProperty("os.name") + " " + System.getProperty("os.arch"));
|
||||
}
|
||||
ElectronRuntime electron = ElectronRuntime.pinned(manifest(), platform);
|
||||
Path root = IrisPlatforms.get().dataFolder(DATA_FOLDER).toPath();
|
||||
Path executable = installElectron(electron, root);
|
||||
Path app = BundledStudioApp.install(root, StudioAppInstaller.class.getClassLoader());
|
||||
removeStaleInstalls(root, List.of(app, root.resolve(electron.folderName())));
|
||||
ready(new StudioAppInstall(executable, app), (System.nanoTime() - startedNanos) / 1_000_000L);
|
||||
} catch (IOException | RuntimeException error) {
|
||||
unavailable(error.getMessage() == null ? error.getClass().getSimpleName() : error.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static Path installElectron(ElectronRuntime electron, Path root) throws IOException {
|
||||
if (!Files.isDirectory(root.resolve(electron.folderName()))) {
|
||||
IrisLogging.info("Downloading the studio app runtime from %s", electron.source());
|
||||
}
|
||||
return electron.install(root, ElectronRuntime.Downloader.http());
|
||||
}
|
||||
|
||||
private static Properties manifest() throws IOException {
|
||||
Properties manifest = new Properties();
|
||||
try (InputStream input = StudioAppInstaller.class.getClassLoader().getResourceAsStream(MANIFEST)) {
|
||||
if (input == null) {
|
||||
throw new IOException("this build does not bundle the studio app; point studio.studioApp at a studio checkout");
|
||||
}
|
||||
manifest.load(input);
|
||||
}
|
||||
return manifest;
|
||||
}
|
||||
|
||||
/** Drops the Electron builds and app copies earlier versions left, and any half-finished download or unpack. */
|
||||
private static void removeStaleInstalls(Path root, List<Path> current) {
|
||||
try (Stream<Path> children = Files.list(root)) {
|
||||
for (Path child : children.toList()) {
|
||||
if (current.contains(child) || !isInstallArtifact(child)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
ZipArchives.deleteRecursively(child);
|
||||
} catch (IOException error) {
|
||||
IrisLogging.debug("Could not remove the old studio install %s: %s", child, error.getMessage());
|
||||
}
|
||||
}
|
||||
} catch (IOException error) {
|
||||
IrisLogging.debug("Could not list the studio folder %s: %s", root, error.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isInstallArtifact(Path child) {
|
||||
String name = child.getFileName().toString();
|
||||
return name.startsWith("electron-v") || BundledStudioApp.isAppFolder(child) || name.endsWith(STAGING_SUFFIX);
|
||||
}
|
||||
|
||||
private static synchronized void ready(StudioAppInstall install, long elapsedMillis) {
|
||||
installed = install;
|
||||
unavailableReason = "";
|
||||
state = StudioAppState.READY;
|
||||
IrisLogging.info("Studio app ready in %d ms", elapsedMillis);
|
||||
}
|
||||
|
||||
private static synchronized void unavailable(String reason) {
|
||||
installed = null;
|
||||
unavailableReason = reason;
|
||||
state = StudioAppState.UNAVAILABLE;
|
||||
IrisLogging.warn("Studio app unavailable: %s", reason);
|
||||
}
|
||||
|
||||
private static boolean isSet(String value) {
|
||||
return value != null && !value.isBlank();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
/** Where the downloaded studio app stands on this server. */
|
||||
public enum StudioAppState {
|
||||
NOT_STARTED,
|
||||
DOWNLOAD_OFF,
|
||||
NO_DISPLAY,
|
||||
DOWNLOADING,
|
||||
READY,
|
||||
UNAVAILABLE
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.AtomicMoveNotSupportedException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* Unpacks archives into a folder that only appears once it is complete: everything lands in a staging folder first,
|
||||
* which is then moved into place, so a crash halfway never leaves a folder that looks installed.
|
||||
*/
|
||||
final class ZipArchives {
|
||||
private static final long DITTO_TIMEOUT_MINUTES = 5;
|
||||
private static final int FILE_TYPE_MASK = 0170000;
|
||||
private static final int SYMLINK_TYPE = 0120000;
|
||||
private static final int PERMISSION_MASK = 0777;
|
||||
private static final List<PosixFilePermission> PERMISSION_BITS = List.of(
|
||||
PosixFilePermission.OTHERS_EXECUTE, PosixFilePermission.OTHERS_WRITE, PosixFilePermission.OTHERS_READ,
|
||||
PosixFilePermission.GROUP_EXECUTE, PosixFilePermission.GROUP_WRITE, PosixFilePermission.GROUP_READ,
|
||||
PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_READ);
|
||||
|
||||
private ZipArchives() {
|
||||
}
|
||||
|
||||
/** Keeps each entry's Unix mode and symlinks, so executables stay executable. */
|
||||
static void extract(Path archive, Path folder) throws IOException {
|
||||
Path staging = staging(folder);
|
||||
boolean posix = staging.getFileSystem().supportedFileAttributeViews().contains("posix");
|
||||
Map<String, Integer> modes = posix ? unixModes(archive) : Map.of();
|
||||
try (ZipFile zip = new ZipFile(archive.toFile())) {
|
||||
for (ZipEntry entry : Collections.list(zip.entries())) {
|
||||
extractEntry(zip, entry, staging, modes.getOrDefault(entry.getName(), 0), posix);
|
||||
}
|
||||
}
|
||||
moveIntoPlace(staging, folder);
|
||||
}
|
||||
|
||||
/** Unpacks with macOS's ditto, which keeps everything an app bundle relies on. */
|
||||
static void extractWithDitto(Path archive, Path folder) throws IOException {
|
||||
Path staging = staging(folder);
|
||||
Process ditto = new ProcessBuilder("ditto", "-x", "-k", archive.toString(), staging.toString())
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
try {
|
||||
if (!ditto.waitFor(DITTO_TIMEOUT_MINUTES, TimeUnit.MINUTES)) {
|
||||
ditto.destroyForcibly();
|
||||
throw new IOException("ditto did not finish unpacking " + archive);
|
||||
}
|
||||
} catch (InterruptedException interrupted) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IOException("unpacking " + archive + " was interrupted", interrupted);
|
||||
}
|
||||
if (ditto.exitValue() != 0) {
|
||||
throw new IOException("ditto could not unpack " + archive + ": "
|
||||
+ new String(ditto.getInputStream().readAllBytes(), StandardCharsets.UTF_8).trim());
|
||||
}
|
||||
moveIntoPlace(staging, folder);
|
||||
}
|
||||
|
||||
static void deleteRecursively(Path path) throws IOException {
|
||||
if (!Files.exists(path, java.nio.file.LinkOption.NOFOLLOW_LINKS)) {
|
||||
return;
|
||||
}
|
||||
try (Stream<Path> walk = Files.walk(path)) {
|
||||
for (Path entry : walk.sorted(Comparator.reverseOrder()).toList()) {
|
||||
Files.delete(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void extractEntry(ZipFile zip, ZipEntry entry, Path staging, int mode, boolean posix) throws IOException {
|
||||
Path target = insideStaging(staging, staging.resolve(entry.getName()));
|
||||
if (entry.isDirectory()) {
|
||||
Files.createDirectories(target);
|
||||
return;
|
||||
}
|
||||
Files.createDirectories(target.getParent());
|
||||
try (InputStream input = zip.getInputStream(entry)) {
|
||||
if (posix && (mode & FILE_TYPE_MASK) == SYMLINK_TYPE) {
|
||||
Path linkTarget = Path.of(new String(input.readAllBytes(), StandardCharsets.UTF_8));
|
||||
insideStaging(staging, target.getParent().resolve(linkTarget));
|
||||
Files.createSymbolicLink(target, linkTarget);
|
||||
return;
|
||||
}
|
||||
Files.copy(input, target);
|
||||
}
|
||||
if (posix && mode != 0) {
|
||||
Files.setPosixFilePermissions(target, permissions(mode));
|
||||
}
|
||||
}
|
||||
|
||||
private static Path insideStaging(Path staging, Path path) throws IOException {
|
||||
Path normalized = path.normalize();
|
||||
if (!normalized.startsWith(staging)) {
|
||||
throw new IOException("archive entry " + path + " points outside its folder");
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private static Set<PosixFilePermission> permissions(int mode) {
|
||||
Set<PosixFilePermission> permissions = EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE);
|
||||
int bits = mode & PERMISSION_MASK;
|
||||
for (int bit = 0; bit < PERMISSION_BITS.size(); bit++) {
|
||||
if ((bits & (1 << bit)) != 0) {
|
||||
permissions.add(PERMISSION_BITS.get(bit));
|
||||
}
|
||||
}
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Each entry's Unix mode, read from the archive's central directory, where zip tools made on Unix keep it in the
|
||||
* high half of the external attributes. {@link ZipFile} reads the entries but not this field.
|
||||
*/
|
||||
static Map<String, Integer> unixModes(Path archive) throws IOException {
|
||||
try (FileChannel channel = FileChannel.open(archive)) {
|
||||
CentralDirectory directory = CentralDirectory.locate(channel);
|
||||
ByteBuffer records = read(channel, directory.offset(), directory.size());
|
||||
Map<String, Integer> modes = new HashMap<>();
|
||||
int position = 0;
|
||||
for (long index = 0; index < directory.entries(); index++) {
|
||||
if (records.getInt(position) != CentralDirectory.ENTRY_SIGNATURE) {
|
||||
throw new IOException(archive + " has a damaged central directory");
|
||||
}
|
||||
int madeBySystem = (records.getShort(position + 4) >> 8) & 0xFF;
|
||||
int nameLength = records.getShort(position + 28) & 0xFFFF;
|
||||
int extraLength = records.getShort(position + 30) & 0xFFFF;
|
||||
int commentLength = records.getShort(position + 32) & 0xFFFF;
|
||||
int externalAttributes = records.getInt(position + 38);
|
||||
byte[] name = new byte[nameLength];
|
||||
records.get(position + 46, name);
|
||||
if (madeBySystem == CentralDirectory.MADE_ON_UNIX) {
|
||||
modes.put(new String(name, StandardCharsets.UTF_8), externalAttributes >>> 16);
|
||||
}
|
||||
position += 46 + nameLength + extraLength + commentLength;
|
||||
}
|
||||
return modes;
|
||||
}
|
||||
}
|
||||
|
||||
private static ByteBuffer read(FileChannel channel, long offset, long length) throws IOException {
|
||||
if (length > Integer.MAX_VALUE - 8 || offset < 0 || offset + length > channel.size()) {
|
||||
throw new IOException("zip structure points outside the archive");
|
||||
}
|
||||
ByteBuffer buffer = ByteBuffer.allocate((int) length).order(ByteOrder.LITTLE_ENDIAN);
|
||||
while (buffer.hasRemaining()) {
|
||||
if (channel.read(buffer, offset + buffer.position()) < 0) {
|
||||
throw new IOException("archive ended early");
|
||||
}
|
||||
}
|
||||
return buffer.flip();
|
||||
}
|
||||
|
||||
private record CentralDirectory(long offset, long size, long entries) {
|
||||
static final int ENTRY_SIGNATURE = 0x02014b50;
|
||||
static final int MADE_ON_UNIX = 3;
|
||||
private static final int END_SIGNATURE = 0x06054b50;
|
||||
private static final int ZIP64_LOCATOR_SIGNATURE = 0x07064b50;
|
||||
private static final int ZIP64_END_SIGNATURE = 0x06064b50;
|
||||
private static final int END_RECORD_LENGTH = 22;
|
||||
private static final int ZIP64_LOCATOR_LENGTH = 20;
|
||||
private static final int MAX_COMMENT_LENGTH = 0xFFFF;
|
||||
|
||||
static CentralDirectory locate(FileChannel channel) throws IOException {
|
||||
long size = channel.size();
|
||||
int tailLength = (int) Math.min(size, END_RECORD_LENGTH + MAX_COMMENT_LENGTH);
|
||||
long tailOffset = size - tailLength;
|
||||
ByteBuffer tail = read(channel, tailOffset, tailLength);
|
||||
for (int end = tailLength - END_RECORD_LENGTH; end >= 0; end--) {
|
||||
if (tail.getInt(end) == END_SIGNATURE) {
|
||||
return fromEndRecord(channel, tail, end, tailOffset + end);
|
||||
}
|
||||
}
|
||||
throw new IOException("not a zip archive");
|
||||
}
|
||||
|
||||
private static CentralDirectory fromEndRecord(FileChannel channel, ByteBuffer tail, int end, long endOffset) throws IOException {
|
||||
long entries = tail.getShort(end + 10) & 0xFFFFL;
|
||||
long size = tail.getInt(end + 12) & 0xFFFFFFFFL;
|
||||
long offset = tail.getInt(end + 16) & 0xFFFFFFFFL;
|
||||
if (entries != 0xFFFFL && size != 0xFFFFFFFFL && offset != 0xFFFFFFFFL) {
|
||||
return new CentralDirectory(offset, size, entries);
|
||||
}
|
||||
ByteBuffer locator = read(channel, endOffset - ZIP64_LOCATOR_LENGTH, ZIP64_LOCATOR_LENGTH);
|
||||
if (locator.getInt(0) != ZIP64_LOCATOR_SIGNATURE) {
|
||||
throw new IOException("zip64 archive without its locator");
|
||||
}
|
||||
ByteBuffer zip64End = read(channel, locator.getLong(8), 56);
|
||||
if (zip64End.getInt(0) != ZIP64_END_SIGNATURE) {
|
||||
throw new IOException("zip64 archive without its end record");
|
||||
}
|
||||
return new CentralDirectory(zip64End.getLong(48), zip64End.getLong(40), zip64End.getLong(32));
|
||||
}
|
||||
}
|
||||
|
||||
private static Path staging(Path folder) throws IOException {
|
||||
Path staging = folder.resolveSibling(folder.getFileName() + ".part");
|
||||
deleteRecursively(staging);
|
||||
Files.createDirectories(staging);
|
||||
return staging;
|
||||
}
|
||||
|
||||
private static void moveIntoPlace(Path staging, Path folder) throws IOException {
|
||||
deleteRecursively(folder);
|
||||
try {
|
||||
Files.move(staging, folder, StandardCopyOption.ATOMIC_MOVE);
|
||||
} catch (AtomicMoveNotSupportedException unsupported) {
|
||||
Files.move(staging, folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.bridge;
|
||||
|
||||
import art.arcane.iris.localization.RuntimeUiMessages;
|
||||
import art.arcane.volmlib.util.localization.TextKey;
|
||||
|
||||
/** How a request to show the studio window ended; every outcome but {@link #OPENED} leaves the bridge link as the only way in. */
|
||||
public enum StudioLaunch {
|
||||
OPENED(null),
|
||||
DOWNLOAD_OFF(RuntimeUiMessages.STUDIO_APP_DOWNLOAD_OFF),
|
||||
NO_DISPLAY(RuntimeUiMessages.STUDIO_APP_NO_DISPLAY),
|
||||
DOWNLOADING(RuntimeUiMessages.STUDIO_APP_DOWNLOADING),
|
||||
UNAVAILABLE(RuntimeUiMessages.STUDIO_APP_UNAVAILABLE),
|
||||
NOT_BUILT(RuntimeUiMessages.STUDIO_APP_NOT_BUILT),
|
||||
FAILED_TO_START(RuntimeUiMessages.STUDIO_APP_FAILED_TO_START);
|
||||
|
||||
private final TextKey failureMessage;
|
||||
|
||||
StudioLaunch(TextKey failureMessage) {
|
||||
this.failureMessage = failureMessage;
|
||||
}
|
||||
|
||||
public boolean opened() {
|
||||
return this == OPENED;
|
||||
}
|
||||
|
||||
public TextKey failureMessage() {
|
||||
return failureMessage;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@ package art.arcane.iris.studio.bridge;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.studio.app.StudioAppInstall;
|
||||
import art.arcane.iris.studio.app.StudioAppInstaller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -28,7 +30,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Opens the Iris Studio window on a bridge, from the app folder the studio settings name. The app keeps one window:
|
||||
* Opens the Iris Studio window on a bridge, from the studio checkout the settings name or else from the app the
|
||||
* server downloaded at startup. The app keeps one window:
|
||||
* a second start hands its link to the open window and exits. Windows the server started close when it stops, as
|
||||
* their bridges go with it.
|
||||
*/
|
||||
@@ -43,25 +46,47 @@ public final class StudioWindow {
|
||||
private StudioWindow() {
|
||||
}
|
||||
|
||||
/** False when no app is set or it could not start, so the caller's printed link is the only way in. */
|
||||
public static synchronized boolean show(StudioBridge bridge) {
|
||||
public static synchronized StudioLaunch show(StudioBridge bridge) {
|
||||
IrisSettings.IrisSettingsStudio settings = IrisSettings.get().getStudio();
|
||||
String appFolder = settings.getStudioApp();
|
||||
if (appFolder == null || appFolder.isBlank()) {
|
||||
return false;
|
||||
String checkout = settings.getStudioApp();
|
||||
if (checkout != null && !checkout.isBlank()) {
|
||||
return showCheckout(Path.of(checkout), electronBinary(settings), bridge.link());
|
||||
}
|
||||
Path app = Path.of(appFolder);
|
||||
return showDownloaded(bridge.link());
|
||||
}
|
||||
|
||||
private static StudioLaunch showCheckout(Path app, String electron, String link) {
|
||||
if (!Files.isRegularFile(app.resolve(BUILT_MAIN))) {
|
||||
IrisLogging.warn("Iris Studio is not built in %s; run npm run build there.", app);
|
||||
return false;
|
||||
return StudioLaunch.NOT_BUILT;
|
||||
}
|
||||
return launch(electron, app, link);
|
||||
}
|
||||
|
||||
private static StudioLaunch showDownloaded(String link) {
|
||||
return switch (StudioAppInstaller.installInBackground()) {
|
||||
case READY -> {
|
||||
StudioAppInstall install = StudioAppInstaller.installed();
|
||||
yield launch(install.electron().toString(), install.app(), link);
|
||||
}
|
||||
case NOT_STARTED, DOWNLOADING -> StudioLaunch.DOWNLOADING;
|
||||
case DOWNLOAD_OFF -> StudioLaunch.DOWNLOAD_OFF;
|
||||
case NO_DISPLAY -> StudioLaunch.NO_DISPLAY;
|
||||
case UNAVAILABLE -> {
|
||||
IrisLogging.warn("Studio app unavailable: %s", StudioAppInstaller.unavailableReason());
|
||||
yield StudioLaunch.UNAVAILABLE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static StudioLaunch launch(String electron, Path app, String link) {
|
||||
try {
|
||||
STARTED.removeIf(process -> !process.isAlive());
|
||||
STARTED.add(start(electronBinary(settings), app, bridge.link()));
|
||||
return true;
|
||||
STARTED.add(start(electron, app, link));
|
||||
return StudioLaunch.OPENED;
|
||||
} catch (IOException error) {
|
||||
IrisLogging.warn("Could not open Iris Studio: %s", error.getMessage());
|
||||
return false;
|
||||
return StudioLaunch.FAILED_TO_START;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -420,7 +420,7 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
|
||||
try {
|
||||
StudioBridge bridge = StudioBridges.open(engine.getWorld().name(), () -> engine, null);
|
||||
studioWatching = true;
|
||||
if (!StudioWindow.show(bridge)) {
|
||||
if (!StudioWindow.show(bridge).opened()) {
|
||||
IrisLogging.info("Iris Studio link for the pregeneration of %s: %s", engine.getWorld().name(), bridge.link());
|
||||
}
|
||||
} catch (IOException error) {
|
||||
|
||||
@@ -1581,6 +1581,14 @@ failed_fragment = " fehlgeschlagen {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aWelt '{world}' verwendet bereits {pack} v{version} mit denselben Generierungseinstellungen. Kein Neustart erforderlich."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Studio-App-Download ist aus: Setze studio.downloadApp in iris.json auf true."
|
||||
app_no_display = "Dieser Server hat keine Anzeige, auf der sich die Studio-App öffnen kann."
|
||||
app_downloading = "Die Studio-App wird noch heruntergeladen; versuche es gleich noch einmal."
|
||||
app_unavailable = "Studio-App nicht verfügbar; siehe Konsole."
|
||||
app_not_built = "Studio-App nicht gebaut: Führe npm run build in ihrem Ordner aus."
|
||||
app_failed_to_start = "Studio-App konnte nicht starten; siehe Konsole."
|
||||
link_copy_button = "[Studio-Link kopieren]"
|
||||
link_copy_hover = "In den Verbindungsbildschirm der Studio-App einfügen"
|
||||
opening = "§6Studio §bÖFFNET"
|
||||
opening_progress = "§6Studio §bÖFFNET§7 {percent}%"
|
||||
failed_progress = "§6Studio §cFEHLGESCHLAGEN§7 {percent}%"
|
||||
|
||||
@@ -1581,6 +1581,14 @@ failed_fragment = " fallidos {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aEl mundo '{world}' ya usa {pack} v{version} con los mismos ajustes de generación. No hace falta reiniciar."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "La descarga de la app de Studio está desactivada: pon studio.downloadApp a true en iris.json."
|
||||
app_no_display = "Este servidor no tiene pantalla donde abrir la app de Studio."
|
||||
app_downloading = "La app de Studio aún se está descargando; vuelve a intentarlo en un momento."
|
||||
app_unavailable = "La app de Studio no está disponible; consulta la consola."
|
||||
app_not_built = "La app de Studio no está compilada: ejecuta npm run build en su carpeta."
|
||||
app_failed_to_start = "La app de Studio no pudo iniciarse; consulta la consola."
|
||||
link_copy_button = "[Copiar enlace de Studio]"
|
||||
link_copy_hover = "Pégalo en la pantalla de conexión de la app de Studio"
|
||||
opening = "§6Studio §bABRIENDO"
|
||||
opening_progress = "§6Studio §bABRIENDO§7 {percent}%"
|
||||
failed_progress = "§6Studio §cFALLÓ§7 {percent}%"
|
||||
|
||||
@@ -1586,6 +1586,14 @@ failed_fragment = " epäonnistui {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aMaailma '{world}' käyttää jo pakettia {pack} v{version} samoilla generointiasetuksilla. Uudelleenkäynnistystä ei tarvita."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Studio-sovelluksen lataus on pois päältä: aseta studio.downloadApp arvoon true tiedostossa iris.json."
|
||||
app_no_display = "Tällä palvelimella ei ole näyttöä, jolla Studio-sovelluksen voisi avata."
|
||||
app_downloading = "Studio-sovellusta ladataan vielä; yritä hetken päästä uudelleen."
|
||||
app_unavailable = "Studio-sovellus ei ole käytettävissä; katso konsoli."
|
||||
app_not_built = "Studio-sovellusta ei ole käännetty: suorita npm run build sen kansiossa."
|
||||
app_failed_to_start = "Studio-sovelluksen käynnistys epäonnistui; katso konsoli."
|
||||
link_copy_button = "[Kopioi Studio-linkki]"
|
||||
link_copy_hover = "Liitä se Studio-sovelluksen yhdistämisnäkymään"
|
||||
opening = "§6Studio §bAVATAAN"
|
||||
opening_progress = "§6Studio §bAVATAAN§7 {percent}%"
|
||||
failed_progress = "§6Studio §cEPÄONNISTUI§7 {percent}%"
|
||||
|
||||
@@ -1581,6 +1581,14 @@ failed_fragment = " échecs {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aLe monde '{world}' utilise déjà {pack} v{version} avec les mêmes paramètres de génération. Aucun redémarrage nécessaire."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Le téléchargement de l'application Studio est désactivé : mettez studio.downloadApp à true dans iris.json."
|
||||
app_no_display = "Ce serveur n'a pas d'écran pour ouvrir l'application Studio."
|
||||
app_downloading = "L'application Studio est encore en téléchargement ; réessayez dans un instant."
|
||||
app_unavailable = "Application Studio indisponible ; consultez la console."
|
||||
app_not_built = "Application Studio non compilée : lancez npm run build dans son dossier."
|
||||
app_failed_to_start = "L'application Studio n'a pas pu démarrer ; consultez la console."
|
||||
link_copy_button = "[Copier le lien Studio]"
|
||||
link_copy_hover = "Collez-le dans l'écran de connexion de l'application Studio"
|
||||
opening = "§6Studio §bOUVERTURE"
|
||||
opening_progress = "§6Studio §bOUVERTURE§7 {percent}%"
|
||||
failed_progress = "§6Studio §cÉCHEC§7 {percent}%"
|
||||
|
||||
@@ -1586,6 +1586,14 @@ failed_fragment = " נכשל {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aהעולם '{world}' כבר משתמש בחבילה {pack} v{version} עם אותן הגדרות יצירה. אין צורך בהפעלה מחדש."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "הורדת אפליקציית Studio כבויה: הגדר את studio.downloadApp ל-true בקובץ iris.json."
|
||||
app_no_display = "לשרת הזה אין מסך שבו אפשר לפתוח את אפליקציית Studio."
|
||||
app_downloading = "אפליקציית Studio עדיין יורדת; נסה שוב בעוד רגע."
|
||||
app_unavailable = "אפליקציית Studio אינה זמינה; ראה את הקונסולה."
|
||||
app_not_built = "אפליקציית Studio לא נבנתה: הרץ npm run build בתיקייה שלה."
|
||||
app_failed_to_start = "אפליקציית Studio לא הצליחה לעלות; ראה את הקונסולה."
|
||||
link_copy_button = "[העתק קישור Studio]"
|
||||
link_copy_hover = "הדבק אותו במסך החיבור של אפליקציית Studio"
|
||||
opening = "§6Studio §bנפתח"
|
||||
opening_progress = "§6Studio §bנפתח§7 {percent}%"
|
||||
failed_progress = "§6Studio §cנכשל§7 {percent}%"
|
||||
|
||||
@@ -1581,6 +1581,14 @@ failed_fragment = " non riusciti {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aIl mondo '{world}' usa già {pack} v{version} con le stesse impostazioni di generazione. Non serve riavviare."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Il download dell'app Studio è disattivato: imposta studio.downloadApp su true in iris.json."
|
||||
app_no_display = "Questo server non ha uno schermo su cui aprire l'app Studio."
|
||||
app_downloading = "L'app Studio è ancora in download; riprova tra un momento."
|
||||
app_unavailable = "App Studio non disponibile; controlla la console."
|
||||
app_not_built = "App Studio non compilata: esegui npm run build nella sua cartella."
|
||||
app_failed_to_start = "Impossibile avviare l'app Studio; controlla la console."
|
||||
link_copy_button = "[Copia link Studio]"
|
||||
link_copy_hover = "Incollalo nella schermata di connessione dell'app Studio"
|
||||
opening = "§6Studio §bAPERTURA"
|
||||
opening_progress = "§6Studio §bAPERTURA§7 {percent}%"
|
||||
failed_progress = "§6Studio §cNON RIUSCITO§7 {percent}%"
|
||||
|
||||
@@ -1584,6 +1584,14 @@ failed_fragment = " 失敗 {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aワールド '{world}' は同じ生成設定の {pack} v{version} を使用しています。再起動は不要です。"
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Studio アプリのダウンロードがオフです: iris.json の studio.downloadApp を true にしてください。"
|
||||
app_no_display = "このサーバーには Studio アプリを開くディスプレイがありません。"
|
||||
app_downloading = "Studio アプリはまだダウンロード中です。少し待ってから再試行してください。"
|
||||
app_unavailable = "Studio アプリを利用できません。コンソールを確認してください。"
|
||||
app_not_built = "Studio アプリがビルドされていません: そのフォルダで npm run build を実行してください。"
|
||||
app_failed_to_start = "Studio アプリを起動できませんでした。コンソールを確認してください。"
|
||||
link_copy_button = "[Studio リンクをコピー]"
|
||||
link_copy_hover = "Studio アプリの接続画面に貼り付けてください"
|
||||
opening = "§6Studio §bオープン中"
|
||||
opening_progress = "§6Studio §bオープン中§7 {percent}%"
|
||||
failed_progress = "§6Studio §c失敗§7 {percent}%"
|
||||
|
||||
@@ -1584,6 +1584,14 @@ failed_fragment = " 실패 {failed}"
|
||||
"commandpack.update_world_unchanged" = "§a월드 '{world}'는 이미 같은 생성 설정으로 {pack} v{version}을 사용 중입니다. 재시작할 필요가 없습니다."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Studio 앱 다운로드가 꺼져 있습니다: iris.json에서 studio.downloadApp을 true로 설정하세요."
|
||||
app_no_display = "이 서버에는 Studio 앱을 열 디스플레이가 없습니다."
|
||||
app_downloading = "Studio 앱을 아직 다운로드하는 중입니다. 잠시 후 다시 시도하세요."
|
||||
app_unavailable = "Studio 앱을 사용할 수 없습니다. 콘솔을 확인하세요."
|
||||
app_not_built = "Studio 앱이 빌드되지 않았습니다: 해당 폴더에서 npm run build를 실행하세요."
|
||||
app_failed_to_start = "Studio 앱을 시작하지 못했습니다. 콘솔을 확인하세요."
|
||||
link_copy_button = "[Studio 링크 복사]"
|
||||
link_copy_hover = "Studio 앱의 연결 화면에 붙여 넣으세요"
|
||||
opening = "§6Studio §b여는 중"
|
||||
opening_progress = "§6Studio §b여는 중§7 {percent}%"
|
||||
failed_progress = "§6Studio §c실패§7 {percent}%"
|
||||
|
||||
@@ -1586,6 +1586,14 @@ failed_fragment = " nepavyko {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aPasaulis '{world}' jau naudoja {pack} v{version} su tais pačiais generavimo nustatymais. Paleisti iš naujo nereikia."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Studio programos atsisiuntimas išjungtas: iris.json faile nustatykite studio.downloadApp į true."
|
||||
app_no_display = "Šis serveris neturi ekrano, kuriame būtų galima atidaryti Studio programą."
|
||||
app_downloading = "Studio programa dar atsisiunčiama; netrukus bandykite dar kartą."
|
||||
app_unavailable = "Studio programa nepasiekiama; žr. konsolę."
|
||||
app_not_built = "Studio programa nesukompiliuota: jos aplanke paleiskite npm run build."
|
||||
app_failed_to_start = "Nepavyko paleisti Studio programos; žr. konsolę."
|
||||
link_copy_button = "[Kopijuoti Studio nuorodą]"
|
||||
link_copy_hover = "Įklijuokite ją Studio programos prisijungimo ekrane"
|
||||
opening = "§6Studio §bATIDAROMA"
|
||||
opening_progress = "§6Studio §bATIDAROMA§7 {percent}%"
|
||||
failed_progress = "§6Studio §cNEPAVYKO§7 {percent}%"
|
||||
|
||||
@@ -1581,6 +1581,14 @@ failed_fragment = " mislukt {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aWereld '{world}' gebruikt al {pack} v{version} met dezelfde generatie-instellingen. Herstarten is niet nodig."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Download van de Studio-app staat uit: zet studio.downloadApp op true in iris.json."
|
||||
app_no_display = "Deze server heeft geen scherm om de Studio-app op te openen."
|
||||
app_downloading = "De Studio-app wordt nog gedownload; probeer het zo opnieuw."
|
||||
app_unavailable = "Studio-app niet beschikbaar; zie de console."
|
||||
app_not_built = "Studio-app niet gebouwd: voer npm run build uit in de map."
|
||||
app_failed_to_start = "Studio-app kon niet starten; zie de console."
|
||||
link_copy_button = "[Studio-link kopiëren]"
|
||||
link_copy_hover = "Plak hem in het verbindingsscherm van de Studio-app"
|
||||
opening = "§6Studio §bOPENEN"
|
||||
opening_progress = "§6Studio §bOPENEN§7 {percent}%"
|
||||
failed_progress = "§6Studio §cMISLUKT§7 {percent}%"
|
||||
|
||||
@@ -1586,6 +1586,14 @@ failed_fragment = " nieudane {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aŚwiat '{world}' już używa {pack} v{version} z tymi samymi ustawieniami generowania. Restart nie jest potrzebny."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Pobieranie aplikacji Studio jest wyłączone: ustaw studio.downloadApp na true w iris.json."
|
||||
app_no_display = "Ten serwer nie ma ekranu, na którym można otworzyć aplikację Studio."
|
||||
app_downloading = "Aplikacja Studio wciąż się pobiera; spróbuj ponownie za chwilę."
|
||||
app_unavailable = "Aplikacja Studio jest niedostępna; sprawdź konsolę."
|
||||
app_not_built = "Aplikacja Studio nie jest zbudowana: uruchom npm run build w jej folderze."
|
||||
app_failed_to_start = "Nie udało się uruchomić aplikacji Studio; sprawdź konsolę."
|
||||
link_copy_button = "[Kopiuj link Studio]"
|
||||
link_copy_hover = "Wklej go na ekranie połączenia aplikacji Studio"
|
||||
opening = "§6Studio §bOTWIERANIE"
|
||||
opening_progress = "§6Studio §bOTWIERANIE§7 {percent}%"
|
||||
failed_progress = "§6Studio §cNIEPOWODZENIE§7 {percent}%"
|
||||
|
||||
@@ -1581,6 +1581,14 @@ failed_fragment = " falhou {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aO mundo '{world}' já utiliza {pack} v{version} com as mesmas definições de geração. Não é necessário reiniciar."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "A transferência da app Studio está desligada: define studio.downloadApp como true no iris.json."
|
||||
app_no_display = "Este servidor não tem ecrã onde abrir a app Studio."
|
||||
app_downloading = "A app Studio ainda está a ser transferida; tenta novamente daqui a pouco."
|
||||
app_unavailable = "A app Studio não está disponível; vê a consola."
|
||||
app_not_built = "A app Studio não está compilada: executa npm run build na pasta dela."
|
||||
app_failed_to_start = "Não foi possível iniciar a app Studio; vê a consola."
|
||||
link_copy_button = "[Copiar link do Studio]"
|
||||
link_copy_hover = "Cola-o no ecrã de ligação da app Studio"
|
||||
opening = "§6Studio §bA ABRIR"
|
||||
opening_progress = "§6Studio §bA ABRIR§7 {percent}%"
|
||||
failed_progress = "§6Studio §cFALHOU§7 {percent}%"
|
||||
|
||||
@@ -1586,6 +1586,14 @@ failed_fragment = " ошибок {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aМир '{world}' уже использует {pack} v{version} с теми же настройками генерации. Перезапуск не требуется."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Загрузка приложения Studio отключена: установите studio.downloadApp в true в iris.json."
|
||||
app_no_display = "У этого сервера нет дисплея, на котором можно открыть приложение Studio."
|
||||
app_downloading = "Приложение Studio ещё загружается; попробуйте снова через минуту."
|
||||
app_unavailable = "Приложение Studio недоступно; см. консоль."
|
||||
app_not_built = "Приложение Studio не собрано: выполните npm run build в его папке."
|
||||
app_failed_to_start = "Не удалось запустить приложение Studio; см. консоль."
|
||||
link_copy_button = "[Копировать ссылку Studio]"
|
||||
link_copy_hover = "Вставьте её на экране подключения приложения Studio"
|
||||
opening = "§6Studio §bОТКРЫТИЕ"
|
||||
opening_progress = "§6Studio §bОТКРЫТИЕ§7 {percent}%"
|
||||
failed_progress = "§6Studio §cОШИБКА§7 {percent}%"
|
||||
|
||||
@@ -1586,6 +1586,14 @@ failed_fragment = " başarısız {failed}"
|
||||
"commandpack.update_world_unchanged" = "§a'{world}' dünyası aynı üretim ayarlarıyla zaten {pack} v{version} kullanıyor. Yeniden başlatma gerekmiyor."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Studio uygulaması indirmesi kapalı: iris.json içinde studio.downloadApp değerini true yap."
|
||||
app_no_display = "Bu sunucuda Studio uygulamasını açacak bir ekran yok."
|
||||
app_downloading = "Studio uygulaması hâlâ indiriliyor; birazdan tekrar dene."
|
||||
app_unavailable = "Studio uygulaması kullanılamıyor; konsola bak."
|
||||
app_not_built = "Studio uygulaması derlenmemiş: klasöründe npm run build çalıştır."
|
||||
app_failed_to_start = "Studio uygulaması başlatılamadı; konsola bak."
|
||||
link_copy_button = "[Studio bağlantısını kopyala]"
|
||||
link_copy_hover = "Studio uygulamasının bağlantı ekranına yapıştır"
|
||||
opening = "§6Studio §bAÇILIYOR"
|
||||
opening_progress = "§6Studio §bAÇILIYOR§7 {percent}%"
|
||||
failed_progress = "§6Studio §cBAŞARISIZ§7 {percent}%"
|
||||
|
||||
@@ -1584,6 +1584,14 @@ failed_fragment = " lỗi {failed}"
|
||||
"commandpack.update_world_unchanged" = "§aThế giới '{world}' đã dùng {pack} v{version} với cùng thiết lập tạo địa hình. Không cần khởi động lại."
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Tải ứng dụng Studio đang tắt: đặt studio.downloadApp thành true trong iris.json."
|
||||
app_no_display = "Máy chủ này không có màn hình để mở ứng dụng Studio."
|
||||
app_downloading = "Ứng dụng Studio vẫn đang tải; hãy thử lại sau giây lát."
|
||||
app_unavailable = "Ứng dụng Studio không khả dụng; xem console."
|
||||
app_not_built = "Ứng dụng Studio chưa được build: chạy npm run build trong thư mục của nó."
|
||||
app_failed_to_start = "Không khởi động được ứng dụng Studio; xem console."
|
||||
link_copy_button = "[Sao chép liên kết Studio]"
|
||||
link_copy_hover = "Dán vào màn hình kết nối của ứng dụng Studio"
|
||||
opening = "§6Studio §bĐANG MỞ"
|
||||
opening_progress = "§6Studio §bĐANG MỞ§7 {percent}%"
|
||||
failed_progress = "§6Studio §cTHẤT BẠI§7 {percent}%"
|
||||
|
||||
@@ -1584,6 +1584,14 @@ failed_fragment = " 失败 {failed}"
|
||||
"commandpack.update_world_unchanged" = "§a世界 '{world}' 已使用 {pack} v{version},且生成设置相同。无需重启。"
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Studio 应用下载已关闭:请在 iris.json 中将 studio.downloadApp 设为 true。"
|
||||
app_no_display = "此服务器没有可打开 Studio 应用的显示器。"
|
||||
app_downloading = "Studio 应用仍在下载;请稍后再试。"
|
||||
app_unavailable = "Studio 应用不可用;请查看控制台。"
|
||||
app_not_built = "Studio 应用未构建:请在其文件夹中运行 npm run build。"
|
||||
app_failed_to_start = "Studio 应用启动失败;请查看控制台。"
|
||||
link_copy_button = "[复制 Studio 链接]"
|
||||
link_copy_hover = "粘贴到 Studio 应用的连接界面"
|
||||
opening = "§6Studio §b正在打开"
|
||||
opening_progress = "§6Studio §b正在打开§7 {percent}%"
|
||||
failed_progress = "§6Studio §c失败§7 {percent}%"
|
||||
|
||||
@@ -1584,6 +1584,14 @@ failed_fragment = " 失敗 {failed}"
|
||||
"commandpack.update_world_unchanged" = "§a世界 '{world}' 已使用 {pack} v{version},且生成設定相同。無需重新啟動。"
|
||||
|
||||
[iris.runtime.studio]
|
||||
app_download_off = "Studio 應用程式下載已關閉:請在 iris.json 中將 studio.downloadApp 設為 true。"
|
||||
app_no_display = "此伺服器沒有可開啟 Studio 應用程式的顯示器。"
|
||||
app_downloading = "Studio 應用程式仍在下載;請稍後再試。"
|
||||
app_unavailable = "Studio 應用程式無法使用;請查看主控台。"
|
||||
app_not_built = "Studio 應用程式未建置:請在其資料夾中執行 npm run build。"
|
||||
app_failed_to_start = "Studio 應用程式無法啟動;請查看主控台。"
|
||||
link_copy_button = "[複製 Studio 連結]"
|
||||
link_copy_hover = "貼到 Studio 應用程式的連線畫面"
|
||||
opening = "§6Studio §b正在開啟"
|
||||
opening_progress = "§6Studio §b正在開啟§7 {percent}%"
|
||||
failed_progress = "§6Studio §c失敗§7 {percent}%"
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ public class IrisCaveCarver3DCellKernelTest {
|
||||
|
||||
@Test
|
||||
public void packStyleProfilesSharingFieldsMatchGoldenWriteSequence() throws Exception {
|
||||
assertScenario(Scenario.PACK_SHARED, 0xdbe20a1ca87f9cc7L, 269035);
|
||||
assertScenario(Scenario.PACK_SHARED, 0xb464b50d050e766dL, 288720);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package art.arcane.iris.generation.noise;
|
||||
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.noise.NoiseGenerator;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public final class IrisNoiseGeneratorFractureMirrorTest {
|
||||
private static final long SEED = 71L;
|
||||
private static final int GRID_SIZE = 40;
|
||||
private static final double GRID_STEP = 7.3D;
|
||||
private static final double MIRRORED = 1.0E-12D;
|
||||
private static final int ALLOWED_MIRRORED_SAMPLES = 2;
|
||||
|
||||
@Test
|
||||
public void aCompositeFractureIsNotMirroredAcrossTheDiagonal() {
|
||||
IrisNoiseGenerator fractured = diagonalSymmetricRoot().setFracture(new KList<>(fracture()));
|
||||
|
||||
assertTrue(mirroredSamples(fractured) <= ALLOWED_MIRRORED_SAMPLES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void theDiagonalSymmetricRootIsMirroredWithoutAFracture() {
|
||||
assertTrue(mirroredSamples(diagonalSymmetricRoot()) > ALLOWED_MIRRORED_SAMPLES);
|
||||
}
|
||||
|
||||
private static int mirroredSamples(IrisNoiseGenerator noise) {
|
||||
int mirroredSamples = 0;
|
||||
for (int i = 0; i < GRID_SIZE; i++) {
|
||||
for (int j = i + 1; j < GRID_SIZE; j++) {
|
||||
double a = i * GRID_STEP;
|
||||
double b = j * GRID_STEP + 0.5D;
|
||||
if (Math.abs(noise.getNoise(SEED, a, b, null) - noise.getNoise(SEED, b, a, null)) < MIRRORED) {
|
||||
mirroredSamples++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return mirroredSamples;
|
||||
}
|
||||
|
||||
private static IrisNoiseGenerator diagonalSymmetricRoot() {
|
||||
IrisNoiseGenerator root = new IrisNoiseGenerator().setStyle(NoiseStyle.SIMPLEX.style()).setSeed(5L);
|
||||
root.getGenerator(SEED, null, null).setGenerator(new DiagonalSymmetricGenerator());
|
||||
return root;
|
||||
}
|
||||
|
||||
private static IrisNoiseGenerator fracture() {
|
||||
return new IrisNoiseGenerator().setStyle(NoiseStyle.SIMPLEX.style()).setSeed(9L).setZoom(40D).setOpacity(40D);
|
||||
}
|
||||
|
||||
private static final class DiagonalSymmetricGenerator implements NoiseGenerator {
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return noise(x, 0D, 0D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return noise(x, z, 0D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return 0.5D + (Math.sin(x * 0.11D) + Math.sin(y * 0.11D) + Math.sin(z * 0.11D)) / 6D;
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-3
@@ -225,6 +225,11 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
|
||||
private static double reference(IrisNoiseGenerator node, long superSeed, double xv, double zv,
|
||||
IrisData data, Engine engine) {
|
||||
return reference(node, superSeed, xv, zv, data, engine, IrisNoiseGenerator.X_AXIS);
|
||||
}
|
||||
|
||||
private static double reference(IrisNoiseGenerator node, long superSeed, double xv, double zv,
|
||||
IrisData data, Engine engine, int axis) {
|
||||
if (!node.isEnabled()) {
|
||||
return node.getOffsetY();
|
||||
}
|
||||
@@ -234,14 +239,16 @@ public final class IrisNoiseGeneratorFractureTest {
|
||||
for (IrisNoiseGenerator child : node.getFracture()) {
|
||||
if (child.isEnabled()) {
|
||||
double offset = child.getOpacity() / 2D;
|
||||
x += reference(child, superSeed + node.getSeed() + salt, xv, zv, data, engine) - offset;
|
||||
z += reference(child, superSeed + node.getSeed() + salt, zv, xv, data, engine) - offset;
|
||||
long childSeed = superSeed + node.getSeed() + salt;
|
||||
x += reference(child, childSeed, xv, zv, data, engine, IrisNoiseGenerator.X_AXIS) - offset;
|
||||
z += reference(child, childSeed, xv, zv, data, engine, IrisNoiseGenerator.Z_AXIS) - offset;
|
||||
}
|
||||
salt += 819;
|
||||
}
|
||||
double sampleX = (x / node.getZoom()) + node.getOffsetX();
|
||||
double sampleZ = (z / node.getZoom()) + node.getOffsetZ();
|
||||
double result = node.getGenerator(superSeed, data, engine).noiseFast2D(sampleX, sampleZ) * node.getOpacity();
|
||||
CNG generator = node.getGenerator(superSeed, data, engine).reseededForAxis(axis);
|
||||
double result = generator.noiseFast2D(sampleX, sampleZ) * node.getOpacity();
|
||||
result = node.isNegative() ? -result + node.getOpacity() : result;
|
||||
result = (node.getExponent() != 1D ? result < 0D ? -Math.pow(-result, node.getExponent())
|
||||
: Math.pow(result, node.getExponent()) : result) + node.getOffsetY();
|
||||
|
||||
@@ -18,7 +18,7 @@ public class NoiseSeedCohesionTest {
|
||||
private static final long[] SEEDS = {813753L, -935731L, Long.MIN_VALUE};
|
||||
private static final double[] COORDINATES = {-29_999_983.25D, -513D, -64D, -1D, 0D, 0.125D, 17D, 64D, 8192D, 29_999_983.25D};
|
||||
private static final double PINNED_SAMPLE_SCALE = 1.0E9D;
|
||||
private static final long PINNED_HASH_WINDOWS = 2597318414939754011L;
|
||||
private static final long PINNED_HASH_WINDOWS = 6074446696529759284L;
|
||||
private static final long PINNED_HASH_MAC = -602781966673993721L;
|
||||
|
||||
@Test
|
||||
|
||||
+10
@@ -208,6 +208,16 @@ public class IrisDepositModifierOrderingTest {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoliagePlantable() {
|
||||
return false;
|
||||
|
||||
+10
@@ -466,6 +466,16 @@ public class IrisDepositModifierParityTest {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoliagePlantable() {
|
||||
return false;
|
||||
|
||||
+10
@@ -339,6 +339,16 @@ public class IrisPerfectionModifierColumnTest {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoliagePlantable() {
|
||||
return false;
|
||||
|
||||
@@ -252,6 +252,16 @@ final class CompatFixtures {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoliagePlantable() {
|
||||
return false;
|
||||
|
||||
@@ -38,17 +38,17 @@ public class IrisMathNoiseHotPathParityTest {
|
||||
.setStyle(NoiseStyle.PERLIN_IRIS.style())
|
||||
.setExponent(1.15D);
|
||||
|
||||
assertEquals(0.5084984235498856D, noiseGenerator.getNoise(9988L, 31.25D, -17.5D, null), 0D);
|
||||
assertEquals(0.4646529061250786D, noiseGenerator.getNoise(9988L, 31.25D, -17.5D, null), 0D);
|
||||
|
||||
IrisGeneratorStyle style = NoiseStyle.IRIS_DOUBLE.style();
|
||||
assertEquals(0.6224926166486215D, style.createNoCache(new RNG(112233L), null).noiseFast2D(42.5D, -19.75D), 0D);
|
||||
assertEquals(0.6855680984398492D, style.createNoCache(new RNG(112233L), null).noiseFast2D(42.5D, -19.75D), 0D);
|
||||
|
||||
IrisGenerator generator = new IrisGenerator()
|
||||
.setZoom(9.5D)
|
||||
.setOpacity(0.91D)
|
||||
.setComposite(new KList<IrisNoiseGenerator>().qadd(noiseGenerator));
|
||||
|
||||
assertEquals(0.43997118860461754D, generator.getHeight(63.0D, -27.0D, 445566L), 0D);
|
||||
assertEquals(0.5023367573389593D, generator.getHeight(63.0D, -27.0D, 445566L), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+5
-1
@@ -119,8 +119,12 @@ public class BukkitPersistedBlockStateTest {
|
||||
IrisCustomData custom = IrisCustomData.of(carrier, Identifier.fromString(key));
|
||||
ExternalDataSVC provider = mock(ExternalDataSVC.class);
|
||||
when(provider.getBlockData(Identifier.fromString(key))).thenReturn(Optional.of(custom));
|
||||
try (MockedStatic<IrisServices> services = mockStatic(IrisServices.class)) {
|
||||
when(provider.withoutDecay(custom)).thenReturn(custom);
|
||||
IrisSettings configuration = new IrisSettings();
|
||||
try (MockedStatic<IrisServices> services = mockStatic(IrisServices.class);
|
||||
MockedStatic<IrisSettings> settings = mockStatic(IrisSettings.class)) {
|
||||
services.when(() -> IrisServices.get(ExternalDataSVC.class)).thenReturn(provider);
|
||||
settings.when(IrisSettings::get).thenReturn(configuration);
|
||||
NativeBlockState decoded = registries.decodeBlockState(key);
|
||||
assertEquals(key, decoded.key());
|
||||
assertEquals(key, decoded.deferredPlacementKey());
|
||||
|
||||
+10
@@ -172,6 +172,16 @@ public class IrisObjectTransformsNearestBlockIndexTest {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoliagePlantable() {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ObjectLeafAndLogRulesTest {
|
||||
@Test
|
||||
public void leavesNeverCutALog() {
|
||||
assertTrue(ObjectBlockPass.keepsExisting(leaves(), log()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leavesReplaceOtherLeavesAndAir() {
|
||||
assertFalse(ObjectBlockPass.keepsExisting(leaves(), leaves()));
|
||||
assertFalse(ObjectBlockPass.keepsExisting(leaves(), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logsStillReplaceLeaves() {
|
||||
assertFalse(ObjectBlockPass.keepsExisting(log(), leaves()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vinesStillKeepSolidBlocks() {
|
||||
NativeBlockState vine = mock(NativeBlockState.class);
|
||||
when(vine.isVineBlock()).thenReturn(true);
|
||||
NativeBlockState solid = mock(NativeBlockState.class);
|
||||
when(solid.isSolid()).thenReturn(true);
|
||||
|
||||
assertTrue(ObjectBlockPass.keepsExisting(vine, solid));
|
||||
assertFalse(ObjectBlockPass.keepsExisting(vine, leaves()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customLeavesLosingTheirDecayAreMadePersistent() {
|
||||
NativeBlockState persistent = mock(NativeBlockState.class);
|
||||
NativeBlockState decaying = mock(NativeBlockState.class);
|
||||
when(decaying.key()).thenReturn("craftengine:test/leaves[persistent=false,distance=7]");
|
||||
when(decaying.withProperty("persistent", "true")).thenReturn(persistent);
|
||||
|
||||
assertSame(persistent, paletteOf(true, decaying).decayed(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customLeavesWithoutADistanceAreMadePersistentToo() {
|
||||
NativeBlockState persistent = mock(NativeBlockState.class);
|
||||
NativeBlockState decaying = mock(NativeBlockState.class);
|
||||
when(decaying.key()).thenReturn("craftengine:test/leaves[persistent=false]");
|
||||
when(decaying.withProperty("persistent", "true")).thenReturn(persistent);
|
||||
|
||||
assertSame(persistent, paletteOf(true, decaying).decayed(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decayIsLeftAloneWhenItIsNotPrevented() {
|
||||
NativeBlockState decaying = mock(NativeBlockState.class);
|
||||
when(decaying.key()).thenReturn("minecraft:oak_leaves[distance=3,persistent=false]");
|
||||
|
||||
assertSame(decaying, paletteOf(false, decaying).decayed(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blocksWithoutAPersistentPropertyAreLeftAlone() {
|
||||
NativeBlockState stone = mock(NativeBlockState.class);
|
||||
when(stone.key()).thenReturn("minecraft:stone");
|
||||
|
||||
assertSame(stone, paletteOf(true, stone).decayed(0));
|
||||
}
|
||||
|
||||
private static PlacementPalette paletteOf(boolean preventingDecay, NativeBlockState state) {
|
||||
return new PlacementPalette(new NativeBlockState[]{state}, new IrisObjectRotation(), 0, 0, 0,
|
||||
preventingDecay, false, java.util.Set.of());
|
||||
}
|
||||
|
||||
private static NativeBlockState leaves() {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(state.isLeaves()).thenReturn(true);
|
||||
return state;
|
||||
}
|
||||
|
||||
private static NativeBlockState log() {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(state.isLog()).thenReturn(true);
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -583,7 +583,17 @@ public class ObjectPlacementGoldenTest {
|
||||
|
||||
@Override
|
||||
public boolean isTreeBlock() {
|
||||
return material.endsWith("_log") || material.endsWith("_leaves");
|
||||
return isLog() || isLeaves();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLog() {
|
||||
return material.endsWith("_log");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
return material.endsWith("_leaves");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BundledStudioAppTest {
|
||||
@Rule
|
||||
public TemporaryFolder temporary = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void unpacksTheBundledAppIntoAFolderNamedByItsChecksum() throws IOException {
|
||||
Path root = temporary.newFolder("studio").toPath();
|
||||
|
||||
try (URLClassLoader resources = jarResources(appArchive("out/main/index.js"))) {
|
||||
Path app = BundledStudioApp.install(root, resources);
|
||||
|
||||
assertTrue(app.getFileName().toString().matches("app-[0-9a-f]{12}"));
|
||||
assertTrue(Files.isRegularFile(app.resolve("package.json")));
|
||||
assertTrue(Files.isRegularFile(app.resolve("out/main/index.js")));
|
||||
assertEquals(app, BundledStudioApp.install(root, resources));
|
||||
assertFalse(Files.exists(root.resolve("studio-app.zip.part")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refusesAnArchiveEntryThatLeavesItsFolder() throws IOException {
|
||||
Path root = temporary.newFolder("studio").toPath();
|
||||
|
||||
try (URLClassLoader resources = jarResources(appArchive("../../escaped.js"))) {
|
||||
assertThrows(IOException.class, () -> BundledStudioApp.install(root, resources));
|
||||
}
|
||||
assertFalse(Files.exists(root.getParent().resolve("escaped.js")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reportsABuildWithoutTheApp() throws IOException {
|
||||
Path root = temporary.newFolder("studio").toPath();
|
||||
|
||||
try (URLClassLoader resources = new URLClassLoader(new URL[0], null)) {
|
||||
assertThrows(IOException.class, () -> BundledStudioApp.install(root, resources));
|
||||
}
|
||||
}
|
||||
|
||||
private Path appArchive(String scriptEntry) throws IOException {
|
||||
Path archive = temporary.newFolder().toPath().resolve("studio-app.zip");
|
||||
try (ZipOutputStream zip = new ZipOutputStream(Files.newOutputStream(archive))) {
|
||||
zip.putNextEntry(new ZipEntry("package.json"));
|
||||
zip.write("{\"main\":\"out/main/index.js\"}".getBytes(StandardCharsets.UTF_8));
|
||||
zip.closeEntry();
|
||||
zip.putNextEntry(new ZipEntry(scriptEntry));
|
||||
zip.write("export {}".getBytes(StandardCharsets.UTF_8));
|
||||
zip.closeEntry();
|
||||
}
|
||||
return archive;
|
||||
}
|
||||
|
||||
private URLClassLoader jarResources(Path archive) throws IOException {
|
||||
Path classpath = temporary.newFolder().toPath();
|
||||
Path resource = classpath.resolve(BundledStudioApp.RESOURCE);
|
||||
Files.createDirectories(resource.getParent());
|
||||
Files.copy(archive, resource);
|
||||
return new URLClassLoader(new URL[]{classpath.toUri().toURL()}, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ElectronRuntimeTest {
|
||||
private static final ElectronRuntime.Platform LINUX = new ElectronRuntime.Platform("linux-x64", "electron");
|
||||
private static final String ELECTRON_FIXTURE = "/studio-app/electron-fixture.zip";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporary = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void namesPlatformsTheWayElectronReleasesDo() {
|
||||
assertEquals("linux-x64", ElectronRuntime.Platform.of("Linux", "amd64").name());
|
||||
assertEquals("linux-arm64", ElectronRuntime.Platform.of("Linux", "aarch64").name());
|
||||
assertEquals("electron.exe", ElectronRuntime.Platform.of("Windows 11", "amd64").executable());
|
||||
assertEquals("Electron.app/Contents/MacOS/Electron", ElectronRuntime.Platform.of("Mac OS X", "aarch64").executable());
|
||||
assertNull(ElectronRuntime.Platform.of("FreeBSD", "amd64"));
|
||||
assertNull(ElectronRuntime.Platform.of("Linux", "riscv64"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downloadsFromTheElectronReleaseOfThePinnedVersion() throws IOException {
|
||||
ElectronRuntime electron = ElectronRuntime.pinned(pins("45.2.3", "0".repeat(64)), LINUX);
|
||||
|
||||
assertEquals(URI.create("https://github.com/electron/electron/releases/download/v45.2.3/electron-v45.2.3-linux-x64.zip"),
|
||||
electron.source());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refusesAPlatformTheBuildDidNotPin() {
|
||||
assertThrows(IOException.class, () -> ElectronRuntime.pinned(pins("45.2.3", "0".repeat(64)),
|
||||
new ElectronRuntime.Platform("darwin-arm64", "Electron.app/Contents/MacOS/Electron")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unpacksAVerifiedArchiveWithItsExecutableBitOnce() throws IOException {
|
||||
Path archive = electronArchive();
|
||||
Path root = temporary.newFolder("studio").toPath();
|
||||
ElectronRuntime electron = ElectronRuntime.pinned(pins("45.2.3", ElectronRuntime.sha256(archive)), LINUX);
|
||||
List<URI> downloads = new ArrayList<>();
|
||||
ElectronRuntime.Downloader downloader = (source, target) -> {
|
||||
downloads.add(source);
|
||||
Files.copy(archive, target);
|
||||
};
|
||||
|
||||
Path executable = electron.install(root, downloader);
|
||||
electron.install(root, downloader);
|
||||
|
||||
assertEquals(root.resolve("electron-v45.2.3-linux-x64/electron"), executable);
|
||||
Path lib = root.resolve("electron-v45.2.3-linux-x64/lib");
|
||||
assertTrue(Files.getPosixFilePermissions(executable).contains(PosixFilePermission.OWNER_EXECUTE));
|
||||
assertFalse(Files.getPosixFilePermissions(lib.resolve("libffmpeg.so")).contains(PosixFilePermission.OWNER_EXECUTE));
|
||||
assertEquals(Path.of("libffmpeg.so"), Files.readSymbolicLink(lib.resolve("libffmpeg.so.1")));
|
||||
assertEquals("library", Files.readString(lib.resolve("libffmpeg.so.1")));
|
||||
assertEquals(1, downloads.size());
|
||||
assertFalse(Files.exists(root.resolve("electron-v45.2.3-linux-x64.zip.part")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leavesNothingInstalledWhenTheChecksumIsWrong() throws IOException {
|
||||
Path archive = electronArchive();
|
||||
Path root = temporary.newFolder("studio").toPath();
|
||||
ElectronRuntime electron = ElectronRuntime.pinned(pins("45.2.3", "0".repeat(64)), LINUX);
|
||||
|
||||
assertThrows(IOException.class, () -> electron.install(root, (source, target) -> Files.copy(archive, target)));
|
||||
|
||||
try (var children = Files.list(root)) {
|
||||
assertEquals(List.of(), children.toList());
|
||||
}
|
||||
}
|
||||
|
||||
/** Made by Info-ZIP, as Electron's archives are: an executable, a plain file and a symlink to it. */
|
||||
private Path electronArchive() throws IOException {
|
||||
Path archive = temporary.getRoot().toPath().resolve("electron.zip");
|
||||
try (InputStream fixture = ElectronRuntimeTest.class.getResourceAsStream(ELECTRON_FIXTURE)) {
|
||||
Files.copy(fixture, archive);
|
||||
}
|
||||
return archive;
|
||||
}
|
||||
|
||||
private static Properties pins(String version, String linuxChecksum) {
|
||||
Properties pins = new Properties();
|
||||
pins.setProperty("electron.version", version);
|
||||
pins.setProperty("linux-x64.sha256", linuxChecksum);
|
||||
return pins;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.studio.app;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class StudioAppInstallerTest {
|
||||
@Test
|
||||
public void seesADisplayOnlyWhenLinuxHasOne() {
|
||||
assertTrue(StudioAppInstaller.hasDisplay("Linux", Map.of("WAYLAND_DISPLAY", "wayland-1")));
|
||||
assertTrue(StudioAppInstaller.hasDisplay("Linux", Map.of("DISPLAY", ":0")));
|
||||
assertFalse(StudioAppInstaller.hasDisplay("Linux", Map.of()));
|
||||
assertFalse(StudioAppInstaller.hasDisplay("Linux", Map.of("DISPLAY", " ")));
|
||||
assertTrue(StudioAppInstaller.hasDisplay("Windows 11", Map.of()));
|
||||
assertTrue(StudioAppInstaller.hasDisplay("Mac OS X", Map.of()));
|
||||
}
|
||||
}
|
||||
@@ -183,6 +183,16 @@ public class TreePlausibilizerTest {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoliagePlantable() {
|
||||
return false;
|
||||
|
||||
@@ -89,6 +89,16 @@ public final class KeyedBlockState implements NativeBlockState {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoliagePlantable() {
|
||||
return false;
|
||||
|
||||
@@ -136,6 +136,16 @@ public final class PlantBlockState implements NativeBlockState {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLeaves() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoliagePlantable() {
|
||||
return false;
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user