Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Client Registry Remapping Only Remapping One Registry #4404

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -103,12 +103,11 @@ public static void apply(RegistryPacketHandler.SyncedPacketData data) throws Rem
}
}

if (registry instanceof RemappableRegistry remappableRegistry) {
remappableRegistry.remap(entry.getValue(), RemappableRegistry.RemapMode.REMOTE);
return;
if (!(registry instanceof RemappableRegistry remappableRegistry)) {
throw new RemapException("Registry " + registryId + " is not remappable");
}

throw new RemapException("Registry " + registryId + " is not remappable");
remappableRegistry.remap(entry.getValue(), RemappableRegistry.RemapMode.REMOTE);
}
}

Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -53,6 +54,7 @@
import net.fabricmc.fabric.impl.registry.sync.RemapException;
import net.fabricmc.fabric.impl.registry.sync.RemappableRegistry;
import net.fabricmc.fabric.impl.registry.sync.packet.DirectRegistryPacketHandler;
import net.fabricmc.fabric.impl.registry.sync.packet.RegistryPacketHandler;

public class RegistryRemapTest {
private RegistryKey<Registry<String>> testRegistryKey;
@@ -248,6 +250,71 @@ void missingRemoteEntries() throws RemapException {
assertEquals(2, testRegistry.getRawId("two"));
}

@Test
void remapRegistryFromPacketData() throws RemapException {
RemappableRegistry remappableRegistry = (RemappableRegistry) testRegistry;

assertEquals(0, testRegistry.getRawId("zero"));
assertEquals(1, testRegistry.getRawId("one"));
assertEquals(2, testRegistry.getRawId("two"));

ClientRegistrySyncHandler.apply(new RegistryPacketHandler.SyncedPacketData(
Map.of(
testRegistryKey.getValue(), asFastMap(Map.of(
id("zero"), 2,
id("one"), 1,
id("two"), 0
))
),
Map.of()
));

assertEquals(2, testRegistry.getRawId("zero"));
assertEquals(1, testRegistry.getRawId("one"));
assertEquals(0, testRegistry.getRawId("two"));

remappableRegistry.unmap();

assertEquals(0, testRegistry.getRawId("zero"));
assertEquals(1, testRegistry.getRawId("one"));
assertEquals(2, testRegistry.getRawId("two"));
}

@Test
void remapRegistryFromPacketDataIgnoreOptional() throws RemapException {
RemappableRegistry remappableRegistry = (RemappableRegistry) testRegistry;

assertEquals(0, testRegistry.getRawId("zero"));
assertEquals(1, testRegistry.getRawId("one"));
assertEquals(2, testRegistry.getRawId("two"));

ClientRegistrySyncHandler.apply(new RegistryPacketHandler.SyncedPacketData(
Map.of(
testRegistryKey.getValue(), asFastMap(Map.of(
id("zero"), 2,
id("one"), 1,
id("two"), 0
)),
Identifier.of("test", "optional"), asFastMap(Map.of(
id("test"), 0
))
),
Map.of(
Identifier.of("test", "optional"), EnumSet.of(RegistryAttribute.OPTIONAL)
)
));

assertEquals(2, testRegistry.getRawId("zero"));
assertEquals(1, testRegistry.getRawId("one"));
assertEquals(0, testRegistry.getRawId("two"));

remappableRegistry.unmap();

assertEquals(0, testRegistry.getRawId("zero"));
assertEquals(1, testRegistry.getRawId("one"));
assertEquals(2, testRegistry.getRawId("two"));
}

private static List<Boolean> receivePayloads(List<DirectRegistryPacketHandler.Payload> payloads) throws RemapException {
var results = new ArrayList<Boolean>();