mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
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:
1 parent
d5e75114ab
commit
8ca183d0c2
2 files changed
+48
-1
No files matched your search
+41
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user