Skip to content

Commit

Permalink
Added a way to get moded block from itemStack
Browse files Browse the repository at this point in the history
  • Loading branch information
tbvns committed Jan 21, 2024
1 parent d4a0c1e commit 7076388
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/main/java/xyz/prismenetwork/kelpmodloader/Item/ItemUtils.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
package xyz.prismenetwork.kelpmodloader.Item;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import xyz.prismenetwork.kelpmodloader.Block.ModdedBlock;
import xyz.prismenetwork.kelpmodloader.Constant;

public class ItemUtils {
public static boolean isModed(ItemStack itemStack) {
if (itemStack.hasItemMeta()) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.getCustomModelData() - 1 != 0) {
System.out.println(itemMeta.getCustomModelData());
if (itemMeta.getCustomModelData() != 0) {
return true;
}
}
return false;
}

/**
* @param itemStack The itemStack to get the Modded item from
* @return The modded item from this itemStack (Null if not modded or block item)
*/
public static ModdedItem getModedItem(ItemStack itemStack) {
if (itemStack.hasItemMeta()) {
ItemMeta itemMeta = itemStack.getItemMeta();
assert itemMeta != null;
if (itemMeta.getCustomModelData() - 1 != 0) {
for (int i = 0; i < Constant.Items.size(); i++) {
ModdedItem item = Constant.Items.get(i);
System.out.println(Constant.Items.get(i));
if (itemMeta.getCustomModelData() == item.getId() - 1 && itemStack.getType() == item.ItemMaterial) {
return item;
}
Expand All @@ -30,4 +37,24 @@ public static ModdedItem getModedItem(ItemStack itemStack) {
}
return null;
}

/**
* @param itemStack The itemStack to get the Modded block from
* @return The modded block from this itemStack (Null if not modded or item)
*/
public static ModdedBlock getModedBlockFromItem(ItemStack itemStack) {
if (itemStack.hasItemMeta()) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.getCustomModelData() - 1 != 0) {
for (int i = 0; i < Constant.Blocks.size(); i++) {
ModdedBlock moddedBlock = Constant.Blocks.get(i);
System.out.println(Constant.Blocks.get(i));
if (itemMeta.getCustomModelData() == moddedBlock.getId() - 1) {
return moddedBlock;
}
}
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void Generate(File blockModelFile, File itemModelFile) throws IOException
//Generate Item models
HashMap<Material, String> MaterialsJson = new HashMap<>();
Items.forEach(I -> {
System.out.println(I.Name + " - "+ I.getId());
if (I.ItemMaterial.equals(Material.STONE)) {
KelpModLoader.getPlugin(KelpModLoader.class).getLogger().warning("You are using \"STONE\" as a material for item \"" + I.Name + "\". This will cause issue.");
}
Expand Down

0 comments on commit 7076388

Please sign in to comment.