Conversation
- Added support for the `item_model`, `max_durability`, `food`, `max_stack_size`, and `rarity` item components. - Additionally made sure that the paper `ItemTag.rarity` didn't conflict with the new >1.20 rarity component mech.
| } | ||
|
|
||
| @Override | ||
| public void setPropertyValue(MapTag element, Mechanism mechanism) { |
There was a problem hiding this comment.
MapTag should probably use "map" instead of "element"
| } | ||
|
|
||
| public static void register() { | ||
| autoRegisterNullable("max_stack_size", ItemMaxDurability.class, ElementTag.class, false); |
| @Override | ||
| public ElementTag getPropertyValue() { | ||
| if (getItemMeta() instanceof Damageable damageable | ||
| && damageable.hasMaxDamage()) { |
| // @name max_durability | ||
| // @input ElementTag | ||
| // @description | ||
| // Controls the maximum durability of an item. |
There was a problem hiding this comment.
The meta for things should generally have more information than this. Give examples. Give limits. Give edge cases (the tag can be null - when/why?)
| public void setPropertyValue(ElementTag element, Mechanism mechanism) { | ||
| editMeta(ItemMeta.class, meta -> { | ||
| if (meta instanceof Damageable damageable) { | ||
| damageable.setMaxDamage(element.asInt()); |
There was a problem hiding this comment.
if there's a hasMaxDamage, that implies there's a way to unset the value - how do you do that with the mech?
There was a problem hiding this comment.
also before doing type conversion (asInt) you should ideally have a check/error handle
| return new ElementTag(item.getItemStack().getRarity()); | ||
| }); | ||
| if (NMSHandler.getVersion().isAtMost(NMSVersion.v1_19)) { | ||
| // <--[tag] |
There was a problem hiding this comment.
meta is double-registered, should just be excluded from a legacy copy
| public void setPropertyValue(MapTag map, Mechanism mechanism) { | ||
| FoodComponent food = getItemMeta().getFood(); | ||
| editMeta(ItemMeta.class, meta -> { | ||
| if (map.getElement("nutrition") != null) { |
There was a problem hiding this comment.
The property is registered with autoRegisterNullable, which means map can be null here (and should be handled by removing the food component)
| public void setPropertyValue(ElementTag element, Mechanism mechanism) { | ||
| editMeta(ItemMeta.class, meta -> { |
| public void setPropertyValue(MapTag map, Mechanism mechanism) { | ||
| FoodComponent food = getItemMeta().getFood(); | ||
| editMeta(ItemMeta.class, meta -> { | ||
| if (map.getElement("nutrition") != null) { |
There was a problem hiding this comment.
should probably be Map#containsKey
There was a problem hiding this comment.
Or alternatively
Object value = map.get(key);
if (value != null) {
thing.set(value)
}|
|
||
| @Override | ||
| public void setPropertyValue(MapTag map, Mechanism mechanism) { | ||
| FoodComponent food = getItemMeta().getFood(); |
There was a problem hiding this comment.
this probably could be moved in the lamba and called from the lambda parameter (meta.getFood())
| public void setPropertyValue(MapTag map, Mechanism mechanism) { | ||
| FoodComponent food = getItemMeta().getFood(); | ||
| editMeta(ItemMeta.class, meta -> { | ||
| if (map.getElement("nutrition") != null) { |
There was a problem hiding this comment.
Or alternatively
Object value = map.get(key);
if (value != null) {
thing.set(value)
}| // @input ElementTag | ||
| // @description | ||
| // Controls the maximum durability of an item, if it can have durability. | ||
| // If the item cannot have durability (e.g. is not a tool or armor), this will return null. |
There was a problem hiding this comment.
I don't think this is necessarily the case? with item components you should be able to give any item durability (also true for other properties here, the point of item components is that you can kinda give any item any component).
There was a problem hiding this comment.
Items can't be stackable and be damageable unfortunately.
| if (attribute.startsWith("max_durability")) { | ||
| return new ElementTag(item.getMaterial().getMaterial().getMaxDurability()) | ||
| .getObjectAttribute(attribute.fulfill(1)); | ||
| } |
There was a problem hiding this comment.
Is this properly backsupported? from what I can see it's completely removed from here and the new property is 1.20+
| // If the item does not have a max durability item component set, this will return the default max durability for the item type. | ||
| // --> |
There was a problem hiding this comment.
This is specific to the tag, and should be under @tag
Added properties for the
item_model,max_durability,food,max_stack_size, andrarityitem components.Additionally made sure that the paper
ItemTag.raritydidn't conflict with the new >1.20 rarity component mech.