-
-
Notifications
You must be signed in to change notification settings - Fork 648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move various settings from non vanilla custom item data to custom item data and allow use in JSON mappings #4655
base: master
Are you sure you want to change the base?
Conversation
…om items - updating implementation soon
…or type in vanilla custom registry
api/src/main/java/org/geysermc/geyser/api/item/custom/CustomItemData.java
Outdated
Show resolved
Hide resolved
api/src/main/java/org/geysermc/geyser/api/item/custom/CustomItemData.java
Outdated
Show resolved
Hide resolved
api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java
Outdated
Show resolved
Hide resolved
Code looks fine to me, but will delegate to someone else for API approval. |
/** | ||
* Gets the stack size of the item. | ||
* | ||
* Returns 0 if not set. When not set (or 0), takes the Java item stack count when based of a vanilla item, or uses 64 when porting a modded item. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's preventing us from inheriting the modded item's stack size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When Geyser registers the modded item mappings (in CustomItemRegistryPopulator#registerCustomItem
), it doesn't actually have access to the properties of the (modded) Java item - all it knows is the properties specified in the mapping, and it creates a Java item instance from that (can be seen here). The current behaviour of modded item mappings is to default to 64 when no stack size is specified, which I copied in this PR.
Note that Geyser does have access to vanilla Java items, which is why it's able to copy the properties of those when creating a vanilla item mapping (here).
I'm not aware of a way for Geyser to automatically fetch the properties of a modded item - if there is, I could implement it in this PR.
* | ||
* Returns -1 if not set. When not set (or below 0), takes the Java item max damage when based of a vanilla item, or uses 0 when porting a modded item. | ||
* | ||
* @return the max damage of the item |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as stack size above
* Gets the attack damage of the item. | ||
* This is purely visual, and only applied to tools | ||
* | ||
* Returns 0 if not set. When 0, takes the Java item attack damage when based of a vanilla item, or uses 0 when porting a modded item. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as stack size above
* | ||
* @return if the item is a hat | ||
*/ | ||
boolean isHat(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced that this (and all other moved api that isn't controlled by a component) should be moved here. lMO it makes more sense to inherit this from the base Java item, as is done in vanilla
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I was a bit conflicted on some of the moves.
The only properties that don't relate to a Java component at all are, I think, toolType
, toolTier
, armorType
and isHat
.
As for toolType
and toolTier
, there is a minecraft:tool
component on Java, but I'm not sure what the functions of the toolType
and toolTier
properties are, and if/how they relate to the Java minecraft:tool
component.
Same goes for the armorType
property, though there isn't an armor component on Java - rather, armor attribute modifiers are in the minecraft:attribute_modifiers
component.
As for isHat
, I moved this because I think it can be useful for custom helmets making use of vanilla items with custom models. On the Java helmet slot, all vanilla items are always rendered, even with custom models, which allows for custom helmet models, while on Bedrock this requires the isHat
property.
Additionally, mods like Polymer allow adding custom helmet items (appearing as vanilla items to the client) that can be equipped in the helmet slot on a vanilla Java client, so I thought it would be useful to copy this to allow for the same behaviour on a Bedrock client.
This PR moves various settings from the
NonVanillaCustomItemData
to theCustomItemData
class, which is useful for datapack/server side mod developers when porting custom items to Bedrock using Geyser's mapping system.Properties that have been moved to the super-interface:
stackSize
maxDamage
attackDamage
toolType
toolTier
armorType
protectionValue
isHat
isFoil
isEdible
canAlwaysEat
- deprecated, won't be movedisTool
The builders for these classes have been correctly updated, alongside the implementations of these classes and their use in
CustomItemRegistryPopulator
.A few notes:
NonVanillaCustomItemData.Builder
class has been given overrides for the moved properties to allow for full backwards compatibility.isTool
boolean field in the implementation ofNonVanillaCustomItemData
(GeyserNonVanillaCustomItemData
) has been removed and not re-implemented in its super class - it has been replaced withdisplayHandheld
and wasn't used anywhere in the implementation anymore. It was not publicly available.TheisTool
method has been moved to the super-interface and redirects to thedisplayHandheld
method (it is marked deprecated, like before).GeyserCustomItemData
has been simplified to simply take its builder as argument.createComponentNbt
method forCustomItemData
has been updated to continue supportingGeyserMappingItem
as well.MappingsReader_v1
has been updated accordingly.edible
property has been updated to include theminecraft:use_modifiers
Bedrock component alongside theminecraft:food
component, which seems to now be required to make edible items behave correctly.A couple of the new JSON mapping properties have been tested (
stack_size
,max_damage
,hat
andedible
), and backwards compatibility of using builder methods inNonVanillaCustomItemData.Builder
in extensions has been tested as well, which all seem to work okay.Feel free to suggest any changes and I'll be sure to implement them!