Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advancement GUI #498

Merged
merged 18 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ All changes are toggleable via config files.
### **🔧 TWEAKS**

* **Accurate Potion Duration:** Always displays the actual potion duration instead of `**:**`
* **Advancement GUI**
* Allows increasing the Advancement GUI to scale with the screen size
* Moves the page buttons to in-line with the rest of the GUI instead of hovering significantly
* Hides page switching buttons when at the maximum/minimum page count
* Disables the background fading when hovering over an advancement
* Adds Advancement Page Title text to the Advancement GUI header
* **Adaptive XP Drops:** Scales dropped experience from entities based on their health
* **AI Improvements:** Replaces/removes entity AI for improved server performance
* **Always Eat:** Allows the consumption of food at any time, regardless of the hunger bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.HashMap;
import java.util.Map;

import com.cleanroommc.configanytime.ConfigAnytime;
import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.core.UTLoadingPlugin;
Expand Down Expand Up @@ -1349,6 +1350,10 @@ public static class ParryCategory

public static class MiscCategory
{
@Config.LangKey("cfg.universaltweaks.tweaks.misc.advancements")
@Config.Name("Advancements")
public final AdvancementsCategory ADVANCEMENTS = new AdvancementsCategory();

@Config.LangKey("cfg.universaltweaks.tweaks.misc.armorcurve")
@Config.Name("Armor Curve")
public final ArmorCurveCategory ARMOR_CURVE = new ArmorCurveCategory();
Expand Down Expand Up @@ -1593,6 +1598,47 @@ public static class MiscCategory
})
public int utXPLevelCap = -1;


public static class AdvancementsCategory
{
@Config.RequiresMcRestart
@Config.Name("[01] Advancements Toggle")
@Config.Comment("Enables Advancement GUI Tweaks")
public boolean utAdvancementsToggle = false;

@Config.Name("[02] Size Toggle")
@Config.Comment("Enables the Vertical and Horizontal Margin settings")
public boolean utSizeToggle = true;

@Config.Name("[03] Vertical Margin")
@Config.Comment("Sets the minimum Vertical Margin of the Advancement GUI. Too high a number may cause the advancement box to render incorrectly, depending on screen size and GUI scale")
public int utVerticalMargin = 50;

@Config.Name("[04] Horizontal Margin")
@Config.Comment("Sets the minimum Horizontal Margin of the Advancement GUI. Too high a number may cause the advancement box to render incorrectly, depending on screen size and GUI scale")
public int utHorizontalMargin = 50;

@Config.Name("[05] Move Arrow Buttons")
@Config.Comment("Move the Arrow Buttons visible to change focused advancement page from above the advancement box to in the empty top corners, preventing them from going offscreen and being unusable on most vertical margin settings")
public boolean utMoveArrowButtons = true;

@Config.Name("[06] Hide Page Header")
@Config.Comment("Hides the page number header, as it will go offscreen and be unusable on most vertical margin settings, and is rarely needed due to the increased page size")
public boolean utHidePageHeader = false;

@Config.Name("[07] Hide Invalid Arrow Buttons")
@Config.Comment("Hides page switching buttons when at the maximum/minimum page count")
public boolean utHideInvalidArrowButtons = true;

@Config.Name("[08] Disable Background Fade on Hover")
@Config.Comment("Disables the background fading when hovering over an advancement")
public boolean utDisableFadeOnHover = true;

@Config.Name("[09] Add Advancement Tab Title to Header")
@Config.Comment("Makes the focused Advancement Tab Title be added to the header, which otherwise is just 'Advancements' for every tab")
public boolean utAddFocusedTabTitleToHeader = true;
}

public static class ArmorCurveCategory
{
@Config.RequiresMcRestart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
put("mixins.tweaks.entities.burning.player.json", () -> UTConfigTweaks.ENTITIES.utFirstPersonBurningOverlay != -0.3D);
put("mixins.tweaks.items.attackcooldown.client.json", () -> UTConfigTweaks.ITEMS.ATTACK_COOLDOWN.utAttackCooldownToggle);
put("mixins.tweaks.items.itementities.client.json", () -> UTConfigTweaks.ITEMS.ITEM_ENTITIES.utItemEntitiesToggle);
put("mixins.tweaks.misc.advancements.guisize.json", () -> UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle);
put("mixins.tweaks.misc.buttons.anaglyph.json", () -> UTConfigTweaks.MISC.ut3DAnaglyphButtonToggle);
put("mixins.tweaks.misc.buttons.realms.json", () -> UTConfigTweaks.MISC.utRealmsButtonToggle && !randomPatchesLoaded);
put("mixins.tweaks.misc.buttons.snooper.client.json", () -> UTConfigTweaks.MISC.utSnooperToggle);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package mod.acgaming.universaltweaks.tweaks.misc.advancements.guisize;

import mod.acgaming.universaltweaks.config.UTConfigTweaks;

// Courtesy of WaitingIdly
public class UTAdvancementInfo
{
public static final int DEFAULT_WIDTH = 252;
public static final int DEFAULT_HEIGHT = 140;
private static final int PADDING = 9;
private static final int HEIGHT_MULT = 28;
private static final int WIDTH_MULT = 32;

private static int utStepwiseWidth(int width)
{
return width / WIDTH_MULT * WIDTH_MULT;
}

private static int utStepwiseHeight(int height)
{
return height / HEIGHT_MULT * HEIGHT_MULT;
}

private static int utClampWidth(int width)
{
return Math.max(width, DEFAULT_WIDTH);
}

private static int utClampHeight(int height)
{
return Math.max(height, DEFAULT_HEIGHT);
}

public static int utPageWidth(int externalWidth)
{
return utStepwiseWidth(utClampWidth(externalWidth - UTConfigTweaks.MISC.ADVANCEMENTS.utHorizontalMargin * 2));
}

public static int utPageWidth(int externalWidth, int padding)
{
return utPageWidth(externalWidth) - padding * PADDING;
}

public static int utPageHeight(int externalHeight)
{
return utStepwiseHeight(utClampHeight(externalHeight - UTConfigTweaks.MISC.ADVANCEMENTS.utVerticalMargin * 2));
}

public static int utPageHeight(int externalHeight, int padding)
{
return utPageHeight(externalHeight) - padding * PADDING;
}

private static int utTabCountForWidth(int width)
{
return utPageWidth(width) / WIDTH_MULT;
}

private static int utTabCountForHeight(int height)
{
return utPageHeight(height) / HEIGHT_MULT;
}

public static int utTabCountForSide(int width, int height, boolean isVertical)
{
return isVertical ? utTabCountForHeight(height) : utTabCountForWidth(width);
}

public static int utMaximumTabCountPerPage(int width, int height)
{
return (utTabCountForWidth(width) + utTabCountForHeight(height)) * 2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package mod.acgaming.universaltweaks.tweaks.misc.advancements.guisize.mixin;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.advancements.AdvancementTabType;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import mod.acgaming.universaltweaks.tweaks.misc.advancements.guisize.UTAdvancementInfo;

// Courtesy of WaitingIdly
@Mixin(value = AdvancementTabType.class)
public abstract class UTAdvancementTabTypeMixin
{
@WrapOperation(method = "draw", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/advancements/AdvancementTabType;max:I"))
private int utIndex(AdvancementTabType instance, Operation<Integer> original, @Local(argsOnly = true, ordinal = 2) int index)
{
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle || Minecraft.getMinecraft().currentScreen == null)
{
return original.call(instance);
}
return UTAdvancementInfo.utTabCountForSide(Minecraft.getMinecraft().currentScreen.width, Minecraft.getMinecraft().currentScreen.height, instance == AdvancementTabType.LEFT || instance == AdvancementTabType.RIGHT);
}

@ModifyConstant(method = "getX", constant = @Constant(intValue = UTAdvancementInfo.DEFAULT_WIDTH - 4))
private int utOverrideX(int original)
{
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle || Minecraft.getMinecraft().currentScreen == null)
{
return original;
}
return UTAdvancementInfo.utPageWidth(Minecraft.getMinecraft().currentScreen.width) - 8;
}

@ModifyConstant(method = "getY", constant = @Constant(intValue = UTAdvancementInfo.DEFAULT_HEIGHT - 4))
private int utOverrideY(int original)
{
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle || Minecraft.getMinecraft().currentScreen == null)
{
return original;
}
return UTAdvancementInfo.utPageHeight(Minecraft.getMinecraft().currentScreen.height) - 4;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package mod.acgaming.universaltweaks.tweaks.misc.advancements.guisize.mixin;

import net.minecraft.client.gui.advancements.AdvancementTabType;
import net.minecraft.client.gui.advancements.GuiAdvancementTab;
import net.minecraft.client.gui.advancements.GuiScreenAdvancements;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import org.spongepowered.asm.mixin.Final;
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.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import mod.acgaming.universaltweaks.tweaks.misc.advancements.guisize.UTAdvancementInfo;

// Courtesy of WaitingIdly
@Mixin(GuiAdvancementTab.class)
public abstract class UTGuiAdvancementTabMixin
{
@Shadow
@Final
private GuiScreenAdvancements screen;

@WrapOperation(method = "create", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/advancements/AdvancementTabType;MAX_TABS:I"))
private static int utAdjustMaxTabs(Operation<Integer> original, @Local(argsOnly = true) GuiScreenAdvancements screen)
{
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original.call();
return UTAdvancementInfo.utMaximumTabCountPerPage(screen.width, screen.height);
}

@WrapOperation(method = "create", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/advancements/AdvancementTabType;getMax()I"))
private static int utAdjustIndividualMaxTabs(AdvancementTabType instance, Operation<Integer> original, @Local(argsOnly = true) GuiScreenAdvancements screen)
{
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original.call(instance);
return UTAdvancementInfo.utTabCountForSide(screen.width, screen.height, instance == AdvancementTabType.LEFT || instance == AdvancementTabType.RIGHT);
}

// update the size
@ModifyConstant(method = {"drawContents", "scroll", "drawToolTips"}, constant = @Constant(intValue = UTAdvancementInfo.DEFAULT_WIDTH - 18))
private int utDrawWidth(int original)
{
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original;
return UTAdvancementInfo.utPageWidth(screen.width, 2) - 4;
}

@ModifyConstant(method = {"drawContents", "scroll", "drawToolTips"}, constant = @Constant(intValue = UTAdvancementInfo.DEFAULT_HEIGHT - 27))
private int utDrawHeight(int original)
{
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original;
return UTAdvancementInfo.utPageHeight(screen.height, 3);
}

// origin of the shown tree within the scrollable space
@ModifyConstant(method = "drawContents", constant = @Constant(intValue = (UTAdvancementInfo.DEFAULT_WIDTH - 18) / 2))
private int utDrawContentsWidth(int original)
{
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original;
return (UTAdvancementInfo.utPageWidth(screen.width, 2) - 4) / 2;
}

@ModifyConstant(method = "drawContents", constant = @Constant(intValue = (UTAdvancementInfo.DEFAULT_HEIGHT - 27) / 2))
private int utDrawContentsHeight(int original)
{
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original;
return UTAdvancementInfo.utPageHeight(screen.height, 3) / 2;
}

// repeat the texture to fill up the drawn space
@ModifyConstant(method = "drawContents", constant = @Constant(intValue = 15))
private int utRepeatingTextureWidth(int original)
{
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original;
return (UTAdvancementInfo.utPageWidth(screen.width) - 4) / 16 + 1;
}

@ModifyConstant(method = "drawContents", constant = @Constant(intValue = 8))
private int utRepeatingTextureHeight(int original)
{
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utSizeToggle) return original;
return UTAdvancementInfo.utPageHeight(screen.height) / 16 + 1;
}

// prevents changing the fade value from 0
@ModifyExpressionValue(method = "drawToolTips", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F"))
private float utRemoveFade(float original)
{
if (!UTConfigTweaks.MISC.ADVANCEMENTS.utAdvancementsToggle || !UTConfigTweaks.MISC.ADVANCEMENTS.utDisableFadeOnHover) return original;
return 0;
}
}
Loading
Loading