3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Fix key regression with pre-built registries

Dieser Commit ist enthalten in:
Camotoy 2024-06-13 11:24:16 -04:00
Ursprung 842e1b4d12
Commit ce3083b9b8
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 5 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -72,7 +72,7 @@ import java.util.function.ToIntFunction;
@Accessors(fluent = true) @Accessors(fluent = true)
@Getter @Getter
public final class RegistryCache { public final class RegistryCache {
private static final Map<Key, Map<String, NbtMap>> DEFAULTS; private static final Map<Key, Map<Key, NbtMap>> DEFAULTS;
private static final Map<Key, BiConsumer<RegistryCache, List<RegistryEntry>>> REGISTRIES = new HashMap<>(); private static final Map<Key, BiConsumer<RegistryCache, List<RegistryEntry>>> REGISTRIES = new HashMap<>();
static { static {
@ -89,14 +89,14 @@ public final class RegistryCache {
// Load from MCProtocolLib's classloader // Load from MCProtocolLib's classloader
NbtMap tag = MinecraftProtocol.loadNetworkCodec(); NbtMap tag = MinecraftProtocol.loadNetworkCodec();
Map<Key, Map<String, NbtMap>> defaults = new HashMap<>(); Map<Key, Map<Key, NbtMap>> defaults = new HashMap<>();
// Don't create a keySet - no need to create the cached object in HashMap if we don't use it again // Don't create a keySet - no need to create the cached object in HashMap if we don't use it again
REGISTRIES.forEach((key, $) -> { REGISTRIES.forEach((key, $) -> {
List<NbtMap> rawValues = tag.getCompound(key.asString()) List<NbtMap> rawValues = tag.getCompound(key.asString())
.getList("value", NbtType.COMPOUND); .getList("value", NbtType.COMPOUND);
Map<String, NbtMap> values = new HashMap<>(); Map<Key, NbtMap> values = new HashMap<>();
for (NbtMap value : rawValues) { for (NbtMap value : rawValues) {
String name = value.getString("name"); Key name = MinecraftKey.key(value.getString("name"));
values.put(name, value.getCompound("element")); values.put(name, value.getCompound("element"));
} }
// Can make these maps immutable and as efficient as possible after initialization // Can make these maps immutable and as efficient as possible after initialization
@ -152,7 +152,7 @@ public final class RegistryCache {
private static <T> void register(String registry, Function<RegistryCache, JavaRegistry<T>> localCacheFunction, BiFunction<GeyserSession, RegistryEntry, T> reader) { private static <T> void register(String registry, Function<RegistryCache, JavaRegistry<T>> localCacheFunction, BiFunction<GeyserSession, RegistryEntry, T> reader) {
Key key = MinecraftKey.key(registry); Key key = MinecraftKey.key(registry);
REGISTRIES.put(key, (registryCache, entries) -> { REGISTRIES.put(key, (registryCache, entries) -> {
Map<String, NbtMap> localRegistry = null; Map<Key, NbtMap> localRegistry = null;
JavaRegistry<T> localCache = localCacheFunction.apply(registryCache); JavaRegistry<T> localCache = localCacheFunction.apply(registryCache);
// Clear each local cache every time a new registry entry is given to us // Clear each local cache every time a new registry entry is given to us
// (e.g. proxy server switches) // (e.g. proxy server switches)

Datei anzeigen

@ -39,7 +39,6 @@ public class JavaClientboundRecipesTranslator extends PacketTranslator<Clientbou
@Override @Override
public void translate(GeyserSession session, ClientboundRecipePacket packet) { public void translate(GeyserSession session, ClientboundRecipePacket packet) {
System.out.println(packet);
UnlockedRecipesPacket recipesPacket = new UnlockedRecipesPacket(); UnlockedRecipesPacket recipesPacket = new UnlockedRecipesPacket();
switch (packet.getAction()) { switch (packet.getAction()) {
case INIT -> { case INIT -> {