Crossbow
Makes items behave like crossbows, with customizable logic.
Example item model definition:
modelDefinition {
model = select(SelectItemModelProperty.ChargedType) {
case[ChargedType.ARROW] = buildModel { getModel("minecraft:item/crossbow_arrow") }
case[ChargedType.ROCKET] = buildModel { getModel("minecraft:item/crossbow_firework") }
fallback = condition(ConditionItemModelProperty.UsingItem) {
onTrue = rangeDispatch(RangeDispatchItemModelProperty.CrossbowPull) {
fallback = buildModel { getModel("minecraft:item/crossbow_pulling_0") }
entry[0.58] = buildModel { getModel("minecraft:item/crossbow_pulling_1") }
entry[1.0] = buildModel { getModel("minecraft:item/crossbow_pulling_2") }
}
onFalse = buildModel { getModel("minecraft:item/crossbow") }
}
}
}
In item model definitions, ChargedType can only differentiate between rockets and arrows, where ChargedType.ARROW is used for any non-rocket projectile. However, ChargedProjectiles allows loading any item type into the crossbow. To address this inconsistency, this behavior writes the item ids of all charged projectiles into the item's client-side custom model data, starting at index customModelDataOffset.
Example item model definition using custom model data (with no offset):
modelDefinition {
model = select(SelectItemModelProperty.CustomModelData) {
case["minecraft:arrow"] = buildModel { getModel("minecraft:item/crossbow_arrow") }
// ... all other arrow types
case["minecraft:firework_rocket"] = buildModel { getModel("minecraft:item/crossbow_firework") }
fallback = condition(ConditionItemModelProperty.UsingItem) {
onTrue = rangeDispatch(RangeDispatchItemModelProperty.CrossbowPull) {
fallback = buildModel { getModel("minecraft:item/crossbow_pulling_0") }
entry[0.58] = buildModel { getModel("minecraft:item/crossbow_pulling_1") }
entry[1.0] = buildModel { getModel("minecraft:item/crossbow_pulling_2") }
}
onFalse = buildModel { getModel("minecraft:item/crossbow") }
}
}
}
Properties
The base data components that every item with this ItemBehavior has.
The NamespacedCompound that every new ItemStack of an item with this ItemBehavior has by default.
The vanilla material properties that an item with this ItemBehavior requires.
Functions
Called when a BlockBreakActionEvent is fired where player breaks a block with an itemStack with this behavior.
Called when a aPlayerItemBreakEvent is fired where an itemStack with this behavior runs out of durability and breaks.
Called when a PlayerItemDamageEvent is fired where an itemStack with this behavior takes damage.
Called when a PlayerInteractAtEntityEvent is fired for an itemStack with this behavior.
Called when a PlayerInteractEvent is fired for an itemStack with this behavior.
Called when entity stops using an itemStack with this behavior in hand, with remainingUseTicks left.
Called every tick while an itemStack with this behavior is being used by entity in hand, with remainingUseTicks left.
Updates the client-side item type for client-side item stacks to be viewed by player in place of the server-side item stack. This is called before modifyClientSideStack and influences the generation of the client-side ItemStack's patch. Called off-main thread.
Updates the client-side item stack that is to be viewed by player in place of the server-side item stack. Called off-main thread.
Modifies the server-side use duration of itemStack with this behavior for entity. The initial value of duration may stem from baseDataComponents. If the use duration is <= 0, the item cannot be used (no right click and hold action).
Creates a string representation of this ItemBehavior and its data in itemStack.