diff options
author | LifeIsAParadox <LifeIsAParadox@users.noreply.github.com> | 2022-01-28 03:46:00 +0100 |
---|---|---|
committer | LifeIsAParadox <LifeIsAParadox@users.noreply.github.com> | 2022-01-28 03:46:00 +0100 |
commit | e0cefac2db16f10490c0c980686fafc6263ead9a (patch) | |
tree | 963d484eb60d238a992dca3fea0c7a4a5a18050a /src/main/java/me/xmrvizzy/skyblocker | |
parent | a3b5cad38376be3da5674480ec60f4610b321671 (diff) | |
download | Skyblocker-e0cefac2db16f10490c0c980686fafc6263ead9a.tar.gz Skyblocker-e0cefac2db16f10490c0c980686fafc6263ead9a.tar.bz2 Skyblocker-e0cefac2db16f10490c0c980686fafc6263ead9a.zip |
implementing KonaeAkira quicknav
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker')
4 files changed, 150 insertions, 2 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index 59781b4f..3eca5fd2 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -39,6 +39,10 @@ public class SkyblockerConfig implements ConfigData { @ConfigEntry.Gui.CollapsibleObject(startExpanded = true) public ItemList itemList = new ItemList(); + @ConfigEntry.Category("quicknav") + @ConfigEntry.Gui.CollapsibleObject(startExpanded = true) + public Quicknav quicknav = new Quicknav(); + @ConfigEntry.Gui.Excluded public List<Integer> lockedSlots = new ArrayList<>(); } @@ -47,8 +51,7 @@ public class SkyblockerConfig implements ConfigData { public boolean enableBars = true; } public static class RichPresence { - @ConfigEntry.Gui.Tooltip() - public boolean enableRichPresence = true; + public boolean enableRichPresence = false; @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public Info info = Info.LOCATION; public String customMessage; @@ -58,6 +61,10 @@ public class SkyblockerConfig implements ConfigData { public boolean enableItemList = true; } + public static class Quicknav { + public boolean enableQuicknav = true; + } + public static class Locations { @ConfigEntry.Category("dungeons") @ConfigEntry.Gui.CollapsibleObject(startExpanded = true) diff --git a/src/main/java/me/xmrvizzy/skyblocker/mixin/HandledScreenMixin.java b/src/main/java/me/xmrvizzy/skyblocker/mixin/HandledScreenMixin.java index 0ed976f3..ef1f99fa 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/mixin/HandledScreenMixin.java +++ b/src/main/java/me/xmrvizzy/skyblocker/mixin/HandledScreenMixin.java @@ -2,17 +2,24 @@ package me.xmrvizzy.skyblocker.mixin; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import me.xmrvizzy.skyblocker.skyblock.itemlist.ItemListWidget; +import me.xmrvizzy.skyblocker.skyblock.quicknav.QuickNav; +import me.xmrvizzy.skyblocker.skyblock.quicknav.QuickNavButton; import me.xmrvizzy.skyblocker.utils.Utils; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.text.Text; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.List; @Mixin(HandledScreen.class) public abstract class HandledScreenMixin extends Screen { + @Shadow protected int backgroundWidth; + @Shadow protected int backgroundHeight; + protected HandledScreenMixin(Text title) { super(title); } @@ -22,5 +29,18 @@ public abstract class HandledScreenMixin extends Screen { if (Utils.isSkyblock && SkyblockerConfig.get().general.itemList.enableItemList) { super.addDrawableChild(new ItemListWidget((HandledScreen)(Object)this)); } + + // quicknav + if (Utils.isSkyblock && SkyblockerConfig.get().general.quicknav.enableQuicknav) { + String title = super.getTitle().getString().trim(); + int left_x = (super.width - this.backgroundWidth) / 2 + 4; + int right_x = (super.width + this.backgroundWidth) / 2 - 3; + int top_y = (super.height - this.backgroundHeight) / 2 - 28; + int bottom_y = (super.height + this.backgroundHeight) / 2 - 4; + if (this.backgroundHeight > 166) --bottom_y; // why is this even a thing + List<QuickNavButton> buttons = QuickNav.init(title, left_x, right_x, top_y, bottom_y); + for (QuickNavButton button : buttons) super.addDrawableChild(button); + + } } } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/quicknav/QuickNav.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/quicknav/QuickNav.java new file mode 100644 index 00000000..b86e6e32 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/quicknav/QuickNav.java @@ -0,0 +1,35 @@ +package me.xmrvizzy.skyblocker.skyblock.quicknav; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.nbt.StringNbtReader; + +import java.util.ArrayList; +import java.util.List; + +public class QuickNav { + public static List<QuickNavButton> init(String title, int left_x, int right_x, int top_y, int bottom_y) { + List<QuickNavButton> buttons = new ArrayList<>(); + + buttons.add(new QuickNavButton(left_x + 29 * 0, top_y, QuickNavButton.Type.TOP, title.contains("Your Skills"), "/skills", new ItemStack(Items.DIAMOND_SWORD))); + buttons.add(new QuickNavButton(left_x + 29 * 1, top_y, QuickNavButton.Type.TOP, title.contains("Collection"), "/collection", new ItemStack(Items.PAINTING))); + + buttons.add(new QuickNavButton(right_x - 29 * 1, bottom_y, QuickNavButton.Type.BOTTOM, title.contains("Craft Item"), "/craft", new ItemStack(Items.CRAFTING_TABLE))); + buttons.add(new QuickNavButton(right_x - 29 * 2, bottom_y, QuickNavButton.Type.BOTTOM, title.contains("Anvil"), "/anvil", new ItemStack(Items.ANVIL))); + buttons.add(new QuickNavButton(right_x - 29 * 3, bottom_y, QuickNavButton.Type.BOTTOM, title.contains("Enchant Item"), "/etable", new ItemStack(Items.ENCHANTING_TABLE))); + + buttons.add(new QuickNavButton(left_x + 29 * 0, bottom_y, QuickNavButton.Type.BOTTOM, false, "/warp hub", new ItemStack(Items.COMPASS))); + buttons.add(new QuickNavButton(left_x + 29 * 1, bottom_y, QuickNavButton.Type.BOTTOM, false, "/warp dungeon_hub", new ItemStack(Items.WITHER_SKELETON_SKULL))); + + buttons.add(new QuickNavButton(right_x - 29 * 1, top_y, QuickNavButton.Type.TOP, title.contains("Storage"), "/storage", new ItemStack(Items.ENDER_CHEST))); + try { + buttons.add(new QuickNavButton(right_x - 29 * 2, top_y, QuickNavButton.Type.TOP, title.contains("Wardrobe"), "/wardrobe", ItemStack.fromNbt(StringNbtReader.parse("{id:\"minecraft:leather_chestplate\", Count:1, tag:{display:{color:8991416}}}")))); + } catch (CommandSyntaxException e) { + e.printStackTrace(); + } + buttons.add(new QuickNavButton(right_x - 29 * 3, top_y, QuickNavButton.Type.TOP, title.contains("Pets"), "/pets", new ItemStack(Items.BONE))); + + return buttons; + } +} diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/quicknav/QuickNavButton.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/quicknav/QuickNavButton.java new file mode 100644 index 00000000..8e79b08e --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/quicknav/QuickNavButton.java @@ -0,0 +1,86 @@ +package me.xmrvizzy.skyblocker.skyblock.quicknav; + +import com.mojang.blaze3d.systems.RenderSystem; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; +import net.minecraft.client.gui.widget.ClickableWidget; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.item.ItemStack; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Identifier; + +@Environment(value=EnvType.CLIENT) +public class QuickNavButton extends ClickableWidget { + private static final MinecraftClient CLIENT = MinecraftClient.getInstance(); + private static final Identifier BUTTON_TEXTURE = new Identifier("textures/gui/container/creative_inventory/tabs.png"); + + @Override + public void appendNarrations(NarrationMessageBuilder builder) { + + } + + public enum Type { + TOP, + BOTTOM, + } + + private final Type type; + private boolean toggled; + private int u; + private int v; + private final String command; + private final ItemStack icon; + + public QuickNavButton(int x, int y, Type type, boolean toggled, String command, ItemStack icon) { + super(x, y, 28, 32, LiteralText.EMPTY); + this.type = type; + if (type == Type.BOTTOM) { + this.u = 28; + this.v = 64; + } else { + this.u = 28; + this.v = 0; + } + this.toggled = toggled; + if (toggled) this.v += 32; + this.command = command; + this.icon = icon; + } + + @Override + public void onClick(double mouseX, double mouseY) { + if (!this.toggled) { + this.toggled = true; + this.v += 32; + CLIENT.player.sendChatMessage(command); + } + } + + @Override + public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) { + RenderSystem.setShaderTexture(0, BUTTON_TEXTURE); + RenderSystem.disableDepthTest(); + // render button background + if (!this.toggled) { + if (this.type == Type.BOTTOM) + this.drawTexture(matrices, this.x, this.y + 4, this.u, this.v + 4, this.width, this.height - 4); + else + this.drawTexture(matrices, this.x, this.y, this.u, this.v, this.width, this.height - 4); + } else this.drawTexture(matrices, this.x, this.y, this.u, this.v, this.width, this.height); + // render button icon + if (!this.toggled) { + if (this.type == Type.BOTTOM) + CLIENT.getItemRenderer().renderInGui(this.icon,this.x + 6, this.y + 6); + else + CLIENT.getItemRenderer().renderInGui(this.icon,this.x + 6, this.y + 9); + } else { + if (this.type == Type.BOTTOM) + CLIENT.getItemRenderer().renderInGui(this.icon,this.x + 6, this.y + 9); + else + CLIENT.getItemRenderer().renderInGui(this.icon,this.x + 6, this.y + 6); + } + RenderSystem.enableDepthTest(); + } +} |