Skip to content

Commit

Permalink
Update to 1.21 (again) (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 authored Jun 25, 2024
1 parent c8da0ae commit 231cae6
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 115 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G

minecraft_version=1.20.6
quilt_mappings=6
minecraft_version=1.21
quilt_mappings=2
loader_version=0.15.11

# Mod Properties
Expand All @@ -12,5 +12,5 @@ archives_base_name=spruceui

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_api_version=0.100.4+1.20.6
modmenu_version=10.0.0
fabric_api_version=0.100.4+1.21
modmenu_version=11.0.1
18 changes: 9 additions & 9 deletions src/main/java/dev/lambdaurora/spruceui/SpruceTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ private SpruceTextures() {

/* Backgrounds */

public static final Identifier MENU_LIST_BACKGROUND = new Identifier("textures/gui/menu_list_background.png");
public static final Identifier INWORLD_MENU_LIST_BACKGROUND = new Identifier("textures/gui/inworld_menu_list_background.png");
public static final Identifier MENU_LIST_BACKGROUND = Identifier.ofDefault("textures/gui/menu_list_background.png");
public static final Identifier INWORLD_MENU_LIST_BACKGROUND = Identifier.ofDefault("textures/gui/inworld_menu_list_background.png");

/**
* The dirt background texture used in pre-1.20.5 versions.
*/
public static final Identifier LEGACY_OPTIONS_BACKGROUND = new Identifier("spruceui", "textures/gui/legacy_options_background.png");
public static final Identifier LEGACY_OPTIONS_BACKGROUND = Identifier.of("spruceui", "textures/gui/legacy_options_background.png");

/* Border */

public static final Identifier MENU_TOP_BORDER = Screen.HEADER_SEPARATOR;
public static final Identifier INWORLD_MENU_TOP_BORDER = Screen.INWORLD_HEADER_SEPARATOR;
public static final Identifier MENU_TOP_RIGHT_BORDER = new Identifier("spruceui", "textures/gui/top_right_border_separator.png");
public static final Identifier INWORLD_MENU_TOP_RIGHT_BORDER = new Identifier("spruceui", "textures/gui/inworld_top_right_border_separator.png");
public static final Identifier MENU_RIGHT_BORDER = new Identifier("spruceui", "textures/gui/right_border_separator.png");
public static final Identifier INWORLD_MENU_RIGHT_BORDER = new Identifier("spruceui", "textures/gui/inworld_right_border_separator.png");
public static final Identifier MENU_BOTTOM_RIGHT_BORDER = new Identifier("spruceui", "textures/gui/bottom_right_border_separator.png");
public static final Identifier INWORLD_MENU_BOTTOM_RIGHT_BORDER = new Identifier("spruceui", "textures/gui/inworld_bottom_right_border_separator.png");
public static final Identifier MENU_TOP_RIGHT_BORDER = Identifier.of("spruceui", "textures/gui/top_right_border_separator.png");
public static final Identifier INWORLD_MENU_TOP_RIGHT_BORDER = Identifier.of("spruceui", "textures/gui/inworld_top_right_border_separator.png");
public static final Identifier MENU_RIGHT_BORDER = Identifier.of("spruceui", "textures/gui/right_border_separator.png");
public static final Identifier INWORLD_MENU_RIGHT_BORDER = Identifier.of("spruceui", "textures/gui/inworld_right_border_separator.png");
public static final Identifier MENU_BOTTOM_RIGHT_BORDER = Identifier.of("spruceui", "textures/gui/bottom_right_border_separator.png");
public static final Identifier INWORLD_MENU_BOTTOM_RIGHT_BORDER = Identifier.of("spruceui", "textures/gui/inworld_bottom_right_border_separator.png");
public static final Identifier MENU_BOTTOM_BORDER = Screen.FOOTER_SEPARATOR;
public static final Identifier INWORLD_MENU_BOTTOM_BORDER = Screen.INWORLD_FOOTER_SEPARATOR;
}
18 changes: 9 additions & 9 deletions src/main/java/dev/lambdaurora/spruceui/border/SimpleBorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
package dev.lambdaurora.spruceui.border;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.Tessellator;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormats;
import com.mojang.blaze3d.vertex.*;
import dev.lambdaurora.spruceui.util.ColorUtil;
import dev.lambdaurora.spruceui.widget.SpruceWidget;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.unmapped.C_fpcijbbg;

import java.util.Arrays;

Expand Down Expand Up @@ -58,9 +56,8 @@ public SimpleBorder(int thickness, int red, int green, int blue, int alpha, int
@Override
public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mouseY, float delta) {
var tessellator = Tessellator.getInstance();
var buffer = tessellator.getBufferBuilder();
var buffer = tessellator.method_60827(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
RenderSystem.setShader(GameRenderer::getPositionColorShader);
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
int x = widget.getX();
int y = widget.getY();
int right = x + widget.getWidth();
Expand All @@ -86,13 +83,16 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mo
this.vertex(buffer, x + this.thickness, bottom, focused);
this.vertex(buffer, x + this.thickness, y, focused);
this.vertex(buffer, x, y, focused);
tessellator.draw();

C_fpcijbbg builtBuffer = buffer.method_60794();
if (builtBuffer != null) {
BufferRenderer.drawWithShader(builtBuffer);
}
tessellator.method_60828();
}

private void vertex(BufferBuilder buffer, int x, int y, boolean focused) {
int[] color = focused ? this.focusedColor : this.color;
buffer.vertex(x, y, 0).color(color[0], color[1], color[2], color[3]).next();
buffer.method_22912(x, y, 0).method_1336(color[0], color[1], color[2], color[3]);
}

@Override
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/dev/lambdaurora/spruceui/hud/Hud.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import dev.lambdaurora.spruceui.util.Identifiable;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.render.DeltaTracker;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -97,11 +98,11 @@ public void init(@NotNull MinecraftClient client, int screenWidth, int screenHei
/**
* Renders the HUD if enabled.
*
* @param tickDelta Progress for linearly interpolating between the previous and current game state.
* @param deltaTracker Progress for linearly interpolating between the previous and current game state.
* @see #isEnabled()
*/
public void render(GuiGraphics graphics, float tickDelta) {
this.components.stream().filter(HudComponent::isEnabled).forEach(component -> component.render(graphics, tickDelta));
public void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
this.components.stream().filter(HudComponent::isEnabled).forEach(component -> component.render(graphics, deltaTracker));
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/dev/lambdaurora/spruceui/hud/HudComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import dev.lambdaurora.spruceui.util.Identifiable;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.render.DeltaTracker;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -63,10 +64,10 @@ public void setEnabled(boolean enabled) {
/**
* Renders the HUD component if enabled.
*
* @param tickDelta Progress for linearly interpolating between the previous and current game state.
* @param deltaTracker Progress for linearly interpolating between the previous and current game state.
* @see #isEnabled()
*/
public abstract void render(GuiGraphics graphics, float tickDelta);
public abstract void render(GuiGraphics graphics, DeltaTracker deltaTracker);

/**
* Updates the HUD each tick if enabled and has tick updates.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/lambdaurora/spruceui/hud/HudManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class HudManager {
private static final Map<Identifier, Hud> HUDS = new Object2ObjectOpenHashMap<>();

public void initialize() {
HudRenderCallback.EVENT.register((graphics, tickDelta) -> HUDS.forEach((id, hud) -> {
HudRenderCallback.EVENT.register((graphics, deltaTracker) -> HUDS.forEach((id, hud) -> {
if (hud.isEnabled() && hud.isVisible())
hud.render(graphics, tickDelta);
hud.render(graphics, deltaTracker);
}));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (!canRenderHuds(client))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import dev.lambdaurora.spruceui.hud.HudComponent;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.render.DeltaTracker;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

Expand Down Expand Up @@ -75,7 +76,7 @@ public void setColor(int color) {
}

@Override
public void render(GuiGraphics graphics, float tickDelta) {
public void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
graphics.drawShadowedText(this.client.textRenderer, this.text, this.x, this.y, this.color);
}
}
66 changes: 38 additions & 28 deletions src/main/java/dev/lambdaurora/spruceui/util/RenderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
package dev.lambdaurora.spruceui.util;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferRenderer;
import com.mojang.blaze3d.vertex.Tessellator;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormats;
import dev.lambdaurora.spruceui.SpruceTextures;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.unmapped.C_fpcijbbg;

public final class RenderUtil {
private RenderUtil() {
Expand Down Expand Up @@ -51,28 +53,31 @@ public static void renderBackgroundTexture(int x, int y, int width, int height,
public static void renderBackgroundTexture(int x, int y, int width, int height, float vOffset,
int red, int green, int blue, int alpha) {
var tessellator = Tessellator.getInstance();
var bufferBuilder = tessellator.getBufferBuilder();
var bufferBuilder = tessellator.method_60827(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f);
RenderSystem.setShaderTexture(0, SpruceTextures.LEGACY_OPTIONS_BACKGROUND);

int right = x + width;
int bottom = y + height;

bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
bufferBuilder.vertex(x, bottom, 0)
.uv(0, bottom / 32.f + vOffset)
.color(red, green, blue, alpha).next();
bufferBuilder.vertex(right, bottom, 0)
.uv(right / 32.f, bottom / 32.f + vOffset)
.color(red, green, blue, alpha).next();
bufferBuilder.vertex(right, y, 0)
.uv(right / 32.f, y / 32.f + vOffset)
.color(red, green, blue, alpha).next();
bufferBuilder.vertex(x, y, 0)
.uv(0, y / 32.f + vOffset)
.color(red, green, blue, alpha).next();
tessellator.draw();
bufferBuilder.method_22912(x, bottom, 0)
.method_22913(0, bottom / 32.f + vOffset)
.method_1336(red, green, blue, alpha);
bufferBuilder.method_22912(right, bottom, 0)
.method_22913(right / 32.f, bottom / 32.f + vOffset)
.method_1336(red, green, blue, alpha);
bufferBuilder.method_22912(right, y, 0)
.method_22913(right / 32.f, y / 32.f + vOffset)
.method_1336(red, green, blue, alpha);
bufferBuilder.method_22912(x, y, 0)
.method_22913(0, y / 32.f + vOffset)
.method_1336(red, green, blue, alpha);
C_fpcijbbg builtBuffer = bufferBuilder.method_60794();
if (builtBuffer != null) {
BufferRenderer.drawWithShader(builtBuffer);
}
tessellator.method_60828();
}

/**
Expand All @@ -89,25 +94,30 @@ public static void renderBackgroundTexture(int x, int y, int width, int height,
*/
public static void renderSelectionBox(int x, int y, int width, int height, int red, int green, int blue, int alpha) {
var tessellator = Tessellator.getInstance();
var bufferBuilder = tessellator.getBufferBuilder();
var bufferBuilder = tessellator.method_60827(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);

int top = y + height;
int right = x + width;

RenderSystem.setShader(GameRenderer::getPositionColorShader);
RenderSystem.setShaderColor(red / 255.f, green / 255.f, blue / 255.f, alpha / 255.f);
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);
bufferBuilder.vertex(x, top, 0).next();
bufferBuilder.vertex(right, top, 0).next();
bufferBuilder.vertex(right, y, 0).next();
bufferBuilder.vertex(x, y, 0).next();
tessellator.draw();
bufferBuilder.method_22912(x, top, 0);
bufferBuilder.method_22912(right, top, 0);
bufferBuilder.method_22912(right, y, 0);
bufferBuilder.method_22912(x, y, 0);
C_fpcijbbg builtBuffer = bufferBuilder.method_60794();
if (builtBuffer != null) {
BufferRenderer.drawWithShader(builtBuffer);
}
RenderSystem.setShaderColor(0, 0, 0, 1.f);
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);
bufferBuilder.vertex(x + 1, top - 1, 0).next();
bufferBuilder.vertex(right - 1, top - 1, 0).next();
bufferBuilder.vertex(right - 1, y + 1, 0).next();
bufferBuilder.vertex(x + 1, y + 1, 0).next();
tessellator.draw();
bufferBuilder.method_22912(x + 1, top - 1, 0);
bufferBuilder.method_22912(right - 1, top - 1, 0);
bufferBuilder.method_22912(right - 1, y + 1, 0);
bufferBuilder.method_22912(x + 1, y + 1, 0);
builtBuffer = bufferBuilder.method_60794();
if (builtBuffer != null) {
BufferRenderer.drawWithShader(builtBuffer);
}
tessellator.method_60828();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public abstract class AbstractSpruceButtonWidget extends AbstractSpruceWidget im
*/
protected static final ClickableWidgetStateTextures
BUTTON_TEXTURES = new ClickableWidgetStateTextures(
new Identifier("widget/button"), new Identifier("widget/button_disabled"), new Identifier("widget/button_highlighted")
Identifier.ofDefault("widget/button"), Identifier.ofDefault("widget/button_disabled"), Identifier.ofDefault("widget/button_highlighted")
);

public AbstractSpruceButtonWidget(Position position, int width, int height, Text message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @since 1.0.0
*/
public class SpruceCheckboxWidget extends AbstractSpruceBooleanButtonWidget {
private static final Identifier TEXTURE = new Identifier("spruceui", "textures/gui/checkbox.png");
private static final Identifier TEXTURE = Identifier.of("spruceui", "textures/gui/checkbox.png");
private boolean showCross = false;
private boolean colored = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public class SpruceSliderWidget extends AbstractSpruceButtonWidget implements To
private String sign;
private boolean inUse = false;

private static final Identifier SLIDER = new Identifier("widget/slider");
private static final Identifier SLIDER_HANDLE = new Identifier("widget/slider_handle");
private static final Identifier SLIDER_HANDLE_HIGHLIGHTED = new Identifier("widget/slider_handle_highlighted");
private static final Identifier SLIDER = Identifier.ofDefault("widget/slider");
private static final Identifier SLIDER_HANDLE = Identifier.ofDefault("widget/slider_handle");
private static final Identifier SLIDER_HANDLE_HIGHLIGHTED = Identifier.ofDefault("widget/slider_handle_highlighted");

public SpruceSliderWidget(Position position, int width, int height, Text message, double value, Consumer<SpruceSliderWidget> applyConsumer, double multiplier, String sign) {
super(position, width, height, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @since 1.0.0
*/
public class SpruceToggleSwitch extends AbstractSpruceBooleanButtonWidget {
private static final Identifier TEXTURE = new Identifier("spruceui", "textures/gui/toggle_switch.png");
private static final Identifier TEXTURE = Identifier.of("spruceui", "textures/gui/toggle_switch.png");

public SpruceToggleSwitch(Position position, int width, int height, Text message, boolean value) {
super(position, width, height, message, value);
Expand Down
Loading

0 comments on commit 231cae6

Please sign in to comment.