mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Modded server registries
- Modded platform hands the running server to registry access - Tile reader is built from the running server - Registry test covers startup, reload and shutdown of dynamic registries
This commit is contained in:
1 parent
241260a762
commit
c20296d106
4 files changed
+45
-21
No files matched your search
+1
-1
@@ -41,7 +41,7 @@ public class ModdedTileParityTest {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
registries = RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY);
|
||||
NativeTileReader nativeTileReader = new NativeTileReader(() -> null);
|
||||
NativeTileReader nativeTileReader = NativeTileReader.forServer(() -> null);
|
||||
TileData.bindPlatformReader(in -> ModdedTileData.wrap(nativeTileReader.read(in)));
|
||||
TileData.bindPlatformFactory(ModdedTileData::fromProperties);
|
||||
}
|
||||
|
||||
+42
-3
@@ -1,20 +1,31 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeRegistryAccess;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeModdedServer;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockProperty;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class NativeRegistryAccessTest {
|
||||
@BeforeClass
|
||||
@@ -25,7 +36,7 @@ public class NativeRegistryAccessTest {
|
||||
|
||||
@Test
|
||||
public void statePropertiesPreserveTypesDefaultsAndSharedGroups() {
|
||||
NativeRegistryAccess access = new NativeRegistryAccess(new NativeRegistryAccess.Configuration(() -> null, () -> null, message -> {}));
|
||||
NativeRegistryAccess access = new NativeRegistryAccess(new NativeRegistryAccess.Configuration(() -> null, message -> {}));
|
||||
Map<String, List<NativeBlockProperty>> properties = access.blockStateProperties();
|
||||
|
||||
assertSame(properties.get("minecraft:stone"), properties.get("minecraft:dirt"));
|
||||
@@ -41,7 +52,7 @@ public class NativeRegistryAccessTest {
|
||||
@Test
|
||||
public void staticRegistriesResolveWithoutAnActiveServerAndDynamicReadsStayEmpty() {
|
||||
List<String> warnings = new ArrayList<>();
|
||||
NativeRegistryAccess access = new NativeRegistryAccess(new NativeRegistryAccess.Configuration(() -> null, () -> null, warnings::add));
|
||||
NativeRegistryAccess access = new NativeRegistryAccess(new NativeRegistryAccess.Configuration(() -> null, warnings::add));
|
||||
|
||||
assertEquals("minecraft:diamond_sword", access.item("DIAMOND SWORD").key());
|
||||
assertEquals("creature", access.entity("minecraft:cow").spawnCategory());
|
||||
@@ -49,6 +60,34 @@ public class NativeRegistryAccessTest {
|
||||
assertTrue(access.biomeKeys().isEmpty());
|
||||
assertTrue(access.structureKeys().isEmpty());
|
||||
assertTrue(access.enchantmentKeys().isEmpty());
|
||||
assertEquals(List.of("biome", "structure", "enchantment"), warnings);
|
||||
assertTrue(access.lootTableKeys().isEmpty());
|
||||
assertEquals(List.of("biome", "structure", "enchantment", "loot table"), warnings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dynamicRegistriesFollowServerStartupReloadAndShutdown() {
|
||||
AtomicReference<NativeModdedServer> activeServer = new AtomicReference<>();
|
||||
List<String> warnings = new ArrayList<>();
|
||||
NativeRegistryAccess access = new NativeRegistryAccess(new NativeRegistryAccess.Configuration(activeServer::get, warnings::add));
|
||||
assertTrue(access.lootTableKeys().isEmpty());
|
||||
|
||||
MinecraftServer server = mock(MinecraftServer.class, RETURNS_DEEP_STUBS);
|
||||
when(server.registryAccess().lookupOrThrow(Registries.BIOME).listElementIds())
|
||||
.thenAnswer(invocation -> Stream.of(ResourceKey.create(Registries.BIOME, Identifier.parse("example:biome"))));
|
||||
when(server.reloadableRegistries().lookup().lookupOrThrow(Registries.LOOT_TABLE).listElementIds())
|
||||
.thenAnswer(invocation -> Stream.of(ResourceKey.create(Registries.LOOT_TABLE, Identifier.parse("example:initial"))));
|
||||
activeServer.set(NativeModdedServer.fromHandle(server));
|
||||
|
||||
assertEquals(List.of("example:biome"), access.biomeKeys());
|
||||
assertEquals(List.of("example:initial"), access.lootTableKeys());
|
||||
HolderLookup.Provider reloadedRegistries = mock(HolderLookup.Provider.class, RETURNS_DEEP_STUBS);
|
||||
when(reloadedRegistries.lookupOrThrow(Registries.LOOT_TABLE).listElementIds())
|
||||
.thenAnswer(invocation -> Stream.of(ResourceKey.create(Registries.LOOT_TABLE, Identifier.parse("example:reloaded"))));
|
||||
when(server.reloadableRegistries().lookup()).thenReturn(reloadedRegistries);
|
||||
assertEquals(List.of("example:reloaded"), access.lootTableKeys());
|
||||
activeServer.set(null);
|
||||
assertTrue(access.biomeKeys().isEmpty());
|
||||
assertTrue(access.lootTableKeys().isEmpty());
|
||||
assertEquals(List.of("loot table", "biome", "loot table"), warnings);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user