Skip to content

Commit

Permalink
Update to Minecraft 1.21.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Oct 18, 2024
1 parent d187df6 commit 6c4cd8f
Show file tree
Hide file tree
Showing 45 changed files with 273 additions and 367 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@

- Updated to Minecraft 1.20.6 ([#51](https://github.com/LambdAurora/SpruceUI/pull/51)).
- Added `MenuBackground` and `MenuBorder` to adapt to Minecraft's new GUI design.

## 6.0.0

- Updated to Minecraft 1.21.2.
- Added `TexturedBorder` for textured borders.
- Updated widget textures to match the new sprite system.
- Removed `ScissorManager` in favor of `GuiGraphics` scissor handling.
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ group = project.property("maven_group") as String
base.archivesName.set(project.property("archives_base_name") as String)

val mcVersion = project.property("minecraft_version") as String
version = "${project.property("mod_version")}+${mcVersion}"
version = project.property("mod_version") as String

val targetJavaVersion = 21

Expand Down Expand Up @@ -171,7 +171,6 @@ dependencies {
modLocalRuntime("com.terraformersmc:modmenu:${project.property("modmenu_version")}") {
isTransitive = false
}
modLocalRuntime(fabricApi.module("fabric-key-binding-api-v1", project.property("fabric_api_version") as String))

"testmodImplementation"(sourceSets.main.get().output)
}
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G

minecraft_version=1.21.1
yalmm_mappings=2
loader_version=0.15.11
minecraft_version=1.21.2-rc1
yalmm_mappings=4
loader_version=0.16.7

# Mod Properties
mod_version=5.1.0
mod_version=6.0.0+1.21.2
maven_group=dev.lambdaurora
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.21
modmenu_version=11.0.1
fabric_api_version=0.106.0+1.21.2
modmenu_version=12.0.0-beta.1
19 changes: 11 additions & 8 deletions src/main/java/dev/lambdaurora/spruceui/SpruceTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Contains the identifiers of various useful textures.
*
* @author LambdAurora
* @version 5.1.0
* @version 6.0.0
* @since 5.1.0
*/
public final class SpruceTextures {
Expand All @@ -32,18 +32,21 @@ private SpruceTextures() {
/**
* The dirt background texture used in pre-1.20.5 versions.
*/
public static final Identifier LEGACY_OPTIONS_BACKGROUND = Identifier.of("spruceui", "textures/gui/legacy_options_background.png");
public static final Identifier LEGACY_OPTIONS_BACKGROUND = SpruceUI.id("textures/gui/legacy_options_background.png");

/* Border */

public static final Identifier SIMPLE_BORDER_SPRITE = SpruceUI.id("border/simple");
public static final Identifier SIMPLE_HIGHLIGHTED_BORDER_SPRITE = SpruceUI.id("border/simple_highlighted");

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 = 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_TOP_RIGHT_BORDER = SpruceUI.id("textures/gui/top_right_border_separator.png");
public static final Identifier INWORLD_MENU_TOP_RIGHT_BORDER = SpruceUI.id("textures/gui/inworld_top_right_border_separator.png");
public static final Identifier MENU_RIGHT_BORDER = SpruceUI.id("textures/gui/right_border_separator.png");
public static final Identifier INWORLD_MENU_RIGHT_BORDER = SpruceUI.id("textures/gui/inworld_right_border_separator.png");
public static final Identifier MENU_BOTTOM_RIGHT_BORDER = SpruceUI.id("textures/gui/bottom_right_border_separator.png");
public static final Identifier INWORLD_MENU_BOTTOM_RIGHT_BORDER = SpruceUI.id("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;
}
39 changes: 39 additions & 0 deletions src/main/java/dev/lambdaurora/spruceui/SpruceUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright © 2024 LambdAurora <email@lambdaurora.dev>
*
* This file is part of SpruceUI.
*
* Licensed under the MIT license. For more information,
* see the LICENSE file.
*/

package dev.lambdaurora.spruceui;

import net.minecraft.resources.Identifier;

/**
* Contains common constants from SpruceUI.
*
* @author LambdAurora
* @version 6.0.0
* @since 6.0.0
*/
public final class SpruceUI {
/**
* The namespace of SpruceUI, whose value is {@value}.
*/
public static final String NAMESPACE = "spruceui";

/**
* {@return a SpruceUI identifier from the given path}
*
* @param path the path
*/
public static Identifier id(String path) {
return Identifier.of(NAMESPACE, path);
}

private SpruceUI() {
throw new UnsupportedOperationException("SpruceUi only contains static definitions.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

package dev.lambdaurora.spruceui.background;

import com.mojang.blaze3d.systems.RenderSystem;
import dev.lambdaurora.spruceui.SpruceTextures;
import dev.lambdaurora.spruceui.widget.SpruceWidget;
import dev.lambdaurora.spruceui.widget.WithBorder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.Identifier;

/**
Expand All @@ -23,7 +23,7 @@
* @param texture the texture used for the background
* @param inWorldTexture the textured used for the background when playing in a world
* @author LambdAurora
* @version 5.1.0
* @version 6.0.0
* @since 5.1.0
*/
public record MenuBackground(Identifier texture, Identifier inWorldTexture) implements Background {
Expand All @@ -38,8 +38,6 @@ public record MenuBackground(Identifier texture, Identifier inWorldTexture) impl
public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int mouseX, int mouseY, float delta) {
int x = widget.getX();
int y = widget.getY();
int endX = widget.getEndX();
int endY = widget.getEndY();
int width = widget.getWidth();
int height = widget.getHeight();

Expand All @@ -48,22 +46,18 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int vOffset, int m

x += border.getLeft();
y += border.getTop();
endX -= border.getRight();
endY -= border.getBottom();

width -= border.getLeft() + border.getRight();
height -= border.getTop() + border.getBottom();
}

RenderSystem.enableBlend();
Identifier identifier = CLIENT.level == null ? this.inWorldTexture : this.texture;
graphics.drawTexture(
identifier,
RenderType::guiTextured, identifier,
x, y,
endX, endY,
0, 0,
width, height,
32, 32
16, 16
);
RenderSystem.disableBlend();
}
}
45 changes: 35 additions & 10 deletions src/main/java/dev/lambdaurora/spruceui/border/MenuBorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import dev.lambdaurora.spruceui.widget.SpruceWidget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.Identifier;

/**
Expand Down Expand Up @@ -47,15 +48,25 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mo
width -= THICKNESS;
}

graphics.drawTexture(topTexture,
widget.getX(), widget.getY(), 0, 0, width, THICKNESS, 32, THICKNESS
graphics.drawTexture(
RenderType::guiTextured,
topTexture,
widget.getX(), widget.getY(),
0, 0,
width, THICKNESS,
32, THICKNESS
);
}

if (this.top && this.right) {
Identifier cornerTexture = CLIENT.level == null ? SpruceTextures.MENU_TOP_RIGHT_BORDER : SpruceTextures.INWORLD_MENU_TOP_RIGHT_BORDER;
graphics.drawTexture(cornerTexture,
widget.getEndX() - THICKNESS, widget.getY(), 0, 0, THICKNESS, THICKNESS, THICKNESS, THICKNESS
graphics.drawTexture(
RenderType::guiTextured,
cornerTexture,
widget.getEndX() - THICKNESS, widget.getY(),
0, 0,
THICKNESS, THICKNESS,
THICKNESS, THICKNESS
);
}

Expand All @@ -74,16 +85,25 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mo
height -= THICKNESS;
}

graphics.drawTexture(rightTexture,
widget.getEndX() - THICKNESS, y, 0, 0, THICKNESS, height, THICKNESS, 32
graphics.drawTexture(
RenderType::guiTextured, rightTexture,
widget.getEndX() - THICKNESS, y,
0, 0,
THICKNESS, height,
THICKNESS, 32
);
}

if (this.bottom && this.right) {
Identifier cornerTexture = CLIENT.level == null
? SpruceTextures.MENU_BOTTOM_RIGHT_BORDER : SpruceTextures.INWORLD_MENU_BOTTOM_RIGHT_BORDER;
graphics.drawTexture(cornerTexture,
widget.getEndX() - THICKNESS, widget.getEndY() - THICKNESS, 0, 0, THICKNESS, THICKNESS, THICKNESS, THICKNESS
graphics.drawTexture(
RenderType::guiTextured,
cornerTexture,
widget.getEndX() - THICKNESS, widget.getEndY() - THICKNESS,
0, 0,
THICKNESS, THICKNESS,
THICKNESS, THICKNESS
);
}

Expand All @@ -96,8 +116,13 @@ public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mo
width -= THICKNESS;
}

graphics.drawTexture(bottomTexture,
widget.getX(), widget.getEndY() - THICKNESS, 0, 0, width, THICKNESS, 32, THICKNESS
graphics.drawTexture(
RenderType::guiTextured,
bottomTexture,
widget.getX(), widget.getEndY() - THICKNESS,
0, 0,
width, THICKNESS,
32, THICKNESS
);
}

Expand Down
60 changes: 15 additions & 45 deletions src/main/java/dev/lambdaurora/spruceui/border/SimpleBorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,32 @@

package dev.lambdaurora.spruceui.border;

import com.mojang.blaze3d.systems.RenderSystem;
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.renderer.GameRenderer;

import java.util.Arrays;

/**
* Represents a simple solid border to draw around a widget.
*
* @author LambdAurora
* @version 5.0.0
* @since 2.0.0
* @version 6.0.0
* @since 6.0.0
*/
public final class SimpleBorder implements Border {
public static final SimpleBorder SIMPLE_BORDER = new SimpleBorder(1, 192, 192, 192, 255);

private final int thickness;
private final int[] color;
private final int[] focusedColor;
private final int color;
private final int focusedColor;

public SimpleBorder(int thickness, int color) {
this(thickness, color, color);
}

public SimpleBorder(int thickness, int color, int focusedColor) {
this.thickness = thickness;
this.color = ColorUtil.unpackARGBColor(color);
this.focusedColor = ColorUtil.unpackARGBColor(focusedColor);
this.color = color;
this.focusedColor = color;
}

public SimpleBorder(int thickness, int red, int green, int blue, int alpha) {
Expand All @@ -48,50 +43,25 @@ public SimpleBorder(int thickness, int red, int green, int blue, int alpha) {

public SimpleBorder(int thickness, int red, int green, int blue, int alpha, int focusedRed, int focusedGreen, int focusedBlue, int focusedAlpha) {
this.thickness = thickness;
this.color = new int[]{red, green, blue, alpha};
this.focusedColor = new int[]{focusedRed, focusedGreen, focusedBlue, focusedAlpha};
this.color = ColorUtil.packARGBColor(red, green, blue, alpha);
this.focusedColor = ColorUtil.packARGBColor(focusedRed, focusedGreen, focusedBlue, focusedAlpha);
}

@Override
public void render(GuiGraphics graphics, SpruceWidget widget, int mouseX, int mouseY, float delta) {
var tessellator = Tessellator.getInstance();
var buffer = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
RenderSystem.setShader(GameRenderer::getPositionColorShader);
int x = widget.getX();
int y = widget.getY();
int right = x + widget.getWidth();
int bottom = y + widget.getHeight();
boolean focused = widget.isFocused();
int color = widget.isFocused() ? this.focusedColor : this.color;
// Top border
this.vertex(buffer, x, y + this.thickness, focused);
this.vertex(buffer, right, y + this.thickness, focused);
this.vertex(buffer, right, y, focused);
this.vertex(buffer, x, y, focused);
graphics.fill(x, y, right, y + this.thickness, color);
// Right border
this.vertex(buffer, right - this.thickness, bottom, focused);
this.vertex(buffer, right, bottom, focused);
this.vertex(buffer, right, y, focused);
this.vertex(buffer, right - this.thickness, y, focused);
graphics.fill(right - this.thickness, y, right, bottom, color);
// Bottom
this.vertex(buffer, x, bottom, focused);
this.vertex(buffer, right, bottom, focused);
this.vertex(buffer, right, bottom - this.thickness, focused);
this.vertex(buffer, x, bottom - this.thickness, focused);
graphics.fill(x, bottom, right, bottom - this.thickness, color);
// Left border
this.vertex(buffer, x, bottom, focused);
this.vertex(buffer, x + this.thickness, bottom, focused);
this.vertex(buffer, x + this.thickness, y, focused);
this.vertex(buffer, x, y, focused);
MeshData builtBuffer = buffer.build();
if (builtBuffer != null) {
BufferUploader.drawWithShader(builtBuffer);
}
tessellator.clear();
}

private void vertex(BufferBuilder buffer, int x, int y, boolean focused) {
int[] color = focused ? this.focusedColor : this.color;
buffer.addVertex(x, y, 0).color(color[0], color[1], color[2], color[3]);
graphics.fill(x, y, x + this.thickness, bottom, color);
}

@Override
Expand All @@ -103,8 +73,8 @@ public int getThickness() {
public String toString() {
return "SimpleBorder{" +
"thickness=" + this.thickness +
", color=" + Arrays.toString(this.color) +
", focusedColor=" + Arrays.toString(this.focusedColor) +
", color=" + Integer.toHexString(this.color) +
", focusedColor=" + Integer.toHexString(this.focusedColor) +
'}';
}
}
Loading

0 comments on commit 6c4cd8f

Please sign in to comment.