Skip to content

Commit

Permalink
Brewing stand overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterCheezeCake committed Aug 27, 2024
1 parent 5b941f6 commit 2633d3a
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 32 deletions.
4 changes: 4 additions & 0 deletions src/main/java/wtf/cheeze/sbt/config/ConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/wtf/cheeze/sbt/config/categories/General.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/wtf/cheeze/sbt/features/BrewingStandOverlay.java
Original file line number Diff line number Diff line change
@@ -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<Slot> 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.<Boolean>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();


}

}

}
21 changes: 20 additions & 1 deletion src/main/java/wtf/cheeze/sbt/mixin/HandledScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends ScreenHandler> 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);}
}
2 changes: 1 addition & 1 deletion src/main/java/wtf/cheeze/sbt/utils/hud/BarHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/wtf/cheeze/sbt/utils/hud/HudLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/wtf/cheeze/sbt/utils/hud/TextHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/wtf/cheeze/sbt/utils/render/Color3f.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
* You should have received a copy of the GNU Lesser General Public License
* along with SkyblockTweaks. If not, see <https://www.gnu.org/licenses/>.
*/
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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
}
}
15 changes: 15 additions & 0 deletions src/main/java/wtf/cheeze/sbt/utils/render/ScreenBounds.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 2633d3a

Please sign in to comment.