Skip to content

Commit

Permalink
Fix Client Registry Remapping Only Remapping One Registry (#4404)
Browse files Browse the repository at this point in the history
* WW DEBUG

Revert "apple log"

This reverts commit e3ba09c.

Possible Fix

apple log

Update RemapStateImpl.java

Revert "WW DEBUG"

This reverts commit 3f2ffa9.

* Fix Client Registry Remapping Only Remapping One Registry

* Add unit test

---------

Co-authored-by: modmuss50 <[email protected]>
  • Loading branch information
AViewFromTheTop and modmuss50 authored Jan 29, 2025
1 parent 4596e0c commit 4ba56ac
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>();

Expand Down

0 comments on commit 4ba56ac

Please sign in to comment.