3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-10-01 23:50:11 +02:00

Add native offhand support for *some* items

About 46 items are data-driven enough where we can tell Bedrock these items are permitted in the offhand.
Dieser Commit ist enthalten in:
Camotoy 2024-05-30 22:29:00 -04:00
Ursprung c8fbffb638
Commit da5d8006ad
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 28 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -38,6 +38,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder; import org.cloudburstmc.nbt.NbtMapBuilder;
import org.cloudburstmc.nbt.NbtType; import org.cloudburstmc.nbt.NbtType;
import org.cloudburstmc.nbt.NbtUtils;
import org.cloudburstmc.protocol.bedrock.codec.v671.Bedrock_v671; import org.cloudburstmc.protocol.bedrock.codec.v671.Bedrock_v671;
import org.cloudburstmc.protocol.bedrock.codec.v685.Bedrock_v685; import org.cloudburstmc.protocol.bedrock.codec.v685.Bedrock_v685;
import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
@ -102,6 +103,13 @@ public class ItemRegistryPopulator {
throw new AssertionError("Unable to load Java runtime item IDs", e); throw new AssertionError("Unable to load Java runtime item IDs", e);
} }
NbtMap vanillaComponents;
try (InputStream stream = bootstrap.getResourceOrThrow("mappings/item_components.nbt")) {
vanillaComponents = (NbtMap) NbtUtils.createGZIPReader(stream, true, true).readTag();
} catch (Exception e) {
throw new AssertionError("Unable to load Bedrock item components", e);
}
boolean customItemsAllowed = GeyserImpl.getInstance().getConfig().isAddNonBedrockItems(); boolean customItemsAllowed = GeyserImpl.getInstance().getConfig().isAddNonBedrockItems();
// List values here is important compared to HashSet - we need to preserve the order of what's given to us // List values here is important compared to HashSet - we need to preserve the order of what's given to us
@ -531,6 +539,25 @@ public class ItemRegistryPopulator {
} }
} }
for (Map.Entry<String, Object> entry : vanillaComponents.entrySet()) {
String id = entry.getKey();
ItemDefinition definition = definitions.get(id);
if (definition == null) {
// Newer item most likely
GeyserImpl.getInstance().getLogger().debug(
"Skipping vanilla component " + id + " for protocol " + palette.protocolVersion()
);
continue;
}
NbtMapBuilder root = NbtMap.builder()
.putString("name", id)
.putInt("id", definition.getRuntimeId())
.putCompound("components", (NbtMap) entry.getValue());
componentItemData.add(new ComponentItemData(id, root.build()));
}
// Register the item forms of custom blocks // Register the item forms of custom blocks
if (BlockRegistries.CUSTOM_BLOCKS.get().length != 0) { if (BlockRegistries.CUSTOM_BLOCKS.get().length != 0) {
for (CustomBlockData customBlock : BlockRegistries.CUSTOM_BLOCKS.get()) { for (CustomBlockData customBlock : BlockRegistries.CUSTOM_BLOCKS.get()) {

@ -1 +1 @@
Subproject commit ec45f59c8590945c9226921ef7e339f510983dc1 Subproject commit 88e50df1008916c266428ac11f76f07dc24638c5