Studio bridge: scene views and Minecraft assets

The bridge lists the scene views the pack's modules registered, their
entries, and encodes a scene as a palette of block states and their
positions from the anchor. Assets come from the Minecraft client jar of
the server's version, fetched from Mojang the first time the studio asks,
checked against Mojang's SHA-1 and cached; until then the route answers
503 with Retry-After.
This commit is contained in:
piexel committed 2026-11-06 01:18:52 +01:00
1 parent 13c0705d44
commit c753a1a7fe
7 files changed
+532

No files matched your search

@@ -0,0 +1,17 @@
package art.arcane.iris.core.studio.assets;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class MinecraftAssetsTest {
@Test
public void onlyFilesInTheClientsAssetFolderAreServed() {
assertTrue(MinecraftAssets.isAssetPath("assets/minecraft/textures/block/stone.png"));
assertFalse(MinecraftAssets.isAssetPath("net/minecraft/client/Main.class"));
assertFalse(MinecraftAssets.isAssetPath("assets/../META-INF/MANIFEST.MF"));
assertFalse(MinecraftAssets.isAssetPath("assets//minecraft/models/block/stone.json"));
assertFalse(MinecraftAssets.isAssetPath("assets\\minecraft\\x.json"));
}
}
@@ -0,0 +1,43 @@
package art.arcane.iris.core.studio.bridge;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.volmit.block.BlockState;
import com.volmit.geometry.BlockBox;
import com.volmit.geometry.BlockPosition;
import com.volmit.object.GeneratedObject;
import com.volmit.object.ObjectBlock;
import org.junit.Test;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import static org.junit.Assert.assertEquals;
public class SceneEncodingTest {
@Test
public void blocksCountFromTheAnchorIndexOnePaletteAndLeaveAirOut() {
GeneratedObject tree = new GeneratedObject(new BlockBox(0, 0, 0, 3, 3, 3), new BlockPosition(1, 0, 1), List.of(
new ObjectBlock(new BlockPosition(1, 0, 1), BlockState.parse("minecraft:oak_log[axis=y]")),
new ObjectBlock(new BlockPosition(1, 1, 1), BlockState.parse("minecraft:oak_log[axis=y]")),
new ObjectBlock(new BlockPosition(0, 2, 1), BlockState.parse("minecraft:air")),
new ObjectBlock(new BlockPosition(1, 2, 1), BlockState.parse("minecraft:oak_leaves"))), List.of());
byte[] encoded = SceneEncoding.encode(tree, new Gson());
ByteBuffer body = ByteBuffer.wrap(encoded).order(ByteOrder.LITTLE_ENDIAN);
int headerLength = body.getInt();
JsonObject header = JsonParser.parseString(new String(encoded, 4, headerLength, StandardCharsets.UTF_8)).getAsJsonObject();
assertEquals("[\"minecraft:oak_log[axis=y]\",\"minecraft:oak_leaves\"]", header.get("palette").toString());
assertEquals(3, header.get("blockCount").getAsInt());
assertEquals("[-1,0,-1]", header.get("min").toString());
assertEquals("[2,3,2]", header.get("max").toString());
int blocksAt = (4 + headerLength + 3) / 4 * 4;
assertEquals(blocksAt + 3 * 16, encoded.length);
body.position(blocksAt + 2 * 16);
assertEquals(List.of(0, 2, 0, 1), List.of(body.getInt(), body.getInt(), body.getInt(), body.getInt()));
}
}