diff options
-rw-r--r-- | src/main/java/me/Danker/utils/Utils.java | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/main/java/me/Danker/utils/Utils.java b/src/main/java/me/Danker/utils/Utils.java index e4f7873..3f54b7d 100644 --- a/src/main/java/me/Danker/utils/Utils.java +++ b/src/main/java/me/Danker/utils/Utils.java @@ -20,6 +20,8 @@ import net.minecraft.entity.item.EntityItemFrame; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.util.*; import org.lwjgl.opengl.GL11; @@ -27,6 +29,7 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.regex.Matcher; @@ -263,7 +266,40 @@ public class Utils { public static String getColouredBoolean(boolean bool) { return bool ? EnumChatFormatting.GREEN + "On" : EnumChatFormatting.RED + "Off"; } - + + //Taken from SkyblockAddons + public static List<String> getItemLore(ItemStack itemStack) { + final int NBT_INTEGER = 3; + final int NBT_STRING = 8; + final int NBT_LIST = 9; + final int NBT_COMPOUND = 10; + + if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("display", NBT_COMPOUND)) { + NBTTagCompound display = itemStack.getTagCompound().getCompoundTag("display"); + + if (display.hasKey("Lore", NBT_LIST)) { + NBTTagList lore = display.getTagList("Lore", NBT_STRING); + + List<String> loreAsList = new ArrayList<>(); + for (int lineNumber = 0; lineNumber < lore.tagCount(); lineNumber++) { + loreAsList.add(lore.getStringTagAt(lineNumber)); + } + + return Collections.unmodifiableList(loreAsList); + } + } + + return Collections.emptyList(); + } + + public static boolean hasRightClickAbility(ItemStack itemStack) { + return Utils.getItemLore(itemStack).stream().anyMatch(line->{ + String stripped = StringUtils.stripControlCodes(line); + return stripped.startsWith("Item Ability:") && stripped.endsWith("RIGHT CLICK"); + }); + } + + public static void draw3DLine(Vec3 pos1, Vec3 pos2, int colourInt, float partialTicks) { Entity render = Minecraft.getMinecraft().getRenderViewEntity(); WorldRenderer worldRenderer = Tessellator.getInstance().getWorldRenderer(); |