From fbec605114d7e61f65a856ff8ee435bc5d90b0fc Mon Sep 17 00:00:00 2001 From: 02Miki <35926600+02Miki@users.noreply.github.com> Date: Wed, 9 Jun 2021 10:26:47 +0200 Subject: [PATCH 1/6] Add back GooeyButton#of(ItemStack, String) --- .../java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java b/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java index 8c620c4..2517f12 100644 --- a/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java +++ b/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java @@ -33,6 +33,12 @@ public static GooeyButton of(ItemStack stack) { .display(stack) .build(); } + public static GooeyButton of(ItemStack stack, String title) { + return builder() + .display(stack) + .title(title) + .build(); + } public static class Builder { From 3f2cff5580ccc95d2b2fa81bcc29be60c2c0744d Mon Sep 17 00:00:00 2001 From: 02Miki <35926600+02Miki@users.noreply.github.com> Date: Sun, 13 Jun 2021 22:38:34 +0200 Subject: [PATCH 2/6] Add GooeyButton.Builder#hideFlags and EnumFlag --- .../gooeylibs2/api/button/EnumFlag.java | 27 +++++++++++++++++++ .../gooeylibs2/api/button/GooeyButton.java | 21 +++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/main/java/ca/landonjw/gooeylibs2/api/button/EnumFlag.java diff --git a/src/main/java/ca/landonjw/gooeylibs2/api/button/EnumFlag.java b/src/main/java/ca/landonjw/gooeylibs2/api/button/EnumFlag.java new file mode 100644 index 0000000..ece02d9 --- /dev/null +++ b/src/main/java/ca/landonjw/gooeylibs2/api/button/EnumFlag.java @@ -0,0 +1,27 @@ +package ca.landonjw.gooeylibs2.api.button; + +public enum EnumFlag { + /** + ENCHANTS only hides tool enchants, as book ones are classified as stored enchantments. + EXTRAS hides multiple things, according to the minecraft wiki (https://minecraft.fandom.com/wiki/Tutorials/Command_NBT_tags) + */ + PIXELMON(0), + ENCHANTS(1), + ATTRIBUTE_MODIFIERS(2), + UNBREAKABLE(4), + CAN_DESTROY(8), + CAN_PLACE_ON(16), + EXTRAS(32), + LEATHER_DYED(64), + ALL(127); + + private final int value; + + EnumFlag(int value) { + this.value = value; + } + + public int getValue() { + return value; + } +} diff --git a/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java b/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java index 2517f12..1192874 100644 --- a/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java +++ b/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java @@ -1,13 +1,17 @@ package ca.landonjw.gooeylibs2.api.button; +import ca.landonjw.gooeylibs2.api.template.LineType; import com.google.common.collect.Lists; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.function.Consumer; public class GooeyButton extends ButtonBase { @@ -46,6 +50,7 @@ public static class Builder { protected String title; protected Collection lore = Lists.newArrayList(); protected Consumer onClick; + protected List hideFlags; public Builder display(@Nonnull ItemStack display) { this.display = display; @@ -62,6 +67,11 @@ public Builder lore(@Nullable Collection lore) { return this; } + public Builder hideFlags(EnumFlag... flags) { + this.hideFlags = Arrays.asList(flags); + return this; + } + public Builder onClick(@Nullable Consumer behaviour) { this.onClick = behaviour; return this; @@ -94,8 +104,15 @@ protected ItemStack buildDisplay() { } display.getOrCreateSubCompound("display").setTag("Lore", nbtLore); } - if (display.hasTagCompound()) { - display.getTagCompound().setString("tooltip", ""); + if (!this.hideFlags.isEmpty() && display.hasTagCompound()) { + if (this.hideFlags.contains(EnumFlag.PIXELMON)) { + display.getTagCompound().setString("tooltip", ""); + } + int value = 0; + for (EnumFlag flag : this.hideFlags) { + value += flag.getValue(); + } + display.getTagCompound().setInteger("HideFlags", value); } return display; } From 2dd4737be96ce963b395a6b6073d7a5144f75d53 Mon Sep 17 00:00:00 2001 From: 02Miki <35926600+02Miki@users.noreply.github.com> Date: Sun, 13 Jun 2021 22:39:56 +0200 Subject: [PATCH 3/6] This edit wasn't needed but it just triggered me --- src/main/java/ca/landonjw/gooeylibs2/api/button/EnumFlag.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ca/landonjw/gooeylibs2/api/button/EnumFlag.java b/src/main/java/ca/landonjw/gooeylibs2/api/button/EnumFlag.java index ece02d9..3cbf8e9 100644 --- a/src/main/java/ca/landonjw/gooeylibs2/api/button/EnumFlag.java +++ b/src/main/java/ca/landonjw/gooeylibs2/api/button/EnumFlag.java @@ -22,6 +22,6 @@ EXTRAS hides multiple things, according to the minecraft wiki (https://minecraft } public int getValue() { - return value; + return this.value; } } From 1222050cbe11f244b07f7cfb15229efcc7113f01 Mon Sep 17 00:00:00 2001 From: 02Miki <35926600+02Miki@users.noreply.github.com> Date: Tue, 15 Jun 2021 13:03:01 +0200 Subject: [PATCH 4/6] Imagine being dumb --- .../java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java b/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java index 1192874..4fbc69d 100644 --- a/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java +++ b/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java @@ -9,6 +9,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -50,7 +51,7 @@ public static class Builder { protected String title; protected Collection lore = Lists.newArrayList(); protected Consumer onClick; - protected List hideFlags; + protected List hideFlags = new ArrayList<>(); public Builder display(@Nonnull ItemStack display) { this.display = display; From 2123e6b33a6f60f6676f329d087c08b36f236111 Mon Sep 17 00:00:00 2001 From: 02Miki <35926600+02Miki@users.noreply.github.com> Date: Tue, 15 Jun 2021 13:11:06 +0200 Subject: [PATCH 5/6] Kinda wouldn't make sense if this didn't happen --- .../java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java b/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java index 4fbc69d..5e756ab 100644 --- a/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java +++ b/src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java @@ -106,7 +106,7 @@ protected ItemStack buildDisplay() { display.getOrCreateSubCompound("display").setTag("Lore", nbtLore); } if (!this.hideFlags.isEmpty() && display.hasTagCompound()) { - if (this.hideFlags.contains(EnumFlag.PIXELMON)) { + if (this.hideFlags.contains(EnumFlag.PIXELMON) || this.hideFlags.contains(EnumFlag.ALL)) { display.getTagCompound().setString("tooltip", ""); } int value = 0; From 0344aa4a2638b1518b37d4d21d38fa397772d73d Mon Sep 17 00:00:00 2001 From: 02Miki <35926600+02Miki@users.noreply.github.com> Date: Fri, 2 Jul 2021 15:26:09 +0200 Subject: [PATCH 6/6] Fixed hideFlags and lore methods returning the wrong Builder --- .../api/button/linked/LinkedPageButton.java | 20 +++++++++++++++++++ .../api/button/moveable/MovableButton.java | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/ca/landonjw/gooeylibs2/api/button/linked/LinkedPageButton.java b/src/main/java/ca/landonjw/gooeylibs2/api/button/linked/LinkedPageButton.java index 6be8b6a..f7443fc 100644 --- a/src/main/java/ca/landonjw/gooeylibs2/api/button/linked/LinkedPageButton.java +++ b/src/main/java/ca/landonjw/gooeylibs2/api/button/linked/LinkedPageButton.java @@ -2,6 +2,7 @@ import ca.landonjw.gooeylibs2.api.UIManager; import ca.landonjw.gooeylibs2.api.button.ButtonAction; +import ca.landonjw.gooeylibs2.api.button.EnumFlag; import ca.landonjw.gooeylibs2.api.button.GooeyButton; import ca.landonjw.gooeylibs2.api.page.LinkedPage; import ca.landonjw.gooeylibs2.api.page.Page; @@ -9,6 +10,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.util.Collection; import java.util.function.Consumer; public class LinkedPageButton extends GooeyButton { @@ -58,6 +60,24 @@ public Builder title(@Nullable String title) { return this; } + @Override + public Builder lore(@Nullable Collection lore) { + super.lore(lore); + return this; + } + + @Override + public Builder hideFlags(EnumFlag... flags) { + super.hideFlags(flags); + return this; + } + + @Override + public Builder onClick(@Nullable Runnable behaviour) { + super.onClick(behaviour); + return this; + } + @Override public Builder onClick(@Nullable Consumer behaviour) { super.onClick(behaviour); diff --git a/src/main/java/ca/landonjw/gooeylibs2/api/button/moveable/MovableButton.java b/src/main/java/ca/landonjw/gooeylibs2/api/button/moveable/MovableButton.java index 32ca479..bfe7f98 100644 --- a/src/main/java/ca/landonjw/gooeylibs2/api/button/moveable/MovableButton.java +++ b/src/main/java/ca/landonjw/gooeylibs2/api/button/moveable/MovableButton.java @@ -1,6 +1,7 @@ package ca.landonjw.gooeylibs2.api.button.moveable; import ca.landonjw.gooeylibs2.api.button.ButtonAction; +import ca.landonjw.gooeylibs2.api.button.EnumFlag; import ca.landonjw.gooeylibs2.api.button.GooeyButton; import net.minecraft.item.ItemStack; @@ -59,6 +60,11 @@ public Builder lore(@Nullable Collection lore) { return this; } + public Builder hideFlags(EnumFlag... flags) { + super.hideFlags(flags); + return this; + } + public Builder onClick(@Nullable Consumer behaviour) { super.onClick(behaviour); return this;