Skip to content

Commit

Permalink
Merge branch '1.12.2-latest' into 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
landonjw committed Jul 11, 2021
2 parents 20a2b3a + b461bab commit 3f4c218
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/main/java/ca/landonjw/gooeylibs2/api/button/EnumFlag.java
Original file line number Diff line number Diff line change
@@ -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 this.value;
}
}
28 changes: 26 additions & 2 deletions src/main/java/ca/landonjw/gooeylibs2/api/button/GooeyButton.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
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.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;

public class GooeyButton extends ButtonBase {
Expand All @@ -33,13 +38,20 @@ 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 {

protected ItemStack display;
protected String title;
protected Collection<String> lore = Lists.newArrayList();
protected Consumer<ButtonAction> onClick;
protected List<EnumFlag> hideFlags = new ArrayList<>();

public Builder display(@Nonnull ItemStack display) {
this.display = display;
Expand All @@ -56,6 +68,11 @@ public Builder lore(@Nullable Collection<String> lore) {
return this;
}

public Builder hideFlags(EnumFlag... flags) {
this.hideFlags = Arrays.asList(flags);
return this;
}

public Builder onClick(@Nullable Consumer<ButtonAction> behaviour) {
this.onClick = behaviour;
return this;
Expand Down Expand Up @@ -88,8 +105,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) || this.hideFlags.contains(EnumFlag.ALL)) {
display.getTagCompound().setString("tooltip", "");
}
int value = 0;
for (EnumFlag flag : this.hideFlags) {
value += flag.getValue();
}
display.getTagCompound().setInteger("HideFlags", value);
}
return display;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

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;
import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.function.Consumer;

public class LinkedPageButton extends GooeyButton {
Expand Down Expand Up @@ -58,6 +60,24 @@ public Builder title(@Nullable String title) {
return this;
}

@Override
public Builder lore(@Nullable Collection<String> 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<ButtonAction> behaviour) {
super.onClick(behaviour);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

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

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

public Builder onClick(@Nullable Consumer<ButtonAction> behaviour) {
super.onClick(behaviour);
return this;
Expand Down

0 comments on commit 3f4c218

Please sign in to comment.