Skip to content

Commit

Permalink
Throw when we cannot find Bedrock item components for vanilla compone…
Browse files Browse the repository at this point in the history
…nt based items; load default Bedrock item_components :(
  • Loading branch information
onebeastchris committed Feb 11, 2025
1 parent 71546b4 commit 9056292
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ public static void populate() {
}

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

// Used for custom items
int nextFreeBedrockId = 0;
// TODO rename or yeet
// TODO yeet
List<ItemDefinition> componentItemData = new ObjectArrayList<>();

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

NbtMap components = null;
if (entry.isComponentBased()) {
// TODO test
components = vanillaComponents.getCompound(entry.getName());
if (components == null) {
throw new RuntimeException("Could not find vanilla components for vanilla component based item! " + entry.getName());
}
}

ItemDefinition definition = new SimpleItemDefinition(entry.getName().intern(), id, entry.getVersion(), entry.isComponentBased(), components);
Expand Down Expand Up @@ -449,8 +452,7 @@ public static void populate() {
int customProtocolId = nextFreeBedrockId++;
mappingItem = mappingItem.withBedrockData(customProtocolId);
bedrockIdentifier = customBlockData.identifier();
// TODO add component nbt here
definition = new SimpleItemDefinition(bedrockIdentifier, customProtocolId, true);
definition = new SimpleItemDefinition(bedrockIdentifier, customProtocolId, 2, false, null);
registry.put(customProtocolId, definition);
customBlockItemDefinitions.put(customBlockData, definition);
customIdMappings.put(customProtocolId, bedrockIdentifier);
Expand Down Expand Up @@ -528,7 +530,7 @@ public static void populate() {
}

// ComponentItemData - used to register some custom properties
componentItemData.add(customMapping.itemDefinition()); // TODO
componentItemData.add(customMapping.itemDefinition());
customItemOptions.add(Pair.of(customItem.customItemOptions(), customMapping.itemDefinition()));
registry.put(customMapping.integerId(), customMapping.itemDefinition());

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

// TODO yeet?
componentItemData.add(registration.mapping().getBedrockDefinition());
ItemMapping mapping = registration.mapping();
Item javaItem = registration.javaItem();
Expand Down Expand Up @@ -663,7 +664,6 @@ public static void populate() {
int customProtocolId = nextFreeBedrockId++;
String identifier = customBlock.identifier();

// TODO
final ItemDefinition definition = new SimpleItemDefinition(identifier, customProtocolId, 2, false, null);
registry.put(customProtocolId, definition);
customBlockItemDefinitions.put(customBlock, definition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
import org.cloudburstmc.protocol.bedrock.data.command.CommandPermission;
import org.cloudburstmc.protocol.bedrock.data.command.SoftEnumUpdateType;
import org.cloudburstmc.protocol.bedrock.data.definitions.DimensionDefinition;
import org.cloudburstmc.protocol.bedrock.data.definitions.SimpleItemDefinition;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.CraftingRecipeData;
Expand Down Expand Up @@ -740,10 +739,9 @@ public void connect() {
sentSpawnPacket = true;
syncEntityProperties();

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

0 comments on commit 9056292

Please sign in to comment.