diff options
author | My-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com> | 2020-12-17 14:07:59 -0500 |
---|---|---|
committer | My-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com> | 2020-12-17 14:07:59 -0500 |
commit | 09a83ca95a990bbdd901560c601efa68ff008c36 (patch) | |
tree | 318edbd20c6deb368874b8963bb1a111c7b17c71 /src/main/java/me/Danker | |
parent | b453d6a47f45d677d7c55b5e8ccc5981b7b90c5b (diff) | |
download | SkyblockMod-09a83ca95a990bbdd901560c601efa68ff008c36.tar.gz SkyblockMod-09a83ca95a990bbdd901560c601efa68ff008c36.tar.bz2 SkyblockMod-09a83ca95a990bbdd901560c601efa68ff008c36.zip |
Update Utils.java
Add getItemLore (taken from SkyblockAddons) and a function to check if the item has a right click ability.
Diffstat (limited to 'src/main/java/me/Danker')
-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(); |