Skip to content

Commit a1c5a26

Browse files
committed
Add glider and remainder to item meta
1 parent 3bd7282 commit a1c5a26

File tree

4 files changed

+196
-64
lines changed

4 files changed

+196
-64
lines changed

src/main/java/com/laytonsmith/abstraction/MCItemMeta.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ public interface MCItemMeta extends AbstractionObject {
186186

187187
void setJukeboxPlayable(String playable);
188188

189+
boolean isGlider();
190+
191+
void setGlider(boolean glider);
192+
193+
boolean hasUseRemainder();
194+
195+
MCItemStack getUseRemainder();
196+
197+
void setUseRemainder(MCItemStack remainder);
198+
189199
boolean hasFood();
190200

191201
MCFoodComponent getFood();

src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCItemMeta.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.laytonsmith.abstraction.MCAttributeModifier;
99
import com.laytonsmith.abstraction.MCFoodComponent;
1010
import com.laytonsmith.abstraction.MCItemMeta;
11+
import com.laytonsmith.abstraction.MCItemStack;
1112
import com.laytonsmith.abstraction.MCTagContainer;
1213
import com.laytonsmith.abstraction.blocks.MCBlockData;
1314
import com.laytonsmith.abstraction.blocks.MCMaterial;
@@ -42,6 +43,7 @@
4243
import org.bukkit.enchantments.Enchantment;
4344
import org.bukkit.inventory.ItemFlag;
4445
import org.bukkit.inventory.ItemRarity;
46+
import org.bukkit.inventory.ItemStack;
4547
import org.bukkit.inventory.meta.BlockDataMeta;
4648
import org.bukkit.inventory.meta.Damageable;
4749
import org.bukkit.inventory.meta.ItemMeta;
@@ -401,6 +403,31 @@ public void setJukeboxPlayable(String playable) {
401403
}
402404
}
403405

406+
@Override
407+
public boolean isGlider() {
408+
return im.isGlider();
409+
}
410+
411+
@Override
412+
public void setGlider(boolean glider) {
413+
im.setGlider(glider);
414+
}
415+
416+
@Override
417+
public boolean hasUseRemainder() {
418+
return im.hasUseRemainder();
419+
}
420+
421+
@Override
422+
public MCItemStack getUseRemainder() {
423+
return new BukkitMCItemStack(im.getUseRemainder());
424+
}
425+
426+
@Override
427+
public void setUseRemainder(MCItemStack remainder) {
428+
im.setUseRemainder((ItemStack) remainder.getHandle());
429+
}
430+
404431
@Override
405432
public boolean hasFood() {
406433
return im.hasFood();

src/main/java/com/laytonsmith/core/ObjectGenerator.java

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,14 @@ public Construct itemMeta(MCItemStack is, Target t) {
524524
ma.set("blockdata", CNull.NULL, t);
525525
}
526526
}
527+
if(meta.hasFood()) {
528+
MCFoodComponent foodComponent = meta.getFood();
529+
CArray food = CArray.GetAssociativeArray(t);
530+
food.set("nutrition", new CInt(foodComponent.getNutrition(), t), t);
531+
food.set("saturation", new CDouble(foodComponent.getSaturation(), t), t);
532+
food.set("always", CBoolean.get(foodComponent.getCanAlwaysEat()), t);
533+
ma.set("food", food, t);
534+
}
527535

528536
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21)) {
529537
if(meta.hasJukeboxPlayable()) {
@@ -535,13 +543,11 @@ public Construct itemMeta(MCItemStack is, Target t) {
535543
if(meta.hasEnchantable()) {
536544
ma.set("enchantability", new CInt(meta.getEnchantable(), t), t);
537545
}
538-
if(meta.hasFood()) {
539-
MCFoodComponent foodComponent = meta.getFood();
540-
CArray food = CArray.GetAssociativeArray(t);
541-
food.set("nutrition", new CInt(foodComponent.getNutrition(), t), t);
542-
food.set("saturation", new CDouble(foodComponent.getSaturation(), t), t);
543-
food.set("always", CBoolean.get(foodComponent.getCanAlwaysEat()), t);
544-
ma.set("food", food, t);
546+
if(meta.isGlider()) {
547+
ma.set("glider", CBoolean.TRUE, t);
548+
}
549+
if(meta.hasUseRemainder()) {
550+
ma.set("remainder", item(meta.getUseRemainder(), t), t);
545551
}
546552
}
547553

@@ -1059,26 +1065,6 @@ public MCItemMeta itemMeta(Mixed c, MCMaterial mat, Target t) throws ConfigRunti
10591065
}
10601066
}
10611067
}
1062-
}
1063-
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21)) {
1064-
if(ma.containsKey("jukeboxsong")) {
1065-
Mixed playable = ma.get("jukeboxsong", t);
1066-
if(playable instanceof CNull) {
1067-
// not yet supported
1068-
} else {
1069-
meta.setJukeboxPlayable(playable.val());
1070-
}
1071-
}
1072-
}
1073-
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21_3)) {
1074-
if(ma.containsKey("enchantability")) {
1075-
Mixed enchantability = ma.get("enchantability", t);
1076-
if(enchantability instanceof CNull) {
1077-
// not yet supported
1078-
} else {
1079-
meta.setEnchantable(ArgumentValidation.getInt32(enchantability, t));
1080-
}
1081-
}
10821068
if(ma.containsKey("food")) {
10831069
Mixed mixedFood = ma.get("food", t);
10841070
if(mixedFood instanceof CNull) {
@@ -1104,6 +1090,42 @@ public MCItemMeta itemMeta(Mixed c, MCMaterial mat, Target t) throws ConfigRunti
11041090
}
11051091
}
11061092
}
1093+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21)) {
1094+
if(ma.containsKey("jukeboxsong")) {
1095+
Mixed playable = ma.get("jukeboxsong", t);
1096+
if(playable instanceof CNull) {
1097+
// not yet supported
1098+
} else {
1099+
meta.setJukeboxPlayable(playable.val());
1100+
}
1101+
}
1102+
}
1103+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21_3)) {
1104+
if(ma.containsKey("enchantability")) {
1105+
Mixed enchantability = ma.get("enchantability", t);
1106+
if(enchantability instanceof CNull) {
1107+
// not yet supported
1108+
} else {
1109+
meta.setEnchantable(ArgumentValidation.getInt32(enchantability, t));
1110+
}
1111+
}
1112+
if(ma.containsKey("glider")) {
1113+
Mixed glider = ma.get("glider", t);
1114+
if(glider instanceof CNull) {
1115+
meta.setGlider(false);
1116+
} else {
1117+
meta.setGlider(ArgumentValidation.getBooleanObject(glider, t));
1118+
}
1119+
}
1120+
if(ma.containsKey("remainder")) {
1121+
Mixed remainder = ma.get("remainder", t);
1122+
if(remainder instanceof CNull) {
1123+
// not yet supported
1124+
} else {
1125+
meta.setUseRemainder(item(remainder, t));
1126+
}
1127+
}
1128+
}
11071129
if(ma.containsKey("damage")) {
11081130
Mixed damage = ma.get("damage", t);
11091131
if(damage instanceof CNull) {

src/main/resources/functionDocs/get_itemmeta

Lines changed: 110 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,112 @@
1-
array {[player,] slot} Returns an associative array of known item meta for the slot given, or null if there isn't any. ----
1+
array {[player,] slot} Returns an associative array of known item data in the slot given, or null if there isn't any.
2+
3+
----
24

35
These fields exist for all items with meta.
4-
* '''display''' : (string) The display name seen when renamed in an anvil (or null).
5-
* '''lore''' : (array) A list of strings that is displayed when hovering the item (or null). As lines are plain text, they do not yet support some advanced text components, but color codes are supported.
6-
* '''model''' : (int) Represents vanilla's CustomModelData tag for use with resource packs (or null). Is converted to a float for the custom_model_data component in 1.21.4+.
7-
* '''flags''' : (array) Flags used to hide meta in the item tooltip: %ITEM_FLAGS%.
8-
* '''repair''' : (int) The additional cost to repair or combine this item in an anvil.
9-
* '''enchants''' : (associative array) The enchantments on this item.
10-
** '''<enchantment_name>''' : (associative array) Name of enchantment as the key (e.g. "fire_aspect") An integer for the level can be used as the value instead of an array.
11-
*** '''elevel''' : (int) The level of the enchantment.
12-
* '''modifiers''' : (array) A list of attribute modifier arrays (or null).
13-
** (associative array)
14-
*** '''attribute''' : (string) One of %ATTRIBUTES%.
15-
*** '''operation''' : (string) One of %OPERATIONS%.
16-
*** '''amount''' : (double) The value used in the modifier operation.
17-
*** '''id''' : (string) An item can only have one modifier with the same id.
18-
*** '''slot''' : (string) Possible slots are %SLOTS% or one of the slot groups %SLOTGROUPS%.
19-
* '''tags''' : (associative array) Custom tags used by plugins (or null).
20-
** '''<custom_key>''' : (associative array) Each tag's key is namespaced (e.g. "commandhelper:mytag"). If not provided, "commandhelper" will be used as a namespace.
21-
*** '''type''' : (string) Possible types: %TAG_TYPES%.
22-
*** '''value''' : (mixed) A valid value for the given tag type.
6+
{| width="100%" cellspacing="1" cellpadding="1" border="1" class="wikitable"
7+
|-
8+
! scope="col" width="15%" | Field
9+
! scope="col" width="15%" | Type
10+
! scope="col" width="70%" | Description
11+
|-
12+
! display
13+
| string
14+
| The display name seen when renamed in an anvil (or null).
15+
|-
16+
! lore
17+
| array
18+
| A list of strings that is displayed when hovering the item (or null). As lines are plain text, they do not yet support some advanced text components, but color codes are supported.
19+
|-
20+
! model
21+
| int
22+
| Represents vanilla's CustomModelData tag for use with resource packs (or null). In 1.21.4+, this represents the first float in custom_model_data rounded down.
23+
|-
24+
! flags
25+
| array
26+
| Flags used to hide meta in the item tooltip: %ITEM_FLAGS%.
27+
|-
28+
! repair
29+
| int
30+
| The additional cost to repair or combine this item in an anvil.
31+
|-
32+
! enchants
33+
| associative array
34+
| The enchantments on this item.
35+
* '''<enchantment_name>''' : (associative array) The name of the enchantment as the key (e.g. "fire_aspect") An integer for the level can be used as the value instead of an array.
36+
** '''elevel''' : (int) The level of the enchantment.
37+
|-
38+
! modifiers
39+
| array
40+
| A list of attribute modifier arrays (or null).
41+
* (associative array)
42+
** '''attribute''' : (string) One of %ATTRIBUTES%.
43+
** '''operation''' : (string) One of %OPERATIONS%.
44+
** '''amount''' : (double) The value used in the modifier operation.
45+
** '''id''' : (string) An item can only have one modifier with the same id.
46+
** '''slot''' : (string) Possible slots are %SLOTS% or one of the slot groups %SLOTGROUPS%.
47+
|-
48+
! tags
49+
| associative array
50+
| Custom tags used by plugins (or null).
51+
* '''<custom_key>''' : (associative array) Each tag's key is namespaced (e.g. "commandhelper:mytag"). If not provided, "commandhelper" will be used as a namespace.
52+
** '''type''' : (string) Possible types: %TAG_TYPES%.
53+
** '''value''' : (mixed) A valid value for the given tag type.
54+
|}
2355

2456
These fields optionally exist for any item type.
25-
* '''damage''' : (int) The amount of damage on the durability of the item. 0 is undamaged. The max value is determined by the item type's default durability or "maxdamage" if set.
26-
* '''unbreakable''' : (boolean) If the item cannot be damaged when used. Also hides item durability bar. Field always exists if "damage" exists.
27-
* '''maxstacksize''' : (int) Overrides the maximum quantity of items with identical meta that will stack. Must be from 1 to 99. (MC 1.20.6+)
28-
* '''maxdamage''' : (int) Overrides an item's max durability. Value must be positive. (MC 1.20.6+)
29-
* '''glint''' : (boolean) Overrides an item's enchantment glint state. (MC 1.20.6+)
30-
* '''rarity''' : (string) Overrides an item's rarity, which affects the item name color. Can be COMMON (white), UNCOMMON (yellow), RARE (aqua), or EPIC (light purple). (MC 1.20.6+)
31-
* '''jukeboxsong''' : (string) Overrides an item's playable jukebox song. (MC 1.21+)
32-
* '''enchantability''' : (int) Overrides an item's enchantability in an enchanting table. Value must be positive. Higher values allow applicable enchantments with higher costs to be picked. (MC 1.21.3+)
33-
* '''food''' : (associative array) Overrides a consumable item's food stats. (MC 1.21.3+)
34-
** '''nutrition''' : (int) Food restored on the hunger bar when consumed. (default: 0)
35-
** '''saturation''' : (double) The amount of saturation that is increased when consumed. (default: 0.0)
36-
** '''always''' : (boolean) Whether the food can be consumed even if the hunger bar is full. (default: false)
57+
{| width="100%" cellspacing="1" cellpadding="1" border="1" class="wikitable"
58+
|-
59+
! scope="col" width="12%" | Field
60+
! scope="col" width="23%" | Type
61+
! scope="col" width="65%" | Description
62+
|-
63+
! damage
64+
| int
65+
| The amount of damage on the durability of the item. 0 is undamaged. The max value is determined by the item type's default durability or "maxdamage" if set.
66+
|-
67+
! unbreakable
68+
| boolean
69+
| If the item cannot be damaged when used. Also hides item durability bar. Field always exists if "damage" exists.
70+
|-
71+
! maxstacksize
72+
| int
73+
| Overrides the maximum quantity of items with identical meta that will stack. Must be from 1 to 99. (MC 1.20.6+)
74+
|-
75+
! maxdamage
76+
| int
77+
| Overrides the item's max durability. Value must be positive. (MC 1.20.6+)
78+
|-
79+
! glint
80+
| boolean
81+
| Overrides the item's enchantment glint state. (MC 1.20.6+)
82+
|-
83+
! rarity
84+
| string
85+
| Overrides the item's rarity, which affects the item name color. Can be COMMON (white), UNCOMMON (yellow), RARE (aqua), or EPIC (light purple). (MC 1.20.6+)
86+
|-
87+
! food
88+
| associative array
89+
| Overrides the consumable item's food stats. (MC 1.20.6+)
90+
* '''nutrition''' : (int) Food restored on the hunger bar when consumed. (default: 0)
91+
* '''saturation''' : (double) The amount of saturation that is increased when consumed. (default: 0.0)
92+
* '''always''' : (boolean) Whether the food can be consumed even if the hunger bar is full. (default: false)
93+
|-
94+
! jukeboxsong
95+
| string
96+
| Overrides the item's playable jukebox song. (MC 1.21+)
97+
|-
98+
! enchantability
99+
| int
100+
| Overrides the item's enchantability in an enchanting table. Value must be positive. Higher values allow applicable enchantments with higher costs to be picked. (MC 1.21.3+)
101+
|-
102+
! glider
103+
| boolean
104+
| Overrides if the item allows gliding when equipped like an elytra. (MC 1.21.3+)
105+
|-
106+
! remainder
107+
| associative array
108+
| Overrides the remaining item when the this item is used. (MC 1.21.3+)
109+
|}
37110

38111
These fields only exist for specific item types.
39112
{| width="80%" cellspacing="1" cellpadding="1" border="1" class="wikitable"
@@ -251,8 +324,8 @@ The entity's custom name is derived from the item "display" string. All other tr
251324

252325
Other data not yet supported in item meta:
253326

254-
MC 1.13.2+: "can_break", "can_place_on"
255-
MC 1.20.6+: "hide_tooltip", "instrument", "intangible_projectile", "item_name", "lock", "note_block_sound", "tool"
256-
MC 1.21.3+: "consumable", "damage_resistant", "death_protection", "equippable", "item_model", "glider", "repairable", "tooltip_style", "use_cooldown", "use_remainder"
257-
MC 1.21.4+: "custom_model_data" for anything other than a single float
258-
MC 1.21.5+: "weapon", "potion_duration_scale", "blocks_attacks", "break_sound", "provides_banner_patterns", "provides_trim_material", "tooltip_display"
327+
* MC 1.13.2 : "can_break" and "can_place_on" (Paper only)
328+
* MC 1.20.5 : "item_name", "note_block_sound", "intangible_projectile" (Paper 1.21.3 only), "instrument" (partial support due to partial server API), "tool" (partial server API), "hide_tooltip" (later integrated into "tooltip_display"), "lock" (insufficient server API)
329+
* MC 1.21.2 : "damage_resistant", "tooltip_style", "use_cooldown", "item_model", "death_protection" (Paper only), "repairable" (Paper only), "consumable" (added in Spigot 1.21.4 API), "equippable" (added in Spigot 1.21.5 API)
330+
* MC 1.21.4 : "custom_model_data" (for anything other than a single float rounded down)
331+
* MC 1.21.5 : "weapon", "blocks_attacks", "break_sound", "provides_banner_patterns", "provides_trim_material", "potion_duration_scale" (Paper only), "tooltip_display" (partially supported with "flags")

0 commit comments

Comments
 (0)