Skip to content

Commit 9056292

Browse files
committed
Throw when we cannot find Bedrock item components for vanilla component based items; load default Bedrock item_components :(
1 parent 71546b4 commit 9056292

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ public static void populate() {
164164
}
165165

166166
NbtMap vanillaComponents;
167-
try (InputStream stream = bootstrap.getResourceOrThrow("mappings/item_components.nbt")) {
167+
// TODO e.g. breeze rod icon does not load with our modified item components
168+
try (InputStream stream = bootstrap.getResourceOrThrow("bedrock/item_components.nbt")) {
168169
vanillaComponents = (NbtMap) NbtUtils.createGZIPReader(stream, true, true).readTag();
169170
} catch (Exception e) {
170171
throw new AssertionError("Unable to load Bedrock item components", e);
@@ -198,7 +199,7 @@ public static void populate() {
198199

199200
// Used for custom items
200201
int nextFreeBedrockId = 0;
201-
// TODO rename or yeet
202+
// TODO yeet
202203
List<ItemDefinition> componentItemData = new ObjectArrayList<>();
203204

204205
Int2ObjectMap<ItemDefinition> registry = new Int2ObjectOpenHashMap<>();
@@ -212,8 +213,10 @@ public static void populate() {
212213

213214
NbtMap components = null;
214215
if (entry.isComponentBased()) {
215-
// TODO test
216216
components = vanillaComponents.getCompound(entry.getName());
217+
if (components == null) {
218+
throw new RuntimeException("Could not find vanilla components for vanilla component based item! " + entry.getName());
219+
}
217220
}
218221

219222
ItemDefinition definition = new SimpleItemDefinition(entry.getName().intern(), id, entry.getVersion(), entry.isComponentBased(), components);
@@ -449,8 +452,7 @@ public static void populate() {
449452
int customProtocolId = nextFreeBedrockId++;
450453
mappingItem = mappingItem.withBedrockData(customProtocolId);
451454
bedrockIdentifier = customBlockData.identifier();
452-
// TODO add component nbt here
453-
definition = new SimpleItemDefinition(bedrockIdentifier, customProtocolId, true);
455+
definition = new SimpleItemDefinition(bedrockIdentifier, customProtocolId, 2, false, null);
454456
registry.put(customProtocolId, definition);
455457
customBlockItemDefinitions.put(customBlockData, definition);
456458
customIdMappings.put(customProtocolId, bedrockIdentifier);
@@ -528,7 +530,7 @@ public static void populate() {
528530
}
529531

530532
// ComponentItemData - used to register some custom properties
531-
componentItemData.add(customMapping.itemDefinition()); // TODO
533+
componentItemData.add(customMapping.itemDefinition());
532534
customItemOptions.add(Pair.of(customItem.customItemOptions(), customMapping.itemDefinition()));
533535
registry.put(customMapping.integerId(), customMapping.itemDefinition());
534536

@@ -623,7 +625,6 @@ public static void populate() {
623625
int customItemId = nextFreeBedrockId++;
624626
NonVanillaItemRegistration registration = CustomItemRegistryPopulator.registerCustomItem(customItem, customItemId, palette.protocolVersion);
625627

626-
// TODO yeet?
627628
componentItemData.add(registration.mapping().getBedrockDefinition());
628629
ItemMapping mapping = registration.mapping();
629630
Item javaItem = registration.javaItem();
@@ -663,7 +664,6 @@ public static void populate() {
663664
int customProtocolId = nextFreeBedrockId++;
664665
String identifier = customBlock.identifier();
665666

666-
// TODO
667667
final ItemDefinition definition = new SimpleItemDefinition(identifier, customProtocolId, 2, false, null);
668668
registry.put(customProtocolId, definition);
669669
customBlockItemDefinitions.put(customBlock, definition);

core/src/main/java/org/geysermc/geyser/session/GeyserSession.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
import org.cloudburstmc.protocol.bedrock.data.command.CommandPermission;
7878
import org.cloudburstmc.protocol.bedrock.data.command.SoftEnumUpdateType;
7979
import org.cloudburstmc.protocol.bedrock.data.definitions.DimensionDefinition;
80-
import org.cloudburstmc.protocol.bedrock.data.definitions.SimpleItemDefinition;
8180
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
8281
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
8382
import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.CraftingRecipeData;
@@ -740,10 +739,9 @@ public void connect() {
740739
sentSpawnPacket = true;
741740
syncEntityProperties();
742741

743-
// TODO test
744742
if (this.protocolVersion() >= 776) {
745743
ItemComponentPacket componentPacket = new ItemComponentPacket();
746-
componentPacket.getItems().addAll(itemMappings.getItemDefinitions().values().stream().map((item) -> new SimpleItemDefinition(item.getIdentifier(), item.getRuntimeId(), item.getVersion(), item.getComponentData() != null, item.getComponentData())).toList());
744+
componentPacket.getItems().addAll(itemMappings.getItemDefinitions().values());
747745
upstream.sendPacket(componentPacket);
748746
} else if (GeyserImpl.getInstance().getConfig().isAddNonBedrockItems()) {
749747
ItemComponentPacket componentPacket = new ItemComponentPacket();
Binary file not shown.

0 commit comments

Comments
 (0)