Skip to content

Commit fae4bcb

Browse files
committed
Implements ability for Player Heads to use CMD
The player heads never used data from input item stack, and always transformed it into plain PLAYER_HEAD. This adds new method `PanelItemBuilder#icon(String, ItemStack)` that applies input icon and assigns name. When skin is assigned to player head, it will copy custom model data from template item, instead of using plain HeadCache data. This adds ability to solve #2774 in warps addon
1 parent 6ad3d5c commit fae4bcb

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/main/java/world/bentobox/bentobox/api/panels/PanelItem.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public interface ClickHandler {
193193
public void setHead(ItemStack itemStack) {
194194
// update amount before replacing.
195195
itemStack.setAmount(this.icon.getAmount());
196+
ItemMeta originalMeta = this.icon.getItemMeta();
197+
196198
this.icon = itemStack;
197199

198200
// Get the meta
@@ -203,6 +205,11 @@ public void setHead(ItemStack itemStack) {
203205
meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
204206
meta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
205207
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
208+
209+
if (originalMeta.hasCustomModelDataComponent()) {
210+
meta.setCustomModelDataComponent(originalMeta.getCustomModelDataComponent());
211+
}
212+
206213
icon.setItemMeta(meta);
207214
}
208215
// Create the final item

src/main/java/world/bentobox/bentobox/api/panels/builders/PanelItemBuilder.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,27 @@ public PanelItemBuilder icon(@Nullable ItemStack icon) {
4242
return this;
4343
}
4444

45+
46+
/**
47+
* Assigns icon and player name to the panel item.
48+
* @param playerName the name of player head icon.
49+
* @param icon the original player head icon
50+
* @return PanelItemBuilder
51+
*/
52+
public PanelItemBuilder icon(String playerName, ItemStack icon) {
53+
this.icon = icon;
54+
this.playerHeadName = playerName;
55+
return this;
56+
}
57+
58+
4559
/**
4660
* Set icon to player's head
4761
* @param playerName - player's name
4862
* @return PanelItemBuilder
4963
*/
5064
public PanelItemBuilder icon(String playerName) {
51-
this.icon = new ItemStack(Material.PLAYER_HEAD);
52-
this.playerHeadName = playerName;
53-
return this;
65+
return this.icon(playerName, new ItemStack(Material.PLAYER_HEAD));
5466
}
5567

5668
public PanelItemBuilder name(@Nullable String name) {

0 commit comments

Comments
 (0)