Skip to content

Conversation

@Golfing7
Copy link
Contributor

The new 'minecraft:item_model' component allows you to change the model of an item. This PR adds support for items with this component.

Copy link
Member

@d0by1 d0by1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I'd like to see the following changes implemented before I merge.

Can you also describe how you tested this, and what Minecraft versions you tested it on, please?

return itemModel;
}

public static float extractCustomModelData(ItemStack itemStack) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is unused, so remove it.

return new ItemNbtData(extractItemModel(nbt), extractCustomModelData(nbt));
}

public static String extractItemModel(ItemStack itemStack) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is unused, remove it.

@@ -1,12 +1,16 @@
package eu.decentsoftware.holograms.hook;

import com.google.gson.Gson;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import

return extractCustomModelData(NBT.itemStackToNBT(itemStack));
}

public static float extractCustomModelData(ReadWriteNBT nbtItem) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can be private

return extractItemModel(NBT.itemStackToNBT(itemStack));
}

public static String extractItemModel(ReadWriteNBT nbtItem) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can be private

modifiableNBT.mergeCompound(originalNBT);

// Load the nbt data
ItemNbtData nbtData = ItemNbtData.fromJson(nbt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At line 50, the value of nbt is used to parse NBT and merge the resulting compound with modifiableNBT. Considering the value of nbt can be a JSON instead of actual NBT, won't that just fail or go wrong?

I also don't like how one variable nbt is used for two different things. It can either be NBT or your JSON with some data that will be added to NBT. Can you somehow separate these?

When you separate them, you may not even need the JSON at all. You could just use the ItemNbtData object in both HologramItem and here, which is much nicer in my opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You bring up a good point. This is something I got stuck on as I was trying to think of a good way to integrate this into the current data fixer solution you use for custom model data.

Here's what I found: When the minecraft:item_model component is passed through the datafixer, it gets mapped under the minecraft:custom_data component instead of being left alone. This breaks the display of the item since the minecraft:item_model component needs to be at the root level similar to CustomModelData. Since this component did not exist in 1.20.4, the data fixer treats it as custom data. That's why I parse the NBT data back into JSon and manually add the component after running the data fixer.

I can make a modification to see how this would work without the data fixer.

@Golfing7
Copy link
Contributor Author

Golfing7 commented Aug 7, 2025

I've made the changes to the pull request. Could you review them and let me know any feedback?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants