diff --git a/src/main/java/com/laytonsmith/abstraction/blocks/MCDecoratedPot.java b/src/main/java/com/laytonsmith/abstraction/blocks/MCDecoratedPot.java index cb82ed632..d6eb99692 100644 --- a/src/main/java/com/laytonsmith/abstraction/blocks/MCDecoratedPot.java +++ b/src/main/java/com/laytonsmith/abstraction/blocks/MCDecoratedPot.java @@ -1,5 +1,7 @@ package com.laytonsmith.abstraction.blocks; +import com.laytonsmith.abstraction.MCItemStack; + import java.util.Map; public interface MCDecoratedPot extends MCBlockState { @@ -8,6 +10,10 @@ public interface MCDecoratedPot extends MCBlockState { void setSherd(Side side, MCMaterial sherd); + MCItemStack getItemStack(); + + void setItemStack(MCItemStack item); + enum Side { BACK, FRONT, diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/blocks/BukkitMCDecoratedPot.java b/src/main/java/com/laytonsmith/abstraction/bukkit/blocks/BukkitMCDecoratedPot.java index d54154f10..142dd2e46 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/blocks/BukkitMCDecoratedPot.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/blocks/BukkitMCDecoratedPot.java @@ -1,9 +1,12 @@ package com.laytonsmith.abstraction.bukkit.blocks; +import com.laytonsmith.abstraction.MCItemStack; import com.laytonsmith.abstraction.blocks.MCDecoratedPot; import com.laytonsmith.abstraction.blocks.MCMaterial; +import com.laytonsmith.abstraction.bukkit.BukkitMCItemStack; import org.bukkit.Material; import org.bukkit.block.DecoratedPot; +import org.bukkit.inventory.ItemStack; import java.util.HashMap; import java.util.Map; @@ -36,4 +39,23 @@ public void setSherd(MCDecoratedPot.Side side, MCMaterial sherd) { DecoratedPot.Side concreteSide = DecoratedPot.Side.valueOf(side.name()); this.dp.setSherd(concreteSide, (Material) sherd.getHandle()); } + + @Override + public MCItemStack getItemStack() { + try { + return new BukkitMCItemStack(dp.getInventory().getItem()); + } catch(NoSuchMethodError ex) { + // probably before 1.20.4 + return null; + } + } + + @Override + public void setItemStack(MCItemStack item) { + try { + dp.getInventory().setItem((ItemStack) item.getHandle()); + } catch(NoSuchMethodError ex) { + // probably before 1.20.4 + } + } } diff --git a/src/main/java/com/laytonsmith/core/ObjectGenerator.java b/src/main/java/com/laytonsmith/core/ObjectGenerator.java index 14351f491..b2dbf0d1b 100644 --- a/src/main/java/com/laytonsmith/core/ObjectGenerator.java +++ b/src/main/java/com/laytonsmith/core/ObjectGenerator.java @@ -77,6 +77,7 @@ import com.laytonsmith.abstraction.enums.MCTagType; import com.laytonsmith.abstraction.enums.MCTrimMaterial; import com.laytonsmith.abstraction.enums.MCTrimPattern; +import com.laytonsmith.abstraction.enums.MCVersion; import com.laytonsmith.core.constructs.CArray; import com.laytonsmith.core.constructs.CBoolean; import com.laytonsmith.core.constructs.CDouble; @@ -568,6 +569,9 @@ public Construct itemMeta(MCItemStack is, Target t) { sherds.set(side.getKey().name().toLowerCase(), side.getValue().name()); } ma.set("sherds", sherds, t); + if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_20_X)) { + ma.set("item", item(decoratedPot.getItemStack(), t), t); + } } else if(bs instanceof MCInventoryHolder) { // Finally, handle InventoryHolders with inventory slots that do not have a special meaning. MCInventory inv = ((MCInventoryHolder) bs).getInventory(); @@ -1073,8 +1077,13 @@ public MCItemMeta itemMeta(Mixed c, MCMaterial mat, Target t) throws ConfigRunti } else { throw new CREFormatException("Expected associative array for decorated pot meta.", t); } - bsm.setBlockState(bs); } + if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_20_X)) { + if(ma.containsKey("item")) { + decoratedPot.setItemStack(item(ma.get("item", t), t)); + } + } + bsm.setBlockState(bs); } else if(bs instanceof MCInventoryHolder) { // Finally, handle InventoryHolders with inventory slots that do not have a special meaning. if(ma.containsKey("inventory")) { diff --git a/src/main/resources/functionDocs/get_itemmeta b/src/main/resources/functionDocs/get_itemmeta index 94a6ee16b..eee0ff153 100644 --- a/src/main/resources/functionDocs/get_itemmeta +++ b/src/main/resources/functionDocs/get_itemmeta @@ -78,6 +78,7 @@ The remaining tags are not yet supported. | Decorated Pots | * '''sherds''' : (array) An associative array of pottery sherds for the '''"front"''', '''"back"''', '''"left"''', and '''"right"''' sides of the decorated pot. Brick is used for empty sides. +* '''item''' : (array) An item array for the stack contained in the decorated pot, or null if empty. (MC 1.20.4+) |- | Enchanted Books |