Unify the useable behaviour #44
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
minecraft:useablebehaviour component.minecraft:use_animationbehaviour component to a field inminecraft:useable; It's not behaviour.Note: this introduces a discrepancy with the
minecraft:start_using_itemaction, so look at ways to fix that!minecraft:useable.Examples are
minecraft:shooterandminecraft:playablefor behaviour components andminecraft:shieldfor items.minecraft:useable. An example use case is the Brush item being used on blocks instead of being used as-is.Note:
minecraft:useable_on_fluidshould be migrated elsewhere or at least renamed later for consistency, as it involves the item being used on a block once instead of using the item over a duration.Changes
Behaviour Components
minecraft:use_animation, which is now part ofminecraft:useableinstead.minecraft:useable.The
ticksfield now takes a provider instead of a hard amount and is optional too, in which case it will be used indefinitely. The field still allows a direct constant amount, just like before. Its value for a specific item stack may be overwritten with the newminecraft:use_durationdata component as well now.Examples:
Constant duration, same as the previous method.
{ "minecraft:useable": { "ticks": 10 } }Indefinite duration.
{ "minecraft:useable": {} }Constant duration as a provider. See the Integer Providers section below for more information.
{ "minecraft:useable": { "ticks": { "type": "minecraft:constant", "amount": 10 } } }Moved the value from
minecraft:use_animationto this component in the optionalanimationfield. If not specified, will usenone. Its value for a specific item stack may be overwritten with the newminecraft:use_animationdata component as well now.So if you had this:
{ "minecraft:use_animation": "eat", "minecraft:useable": { "ticks": 32 } }You now have to use this instead:
{ "minecraft:useable": { "animation": "eat", "ticks": { "type": "minecraft:constant", "amount": 32 } } }Added an optional
passesfield, which is a list of strings that allows its user to start using the item given a certain context.normal: Allows the user to start using the item as-is.block: Allows the user to start using the item when used on a block.entity: Allows the user to start using the item when used on an entity.Its default value is
["normal"].Example:
{ "minecraft:useable": { "passes": [ "block" ], "ticks": { "type": "minecraft:constant", "amount": 200 } } }minecraft:shooter.minecraft:useable. An integer provider namedminecraft:shooterwas added that can be used in its place. See the Integer Providers section below for more information. Additionally, theammunitionandheld_ammunitionfields are now registry entry lists and thus require an additional#prefix to use a tag. They are also now modifiable on specific item stacks via theminecraft:shooter_ammunitionandminecraft:shooter_held_ammunitiondata components respectively.So if you had this:
{ "minecraft:shooter": { "ammunition": "minecraft:bow_ammunition", "held_ammunition": "minecraft:bow_ammunition", "range": 15 } }{ "minecraft:shooter": { "ammunition": "#minecraft:bow_ammunition", "held_ammunition": "#minecraft:bow_ammunition", "range": 15 } }{ "minecraft:shooter": { "ammunition": "#minecraft:bow_ammunition", "held_ammunition": "#minecraft:bow_ammunition", "range": 15 }, "minecraft:useable": { "ticks": { "type": "minecraft:shooter" } } }{ "minecraft:shooter": { "ammunition": "#minecraft:bow_ammunition", "chargeable": { "quick_charge_sounds": { "default": "minecraft:item.crossbow.loading_start", "levels": [ "minecraft:item.crossbow.quick_charge_1", "minecraft:item.crossbow.quick_charge_2", "minecraft:item.crossbow.quick_charge_3" ] } }, "held_ammunition": "#minecraft:crossbow_ammunition", "range": 8 }, "minecraft:useable": { "ticks": { "type": "minecraft:shooter" } } }minecraft:throwable.use_riptide_checkfield as this is now part of an integer provider namedminecraft:tridentinstead, which can be used in its place inminecraft:useable.draw_durationfield is specified and now requiresminecraft:useable. Thedraw_durationfield is now only used to check whether its user has been using the item for the specified duration when they stop using the item.Data Components
minecraft:use_duration.minecraft:useablebehaviour component. If this data component is removed, theminecraft:useablebehaviour will no longer work. The format is the same as the map specified in theminecraft:useablebehaviour component, with one addition, that being that it allows for a single integer as another shorthand.Examples:
Constant duration, simplest form.
{ "minecraft:use_duration": 10 }{ "minecraft:use_duration": { "ticks": 10 } }{ "minecraft:use_duration": {} }{ "minecraft:use_duration": { "ticks": { "type": "minecraft:constant", "amount": 10 } } }minecraft:use_animation.minecraft:useablebehaviour component. If this data component is removed, thenoneanimation will be used instead. Its value is the same one as the one specified previously in theminecraft:use_animationitem component.Examples:
{ "minecraft:use_animation": "eat" }{ "minecraft:use_animation": "drink" }minecraft:shooter_ammunitionandminecraft:shooter_held_ammunition.minecraft:shooterbehaviour component. If this data component is removed, theminecraft:shooterbehaviour will no longer work. Its value is an item, list of items or hash-prefixed item tag.Examples:
"#minecraft:bow_ammunition""#minecraft:crossbow_ammunition"Integer Providers
These providers are added so the use duration is not hardcoded for specific behaviour components by using different sources. The integer provider type is determined by the
typefield, and all types are visible further down. An integer provider may return an empty value, in which case the user will not start using the item.minecraft:constantUses the item for a constant duration.
Fields
amount: A positive integer. How long to use the item for.Example
{ "type": "minecraft:constant", "amount": 32 }minecraft:playableUses the
minecraft:playableitem behaviour component to get the use duration from theminecraft:instrumentdata component or from a default set of instruments as defined byminecraft:playableotherwise.Example
{ "type": "minecraft:playable" }minecraft:shooterUses the
minecraft:shooteritem behaviour component to use the item indefinitely if the user is either holding ammunition as defined by theminecraft:shooter_held_ammunitiondata component or has ammunition in their inventory as defined by theminecraft:shooter_ammunitiondata component.Example
{ "type": "minecraft:shooter" }minecraft:tridentUses the item indefinitely if the item stack has the Riptide enchantment and is either not damageable or not in a broken state and if its user is touching water or rain.
Example
{ "type": "minecraft:trident" }