diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java index e6df6506c9..58c7a065c6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItemStack.java @@ -1,6 +1,7 @@ package io.github.thebusybiscuit.slimefun4.api.items; import io.github.bakedlibs.dough.common.CommonPatterns; +import io.github.bakedlibs.dough.items.CustomItemStack; import io.github.bakedlibs.dough.items.ItemMetaSnapshot; import io.github.bakedlibs.dough.skins.PlayerHead; import io.github.bakedlibs.dough.skins.PlayerSkin; @@ -46,38 +47,31 @@ public class SlimefunItemStack extends ItemStack { private boolean locked = false; private String texture = null; - public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item) { + public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item, @Nonnull Consumer consumer) { super(item.getType(), item.getAmount()); - if (item.hasItemMeta()) { - setItemMeta(item.getItemMeta()); - } - Validate.notNull(id, "The Item id must never be null!"); Validate.isTrue( - id.equals(id.toUpperCase(Locale.ROOT)), "Slimefun Item Ids must be uppercase! (e.g. 'MY_ITEM_ID')"); + id.equals(id.toUpperCase(Locale.ROOT)), "Slimefun Item Ids must be uppercase! (e.g. 'MY_ITEM_ID')"); if (Slimefun.instance() == null) { throw new PrematureCodeException( - "A SlimefunItemStack must never be be created before your Plugin was enabled."); + "A SlimefunItemStack must never be be created before your Plugin was enabled."); } this.id = id; - ItemMeta meta = getItemMeta(); + ItemMeta meta = item.hasItemMeta()?item.getItemMeta(): getItemMeta(); Slimefun.getItemDataService().setItemData(meta, id); Slimefun.getItemTextureService().setTexture(meta, id); + consumer.accept(meta); setItemMeta(meta); } - - public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item, @Nonnull Consumer consumer) { - this(id, item); - - ItemMeta im = getItemMeta(); - consumer.accept(im); - setItemMeta(im); + private static final Consumer DEFAULT_CONSUMER=(itemMeta -> {}); + public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item) { + this(id, item,DEFAULT_CONSUMER); } public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nonnull Consumer consumer) { @@ -85,7 +79,7 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nonnull Co } public SlimefunItemStack( - @Nonnull String id, @Nonnull Material type, @Nullable String name, @Nonnull Consumer consumer) { + @Nonnull String id, @Nonnull Material type, @Nullable String name, @Nonnull Consumer consumer) { this(id, type, meta -> { if (name != null) { meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); @@ -117,7 +111,7 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nullable S } public SlimefunItemStack( - @Nonnull String id, @Nonnull Material type, @Nonnull Color color, @Nullable String name, String... lore) { + @Nonnull String id, @Nonnull Material type, @Nonnull Color color, @Nullable String name, String... lore) { this(id, type, im -> { if (name != null) { im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); @@ -144,11 +138,11 @@ public SlimefunItemStack( } public SlimefunItemStack( - @Nonnull String id, - @Nonnull Color color, - @Nonnull PotionEffect effect, - @Nullable String name, - String... lore) { + @Nonnull String id, + @Nonnull Color color, + @Nonnull PotionEffect effect, + @Nullable String name, + String... lore) { this(id, Material.POTION, im -> { if (name != null) { im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); @@ -190,7 +184,7 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull HeadTexture head, @Nullabl } public SlimefunItemStack( - @Nonnull String id, @Nonnull String texture, @Nullable String name, @Nonnull Consumer consumer) { + @Nonnull String id, @Nonnull String texture, @Nullable String name, @Nonnull Consumer consumer) { this(id, getSkull(id, texture), meta -> { if (name != null) { meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); @@ -309,17 +303,22 @@ public void lock() { return texture; } else if (CommonPatterns.HEXADECIMAL.matcher(texture).matches()) { String value = - "{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" + texture + "\"}}}"; + "{\"textures\":{\"SKIN\":{\"url\":\"http://textures.minecraft.net/texture/" + texture + "\"}}}"; return Base64.getEncoder().encodeToString(value.getBytes(StandardCharsets.UTF_8)); } else { throw new IllegalArgumentException( - "The provided texture for Item \"" + id + "\" does not seem to be a valid texture String!"); + "The provided texture for Item \"" + id + "\" does not seem to be a valid texture String!"); } } @Override public ItemStack clone() { - return new SlimefunItemStack(id, this); + //return new SlimefunItemStack(id, this); + ItemStack stack=super.clone(); + if(stack instanceof SlimefunItemStack sfitem){ + sfitem.locked=false; + } + return stack; } @Override