Save custom blocks in the mantle under their custom id

A custom state's key is its base block, so a provider block (Nexo,
ItemsAdder) held in a mantle section that was written to disk before
its chunk generated read back as the vanilla base block. The mantle now
saves it under its custom id, which reads back through its provider.
This commit is contained in:
piexel committed 2026-11-05 21:44:32 +01:00
1 parent d5e75114ab
commit 8ca183d0c2
2 files changed
+48 -1

No files matched your search

@@ -28,7 +28,13 @@ public class PlatformBlockMatter extends RawMatter<PlatformBlockState> {
@Override
public void writeNode(PlatformBlockState b, DataOutputStream dos) throws IOException {
dos.writeUTF(b.key());
dos.writeUTF(persistedKey(b));
}
/** A custom block's key is its base block, so it is saved under its custom id, which reads back through its provider. */
private static String persistedKey(PlatformBlockState state) {
String customKey = state.isCustom() ? state.deferredPlacementKey() : null;
return customKey == null ? state.key() : customKey;
}
@Override
@@ -0,0 +1,41 @@
package art.arcane.iris.util.project.matter.slices;
import art.arcane.iris.spi.PlatformBlockState;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/** What the mantle saves for a block; reading a key back goes through {@code B.getState}, which resolves provider ids. */
public class PlatformBlockMatterTest {
@Test
public void aCustomBlockIsSavedUnderItsCustomIdNotItsBaseBlock() throws IOException {
PlatformBlockState customBlock = mock(PlatformBlockState.class);
when(customBlock.isCustom()).thenReturn(true);
when(customBlock.key()).thenReturn("minecraft:note_block[instrument=harp,note=3,powered=false]");
when(customBlock.deferredPlacementKey()).thenReturn("nexo:ruby_block");
assertEquals("nexo:ruby_block", written(customBlock));
}
@Test
public void aPlainBlockIsSavedUnderItsKey() throws IOException {
PlatformBlockState stone = mock(PlatformBlockState.class);
when(stone.key()).thenReturn("minecraft:stone");
assertEquals("minecraft:stone", written(stone));
}
private static String written(PlatformBlockState state) throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
new PlatformBlockMatter().writeNode(state, new DataOutputStream(bytes));
return new DataInputStream(new ByteArrayInputStream(bytes.toByteArray())).readUTF();
}
}