Skip to content

Commit 3bd7282

Browse files
committed
Add new data to item meta
The following fields were added: * maxstacksize (1.20.6) * maxdamage (1.20.6) * glint (1.20.6) * rarity (1.20.6) * ominousamplifier (1.20.6) * jukeboxsong (1.21) * enchantability (1.21.3) * food (1.21.3)
1 parent 578ee3e commit 3bd7282

File tree

15 files changed

+574
-144
lines changed

15 files changed

+574
-144
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.laytonsmith.abstraction;
2+
3+
public interface MCFoodComponent extends AbstractionObject {
4+
int getNutrition();
5+
void setNutrition(int nutrition);
6+
float getSaturation();
7+
void setSaturation(float saturation);
8+
boolean getCanAlwaysEat();
9+
void setCanAlwaysEat(boolean canAlwaysEat);
10+
}

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.laytonsmith.abstraction.blocks.MCMaterial;
55
import com.laytonsmith.abstraction.enums.MCEnchantment;
66
import com.laytonsmith.abstraction.enums.MCItemFlag;
7+
import com.laytonsmith.abstraction.enums.MCItemRarity;
8+
79
import java.util.List;
810
import java.util.Map;
911
import java.util.Set;
@@ -110,6 +112,8 @@ public interface MCItemMeta extends AbstractionObject {
110112

111113
void setUnbreakable(boolean unbreakable);
112114

115+
boolean hasDamage();
116+
113117
int getDamage();
114118

115119
void setDamage(int damage);
@@ -118,7 +122,7 @@ public interface MCItemMeta extends AbstractionObject {
118122

119123
int getMaxDamage();
120124

121-
void setMaxDamage(int damage);
125+
void setMaxDamage(Integer damage);
122126

123127
MCBlockData getBlockData(MCMaterial material);
124128

@@ -162,5 +166,30 @@ public interface MCItemMeta extends AbstractionObject {
162166

163167
int getMaxStackSize();
164168

165-
void setMaxStackSize(int size);
169+
void setMaxStackSize(Integer size);
170+
171+
boolean hasRarity();
172+
173+
MCItemRarity getRarity();
174+
175+
void setRarity(MCItemRarity rarity);
176+
177+
boolean hasEnchantable();
178+
179+
int getEnchantable();
180+
181+
void setEnchantable(Integer enchantability);
182+
183+
boolean hasJukeboxPlayable();
184+
185+
String getJukeboxPlayable();
186+
187+
void setJukeboxPlayable(String playable);
188+
189+
boolean hasFood();
190+
191+
MCFoodComponent getFood();
192+
193+
void setFood(MCFoodComponent component);
194+
166195
}

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

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,55 @@
77

88
public interface MCItemStack extends AbstractionObject {
99

10-
void addEnchantment(MCEnchantment e, int level);
10+
/**
11+
* Returns the item type in this stack. May return air if empty.
12+
*
13+
* @return the item type
14+
*/
15+
MCMaterial getType();
1116

12-
void addUnsafeEnchantment(MCEnchantment e, int level);
17+
/**
18+
* Returns the default maximum stack size for the item type in this stack, or if the item has
19+
* a max_stack_size item data component, that component's value will be returned instead.
20+
* Use {@link MCMaterial#getMaxStackSize()} to always get the default max stack size for this item type.
21+
*
22+
* @return the effective maximum stack size
23+
*/
24+
int maxStackSize();
1325

14-
Map<MCEnchantment, Integer> getEnchantments();
26+
/**
27+
* Returns the quantity of items in this stack.
28+
*
29+
* @return the stack quantity
30+
*/
31+
int getAmount();
1532

16-
void removeEnchantment(MCEnchantment e);
33+
/**
34+
* Sets the quantity of items in this stack. Setting to zero makes this stack empty.
35+
*
36+
* @param amt the stack quantity
37+
*/
38+
void setAmount(int amt);
1739

18-
MCMaterial getType();
40+
/**
41+
* Returns if the stack has any valid items in it.
42+
* This should be checked first before using most other methods.
43+
*
44+
* @return true if not empty
45+
*/
46+
boolean isEmpty();
1947

20-
void setType(MCMaterial type);
48+
void addEnchantment(MCEnchantment e, int level);
2149

22-
int maxStackSize();
50+
void addUnsafeEnchantment(MCEnchantment e, int level);
2351

24-
int getAmount();
52+
Map<MCEnchantment, Integer> getEnchantments();
2553

26-
void setAmount(int amt);
54+
void removeEnchantment(MCEnchantment e);
2755

2856
boolean hasItemMeta();
2957

3058
MCItemMeta getItemMeta();
3159

3260
void setItemMeta(MCItemMeta im);
33-
34-
boolean isEmpty();
3561
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.laytonsmith.abstraction;
2+
3+
public interface MCOminousBottleMeta extends MCItemMeta {
4+
boolean hasAmplifier();
5+
int getAmplifier();
6+
void setAmplifier(int value);
7+
}

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
import org.bukkit.inventory.meta.LeatherArmorMeta;
183183
import org.bukkit.inventory.meta.MapMeta;
184184
import org.bukkit.inventory.meta.MusicInstrumentMeta;
185+
import org.bukkit.inventory.meta.OminousBottleMeta;
185186
import org.bukkit.inventory.meta.PotionMeta;
186187
import org.bukkit.inventory.meta.SkullMeta;
187188
import org.bukkit.inventory.meta.SuspiciousStewMeta;
@@ -692,23 +693,31 @@ public static MCItemMeta BukkitGetCorrectMeta(ItemMeta im) {
692693
if(im instanceof KnowledgeBookMeta) {
693694
return new BukkitMCKnowledgeBookMeta((KnowledgeBookMeta) im);
694695
}
695-
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_17)) {
696+
MCVersion version = Static.getServer().getMinecraftVersion();
697+
if(version.gte(MCVersion.MC1_17)) {
696698
if(im instanceof BundleMeta) {
697699
return new BukkitMCBundleMeta((BundleMeta) im);
698700
}
699-
if(im instanceof AxolotlBucketMeta) {
700-
return new BukkitMCAxolotlBucketMeta((AxolotlBucketMeta) im);
701-
}
702-
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_19_3)) {
703-
if(im instanceof MusicInstrumentMeta) {
704-
return new BukkitMCMusicInstrumentMeta((MusicInstrumentMeta) im);
701+
if(version.gte(MCVersion.MC1_17_X)) {
702+
if(im instanceof AxolotlBucketMeta) {
703+
return new BukkitMCAxolotlBucketMeta((AxolotlBucketMeta) im);
705704
}
706-
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_20)) {
707-
if(im instanceof ColorableArmorMeta) { // Must be before ArmorMeta and LeatherArmorMeta
708-
return new BukkitMCColorableArmorMeta((ColorableArmorMeta) im);
705+
if(version.gte(MCVersion.MC1_19_3)) {
706+
if(im instanceof MusicInstrumentMeta) {
707+
return new BukkitMCMusicInstrumentMeta((MusicInstrumentMeta) im);
709708
}
710-
if(im instanceof ArmorMeta) {
711-
return new BukkitMCArmorMeta((ArmorMeta) im);
709+
if(version.gte(MCVersion.MC1_20)) {
710+
if(im instanceof ColorableArmorMeta) { // Must be before ArmorMeta and LeatherArmorMeta
711+
return new BukkitMCColorableArmorMeta((ColorableArmorMeta) im);
712+
}
713+
if(im instanceof ArmorMeta) {
714+
return new BukkitMCArmorMeta((ArmorMeta) im);
715+
}
716+
if(version.gte(MCVersion.MC1_20_6)) {
717+
if(im instanceof OminousBottleMeta) {
718+
return new BukkitMCOminousBottleMeta((OminousBottleMeta) im);
719+
}
720+
}
712721
}
713722
}
714723
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.laytonsmith.abstraction.bukkit;
2+
3+
import com.laytonsmith.abstraction.MCFoodComponent;
4+
import org.bukkit.inventory.meta.components.FoodComponent;
5+
6+
public class BukkitMCFoodComponent implements MCFoodComponent {
7+
8+
private final FoodComponent foodComponent;
9+
10+
public BukkitMCFoodComponent(FoodComponent foodComponent) {
11+
this.foodComponent = foodComponent;
12+
}
13+
14+
@Override
15+
public int getNutrition() {
16+
return foodComponent.getNutrition();
17+
}
18+
19+
@Override
20+
public void setNutrition(int nutrition) {
21+
foodComponent.setNutrition(nutrition);
22+
}
23+
24+
@Override
25+
public float getSaturation() {
26+
return foodComponent.getSaturation();
27+
}
28+
29+
@Override
30+
public void setSaturation(float saturation) {
31+
foodComponent.setSaturation(saturation);
32+
}
33+
34+
@Override
35+
public boolean getCanAlwaysEat() {
36+
return foodComponent.canAlwaysEat();
37+
}
38+
39+
@Override
40+
public void setCanAlwaysEat(boolean canAlwaysEat) {
41+
foodComponent.setCanAlwaysEat(canAlwaysEat);
42+
}
43+
44+
@Override
45+
public Object getHandle() {
46+
return foodComponent;
47+
}
48+
49+
@Override
50+
public String toString() {
51+
return foodComponent.toString();
52+
}
53+
54+
@Override
55+
public boolean equals(Object o) {
56+
return o instanceof BukkitMCFoodComponent && foodComponent.equals(((BukkitMCFoodComponent) o).foodComponent);
57+
}
58+
59+
@Override
60+
public int hashCode() {
61+
return foodComponent.hashCode();
62+
}
63+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public MCItemStack getItem(int slot) {
6666
@Override
6767
public void setItem(int slot, MCItemStack stack) {
6868
try {
69-
this.i.setItem(slot, stack == null ? null : ((BukkitMCItemStack) stack).is);
69+
this.i.setItem(slot, stack == null ? null : (ItemStack) stack.getHandle());
7070
} catch (ArrayIndexOutOfBoundsException aioobe) {
7171
if(slot > 0 && slot < getSize()) {
7272
MSLog.GetLogger().Log(Tags.RUNTIME, LogLevel.WARNING, "The API claims that a particular slot is"
@@ -111,7 +111,7 @@ public int hashCode() {
111111

112112
@Override
113113
public Map<Integer, MCItemStack> addItem(MCItemStack stack) {
114-
Map<Integer, ItemStack> h = i.addItem(((BukkitMCItemStack) stack).is);
114+
Map<Integer, ItemStack> h = i.addItem((ItemStack) stack.getHandle());
115115
Map<Integer, MCItemStack> m = new HashMap<>();
116116
for(Map.Entry<Integer, ItemStack> entry : h.entrySet()) {
117117
Integer key = entry.getKey();

0 commit comments

Comments
 (0)