Skip to content

Commit

Permalink
Add item stack to decorated pot meta
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Jan 23, 2024
1 parent 7090276 commit c410f55
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.laytonsmith.abstraction.blocks;

import com.laytonsmith.abstraction.MCItemStack;

import java.util.Map;

public interface MCDecoratedPot extends MCBlockState {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
}
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/laytonsmith/core/ObjectGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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")) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/functionDocs/get_itemmeta
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down

0 comments on commit c410f55

Please sign in to comment.