From 540f77965c1404b14f19d42907959843b8598f3f Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Thu, 19 Mar 2020 18:48:25 +0100 Subject: [PATCH] Changes to allow overwriting the player_head model with custom model data --- Minepacks/resources/backpacks.yml | 7 ++++--- .../Minepacks/Bukkit/Item/BackpacksConfig.java | 5 +++-- .../pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfig.java | 1 + .../Minepacks/Bukkit/Item/ItemConfigHead.java | 6 ++++-- .../Minepacks/Bukkit/Item/ItemConfigItem.java | 9 +++------ 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Minepacks/resources/backpacks.yml b/Minepacks/resources/backpacks.yml index aeb4b17..fe28b7b 100644 --- a/Minepacks/resources/backpacks.yml +++ b/Minepacks/resources/backpacks.yml @@ -7,15 +7,16 @@ Items: # The texture value for the head. # Heads can be found here: https://minecraft-heads.com/custom-heads/ # The correct value is the one listed on the head page under Other/Value - Model: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGRjYzZlYjQwZjNiYWRhNDFlNDMzOTg4OGQ2ZDIwNzQzNzU5OGJkYmQxNzVjMmU3MzExOTFkNWE5YTQyZDNjOCJ9fX0=" + HeadValue: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGRjYzZlYjQwZjNiYWRhNDFlNDMzOTg4OGQ2ZDIwNzQzNzU5OGJkYmQxNzVjMmU3MzExOTFkNWE5YTQyZDNjOCJ9fX0=" + # Only relevant for MC 1.14 and newer. Will set the custom_model_data so that you can overwrite the head with your own model if your players are using your texture pack + Model: 57045 DisplayName: "&eBackpack" Lore: - "Right click to open your backpack." - "Drag items on it to place them in your backpack." Minepacks: Material: shulker_shell - # Will set the damage value and unbreakable - on MC versions older than 1.14 or the custom_model_data for MC 1.14 and newer + # Will set the damage value and unbreakable on MC versions older than 1.14 or the custom_model_data for MC 1.14 and newer Model: 10 DisplayName: "&eBackpack" Lore: diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/BackpacksConfig.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/BackpacksConfig.java index 3e057ba..e673a0c 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/BackpacksConfig.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/BackpacksConfig.java @@ -60,13 +60,14 @@ private void loadItemConfigs() } final String displayName = ChatColor.translateAlternateColorCodes('&', getConfigE().getString(key + ".DisplayName", "&eBackpack")); final String material = getYamlE().getString(key + ".Material", "player_head"); + final int model = getYamlE().getInt(key + ".Model", 1); if(material.equalsIgnoreCase("player_head")) { - itemConfigs.put(key, new ItemConfigHead(displayName, getConfigE().getString(key + ".Model", ""), loreFinal)); + itemConfigs.put(key, new ItemConfigHead(displayName, getConfigE().getString(key + ".HeadValue", ""), model, loreFinal)); } else { - itemConfigs.put(key, new ItemConfigItem(getMaterialFromString(material), displayName, getYamlE().getInt(key + ".Model", 1), loreFinal)); + itemConfigs.put(key, new ItemConfigItem(getMaterialFromString(material), displayName, model, loreFinal)); } }); } diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfig.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfig.java index 523d2d4..e2607e1 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfig.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfig.java @@ -33,6 +33,7 @@ public abstract class ItemConfig { protected final @NotNull String displayName; protected final @Nullable List lore; + protected final int model; public abstract ItemStack make(final int amount); diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfigHead.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfigHead.java index 6be6385..106178c 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfigHead.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfigHead.java @@ -18,6 +18,7 @@ package at.pcgamingfreaks.Minepacks.Bukkit.Item; import at.pcgamingfreaks.Bukkit.HeadUtils; +import at.pcgamingfreaks.Bukkit.MCVersion; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -35,9 +36,9 @@ public class ItemConfigHead extends ItemConfig private static final UUID MINEPACKS_UUID = UUID.nameUUIDFromBytes("Minepacks".getBytes()); @Getter protected final String value; - public ItemConfigHead(final @NotNull String displayName, final @NotNull String value, final @Nullable List lore) + public ItemConfigHead(final @NotNull String displayName, final @NotNull String value, final int model, final @Nullable List lore) { - super(displayName, lore); + super(displayName, lore, MCVersion.isNewerOrEqualThan(MCVersion.MC_1_14) ? model : -1); this.value = value; } @@ -49,6 +50,7 @@ public ItemStack make(final int amount) { ItemMeta meta = stack.getItemMeta(); meta.setLore(lore); + if(model >= 0) meta.setCustomModelData(model); stack.setItemMeta(meta); } return stack; diff --git a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfigItem.java b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfigItem.java index e36e635..6957a96 100644 --- a/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfigItem.java +++ b/Minepacks/src/at/pcgamingfreaks/Minepacks/Bukkit/Item/ItemConfigItem.java @@ -20,7 +20,6 @@ import at.pcgamingfreaks.Bukkit.MCVersion; import org.bukkit.Material; -import org.bukkit.attribute.Attribute; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; @@ -35,13 +34,11 @@ public class ItemConfigItem extends ItemConfig { private static final Producer PRODUCER = MCVersion.isOlderThan(MCVersion.MC_1_14) ? new ProducerLegacy() : new ProducerModelId(); protected final @NotNull Material material; - protected final int value; public ItemConfigItem(final @NotNull Material material, final @NotNull String displayName, final int value, final @Nullable List lore) { - super(displayName, lore); + super(displayName, lore, value); this.material = material; - this.value = value; } @Override @@ -61,7 +58,7 @@ private static class ProducerLegacy implements Producer @Override public ItemStack make(final @NotNull ItemConfigItem itemConfig, final int amount) { - ItemStack stack = new ItemStack(itemConfig.material, amount, (short) itemConfig.value); + ItemStack stack = new ItemStack(itemConfig.material, amount, (short) itemConfig.model); ItemMeta meta = stack.getItemMeta(); assert meta != null; meta.setDisplayName(itemConfig.displayName); @@ -81,7 +78,7 @@ public ItemStack make(@NotNull ItemConfigItem itemConfig, int amount) ItemMeta meta = stack.getItemMeta(); assert meta != null; meta.setDisplayName(itemConfig.displayName); - meta.setCustomModelData(itemConfig.value); + meta.setCustomModelData(itemConfig.model); if(itemConfig.lore != null) meta.setLore(itemConfig.lore); stack.setItemMeta(meta); return stack;