Skip to content

Commit

Permalink
✨ Validate type of item model select cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsjo committed Jan 19, 2025
1 parent eb3e718 commit 0f20eb9
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions java/assets/item_definition.mcdoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ::java::assets::model::ModelRef
use ::java::assets::model::ItemTransformType
use ::java::server::util::color::RGB
use ::java::server::util::color::ColorString
use ::java::server::util::direction::Direction
Expand Down Expand Up @@ -64,14 +65,16 @@ dispatch minecraft:item_model[range_dispatch] to struct RangeDispatch {
dispatch minecraft:item_model[select] to struct Select {
property: #[id] SelectPropertyType,
...minecraft:select_item_property[[property]],
cases: [struct SelectCase {
when: (string | [string]),
model: ItemModel
}],
cases: [SelectCase<minecraft:select_item_type[[%parent.property]]<minecraft:data_component[[%parent.component]]>>],
/// Item model to render if none of the cases matched the value.
fallback?: ItemModel,
}

type SelectCase<T> = struct {
when: (T | [T]),
model: ItemModel
}

dispatch minecraft:item_model[special] to struct Special {
/// Renders a special hardcoded model.
model: struct SpecialModel {
Expand Down Expand Up @@ -285,7 +288,7 @@ dispatch minecraft:select_item_property[block_state] to struct BlockState {

dispatch minecraft:select_item_property[component] to struct Component {
/// The component type to check the values of.
component: #[id="data_component"] string,
component: #[id="data_component_type"] string,
}

dispatch minecraft:select_item_property[custom_model_data] to struct CustomModelDataStrings {
Expand All @@ -305,6 +308,26 @@ dispatch minecraft:select_item_property[local_time] to struct LocalTime {
time_zone?: string,
}

dispatch minecraft:select_item_type[%unknown] to string

dispatch minecraft:select_item_type[charge_type] to enum(string) CrossbowChargeType {
NONE = "none",
ARROW = "arrow",
ROCKET = "rocket"
}

dispatch minecraft:select_item_type[component]<Comp> to Comp

dispatch minecraft:select_item_type[context_dimension] to #[id="dimension"] string

dispatch minecraft:select_item_type[context_entity_type] to #[id="entity_type"] string

dispatch minecraft:select_item_type[display_context] to ItemTransformType

dispatch minecraft:select_item_type[main_hand] to ("left" | "right")

dispatch minecraft:select_item_type[trim_material] to #[id="trim_material"] string


enum(string) SpecialModelType {
Banner = "banner",
Expand Down

0 comments on commit 0f20eb9

Please sign in to comment.