diff --git a/src/main/java/wtf/cheeze/sbt/config/ConfigImpl.java b/src/main/java/wtf/cheeze/sbt/config/ConfigImpl.java index c7915c3..19fe1ce 100644 --- a/src/main/java/wtf/cheeze/sbt/config/ConfigImpl.java +++ b/src/main/java/wtf/cheeze/sbt/config/ConfigImpl.java @@ -21,6 +21,7 @@ import dev.isxander.yacl3.config.v2.api.SerialEntry; import wtf.cheeze.sbt.config.categories.General; import wtf.cheeze.sbt.config.categories.Huds; +import wtf.cheeze.sbt.features.BrewingStandOverlay; import wtf.cheeze.sbt.features.MenuHighlights; import wtf.cheeze.sbt.features.PartyFeatures; import wtf.cheeze.sbt.utils.Version; @@ -49,6 +50,9 @@ public class ConfigImpl { @SerialEntry public PartyFeatures.Config partyCommands = new PartyFeatures.Config(); + @SerialEntry + public BrewingStandOverlay.Config brewingStandOverlay = new BrewingStandOverlay.Config(); + @SerialEntry public Huds huds = new Huds(); diff --git a/src/main/java/wtf/cheeze/sbt/config/SkyblockTweaksScreenMain.java b/src/main/java/wtf/cheeze/sbt/config/SkyblockTweaksScreenMain.java index 56c1a74..eb08d8c 100644 --- a/src/main/java/wtf/cheeze/sbt/config/SkyblockTweaksScreenMain.java +++ b/src/main/java/wtf/cheeze/sbt/config/SkyblockTweaksScreenMain.java @@ -26,7 +26,7 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; import wtf.cheeze.sbt.SkyblockTweaks; -import wtf.cheeze.sbt.utils.RenderUtils; +import wtf.cheeze.sbt.utils.render.RenderUtils; import wtf.cheeze.sbt.utils.hud.HudScreen; public class SkyblockTweaksScreenMain extends Screen { diff --git a/src/main/java/wtf/cheeze/sbt/config/categories/General.java b/src/main/java/wtf/cheeze/sbt/config/categories/General.java index fb671fd..16a3862 100644 --- a/src/main/java/wtf/cheeze/sbt/config/categories/General.java +++ b/src/main/java/wtf/cheeze/sbt/config/categories/General.java @@ -8,6 +8,7 @@ import net.minecraft.text.Text; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SkyblockTweaksConfig; +import wtf.cheeze.sbt.features.BrewingStandOverlay; import wtf.cheeze.sbt.features.MenuHighlights; import wtf.cheeze.sbt.features.PartyFeatures; import wtf.cheeze.sbt.utils.Version; @@ -21,6 +22,7 @@ public static ConfigCategory getCategory(ConfigImpl defaults, ConfigImpl config) .option(Version.getStreamOption(defaults, config)) .group(InventoryTweaks.getGroup(defaults, config)) .group(MenuHighlights.Config.getGroup(defaults, config)) + .group(BrewingStandOverlay.Config.getGroup(defaults, config)) .group(PartyFeatures.Config.getGroup(defaults, config)) .option(PartyFeatures.Config.getBlackList(defaults, config)) .group(HudTweaks.getGroup(defaults, config)) diff --git a/src/main/java/wtf/cheeze/sbt/features/BrewingStandOverlay.java b/src/main/java/wtf/cheeze/sbt/features/BrewingStandOverlay.java new file mode 100644 index 0000000..c7b3d1b --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/features/BrewingStandOverlay.java @@ -0,0 +1,85 @@ +package wtf.cheeze.sbt.features; + +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.OptionDescription; +import dev.isxander.yacl3.api.OptionGroup; +import dev.isxander.yacl3.config.v2.api.SerialEntry; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.screen.slot.Slot; +import net.minecraft.text.Text; +import net.minecraft.util.collection.DefaultedList; +import wtf.cheeze.sbt.SkyblockTweaks; +import wtf.cheeze.sbt.config.ConfigImpl; +import wtf.cheeze.sbt.config.SkyblockTweaksConfig; +import wtf.cheeze.sbt.utils.render.RenderUtils; + +public class BrewingStandOverlay { + + private static final int DRAW_OFFSET_X = 20; + private static final int DRAW_OFFSET_Y = 4; + // One more than the z offset that items are rendered at + private static final float Z_OFFSET = 250.0f; + + public static void render(DefaultedList slots, DrawContext context) { + if (!SkyblockTweaks.CONFIG.config.brewingStandOverlay.enabled) return; + + var slot13 = slots.get(13); + var slot24 = slots.get(24); + var slot42 = slots.get(42); + + context.getMatrices().push(); + context.getMatrices().translate(0.0f, 0.0f, Z_OFFSET); + + if (slot13.hasStack()) { + drawName(slot13, context); + } + if (!slot24.getStack().getName().getString().startsWith("Place Water Bottles")) { + drawName(slot24, context); + } + if (slot42.hasStack()) { + drawName(slot42, context); + } + context.getMatrices().pop(); + } + + private static void drawName(Slot slot, DrawContext context) { + var name = slot.getStack().getName(); + var color = name.getStyle().getColor(); + int rcolor; + if (color == null) { + rcolor = 0xFFFFFF; + } else { + rcolor = color.getRgb(); + } + RenderUtils.drawString(context, name, slot.x + DRAW_OFFSET_X, slot.y + DRAW_OFFSET_Y, rcolor, false); + } + + public static class Config { + @SerialEntry + public boolean enabled = true; + + public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { + var enabled = Option.createBuilder() + .name(Text.literal("Brewing Stand Overlay")) + .description(OptionDescription.of(Text.literal("Enables the overlay for the brewing stand"))) + .controller(SkyblockTweaksConfig::generateBooleanController) + .binding( + defaults.brewingStandOverlay.enabled, + () -> config.brewingStandOverlay.enabled, + value -> config.brewingStandOverlay.enabled = (Boolean) value + ) + .build(); + + return OptionGroup.createBuilder() + .name(Text.literal("Brewing Stand Overlay")) + .description(OptionDescription.of(Text.literal("Options for the brewing stand overlay"))) + .option(enabled) + .build(); + + + } + + } + +} diff --git a/src/main/java/wtf/cheeze/sbt/mixin/HandledScreenMixin.java b/src/main/java/wtf/cheeze/sbt/mixin/HandledScreenMixin.java index da92aca..a2010de 100644 --- a/src/main/java/wtf/cheeze/sbt/mixin/HandledScreenMixin.java +++ b/src/main/java/wtf/cheeze/sbt/mixin/HandledScreenMixin.java @@ -20,30 +20,49 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.BrewingStandScreen; import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.screen.BrewingStandScreenHandler; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; +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.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import wtf.cheeze.sbt.features.BrewingStandOverlay; import wtf.cheeze.sbt.features.MenuHighlights; @Mixin(HandledScreen.class) public abstract class HandledScreenMixin extends Screen { + + @Shadow @Final protected T handler; + + @Shadow protected int x; + + @Shadow protected int y; + @Inject(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawItem(Lnet/minecraft/item/ItemStack;III)V")) - protected void sbt$onDrawSlot(DrawContext context, Slot slot, CallbackInfo ci) { + protected void sbt$beforeDrawItem(DrawContext context, Slot slot, CallbackInfo ci) { var title = this.getTitle().getString(); switch (title) { case "SkyBlock Hub Selector" -> MenuHighlights.tryDrawHighlight(context, slot); case "Dungeon Hub Selector" -> MenuHighlights.tryDrawHighlightDH(context, slot); case "Heart of the Mountain" -> MenuHighlights.tryDrawHighlightHOTM(context, slot); + case "Brewing Stand" -> { + // We do this so it only attempts to handle Skyblock brewing stands, not vanilla ones + if (this.handler instanceof BrewingStandScreenHandler) return; + if (slot.id == 13) BrewingStandOverlay.render(handler.slots, context); + + } } if (title.contains("Widget") || title.contains("Setting")) { MenuHighlights.tryDrawHighlightWidget(context, slot); } } + private HandledScreenMixin(Text t) {super(t);} } diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/BarHUD.java b/src/main/java/wtf/cheeze/sbt/utils/hud/BarHUD.java index e719f39..588cf38 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/BarHUD.java +++ b/src/main/java/wtf/cheeze/sbt/utils/hud/BarHUD.java @@ -21,7 +21,7 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.util.Identifier; import wtf.cheeze.sbt.SkyblockTweaks; -import wtf.cheeze.sbt.utils.RenderUtils; +import wtf.cheeze.sbt.utils.render.RenderUtils; /** * A HUD that displays a bar, code liberally inspired by SBA, but way simpler thanks to modern mc, bar textures taken directly from SBA diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/HudLine.java b/src/main/java/wtf/cheeze/sbt/utils/hud/HudLine.java index b476b02..68d7e6b 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/HudLine.java +++ b/src/main/java/wtf/cheeze/sbt/utils/hud/HudLine.java @@ -3,9 +3,8 @@ import dev.isxander.yacl3.api.NameableEnum; import net.minecraft.client.gui.DrawContext; import net.minecraft.text.Text; -import net.minecraft.util.Identifier; import org.jetbrains.annotations.Nullable; -import wtf.cheeze.sbt.utils.RenderUtils; +import wtf.cheeze.sbt.utils.render.RenderUtils; import java.util.function.Supplier; diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/TextHUD.java b/src/main/java/wtf/cheeze/sbt/utils/hud/TextHUD.java index d5940f2..48f480d 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/TextHUD.java +++ b/src/main/java/wtf/cheeze/sbt/utils/hud/TextHUD.java @@ -20,7 +20,7 @@ import net.minecraft.client.gui.DrawContext; import wtf.cheeze.sbt.SkyblockTweaks; -import wtf.cheeze.sbt.utils.RenderUtils; +import wtf.cheeze.sbt.utils.render.RenderUtils; public abstract class TextHUD extends HUD { //public abstract String getText(); diff --git a/src/main/java/wtf/cheeze/sbt/utils/render/Color3f.java b/src/main/java/wtf/cheeze/sbt/utils/render/Color3f.java new file mode 100644 index 0000000..7db6583 --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/utils/render/Color3f.java @@ -0,0 +1,14 @@ +package wtf.cheeze.sbt.utils.render; + +public class Color3f { + + public float red; + public float green; + public float blue; + + Color3f (int color) { + this.red = (float) (color >> 16 & 255) / 255.0F; + this.green = (float) (color >> 8 & 255) / 255.0F; + this.blue = (float) (color & 255) / 255.0F; + } +} diff --git a/src/main/java/wtf/cheeze/sbt/utils/RenderUtils.java b/src/main/java/wtf/cheeze/sbt/utils/render/RenderUtils.java similarity index 67% rename from src/main/java/wtf/cheeze/sbt/utils/RenderUtils.java rename to src/main/java/wtf/cheeze/sbt/utils/render/RenderUtils.java index 0c35caa..80ef650 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/RenderUtils.java +++ b/src/main/java/wtf/cheeze/sbt/utils/render/RenderUtils.java @@ -16,12 +16,15 @@ * You should have received a copy of the GNU Lesser General Public License * along with SkyblockTweaks. If not, see . */ -package wtf.cheeze.sbt.utils; +package wtf.cheeze.sbt.utils.render; +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.Window; +import net.minecraft.client.render.*; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; +import net.minecraft.util.math.Vec3d; import wtf.cheeze.sbt.SkyblockTweaks; public class RenderUtils { @@ -33,6 +36,7 @@ public static void beginScale(DrawContext context, float scale) { public static void endScale(DrawContext context) { context.getMatrices().pop(); } + public static void drawString(DrawContext context, Text text, int x, int y, int color, boolean shadow, float scale) { beginScale(context, scale); drawString(context, text, (int) (x/scale), (int) (y/scale), color, shadow); @@ -66,20 +70,6 @@ public static void drawCenteredString(DrawContext context, Text text, int x, int drawString(context, text, x - width / 2, y, color, shadow); } - public static class ScreenBounds { - public int width; - public int height; - private ScreenBounds() { - Window window = MinecraftClient.getInstance().getWindow(); - this.width = window.getScaledWidth(); - this.height = window.getScaledHeight(); - } - } - - public static ScreenBounds getScreenBounds() { - return new ScreenBounds(); - } - public static int getStringWidth(Text text) { return SkyblockTweaks.mc.textRenderer.getWidth(text); } @@ -93,16 +83,40 @@ public static int getRelativeStringWidth(String text) { public static Color3f getColor3f(int color) { return new Color3f(color); } - public static class Color3f { + public static ScreenBounds getScreenBounds() { + return new ScreenBounds(); + } - public float red; - public float green; - public float blue; + // public static class Color4f extends Color3f { +// public float alpha; +// +// private Color4f(int color) { +// super(color); +// this.alpha = (float) (color >> 24 & 255) / 255.0F; +// } +// } +// public static Color4f getColor4f(int color) { +// return new Color4f(color); +// } + // Adapted from Skyblocker +// private static void renderFilledInternal(WorldRenderContext context, Vec3d pos, Vec3d dimensions, Color3f color, float alpha, boolean throughWalls) { +// var matrices = context.matrixStack(); +// var camera = context.camera().getPos(); +// matrices.push(); +// matrices.translate(-camera.x, -camera.y, -camera.z); +// var consumers = context.consumers(); +// var buffer = consumers.getBuffer(throughWalls ? SkyblockerRenderLayers.FILLED_THROUGH_WALLS : SkyblockerRenderLayers.FILLED); +// WorldRenderer.renderFilledBox(matrices, buffer, pos.x, pos.y, pos.z, pos.x + dimensions.x, pos.y + dimensions.y, pos.z + dimensions.z, color.red, color.green, color.blue, alpha); +// matrices.pop(); +// } +// +// +// public static final RenderLayer.MultiPhase FILLED = RenderLayer.of("filled", VertexFormats.POSITION_COLOR, VertexFormat.DrawMode.TRIANGLE_STRIP, RenderLayer.CUTOUT_BUFFER_SIZE, false, true, RenderLayer.MultiPhaseParameters.builder() +// .program(RenderPhase.COLOR_PROGRAM) +// .cull(RenderPhase.Cull.DISABLE_CULLING) +// .layering(RenderPhase.POLYGON_OFFSET_LAYERING) +// .transparency(DEFAULT_TRANSPARENCY) +// .depthTest(RenderPhase.DepthTest.LEQUAL_DEPTH_TEST) +// .build(false)); - private Color3f(int color) { - this.red = (float) (color >> 16 & 255) / 255.0F; - this.green = (float) (color >> 8 & 255) / 255.0F; - this.blue = (float) (color & 255) / 255.0F; - } - } } diff --git a/src/main/java/wtf/cheeze/sbt/utils/render/ScreenBounds.java b/src/main/java/wtf/cheeze/sbt/utils/render/ScreenBounds.java new file mode 100644 index 0000000..e035cab --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/utils/render/ScreenBounds.java @@ -0,0 +1,15 @@ +package wtf.cheeze.sbt.utils.render; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.util.Window; + +public class ScreenBounds { + public int width; + public int height; + + ScreenBounds() { + Window window = MinecraftClient.getInstance().getWindow(); + this.width = window.getScaledWidth(); + this.height = window.getScaledHeight(); + } +}