Skip to content

Commit

Permalink
Refactor hide flag enum, add generations flag
Browse files Browse the repository at this point in the history
  • Loading branch information
landonjw committed Jul 16, 2021
1 parent 8826cd6 commit 0f9f4a0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 36 deletions.
27 changes: 0 additions & 27 deletions src/main/java/ca/landonjw/gooeylibs2/api/button/EnumFlag.java

This file was deleted.

31 changes: 31 additions & 0 deletions src/main/java/ca/landonjw/gooeylibs2/api/button/FlagType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ca.landonjw.gooeylibs2.api.button;

public enum FlagType
{
/**
* 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)
*/
Reforged(0),
Generations(0),
Enchantments(1),
Attribute_Modifiers(2),
Unbreakable(4),
Can_Destroy(8),
Can_Place_On(16),
Extras(32),
Dyed_Leather(64),
All(127);

private final int value;

FlagType(int value)
{
this.value = value;
}

public int getValue()
{
return this.value;
}
}
18 changes: 13 additions & 5 deletions src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static class Builder {
protected String title;
protected Collection<String> lore = Lists.newArrayList();
protected Consumer<ButtonAction> onClick;
protected List<EnumFlag> hideFlags = new ArrayList<>();
protected List<FlagType> hideFlags = new ArrayList<>();

public Builder display(@Nonnull ItemStack display) {
this.display = display.copy();
Expand All @@ -66,7 +66,8 @@ public Builder lore(@Nullable Collection<String> lore) {
return this;
}

public Builder hideFlags(EnumFlag... flags) {
public Builder hideFlags(FlagType... flags)
{
this.hideFlags = Arrays.asList(flags);
return this;
}
Expand Down Expand Up @@ -103,12 +104,19 @@ protected ItemStack buildDisplay() {
}
display.getOrCreateSubCompound("display").setTag("Lore", nbtLore);
}
if (!this.hideFlags.isEmpty() && display.hasTagCompound()) {
if (this.hideFlags.contains(EnumFlag.PIXELMON) || this.hideFlags.contains(EnumFlag.ALL)) {
if (!this.hideFlags.isEmpty() && display.hasTagCompound())
{
if (this.hideFlags.contains(FlagType.Reforged) || this.hideFlags.contains(FlagType.All))
{
display.getTagCompound().setString("tooltip", "");
}
if (this.hideFlags.contains(FlagType.Generations) || this.hideFlags.contains(FlagType.All))
{
display.getTagCompound().setBoolean("HideTooltip", true);
}
int value = 0;
for (EnumFlag flag : this.hideFlags) {
for (FlagType flag : this.hideFlags)
{
value += flag.getValue();
}
display.getTagCompound().setInteger("HideFlags", value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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.FlagType;
import ca.landonjw.gooeylibs2.api.button.GooeyButton;
import ca.landonjw.gooeylibs2.api.page.LinkedPage;
import ca.landonjw.gooeylibs2.api.page.Page;
Expand Down Expand Up @@ -67,7 +67,8 @@ public Builder lore(@Nullable Collection<String> lore) {
}

@Override
public Builder hideFlags(EnumFlag... flags) {
public Builder hideFlags(FlagType... flags)
{
super.hideFlags(flags);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +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.FlagType;
import ca.landonjw.gooeylibs2.api.button.GooeyButton;
import net.minecraft.item.ItemStack;

Expand Down Expand Up @@ -60,7 +60,8 @@ public Builder lore(@Nullable Collection<String> lore) {
return this;
}

public Builder hideFlags(EnumFlag... flags) {
public Builder hideFlags(FlagType... flags)
{
super.hideFlags(flags);
return this;
}
Expand Down

0 comments on commit 0f9f4a0

Please sign in to comment.