Skip to content
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

Add ability to set molang tags for custom items #4041

Merged
merged 20 commits into from
Nov 9, 2023

Conversation

onebeastchris
Copy link
Member

@onebeastchris onebeastchris commented Aug 7, 2023

These changes should allow for two things:

  • Geyser would add a tag to all custom items, currently called "geyser_custom", that way, a molang query checking minecraft:is_geyser_custom now: geyser:is_custom would find all custom items.
  • Ability to assign custom tags (thereby allowing tag group creating) via a "tags" entry. For this purpose, i added a nonnull set of strings to CustomItemData, which can be set either using an extension, or a mappings json. For the latter, the following format would specify additional tags to add:
"tags" : ["test:is_tag_one", "test:is_tag_two"]

(example query: query.equipped_item_any_tag('test:is_tag_one')) - any tag, including minecraft tags can be set. A namespace isn't necessary, but should exist for good measure.
Fixes #3988

@Camotoy
Copy link
Member

Camotoy commented Aug 7, 2023

Can we make our custom tag geysermc:is_custom?

@Kas-tle
Copy link
Member

Kas-tle commented Aug 7, 2023

Imo it should use the same namespace we give to items/blocks which is geyser_custom:

@onebeastchris
Copy link
Member Author

Not against changing the namespace (both for the custom tags, or the tag for all custom items), but imo it would be odd to name it geyser_custom:is_custom. Idk, not up to me

@onebeastchris
Copy link
Member Author

For now, i went with Kastle's suggestion and set the namespace to "geyser_custom". Personally, i would prefer "geysermc" or maybe just "geyser"; but i see how consistency would be nice.
With the latest commit, a tag would e.g. be geyser_custom:is_tag_one (only "tag_one" would be specified in the mappings). Could also drop the "is_" (although seeing how Minecraft does it, that again would be inconsistent).

Copy link
Member

@Konicai Konicai left a comment

Choose a reason for hiding this comment

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

lgtm after this :)

@Konicai Konicai added the PR: Needs Testing When a PR needs testing but is currently not under review label Aug 7, 2023
@ofunny
Copy link
Contributor

ofunny commented Aug 23, 2023

I have tested the default tag is_custom and also the assignment via the mapping file, both seem to work fine using e.g.
query.equipped_item_any_tag('slot.weapon.mainhand', 'geyser_custom:is_custom')

While doing the tests I noticed that my player controller is not handling all conditions with filled maps, bows and shields correctly, this is unrelated to the tag implementation (already existed while using is_name_any), but I soon will update my controller using tags. If that works well, this should be ready for merge.

@ofunny
Copy link
Contributor

ofunny commented Aug 24, 2023

Works well for me, I implemented tags now in my test pack, here is an example for all custom shields within the "pre_animation" section.

                "pre_animation": [
                    "variable.is_blocking_main_hand = query.blocking && !query.is_item_name_any('slot.weapon.offhand', 'minecraft:shield') && !query.equipped_item_any_tag('slot.weapon.offhand', 'geyser_custom:is_shield') && (query.is_item_name_any('slot.weapon.mainhand', 'minecraft:shield') || query.equipped_item_any_tag('slot.weapon.mainhand', 'geyser_custom:is_shield'));",
                    "variable.is_blocking_off_hand = query.blocking && (query.is_item_name_any('slot.weapon.offhand', 'minecraft:shield') || query.equipped_item_any_tag('slot.weapon.offhand', 'geyser_custom:is_shield'));",
                    "variable.is_using_bow = (query.is_item_name_any('slot.weapon.mainhand', 'minecraft:bow') || query.equipped_item_any_tag('slot.weapon.mainhand', 'geyser_custom:is_bow')) && (query.main_hand_item_use_duration > 0.0f);"
                ],

Had no issues so far related to this implementation.

# Conflicts:
#	core/src/main/java/org/geysermc/geyser/item/mappings/versions/MappingsReader_v1.java
#	core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java
@onebeastchris onebeastchris removed the PR: Needs Testing When a PR needs testing but is currently not under review label Aug 24, 2023
@onebeastchris
Copy link
Member Author

Updated to latest master changes:

  • Deleted ToolBreakSpeedsUtils, not used anymore
  • updated tags reading to how it's done with custom block tags here

Worth noting: minecraft:is_pickaxe, minecraft:is_axe, minecraft:is_shovel, and minecraft:is_hoe are no longer set; this however shouldn't be major since you can now set your own tags however needed

@onebeastchris onebeastchris requested a review from Konicai August 24, 2023 14:02
@onebeastchris onebeastchris added the PR: Feature When a PR implements a new feature label Aug 24, 2023
@Camotoy
Copy link
Member

Camotoy commented Aug 25, 2023

geyser_custom:is_custom just sounds weird... I'm fine with geyser:is_custom (or the geysermc namespace) because it's a tag we define, and not one a user creates.

@onebeastchris
Copy link
Member Author

https://github.com/GeyserMC/Geyser/blob/master/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java#L500-L509
Considering block tags can be set now, I'd use the same namespace that's set for the tags there - although I agree that geyser_custom:is_custom just sounds weird.
Inconsistency would be worse though

@Kas-tle
Copy link
Member

Kas-tle commented Aug 25, 2023

Actually blocks just let you set whatever you want so I'm fine with that. For tags the namespace isn't even required it's only convention.

@onebeastchris
Copy link
Member Author

Addressed; now the namespace for tags is just "geyser" instead of "geyser_custom".

@Kas-tle
Copy link
Member

Kas-tle commented Aug 26, 2023

But why are we forcing any namespace? We can just use whatever they give us like for blocks?

@onebeastchris
Copy link
Member Author

Sure, that should work
Only reason I had a namespace is because the Mojang item tags that can be used for queries are similar to "minecraft:is_pickaxe", I assumed we wanted to follow that.
Would you suggest dropping the namespace fully?
Imo "geyser:is_custom" sounds better than just "is_custom"

@Kas-tle
Copy link
Member

Kas-tle commented Aug 26, 2023

Oh sorry I thought you meant forcing user tags to have a namespace. Whatever you want to do for the global custom item tag is fine.

@onebeastchris

This comment was marked as outdated.

@onebeastchris
Copy link
Member Author

onebeastchris commented Aug 26, 2023

After internal discussion + Kastle's comment; changed it so no namespace is set at all. Can be defined manually though, which together with the changes made in the recipes PR (usage of itemTags wherever feasible/useful in recipes) might come in handy to set a minecraft namespaced tag; atleast in theory.
I will then leave geyser:is_custom namespaced, since a tag added by us would then be unlikely to conflict with other custom tags set.

@onebeastchris onebeastchris requested a review from Konicai October 2, 2023 11:56
@onebeastchris onebeastchris dismissed Konicai’s stale review October 9, 2023 16:18

Addressed; please re-review :)

@onebeastchris onebeastchris added the PR: Needs review Indicates that a PR is functional and review-ready. label Oct 17, 2023
@Kas-tle
Copy link
Member

Kas-tle commented Nov 4, 2023

Also should update the wiki^

@onebeastchris onebeastchris merged commit f40ca20 into GeyserMC:master Nov 9, 2023
@onebeastchris onebeastchris deleted the tags branch November 9, 2023 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Feature When a PR implements a new feature PR: Needs review Indicates that a PR is functional and review-ready.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding the possibility to auto and manually add custom tags to the mappings to group items
6 participants