Skip to content

Commit

Permalink
Update for 1.21 Pre 2 (#734)
Browse files Browse the repository at this point in the history
* Fix update checker not being called when screen is closed in a way other than the button

- Fix update checker not being run when config screen is closed without the Done button

* Updates for 1.21 compatibility

* Merge update checker from 1.20.3 base

* Undo changing of default release type

* Bump FAPI to 0.99.2-1.21

* Update ModListEntry.java

* Update ModMenuOptionsScreen.java

* Update src/main/java/com/terraformersmc/modmenu/gui/widget/UpdateAvailableBadge.java

Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>

* Update src/main/java/com/terraformersmc/modmenu/gui/widget/entries/ModListEntry.java

Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>

* Update src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java

Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>

* Update src/main/java/com/terraformersmc/modmenu/gui/ModMenuOptionsScreen.java

Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>

* Update src/main/java/com/terraformersmc/modmenu/gui/widget/DescriptionListWidget.java

Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>

* Update src/main/java/com/terraformersmc/modmenu/gui/widget/ModListWidget.java

Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>

* Update src/main/java/com/terraformersmc/modmenu/gui/widget/ModListWidget.java

Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>

* BUMP to 1.21-pre2

---------

Co-authored-by: Prospector <prospectordev@gmail.com>
Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>
  • Loading branch information
4 people committed Jun 4, 2024
1 parent 8798223 commit b123e04
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 110 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx1G
maven_group=com.terraformersmc
archive_name=modmenu

minecraft_version=1.20.5-rc3
yarn_mappings=1.20.5-rc3+build.2
loader_version=0.15.10
fabric_version=0.97.5+1.20.5
minecraft_version=1.21-pre2
yarn_mappings=1.21-pre2+build.2
loader_version=0.15.11
fabric_version=0.99.4+1.21
quilt_loader_version=0.17.7

# Project Metadata
Expand All @@ -20,13 +20,13 @@ default_release_type=stable
# Modrinth Metadata
modrinth_slug=modmenu
modrinth_id=mOgUt4GM
modrinth_game_versions=1.20.5-rc3
modrinth_game_versions=1.21-pre2
modrinth_mod_loaders=fabric, quilt

# CurseForge Metadata
curseforge_slug=modmenu
curseforge_id=308702
curseforge_game_versions=1.20.5-Snapshot, Fabric, Quilt
curseforge_game_versions=1.21-Snapshot, Fabric, Quilt
curseforge_required_dependencies=
curseforge_optional_dependencies=

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.List;

public class ModMenuEventHandler {
public static final Identifier FABRIC_ICON_BUTTON_LOCATION = new Identifier(ModMenu.MOD_ID, "textures/gui/mods_button.png");
public static final Identifier FABRIC_ICON_BUTTON_LOCATION = Identifier.of(ModMenu.MOD_ID, "textures/gui/mods_button.png");
private static KeyBinding MENU_KEY_BIND;

public static void register() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ public ModMenuOptionsScreen(Screen previous) {

@Override
protected void init() {
this.list = this.addDrawableChild(new OptionListWidget(this.client, this.width, this.height, this));
this.list = this.addDrawableChild(new OptionListWidget(this.client, this.width, this));
this.list.addAll(ModMenuConfig.asOptions());
super.init();
}

@Override
protected void addOptions() {
// NO-OP
}

@Override
protected void initTabNavigation() {
super.initTabNavigation();
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/terraformersmc/modmenu/gui/ModsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.render.*;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.client.toast.SystemToast;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;
Expand All @@ -46,8 +44,8 @@
import java.util.stream.Collectors;

public class ModsScreen extends Screen {
private static final Identifier FILTERS_BUTTON_LOCATION = new Identifier(ModMenu.MOD_ID, "textures/gui/filters_button.png");
private static final Identifier CONFIGURE_BUTTON_LOCATION = new Identifier(ModMenu.MOD_ID, "textures/gui/configure_button.png");
private static final Identifier FILTERS_BUTTON_LOCATION = Identifier.of(ModMenu.MOD_ID, "textures/gui/filters_button.png");
private static final Identifier CONFIGURE_BUTTON_LOCATION = Identifier.of(ModMenu.MOD_ID, "textures/gui/configure_button.png");

private static final Logger LOGGER = LoggerFactory.getLogger("Mod Menu | ModsScreen");
private final Screen previousScreen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.Selectable;
import net.minecraft.client.gui.screen.ConfirmLinkScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.screen.narration.NarrationPart;
import net.minecraft.client.gui.screen.option.CreditsAndAttributionScreen;
Expand All @@ -28,10 +27,7 @@
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

public class DescriptionListWidget extends EntryListWidget<DescriptionListWidget.DescriptionEntry> {

Expand Down Expand Up @@ -248,17 +244,18 @@ public void renderList(DrawContext DrawContext, int mouseX, int mouseY, float de
}

Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
BufferBuilder bufferBuilder;
BuiltBuffer builtBuffer;

// {
// RenderSystem.setShader(GameRenderer::getPositionTexColorProgram);
// RenderSystem.setShaderTexture(0, Screen.OPTIONS_BACKGROUND_TEXTURE);
// RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
// bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
// bufferBuilder.vertex(this.getX(), this.getBottom(), 0.0D).texture(this.getX() / 32.0F, (this.getBottom() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).next();
// bufferBuilder.vertex(this.getRight(), this.getBottom(), 0.0D).texture(this.getRight() / 32.0F, (this.getBottom() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).next();
// bufferBuilder.vertex(this.getRight(), this.getY(), 0.0D).texture(this.getRight() / 32.0F, (this.getY() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).next();
// bufferBuilder.vertex(this.getX(), this.getY(), 0.0D).texture(this.getX() / 32.0F, (this.getY() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255).next();
// bufferBuilder.vertex(this.getX(), this.getBottom(), 0.0D).texture(this.getX() / 32.0F, (this.getBottom() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255);
// bufferBuilder.vertex(this.getRight(), this.getBottom(), 0.0D).texture(this.getRight() / 32.0F, (this.getBottom() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255);
// bufferBuilder.vertex(this.getRight(), this.getY(), 0.0D).texture(this.getRight() / 32.0F, (this.getY() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255);
// bufferBuilder.vertex(this.getX(), this.getY(), 0.0D).texture(this.getX() / 32.0F, (this.getY() + (int) this.getScrollAmount()) / 32.0F).color(32, 32, 32, 255);
// tessellator.draw();
// }

Expand All @@ -272,55 +269,53 @@ public void renderList(DrawContext DrawContext, int mouseX, int mouseY, float de
RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ZERO, GlStateManager.DstFactor.ONE);
RenderSystem.setShader(GameRenderer::getPositionColorProgram);

bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex(this.getX(), (this.getY() + 4), 0.0D).

color(0, 0, 0, 0).

next();
bufferBuilder.vertex(this.getRight(), (this.getY() + 4), 0.0D).

color(0, 0, 0, 0).

next();
bufferBuilder.vertex(this.getRight(), this.getY(), 0.0D).

color(0, 0, 0, 255).

next();
bufferBuilder.vertex(this.getX(), this.getY(), 0.0D).

color(0, 0, 0, 255).

next();
bufferBuilder.vertex(this.getX(), this.getBottom(), 0.0D).

color(0, 0, 0, 255).

next();
bufferBuilder.vertex(this.getRight(), this.getBottom(), 0.0D).

color(0, 0, 0, 255).

next();
bufferBuilder.vertex(this.getRight(), (this.getBottom() - 4), 0.0D).

color(0, 0, 0, 0).

next();
bufferBuilder.vertex(this.getX(), (this.getBottom() - 4), 0.0D).

color(0, 0, 0, 0).

next();
tessellator.draw();

bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex(this.getX(), (this.getY() + 4), 0.0F).

color(0, 0, 0, 0);

bufferBuilder.vertex(this.getRight(), (this.getY() + 4), 0.0F).

color(0, 0, 0, 0);

bufferBuilder.vertex(this.getRight(), this.getY(), 0.0F).

color(0, 0, 0, 255);

bufferBuilder.vertex(this.getX(), this.getY(), 0.0F).

color(0, 0, 0, 255);

bufferBuilder.vertex(this.getX(), this.getBottom(), 0.0F).

color(0, 0, 0, 255);

bufferBuilder.vertex(this.getRight(), this.getBottom(), 0.0F).

color(0, 0, 0, 255);

bufferBuilder.vertex(this.getRight(), (this.getBottom() - 4), 0.0F).

color(0, 0, 0, 0);

bufferBuilder.vertex(this.getX(), (this.getBottom() - 4), 0.0F).

color(0, 0, 0, 0);

try {
builtBuffer = bufferBuilder.end();
BufferRenderer.drawWithGlobalProgram(builtBuffer);
builtBuffer.close();
} catch (Exception e) {
// Ignored
}
this.renderScrollBar(bufferBuilder, tessellator);

RenderSystem.disableBlend();
}

public void renderScrollBar(BufferBuilder bufferBuilder, Tessellator tessellator) {
BuiltBuffer builtBuffer;
int scrollbarStartX = this.getScrollbarX();
int scrollbarEndX = scrollbarStartX + 6;
int maxScroll = this.getMaxScroll();
Expand All @@ -333,20 +328,26 @@ public void renderScrollBar(BufferBuilder bufferBuilder, Tessellator tessellator
}

RenderSystem.setShader(GameRenderer::getPositionColorProgram);
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex(scrollbarStartX, this.getBottom(), 0.0D).color(0, 0, 0, 255).next();
bufferBuilder.vertex(scrollbarEndX, this.getBottom(), 0.0D).color(0, 0, 0, 255).next();
bufferBuilder.vertex(scrollbarEndX, this.getY(), 0.0D).color(0, 0, 0, 255).next();
bufferBuilder.vertex(scrollbarStartX, this.getY(), 0.0D).color(0, 0, 0, 255).next();
bufferBuilder.vertex(scrollbarStartX, q + p, 0.0D).color(128, 128, 128, 255).next();
bufferBuilder.vertex(scrollbarEndX, q + p, 0.0D).color(128, 128, 128, 255).next();
bufferBuilder.vertex(scrollbarEndX, q, 0.0D).color(128, 128, 128, 255).next();
bufferBuilder.vertex(scrollbarStartX, q, 0.0D).color(128, 128, 128, 255).next();
bufferBuilder.vertex(scrollbarStartX, q + p - 1, 0.0D).color(192, 192, 192, 255).next();
bufferBuilder.vertex(scrollbarEndX - 1, q + p - 1, 0.0D).color(192, 192, 192, 255).next();
bufferBuilder.vertex(scrollbarEndX - 1, q, 0.0D).color(192, 192, 192, 255).next();
bufferBuilder.vertex(scrollbarStartX, q, 0.0D).color(192, 192, 192, 255).next();
tessellator.draw();
bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex(scrollbarStartX, this.getBottom(), 0.0F).color(0, 0, 0, 255);
bufferBuilder.vertex(scrollbarEndX, this.getBottom(), 0.0F).color(0, 0, 0, 255);
bufferBuilder.vertex(scrollbarEndX, this.getY(), 0.0F).color(0, 0, 0, 255);
bufferBuilder.vertex(scrollbarStartX, this.getY(), 0.0F).color(0, 0, 0, 255);
bufferBuilder.vertex(scrollbarStartX, q + p, 0.0F).color(128, 128, 128, 255);
bufferBuilder.vertex(scrollbarEndX, q + p, 0.0F).color(128, 128, 128, 255);
bufferBuilder.vertex(scrollbarEndX, q, 0.0F).color(128, 128, 128, 255);
bufferBuilder.vertex(scrollbarStartX, q, 0.0F).color(128, 128, 128, 255);
bufferBuilder.vertex(scrollbarStartX, q + p - 1, 0.0F).color(192, 192, 192, 255);
bufferBuilder.vertex(scrollbarEndX - 1, q + p - 1, 0.0F).color(192, 192, 192, 255);
bufferBuilder.vertex(scrollbarEndX - 1, q, 0.0F).color(192, 192, 192, 255);
bufferBuilder.vertex(scrollbarStartX, q, 0.0F).color(192, 192, 192, 255);
try {
builtBuffer = bufferBuilder.end();
BufferRenderer.drawWithGlobalProgram(builtBuffer);
builtBuffer.close();
} catch (Exception e) {
// Ignored
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.render.*;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;
import org.joml.Matrix4f;
Expand Down Expand Up @@ -202,7 +197,7 @@ private void filter(String searchTerm, boolean refresh, boolean search) {
protected void renderList(DrawContext DrawContext, int mouseX, int mouseY, float delta) {
int entryCount = this.getEntryCount();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();
BufferBuilder buffer;

for (int index = 0; index < entryCount; ++index) {
int entryTop = this.getRowTop(index) + 2;
Expand All @@ -219,20 +214,33 @@ protected void renderList(DrawContext DrawContext, int mouseX, int mouseY, float
RenderSystem.setShader(GameRenderer::getPositionProgram);
RenderSystem.setShaderColor(float_2, float_2, float_2, 1.0F);
Matrix4f matrix = DrawContext.getMatrices().peek().getPositionMatrix();
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);
buffer.vertex(matrix, entryLeft, entryTop + entryHeight + 2, 0.0F).next();
buffer.vertex(matrix, selectionRight, entryTop + entryHeight + 2, 0.0F).next();
buffer.vertex(matrix, selectionRight, entryTop - 2, 0.0F).next();
buffer.vertex(matrix, entryLeft, entryTop - 2, 0.0F).next();
tessellator.draw();
BuiltBuffer builtBuffer;
buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);
buffer.vertex(matrix, entryLeft, entryTop + entryHeight + 2, 0.0F);
buffer.vertex(matrix, selectionRight, entryTop + entryHeight + 2, 0.0F);
buffer.vertex(matrix, selectionRight, entryTop - 2, 0.0F);
buffer.vertex(matrix, entryLeft, entryTop - 2, 0.0F);
try {
builtBuffer = buffer.end();
BufferRenderer.drawWithGlobalProgram(builtBuffer);
builtBuffer.close();
} catch (Exception e) {
// Ignored
}
RenderSystem.setShader(GameRenderer::getPositionProgram);
RenderSystem.setShaderColor(0.0F, 0.0F, 0.0F, 1.0F);
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);
buffer.vertex(matrix, entryLeft + 1, entryTop + entryHeight + 1, 0.0F).next();
buffer.vertex(matrix, selectionRight - 1, entryTop + entryHeight + 1, 0.0F).next();
buffer.vertex(matrix, selectionRight - 1, entryTop - 1, 0.0F).next();
buffer.vertex(matrix, entryLeft + 1, entryTop - 1, 0.0F).next();
tessellator.draw();
buffer = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);
buffer.vertex(matrix, entryLeft + 1, entryTop + entryHeight + 1, 0.0F);
buffer.vertex(matrix, selectionRight - 1, entryTop + entryHeight + 1, 0.0F);
buffer.vertex(matrix, selectionRight - 1, entryTop - 1, 0.0F);
buffer.vertex(matrix, entryLeft + 1, entryTop - 1, 0.0F);
try {
builtBuffer = buffer.end();
BufferRenderer.drawWithGlobalProgram(builtBuffer);
builtBuffer.close();
} catch (Exception e) {
// Ignored
}
}

entryLeft = this.getRowLeft();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;

public class UpdateAvailableBadge {
private static final Identifier UPDATE_ICON = new Identifier("icon/trial_available");
private static final Identifier UPDATE_ICON = Identifier.ofVanilla("icon/trial_available");

public static void renderBadge(DrawContext DrawContext, int x, int y) {
RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget;
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.Language;
import net.minecraft.util.Util;

public class ModListEntry extends AlwaysSelectedEntryListWidget.Entry<ModListEntry> {
public static final Identifier UNKNOWN_ICON = new Identifier("textures/misc/unknown_pack.png");
private static final Identifier MOD_CONFIGURATION_ICON = new Identifier("modmenu", "textures/gui/mod_configuration.png");
private static final Identifier ERROR_ICON = new Identifier("minecraft", "world_list/error");
private static final Identifier ERROR_HIGHLIGHTED_ICON = new Identifier("minecraft", "world_list/error_highlighted");
public static final Identifier UNKNOWN_ICON = Identifier.ofVanilla("textures/misc/unknown_pack.png");
private static final Identifier MOD_CONFIGURATION_ICON = Identifier.of(ModMenu.MOD_ID, "textures/gui/mod_configuration.png");
private static final Identifier ERROR_ICON = Identifier.ofVanilla("world_list/error");
private static final Identifier ERROR_HIGHLIGHTED_ICON = Identifier.ofVanilla("world_list/error_highlighted");

protected final MinecraftClient client;
public final Mod mod;
Expand Down Expand Up @@ -127,7 +126,7 @@ public Mod getMod() {

public Identifier getIconTexture() {
if (this.iconLocation == null) {
this.iconLocation = new Identifier(ModMenu.MOD_ID, mod.getId() + "_icon");
this.iconLocation = Identifier.of(ModMenu.MOD_ID, mod.getId() + "_icon");
NativeImageBackedTexture icon = mod.getIcon(list.getFabricIconHandler(), 64 * this.client.options.getGuiScale().getValue());
if (icon != null) {
this.client.getTextureManager().registerTexture(this.iconLocation, icon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.terraformersmc.modmenu.util.mod.ModSearch;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
Expand All @@ -19,7 +18,7 @@
import java.util.Objects;

public class ParentEntry extends ModListEntry {
private static final Identifier PARENT_MOD_TEXTURE = new Identifier(ModMenu.MOD_ID, "textures/gui/parent_mod.png");
private static final Identifier PARENT_MOD_TEXTURE = Identifier.of(ModMenu.MOD_ID, "textures/gui/parent_mod.png");
protected List<Mod> children;
protected ModListWidget list;
protected boolean hoveringIcon = false;
Expand Down
Loading

0 comments on commit b123e04

Please sign in to comment.