From 29c3a2d2b342d9679c7a7a4295851a02772eb63c Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 11 Sep 2024 00:05:13 +0900 Subject: [PATCH] Update to 24w36a --- .github/workflows/publish.yml | 1 + common/build.gradle | 2 +- .../ScissorsHandler.java => CCTextures.java} | 29 ++-- .../clothconfig2/api/ScrollingContainer.java | 19 +-- .../api/scroll/ScrollingContainer.java | 27 ++-- .../gui/AbstractConfigScreen.java | 33 ++--- .../clothconfig2/gui/ClothConfigScreen.java | 100 +++++--------- .../gui/GlobalizedClothConfigScreen.java | 105 +++++++------- .../gui/entries/BaseListEntry.java | 7 +- .../gui/entries/DropdownBoxEntry.java | 33 +---- .../gui/entries/MultiElementListEntry.java | 15 +- .../gui/entries/SubCategoryListEntry.java | 10 +- .../gui/entries/TextListEntry.java | 5 + .../gui/widget/DynamicEntryListWidget.java | 116 ++++++++-------- ...amicNewSmoothScrollingEntryListWidget.java | 12 +- ...DynamicSmoothScrollingEntryListWidget.java | 12 +- .../impl/ScissorsHandlerImpl.java | 129 ------------------ .../impl/builders/DropdownMenuBuilder.java | 8 +- fabric/build.gradle | 4 +- fabric/src/main/resources/fabric.mod.json | 4 +- gradle.properties | 12 +- .../resources/META-INF/neoforge.mods.toml | 2 +- settings.gradle | 4 +- 23 files changed, 231 insertions(+), 458 deletions(-) rename common/src/main/java/me/shedaniel/clothconfig2/{api/ScissorsHandler.java => CCTextures.java} (54%) delete mode 100644 common/src/main/java/me/shedaniel/clothconfig2/impl/ScissorsHandlerImpl.java diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0d15aed3..ec8ed143 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -22,6 +22,7 @@ on: - v14 - v14-24w14potato - v15 + - v16 jobs: build: diff --git a/common/build.gradle b/common/build.gradle index cb68a5ab..7d3a5d8a 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -31,7 +31,7 @@ dependencies { } architectury { - common("fabric", "forge", "neoforge") + common("fabric"/*, "forge", "neoforge"*/) } task sourcesJar(type: Jar, dependsOn: classes) { diff --git a/common/src/main/java/me/shedaniel/clothconfig2/api/ScissorsHandler.java b/common/src/main/java/me/shedaniel/clothconfig2/CCTextures.java similarity index 54% rename from common/src/main/java/me/shedaniel/clothconfig2/api/ScissorsHandler.java rename to common/src/main/java/me/shedaniel/clothconfig2/CCTextures.java index 2bc1b3bc..de1ba0e7 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/api/ScissorsHandler.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/CCTextures.java @@ -17,26 +17,15 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package me.shedaniel.clothconfig2.api; +package me.shedaniel.clothconfig2; -import me.shedaniel.clothconfig2.impl.ScissorsHandlerImpl; -import me.shedaniel.math.Rectangle; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; -import java.util.List; - -@Environment(EnvType.CLIENT) -public interface ScissorsHandler { - ScissorsHandler INSTANCE = ScissorsHandlerImpl.INSTANCE; - - void clearScissors(); - - List getScissorsAreas(); - - void scissor(Rectangle rectangle); - - void removeLastScissor(); - - void applyScissors(); +@ApiStatus.Internal +public class CCTextures { + private static final String MOD_ID = "cloth-config2"; + public static final ResourceLocation VERTICAL_HEADER_SEPARATOR = ResourceLocation.fromNamespaceAndPath(MOD_ID, "textures/gui/vertical_header_separator.png"); + public static final ResourceLocation VERTICAL_FOOTER_SEPARATOR = ResourceLocation.fromNamespaceAndPath(MOD_ID, "textures/gui/vertical_footer_separator.png"); + public static final ResourceLocation CONFIG = ResourceLocation.fromNamespaceAndPath(MOD_ID, "textures/gui/cloth_config.png"); } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/api/ScrollingContainer.java b/common/src/main/java/me/shedaniel/clothconfig2/api/ScrollingContainer.java index d6e1092f..aae46063 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/api/ScrollingContainer.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/api/ScrollingContainer.java @@ -28,11 +28,14 @@ import me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget; import me.shedaniel.clothconfig2.impl.EasingMethod; import me.shedaniel.math.Rectangle; -import me.shedaniel.math.impl.PointHelper; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.util.FastColor; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.util.ARGB; import net.minecraft.util.Mth; +import static me.shedaniel.clothconfig2.api.scroll.ScrollingContainer.SCROLLER_BACKGROUND_SPRITE; +import static me.shedaniel.clothconfig2.api.scroll.ScrollingContainer.SCROLLER_SPRITE; + @Deprecated public abstract class ScrollingContainer { public double scrollAmount; @@ -141,16 +144,8 @@ public void renderScrollBar(GuiGraphics graphics, int background, float alpha, f int minY = Math.min(Math.max((int) scrollAmount * (bounds.height - height) / maxScroll + bounds.y, bounds.y), bounds.getMaxY() - height); int scrollbarPositionMinX = getScrollBarX(); - int scrollbarPositionMaxX = scrollbarPositionMinX + 6; - boolean hovered = (new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height)).contains(PointHelper.ofMouse()); - float bottomC = (hovered ? .67f : .5f) * scrollBarAlphaOffset; - float topC = (hovered ? .87f : .67f) * scrollBarAlphaOffset; - - graphics.fill(scrollbarPositionMinX, bounds.y, scrollbarPositionMaxX, bounds.getMaxY(), background); - graphics.fill(scrollbarPositionMinX, minY, scrollbarPositionMaxX, minY + height, - FastColor.ARGB32.color(Math.round(alpha * 255.0F), Math.round(bottomC * 255.0F), Math.round(bottomC * 255.0F), Math.round(bottomC * 255.0F))); - graphics.fill(scrollbarPositionMinX, minY, scrollbarPositionMaxX - 1, minY + height - 1, - FastColor.ARGB32.color(Math.round(alpha * 255.0F), Math.round(topC * 255.0F), Math.round(topC * 255.0F), Math.round(topC * 255.0F))); + graphics.blitSprite(RenderType::guiTextured, SCROLLER_BACKGROUND_SPRITE, scrollbarPositionMinX, bounds.y, 6, bounds.height, background); + graphics.blitSprite(RenderType::guiTextured, SCROLLER_SPRITE, scrollbarPositionMinX, minY, 6, height, ARGB.white(alpha)); } } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/api/scroll/ScrollingContainer.java b/common/src/main/java/me/shedaniel/clothconfig2/api/scroll/ScrollingContainer.java index 49c114a2..f91f62d4 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/api/scroll/ScrollingContainer.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/api/scroll/ScrollingContainer.java @@ -29,12 +29,15 @@ import me.shedaniel.clothconfig2.api.animator.ValueAnimator; import me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget; import me.shedaniel.math.Rectangle; -import me.shedaniel.math.impl.PointHelper; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.util.FastColor; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.ARGB; import net.minecraft.util.Mth; public abstract class ScrollingContainer { + public static final ResourceLocation SCROLLER_SPRITE = ResourceLocation.withDefaultNamespace("widget/scroller"); + public static final ResourceLocation SCROLLER_BACKGROUND_SPRITE = ResourceLocation.withDefaultNamespace("widget/scroller_background"); private final NumberAnimator scroll = ValueAnimator.ofDouble(); private boolean draggingScrollBar = false; private long scrollDuration = ClothConfigInitializer.getScrollDuration(); @@ -106,6 +109,10 @@ public final void scrollTo(double value, boolean animated, long duration) { } } + public void setScrollTarget(double scrollTarget) { + this.scroll.setTarget(scrollTarget); + } + public void updatePosition(float delta) { scroll.setTarget(handleBounceBack(this.scrollTarget(), this.getMaxScroll(), delta)); this.scroll.update(delta); @@ -137,10 +144,10 @@ public static double clampExtension(double v, double maxScroll, double clampExte } public void renderScrollBar(GuiGraphics graphics) { - renderScrollBar(graphics, 0, 1, 1); + renderScrollBar(graphics, ARGB.alpha(255), 1); } - public void renderScrollBar(GuiGraphics graphics, int background, float alpha, float scrollBarAlphaOffset) { + public void renderScrollBar(GuiGraphics graphics, int background, float alpha) { if (hasScrollBar()) { Rectangle bounds = getBounds(); int maxScroll = getMaxScroll(); @@ -151,16 +158,8 @@ public void renderScrollBar(GuiGraphics graphics, int background, float alpha, f int minY = Math.min(Math.max((int) scrollAmount() * (bounds.height - height) / maxScroll + bounds.y, bounds.y), bounds.getMaxY() - height); int scrollbarPositionMinX = getScrollBarX(bounds.getMaxX()); - int scrollbarPositionMaxX = scrollbarPositionMinX + 6; - boolean hovered = (new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height)).contains(PointHelper.ofMouse()); - float bottomC = (hovered ? .67f : .5f) * scrollBarAlphaOffset; - float topC = (hovered ? .87f : .67f) * scrollBarAlphaOffset; - - graphics.fill(scrollbarPositionMinX, bounds.y, scrollbarPositionMaxX, bounds.getMaxY(), background); - graphics.fill(scrollbarPositionMinX, minY, scrollbarPositionMaxX, minY + height, - FastColor.ARGB32.color(Math.round(alpha * 255.0F), Math.round(bottomC * 255.0F), Math.round(bottomC * 255.0F), Math.round(bottomC * 255.0F))); - graphics.fill(scrollbarPositionMinX, minY, scrollbarPositionMaxX - 1, minY + height - 1, - FastColor.ARGB32.color(Math.round(alpha * 255.0F), Math.round(topC * 255.0F), Math.round(topC * 255.0F), Math.round(topC * 255.0F))); + graphics.blitSprite(RenderType::guiTextured, SCROLLER_BACKGROUND_SPRITE, scrollbarPositionMinX, bounds.y, 6, bounds.height, background); + graphics.blitSprite(RenderType::guiTextured, SCROLLER_SPRITE, scrollbarPositionMinX, minY, 6, height, ARGB.white(alpha)); } } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/AbstractConfigScreen.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/AbstractConfigScreen.java index f87c46d0..37a6c54c 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/AbstractConfigScreen.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/AbstractConfigScreen.java @@ -21,8 +21,7 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.InputConstants; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; +import com.mojang.blaze3d.vertex.VertexConsumer; import it.unimi.dsi.fastutil.booleans.BooleanConsumer; import me.shedaniel.clothconfig2.ClothConfigInitializer; import me.shedaniel.clothconfig2.api.*; @@ -36,7 +35,7 @@ import net.minecraft.client.gui.screens.ConfirmLinkScreen; import net.minecraft.client.gui.screens.ConfirmScreen; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; @@ -366,26 +365,16 @@ public void addTooltip(Tooltip tooltip) { this.tooltips.add(tooltip); } + @Deprecated protected void overlayBackground(GuiGraphics graphics, Rectangle rect, int red, int green, int blue, int startAlpha, int endAlpha) { - overlayBackground(graphics.pose(), rect, red, green, blue, startAlpha, endAlpha); - } - - protected void overlayBackground(PoseStack matrices, Rectangle rect, int red, int green, int blue, int startAlpha, int endAlpha) { - overlayBackground(matrices.last().pose(), rect, red, green, blue, startAlpha, endAlpha); - } - - protected void overlayBackground(Matrix4f matrix, Rectangle rect, int red, int green, int blue, int startAlpha, int endAlpha) { - if (isTransparentBackground()) - return; - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); - RenderSystem.setShaderTexture(0, getBackgroundLocation()); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - buffer.addVertex(matrix, rect.getMinX(), rect.getMaxY(), 0.0F).setUv(rect.getMinX() / 32.0F, rect.getMaxY() / 32.0F).setColor(red, green, blue, endAlpha); - buffer.addVertex(matrix, rect.getMaxX(), rect.getMaxY(), 0.0F).setUv(rect.getMaxX() / 32.0F, rect.getMaxY() / 32.0F).setColor(red, green, blue, endAlpha); - buffer.addVertex(matrix, rect.getMaxX(), rect.getMinY(), 0.0F).setUv(rect.getMaxX() / 32.0F, rect.getMinY() / 32.0F).setColor(red, green, blue, startAlpha); - buffer.addVertex(matrix, rect.getMinX(), rect.getMinY(), 0.0F).setUv(rect.getMinX() / 32.0F, rect.getMinY() / 32.0F).setColor(red, green, blue, startAlpha); + graphics.drawSpecial(source -> { + VertexConsumer buffer = source.getBuffer(RenderType.guiTextured(getBackgroundLocation())); + Matrix4f matrix = graphics.pose().last().pose(); + buffer.addVertex(matrix, rect.getMinX(), rect.getMaxY(), 0.0F).setUv(rect.getMinX() / 32.0F, rect.getMaxY() / 32.0F).setColor(red, green, blue, endAlpha); + buffer.addVertex(matrix, rect.getMaxX(), rect.getMaxY(), 0.0F).setUv(rect.getMaxX() / 32.0F, rect.getMaxY() / 32.0F).setColor(red, green, blue, endAlpha); + buffer.addVertex(matrix, rect.getMaxX(), rect.getMinY(), 0.0F).setUv(rect.getMaxX() / 32.0F, rect.getMinY() / 32.0F).setColor(red, green, blue, startAlpha); + buffer.addVertex(matrix, rect.getMinX(), rect.getMinY(), 0.0F).setUv(rect.getMinX() / 32.0F, rect.getMinY() / 32.0F).setColor(red, green, blue, startAlpha); + }); } @Override diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigScreen.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigScreen.java index 33f2b2ef..281a17a2 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigScreen.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigScreen.java @@ -22,9 +22,12 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; +import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.Tesselator; +import com.mojang.blaze3d.vertex.VertexConsumer; import me.shedaniel.clothconfig2.api.*; import me.shedaniel.clothconfig2.api.animator.ValueAnimator; +import me.shedaniel.clothconfig2.api.scroll.ScrollingContainer; import me.shedaniel.clothconfig2.gui.entries.EmptyEntry; import me.shedaniel.clothconfig2.gui.widget.DynamicElementListWidget; import me.shedaniel.clothconfig2.gui.widget.SearchFieldEntry; @@ -38,9 +41,12 @@ import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.ARGB; import net.minecraft.util.Mth; import net.minecraft.util.Tuple; import org.jetbrains.annotations.ApiStatus; @@ -51,7 +57,7 @@ import java.util.function.UnaryOperator; import java.util.stream.Collectors; -@SuppressWarnings({"deprecation", "rawtypes", "DuplicatedCode", "NullableProblems"}) +@SuppressWarnings({"rawtypes", "DuplicatedCode"}) @Environment(EnvType.CLIENT) public class ClothConfigScreen extends AbstractTabbedConfigScreen { private final ScrollingContainer tabsScroller = new ScrollingContainer() { @@ -68,7 +74,7 @@ public int getMaxScrollHeight() { @Override public void updatePosition(float delta) { super.updatePosition(delta); - scrollAmount = clamp(scrollAmount, 0); + setScrollTarget(clamp(scrollTarget(), 0)); } }; public ListWidget>> listWidget; @@ -156,13 +162,7 @@ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float del childrenL().add(buttonLeftTab = new Button(4, 44, 12, 18, Component.empty(), button -> tabsScroller.scrollTo(0, true), Supplier::get) { @Override public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, CONFIG_TEX); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha); - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(770, 771, 0, 1); - RenderSystem.blendFunc(770, 771); - graphics.blit(CONFIG_TEX, getX(), getY(), 12, 18 * (!this.isActive() ? 0 : this.isHoveredOrFocused() ? 2 : 1), width, height); + graphics.blit(RenderType::guiTextured, CONFIG_TEX, getX(), getY(), 12, 18 * (!this.isActive() ? 0 : this.isHoveredOrFocused() ? 2 : 1), width, height, 256, 256, ARGB.white(this.alpha)); } }); int j = 0; @@ -174,13 +174,7 @@ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float del childrenL().add(buttonRightTab = new Button(width - 16, 44, 12, 18, Component.empty(), button -> tabsScroller.scrollTo(tabsScroller.getMaxScroll(), true), Supplier::get) { @Override public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, CONFIG_TEX); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha); - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(770, 771, 0, 1); - RenderSystem.blendFunc(770, 771); - graphics.blit(CONFIG_TEX, getX(), getY(), 0, 18 * (!this.isActive() ? 0 : this.isHoveredOrFocused() ? 2 : 1), width, height); + graphics.blit(RenderType::guiTextured, CONFIG_TEX, getX(), getY(), 0, 18 * (!this.isActive() ? 0 : this.isHoveredOrFocused() ? 2 : 1), width, height, 256, 256, ARGB.white(this.alpha)); } }); } else { @@ -220,13 +214,13 @@ public void resetTabsMaximumScrolled() { public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { if (isShowingTabs()) { tabsScroller.updatePosition(delta * 3); - int xx = 24 - (int) tabsScroller.scrollAmount; + int xx = 24 - tabsScroller.scrollAmountInt(); for (ClothConfigTabButton tabButton : tabButtons) { tabButton.setX(xx); xx += tabButton.getWidth() + 2; } - buttonLeftTab.active = tabsScroller.scrollAmount > 0d; - buttonRightTab.active = tabsScroller.scrollAmount < getTabsMaximumScrolled() - width + 40; + buttonLeftTab.active = tabsScroller.scrollAmount() > 0d; + buttonRightTab.active = tabsScroller.scrollAmount() < getTabsMaximumScrolled() - width + 40; } if (!isTransparentBackground()) { renderMenuBackground(graphics); @@ -234,25 +228,25 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { if (this.minecraft.level == null) { this.renderPanorama(graphics, delta); } - renderBlurredBackground(delta); + renderBlurredBackground(); renderMenuBackground(graphics); } listWidget.render(graphics, mouseX, mouseY, delta); - ScissorsHandler.INSTANCE.scissor(new Rectangle(listWidget.left, listWidget.top, listWidget.width, listWidget.bottom - listWidget.top)); + graphics.enableScissor(listWidget.left, listWidget.top, listWidget.left + listWidget.width, listWidget.bottom); for (AbstractConfigEntry child : listWidget.children()) child.lateRender(graphics, mouseX, mouseY, delta); - ScissorsHandler.INSTANCE.removeLastScissor(); + graphics.disableScissor(); if (isShowingTabs()) { graphics.drawCenteredString(minecraft.font, title, width / 2, 18, -1); Rectangle onlyInnerTabBounds = new Rectangle(tabsBounds.x + 20, tabsBounds.y, tabsBounds.width - 40, tabsBounds.height); - ScissorsHandler.INSTANCE.scissor(onlyInnerTabBounds); + graphics.enableScissor(onlyInnerTabBounds.x, onlyInnerTabBounds.y, onlyInnerTabBounds.getMaxX(), onlyInnerTabBounds.getMaxY()); if (isTransparentBackground()) graphics.fillGradient(onlyInnerTabBounds.x, onlyInnerTabBounds.y, onlyInnerTabBounds.getMaxX(), onlyInnerTabBounds.getMaxY(), 0x68000000, 0x68000000); else overlayBackground(graphics, onlyInnerTabBounds, 32, 32, 32, 255, 255); tabButtons.forEach(widget -> widget.render(graphics, mouseX, mouseY, delta)); drawTabsShades(graphics, 0, isTransparentBackground() ? 120 : 255); - ScissorsHandler.INSTANCE.removeLastScissor(); + graphics.disableScissor(); buttonLeftTab.render(graphics, mouseX, mouseY, delta); buttonRightTab.render(graphics, mouseX, mouseY, delta); } else @@ -265,15 +259,12 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { if (entry.getConfigError().isPresent()) errors.add(entry.getConfigError().get()); if (errors.size() > 0) { - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, CONFIG_TEX); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); String text = "§c" + (errors.size() == 1 ? errors.get(0).plainCopy().getString() : I18n.get("text.cloth-config.multi_error")); if (isTransparentBackground()) { int stringWidth = minecraft.font.width(text); graphics.fillGradient(8, 9, 20 + stringWidth, 14 + minecraft.font.lineHeight, 0x68000000, 0x68000000); } - graphics.blit(CONFIG_TEX, 10, 10, 0, 54, 3, 11); + graphics.blit(RenderType::guiTextured, CONFIG_TEX, 10, 10, 0, 54, 3, 11, 256, 256); graphics.drawString(minecraft.font, text, 18, 12, -1); if (errors.size() > 1) { int stringWidth = minecraft.font.width(text); @@ -282,15 +273,12 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { } } } else if (!isEditable()) { - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, CONFIG_TEX); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); String text = "§c" + I18n.get("text.cloth-config.not_editable"); if (isTransparentBackground()) { int stringWidth = minecraft.font.width(text); graphics.fillGradient(8, 9, 20 + stringWidth, 14 + minecraft.font.lineHeight, 0x68000000, 0x68000000); } - graphics.blit(CONFIG_TEX, 10, 10, 0, 54, 3, 11); + graphics.blit(RenderType::guiTextured, CONFIG_TEX, 10, 10, 0, 54, 3, 11, 256, 256); graphics.drawString(minecraft.font, text, 18, 12, -1); } super.render(graphics, mouseX, mouseY, delta); @@ -301,19 +289,13 @@ public void renderBackground(GuiGraphics guiGraphics, int i, int j, float f) { } private void drawTabsShades(GuiGraphics graphics, int lightColor, int darkColor) { - drawTabsShades(graphics.pose(), lightColor, darkColor); - } - - private void drawTabsShades(PoseStack matrices, int lightColor, int darkColor) { - drawTabsShades(matrices.last().pose(), lightColor, darkColor); + graphics.drawSpecial(source -> { + drawTabsShades(source, graphics.pose().last().pose(), lightColor, darkColor); + }); } - private void drawTabsShades(Matrix4f matrix, int lightColor, int darkColor) { - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(770, 771, 0, 1); - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); + private void drawTabsShades(MultiBufferSource source, Matrix4f matrix, int lightColor, int darkColor) { + VertexConsumer buffer = source.getBuffer(RenderType.gui()); buffer.addVertex(matrix, tabsBounds.getMinX() + 20, tabsBounds.getMinY() + 4, 0.0F).setUv(0, 1f).setColor(0, 0, 0, lightColor); buffer.addVertex(matrix, tabsBounds.getMaxX() - 20, tabsBounds.getMinY() + 4, 0.0F).setUv(1f, 1f).setColor(0, 0, 0, lightColor); buffer.addVertex(matrix, tabsBounds.getMaxX() - 20, tabsBounds.getMinY(), 0.0F).setUv(1f, 0).setColor(0, 0, 0, darkColor); @@ -322,7 +304,6 @@ private void drawTabsShades(Matrix4f matrix, int lightColor, int darkColor) { buffer.addVertex(matrix, tabsBounds.getMaxX() - 20, tabsBounds.getMaxY(), 0.0F).setUv(1f, 1f).setColor(0, 0, 0, darkColor); buffer.addVertex(matrix, tabsBounds.getMaxX() - 20, tabsBounds.getMaxY() - 4, 0.0F).setUv(1f, 0).setColor(0, 0, 0, lightColor); buffer.addVertex(matrix, tabsBounds.getMinX() + 20, tabsBounds.getMaxY() - 4, 0.0F).setUv(0, 0).setColor(0, 0, 0, lightColor); - RenderSystem.disableBlend(); } @Override @@ -343,7 +324,7 @@ public static class ListWidget> 24 & 255) / 255.0F; float g = (float) (j >> 16 & 255) / 255.0F; float h = (float) (j >> 8 & 255) / 255.0F; @@ -395,10 +376,10 @@ protected static void fillGradient(Matrix4f matrix4f, BufferBuilder bufferBuilde float n = (float) (k >> 16 & 255) / 255.0F; float o = (float) (k >> 8 & 255) / 255.0F; float p = (float) (k & 255) / 255.0F; - bufferBuilder.addVertex(matrix4f, (float) xEnd, (float) yStart, (float) i).setColor(g, h, l, f); - bufferBuilder.addVertex(matrix4f, (float) xStart, (float) yStart, (float) i).setColor(g, h, l, f); - bufferBuilder.addVertex(matrix4f, (float) xStart, (float) yEnd, (float) i).setColor(n, o, p, m); - bufferBuilder.addVertex(matrix4f, (float) xEnd, (float) yEnd, (float) i).setColor(n, o, p, m); + bufferBuilder.addVertex(matrix, (float) xEnd, (float) yStart, (float) i).setColor(g, h, l, f); + bufferBuilder.addVertex(matrix, (float) xStart, (float) yStart, (float) i).setColor(g, h, l, f); + bufferBuilder.addVertex(matrix, (float) xStart, (float) yEnd, (float) i).setColor(n, o, p, m); + bufferBuilder.addVertex(matrix, (float) xEnd, (float) yEnd, (float) i).setColor(n, o, p, m); } @Override @@ -423,23 +404,6 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { } } - @Override - protected void renderBackBackground(GuiGraphics graphics, BufferBuilder buffer, Tesselator tessellator) { - if (!screen.isTransparentBackground()) - super.renderBackBackground(graphics, buffer, tessellator); - else { - RenderSystem.enableBlend(); - graphics.blit(ResourceLocation.withDefaultNamespace("textures/gui/menu_list_background.png"), this.left, this.top, this.right, this.bottom, this.width, this.bottom - this.top, 32, 32); - RenderSystem.disableBlend(); - } - } - - @Override - protected void renderHoleBackground(GuiGraphics graphics, int y1, int y2, int alpha1, int alpha2) { - if (!screen.isTransparentBackground()) - super.renderHoleBackground(graphics, y1, y2, alpha1, alpha2); - } - @Override public List children() { return entriesTransformer.apply(super.children()); diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/GlobalizedClothConfigScreen.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/GlobalizedClothConfigScreen.java index 682d53f9..45a35408 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/GlobalizedClothConfigScreen.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/GlobalizedClothConfigScreen.java @@ -22,15 +22,12 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.blaze3d.vertex.VertexFormat; +import com.mojang.blaze3d.vertex.VertexConsumer; +import me.shedaniel.clothconfig2.CCTextures; import me.shedaniel.clothconfig2.ClothConfigInitializer; import me.shedaniel.clothconfig2.api.*; import me.shedaniel.clothconfig2.api.scroll.ScrollingContainer; import me.shedaniel.clothconfig2.gui.entries.EmptyEntry; -import me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget; import me.shedaniel.clothconfig2.gui.widget.SearchFieldEntry; import me.shedaniel.math.Rectangle; import net.minecraft.ChatFormatting; @@ -44,9 +41,7 @@ import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.navigation.FocusNavigationEvent; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; @@ -215,26 +210,26 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { } int sliderPosition = getSideSliderPosition(); if (!isTransparentBackground()) { - ScissorsHandler.INSTANCE.scissor(new Rectangle(sliderPosition, 0, width - sliderPosition, height)); + graphics.enableScissor(sliderPosition, 0, width, height); renderMenuBackground(graphics); overlayBackground(graphics, new Rectangle(14, 0, width, height), 64, 64, 64, 255, 255); } else { if (this.minecraft.level == null) { this.renderPanorama(graphics, delta); } - renderBlurredBackground(delta); + renderBlurredBackground(); renderMenuBackground(graphics); - ScissorsHandler.INSTANCE.scissor(new Rectangle(sliderPosition, 0, width - sliderPosition, height)); + graphics.enableScissor(sliderPosition, 0, width, height); } listWidget.width = width - sliderPosition; listWidget.setLeftPos(sliderPosition); listWidget.render(graphics, mouseX, mouseY, delta); - ScissorsHandler.INSTANCE.scissor(new Rectangle(listWidget.left, listWidget.top, listWidget.width, listWidget.bottom - listWidget.top)); + graphics.enableScissor(listWidget.left, listWidget.top, listWidget.left + listWidget.width, listWidget.bottom); for (AbstractConfigEntry child : listWidget.children()) child.lateRender(graphics, mouseX, mouseY, delta); - ScissorsHandler.INSTANCE.removeLastScissor(); + graphics.disableScissor(); graphics.drawString(font, title.getVisualOrderText(), (int) (sliderPosition + (width - sliderPosition) / 2f - font.width(title) / 2f), 12, -1); - ScissorsHandler.INSTANCE.removeLastScissor(); + graphics.disableScissor(); cancelButton.setX(sliderPosition + (width - sliderPosition) / 2 - cancelButton.getWidth() - 3); exitButton.setX(sliderPosition + (width - sliderPosition) / 2 + 3); super.render(graphics, mouseX, mouseY, delta); @@ -242,58 +237,54 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { sideScroller.updatePosition(delta); if (isTransparentBackground()) { RenderSystem.enableBlend(); - graphics.blit(ResourceLocation.withDefaultNamespace("textures/gui/menu_list_background.png"), 0, 0, sliderPosition, height, sliderPosition, height, 32, 32); - graphics.blit(ResourceLocation.withDefaultNamespace("textures/gui/menu_list_background.png"), 0, 0, sliderPosition - 14, height, sliderPosition - 14, height, 32, 32); - graphics.blit(DynamicEntryListWidget.VERTICAL_HEADER_SEPARATOR, sliderPosition - 1, 0, 0.0F, 0.0F, 1, this.height, 2, 32); + graphics.blit(RenderType::guiTextured, ResourceLocation.withDefaultNamespace("textures/gui/menu_list_background.png"), 0, 0, sliderPosition, height, sliderPosition, height, 32, 32); + graphics.blit(RenderType::guiTextured, ResourceLocation.withDefaultNamespace("textures/gui/menu_list_background.png"), 0, 0, sliderPosition - 14, height, sliderPosition - 14, height, 32, 32); + graphics.blit(RenderType::guiTextured, CCTextures.VERTICAL_HEADER_SEPARATOR, sliderPosition - 1, 0, 0.0F, 0.0F, 1, this.height, 2, 32); if (sliderPosition - 14 - 1 > 0) { - graphics.blit(DynamicEntryListWidget.VERTICAL_HEADER_SEPARATOR, sliderPosition - 14 - 1, 0, 0.0F, 0.0F, 1, this.height, 2, 32); + graphics.blit(RenderType::guiTextured, CCTextures.VERTICAL_HEADER_SEPARATOR, sliderPosition - 14 - 1, 0, 0.0F, 0.0F, 1, this.height, 2, 32); } RenderSystem.disableBlend(); } else { - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); - RenderSystem.setShaderTexture(0, getBackgroundLocation()); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - float f = 32.0F; - buffer.addVertex(sliderPosition - 14, height, 0.0F).setUv(0, height / 32.0F).setColor(68, 68, 68, 255); - buffer.addVertex(sliderPosition, height, 0.0F).setUv(14 / 32.0F, height / 32.0F).setColor(68, 68, 68, 255); - buffer.addVertex(sliderPosition, 0, 0.0F).setUv(14 / 32.0F, 0).setColor(68, 68, 68, 255); - buffer.addVertex(sliderPosition - 14, 0, 0.0F).setUv(0, 0).setColor(68, 68, 68, 255); - - buffer.addVertex(0, height, 0.0F).setUv(0, (height + sideScroller.scrollAmountInt()) / 32.0F).setColor(32, 32, 32, 255); - buffer.addVertex(sliderPosition - 14, height, 0.0F).setUv((sliderPosition - 14) / 32.0F, (height + sideScroller.scrollAmountInt()) / 32.0F).setColor(32, 32, 32, 255); - buffer.addVertex(sliderPosition - 14, 0, 0.0F).setUv((sliderPosition - 14) / 32.0F, sideScroller.scrollAmountInt() / 32.0F).setColor(32, 32, 32, 255); - buffer.addVertex(0, 0, 0.0F).setUv(0, sideScroller.scrollAmountInt() / 32.0F).setColor(32, 32, 32, 255); - - Matrix4f matrix = graphics.pose().last().pose(); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.setShader(GameRenderer::getPositionColorShader); - int shadeColor = isTransparentBackground() ? 120 : 160; - buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - buffer.addVertex(matrix, sliderPosition + 4, 0, 100.0F).setColor(0, 0, 0, 0); - buffer.addVertex(matrix, sliderPosition, 0, 100.0F).setColor(0, 0, 0, shadeColor); - buffer.addVertex(matrix, sliderPosition, height, 100.0F).setColor(0, 0, 0, shadeColor); - buffer.addVertex(matrix, sliderPosition + 4, height, 100.0F).setColor(0, 0, 0, 0); - shadeColor /= 2; - buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - buffer.addVertex(matrix, sliderPosition - 14, 0, 100.0F).setColor(0, 0, 0, shadeColor); - buffer.addVertex(matrix, sliderPosition - 14 - 4, 0, 100.0F).setColor(0, 0, 0, 0); - buffer.addVertex(matrix, sliderPosition - 14 - 4, height, 100.0F).setColor(0, 0, 0, 0); - buffer.addVertex(matrix, sliderPosition - 14, height, 100.0F).setColor(0, 0, 0, shadeColor); - RenderSystem.disableBlend(); + graphics.drawSpecial(source -> { + VertexConsumer buffer = source.getBuffer(RenderType.guiTextured(getBackgroundLocation())); + Matrix4f matrix = graphics.pose().last().pose(); + float f = 32.0F; + buffer.addVertex(matrix, sliderPosition - 14, height, 0.0F).setUv(0, height / 32.0F).setColor(68, 68, 68, 255); + buffer.addVertex(matrix, sliderPosition, height, 0.0F).setUv(14 / 32.0F, height / 32.0F).setColor(68, 68, 68, 255); + buffer.addVertex(matrix, sliderPosition, 0, 0.0F).setUv(14 / 32.0F, 0).setColor(68, 68, 68, 255); + buffer.addVertex(matrix, sliderPosition - 14, 0, 0.0F).setUv(0, 0).setColor(68, 68, 68, 255); + + buffer.addVertex(matrix, 0, height, 0.0F).setUv(0, (height + sideScroller.scrollAmountInt()) / 32.0F).setColor(32, 32, 32, 255); + buffer.addVertex(matrix, sliderPosition - 14, height, 0.0F).setUv((sliderPosition - 14) / 32.0F, (height + sideScroller.scrollAmountInt()) / 32.0F).setColor(32, 32, 32, 255); + buffer.addVertex(matrix, sliderPosition - 14, 0, 0.0F).setUv((sliderPosition - 14) / 32.0F, sideScroller.scrollAmountInt() / 32.0F).setColor(32, 32, 32, 255); + buffer.addVertex(matrix, 0, 0, 0.0F).setUv(0, sideScroller.scrollAmountInt() / 32.0F).setColor(32, 32, 32, 255); + + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + int shadeColor = isTransparentBackground() ? 120 : 160; + buffer = source.getBuffer(RenderType.gui()); + buffer.addVertex(matrix, sliderPosition + 4, 0, 100.0F).setColor(0, 0, 0, 0); + buffer.addVertex(matrix, sliderPosition, 0, 100.0F).setColor(0, 0, 0, shadeColor); + buffer.addVertex(matrix, sliderPosition, height, 100.0F).setColor(0, 0, 0, shadeColor); + buffer.addVertex(matrix, sliderPosition + 4, height, 100.0F).setColor(0, 0, 0, 0); + shadeColor /= 2; + buffer.addVertex(matrix, sliderPosition - 14, 0, 100.0F).setColor(0, 0, 0, shadeColor); + buffer.addVertex(matrix, sliderPosition - 14 - 4, 0, 100.0F).setColor(0, 0, 0, 0); + buffer.addVertex(matrix, sliderPosition - 14 - 4, height, 100.0F).setColor(0, 0, 0, 0); + buffer.addVertex(matrix, sliderPosition - 14, height, 100.0F).setColor(0, 0, 0, shadeColor); + RenderSystem.disableBlend(); + }); } Rectangle slideArrowBounds = new Rectangle(sliderPosition - 14, 0, 14, height); { - MultiBufferSource.BufferSource immediate = graphics.bufferSource(); - font.renderText(">", sliderPosition - 7 - font.width(">") / 2f, height / 2, (slideArrowBounds.contains(mouseX, mouseY) ? 16777120 : 16777215) | Mth.clamp(Mth.ceil((1 - sideSlider.scrollAmount()) * 255.0F), 0, 255) << 24, false, graphics.pose().last().pose(), immediate, Font.DisplayMode.NORMAL, 0, 15728880); - font.renderText("<", sliderPosition - 7 - font.width("<") / 2f, height / 2, (slideArrowBounds.contains(mouseX, mouseY) ? 16777120 : 16777215) | Mth.clamp(Mth.ceil(sideSlider.scrollAmount() * 255.0F), 0, 255) << 24, false, graphics.pose().last().pose(), immediate, Font.DisplayMode.NORMAL, 0, 15728880); - graphics.flush(); + graphics.drawSpecial(source -> { + font.renderText(">", sliderPosition - 7 - font.width(">") / 2f, height / 2, (slideArrowBounds.contains(mouseX, mouseY) ? 16777120 : 16777215) | Mth.clamp(Mth.ceil((1 - sideSlider.scrollAmount()) * 255.0F), 0, 255) << 24, false, graphics.pose().last().pose(), source, Font.DisplayMode.NORMAL, 0, 15728880); + font.renderText("<", sliderPosition - 7 - font.width("<") / 2f, height / 2, (slideArrowBounds.contains(mouseX, mouseY) ? 16777120 : 16777215) | Mth.clamp(Mth.ceil(sideSlider.scrollAmount() * 255.0F), 0, 255) << 24, false, graphics.pose().last().pose(), source, Font.DisplayMode.NORMAL, 0, 15728880); + }); Rectangle scrollerBounds = sideScroller.getBounds(); if (!scrollerBounds.isEmpty()) { - ScissorsHandler.INSTANCE.scissor(new Rectangle(0, 0, sliderPosition - 14, height)); + graphics.enableScissor(0, 0, sliderPosition - 14, height); int scrollOffset = scrollerBounds.y - sideScroller.scrollAmountInt(); for (Reference reference : references) { graphics.pose().pushPose(); @@ -305,7 +296,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { graphics.pose().popPose(); scrollOffset += (font.lineHeight + 3) * reference.getScale(); } - ScissorsHandler.INSTANCE.removeLastScissor(); + graphics.disableScissor(); sideScroller.renderScrollBar(graphics); } } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListEntry.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListEntry.java index 8d98d830..0f940625 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListEntry.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListEntry.java @@ -32,6 +32,7 @@ import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -290,11 +291,11 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth boolean insideLabel = labelWidget.rectangle.contains(mouseX, mouseY); boolean insideCreateNew = isInsideCreateNew(mouseX, mouseY); boolean insideDelete = isInsideDelete(mouseX, mouseY); - graphics.blit(CONFIG_TEX, x - 15, y + 5, 24 + 9, (isEnabled() ? (insideLabel && !insideCreateNew && !insideDelete ? 18 : 0) : 36) + (isExpanded() ? 9 : 0), 9, 9); + graphics.blit(RenderType::guiTextured, CONFIG_TEX, x - 15, y + 5, 24 + 9, (isEnabled() ? (insideLabel && !insideCreateNew && !insideDelete ? 18 : 0) : 36) + (isExpanded() ? 9 : 0), 9, 9, 256, 256); if (isInsertButtonEnabled()) - graphics.blit(CONFIG_TEX, x - 15 + 13, y + 5, 24 + 18, insideCreateNew ? 9 : 0, 9, 9); + graphics.blit(RenderType::guiTextured, CONFIG_TEX, x - 15 + 13, y + 5, 24 + 18, insideCreateNew ? 9 : 0, 9, 9, 256, 256); if (isDeleteButtonEnabled()) - graphics.blit(CONFIG_TEX, x - 15 + (isInsertButtonEnabled() ? 26 : 13), y + 5, 24 + 27, focused == null ? 0 : insideDelete ? 18 : 9, 9, 9); + graphics.blit(RenderType::guiTextured, CONFIG_TEX, x - 15 + (isInsertButtonEnabled() ? 26 : 13), y + 5, 24 + 27, focused == null ? 0 : insideDelete ? 18 : 9, 9, 9, 256, 256); resetWidget.setX(x + entryWidth - resetWidget.getWidth()); resetWidget.setY(y); resetWidget.active = isEditable() && getDefaultValue().isPresent() && !isMatchDefault(); diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/DropdownBoxEntry.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/DropdownBoxEntry.java index 1ddfc731..3cf7df71 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/DropdownBoxEntry.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/DropdownBoxEntry.java @@ -22,16 +22,9 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.Window; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.blaze3d.vertex.VertexFormat; import me.shedaniel.clothconfig2.ClothConfigInitializer; -import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.clothconfig2.api.ScrollingContainer; import me.shedaniel.math.Rectangle; -import me.shedaniel.math.impl.PointHelper; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -45,7 +38,7 @@ import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.navigation.FocusNavigationEvent; -import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import org.jetbrains.annotations.ApiStatus; @@ -58,6 +51,7 @@ import java.util.function.Supplier; import static me.shedaniel.clothconfig2.api.ScrollingContainer.handleScrollingPosition; +import static me.shedaniel.clothconfig2.api.scroll.ScrollingContainer.SCROLLER_SPRITE; @SuppressWarnings("deprecation") @Environment(EnvType.CLIENT) @@ -414,7 +408,7 @@ public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta graphics.pose().pushPose(); graphics.pose().translate(0, 0, 300f); - ScissorsHandler.INSTANCE.scissor(new Rectangle(lastRectangle.x, lastRectangle.y + lastRectangle.height + 1, cWidth - 6, last10Height - 1)); + graphics.enableScissor(lastRectangle.x, lastRectangle.y + lastRectangle.height + 1, lastRectangle.x + cWidth - 6, lastRectangle.y + lastRectangle.height + last10Height); double yy = lastRectangle.y + lastRectangle.height - scroll; for (SelectionCellElement cell : currentElements) { if (yy + getCellCreator().getCellHeight() >= lastRectangle.y + lastRectangle.height && yy <= lastRectangle.y + lastRectangle.height + last10Height + 1) { @@ -424,7 +418,7 @@ public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta cell.dontRender(graphics, delta); yy += getCellCreator().getCellHeight(); } - ScissorsHandler.INSTANCE.removeLastScissor(); + graphics.disableScissor(); if (currentElements.isEmpty()) { Font textRenderer = Minecraft.getInstance().font; @@ -433,7 +427,6 @@ public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta } if (getMaxScrollPosition() > 6) { - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); int scrollbarPositionMinX = lastRectangle.x + getCellCreator().getCellWidth() - 6; int scrollbarPositionMaxX = scrollbarPositionMinX + 6; int height = (int) (((last10Height) * (last10Height)) / this.getMaxScrollPosition()); @@ -442,23 +435,7 @@ public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta height = Math.max(10, height); int minY = (int) Math.min(Math.max((int) scroll * (last10Height - height) / getMaxScrollPosition() + (lastRectangle.y + lastRectangle.height + 1), (lastRectangle.y + lastRectangle.height + 1)), (lastRectangle.y + lastRectangle.height + 1 + last10Height) - height); - int bottomc = new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height).contains(PointHelper.ofMouse()) ? 168 : 128; - int topc = new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height).contains(PointHelper.ofMouse()) ? 222 : 172; - - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - - // Bottom - buffer.addVertex(scrollbarPositionMinX, minY + height, 0.0F).setColor(bottomc, bottomc, bottomc, 255); - buffer.addVertex(scrollbarPositionMaxX, minY + height, 0.0F).setColor(bottomc, bottomc, bottomc, 255); - buffer.addVertex(scrollbarPositionMaxX, minY, 0.0F).setColor(bottomc, bottomc, bottomc, 255); - buffer.addVertex(scrollbarPositionMinX, minY, 0.0F).setColor(bottomc, bottomc, bottomc, 255); - - // Top - buffer.addVertex(scrollbarPositionMinX, (minY + height - 1), 0.0F).setColor(topc, topc, topc, 255); - buffer.addVertex((scrollbarPositionMaxX - 1), (minY + height - 1), 0.0F).setColor(topc, topc, topc, 255); - buffer.addVertex((scrollbarPositionMaxX - 1), minY, 0.0F).setColor(topc, topc, topc, 255); - buffer.addVertex(scrollbarPositionMinX, minY, 0.0F).setColor(topc, topc, topc, 255); + graphics.blitSprite(RenderType::guiTextured, SCROLLER_SPRITE, scrollbarPositionMinX, minY, 6, height); } graphics.pose().popPose(); } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/MultiElementListEntry.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/MultiElementListEntry.java index f7fc1571..dccc39e6 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/MultiElementListEntry.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/MultiElementListEntry.java @@ -21,7 +21,7 @@ import com.google.common.collect.Iterators; import com.google.common.collect.Lists; -import com.mojang.blaze3d.systems.RenderSystem; +import me.shedaniel.clothconfig2.CCTextures; import me.shedaniel.clothconfig2.api.AbstractConfigListEntry; import me.shedaniel.clothconfig2.api.Expandable; import me.shedaniel.math.Rectangle; @@ -33,9 +33,9 @@ import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.narration.NarratedElementType; import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import org.jetbrains.annotations.ApiStatus; @@ -44,8 +44,6 @@ @Environment(EnvType.CLIENT) public class MultiElementListEntry extends TooltipListEntry implements Expandable { - - private static final ResourceLocation CONFIG_TEX = ResourceLocation.fromNamespaceAndPath("cloth-config2", "textures/gui/cloth_config.png"); private final T object; private final List> entries; private final MultiElementListEntry.CategoryLabelWidget widget; @@ -115,10 +113,9 @@ public Optional getDefaultValue() { public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isHovered, float delta) { super.render(graphics, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isHovered, delta); boolean insideWidget = widget.rectangle.contains(mouseX, mouseY); - RenderSystem.setShaderTexture(0, CONFIG_TEX); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - graphics.blit(CONFIG_TEX, x - 15, y + 5, 24, (isEnabled() ? (insideWidget ? 18 : 0) : 36) + (isExpanded() ? 9 : 0), 9, 9); + graphics.blit(RenderType::guiTextured, CCTextures.CONFIG, x - 15, y + 5, 24, (isEnabled() ? (insideWidget ? 18 : 0) : 36) + (isExpanded() ? 9 : 0), 9, 9, 256, 256); graphics.drawString(Minecraft.getInstance().font, getDisplayedFieldName().getVisualOrderText(), x, y + 6, insideWidget ? 0xffe6fe16 : -1); + //noinspection rawtypes for (AbstractConfigListEntry entry : entries) { entry.setParent(getParent()); entry.setScreen(getConfigScreen()); @@ -241,9 +238,9 @@ public boolean mouseClicked(double mouseX, double mouseY, int int_1) { @Override public void setFocused(boolean bl) { - + } - + @Override public boolean isFocused() { return false; diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/SubCategoryListEntry.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/SubCategoryListEntry.java index 4355c499..d8395768 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/SubCategoryListEntry.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/SubCategoryListEntry.java @@ -21,7 +21,7 @@ import com.google.common.collect.Iterators; import com.google.common.collect.Lists; -import com.mojang.blaze3d.systems.RenderSystem; +import me.shedaniel.clothconfig2.CCTextures; import me.shedaniel.clothconfig2.api.AbstractConfigEntry; import me.shedaniel.clothconfig2.api.AbstractConfigListEntry; import me.shedaniel.clothconfig2.api.Expandable; @@ -35,9 +35,9 @@ import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.narration.NarratedElementType; import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import org.jetbrains.annotations.Nullable; @@ -45,8 +45,6 @@ @Environment(EnvType.CLIENT) public class SubCategoryListEntry extends TooltipListEntry> implements Expandable { - - private static final ResourceLocation CONFIG_TEX = ResourceLocation.fromNamespaceAndPath("cloth-config2", "textures/gui/cloth_config.png"); private final List entries; private final CategoryLabelWidget widget; private final List children; // GuiEventListener & NarratableEntry @@ -129,10 +127,8 @@ public Optional> getDefaultValue() { @Override public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isHovered, float delta) { super.render(graphics, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isHovered, delta); - RenderSystem.setShaderTexture(0, CONFIG_TEX); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); boolean insideWidget = widget.rectangle.contains(mouseX, mouseY); - graphics.blit(CONFIG_TEX, x - 15, y + 5, 24, (isEnabled() ? (insideWidget ? 18 : 0) : 36) + (isExpanded() ? 9 : 0), 9, 9); + graphics.blit(RenderType::guiTextured, CCTextures.CONFIG, x - 15, y + 5, 24, (isEnabled() ? (insideWidget ? 18 : 0) : 36) + (isExpanded() ? 9 : 0), 9, 9, 256, 256); graphics.drawString(Minecraft.getInstance().font, getDisplayedFieldName().getVisualOrderText(), x, y + 6, insideWidget ? 0xffe6fe16 : 0xffffffff); for (AbstractConfigListEntry entry : entries) { entry.setParent((DynamicEntryListWidget) getParent()); diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/TextListEntry.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/TextListEntry.java index d88723b5..7dcf8bc5 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/TextListEntry.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/TextListEntry.java @@ -29,6 +29,7 @@ import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.Style; import net.minecraft.util.FormattedCharSequence; import net.minecraft.util.Mth; @@ -94,6 +95,10 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth AbstractConfigScreen configScreen = this.getConfigScreen(); if (style != null && configScreen != null) { + if (Minecraft.getInstance().level == null && style.getHoverEvent() != null && style.getHoverEvent().getAction() == HoverEvent.Action.SHOW_ITEM) { + return; + } + graphics.renderComponentHoverEffect(Minecraft.getInstance().font, style, mouseX, mouseY); } } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicEntryListWidget.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicEntryListWidget.java index 1428bd71..43ed8cda 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicEntryListWidget.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicEntryListWidget.java @@ -21,12 +21,11 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.blaze3d.vertex.VertexFormat; -import me.shedaniel.clothconfig2.api.*; -import me.shedaniel.math.Rectangle; +import com.mojang.blaze3d.vertex.*; +import me.shedaniel.clothconfig2.api.DisableableWidget; +import me.shedaniel.clothconfig2.api.HideableWidget; +import me.shedaniel.clothconfig2.api.Requirement; +import me.shedaniel.clothconfig2.api.TickableWidget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -40,8 +39,7 @@ import net.minecraft.client.gui.navigation.ScreenDirection; import net.minecraft.client.gui.navigation.ScreenRectangle; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen; -import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -52,10 +50,11 @@ import java.util.*; import java.util.function.Predicate; +import static me.shedaniel.clothconfig2.api.scroll.ScrollingContainer.SCROLLER_BACKGROUND_SPRITE; +import static me.shedaniel.clothconfig2.api.scroll.ScrollingContainer.SCROLLER_SPRITE; + @Environment(EnvType.CLIENT) public abstract class DynamicEntryListWidget> extends AbstractContainerEventHandler implements Renderable, NarratableEntry { - public static final ResourceLocation VERTICAL_HEADER_SEPARATOR = ResourceLocation.parse("cloth-config2:textures/gui/vertical_header_separator.png"); - public static final ResourceLocation VERTICAL_FOOTER_SEPARATOR = ResourceLocation.parse("cloth-config2:textures/gui/vertical_footer_separator.png"); protected static final int DRAG_OUTSIDE = -2; protected final Minecraft client; private final List entries = new Entries(); @@ -77,9 +76,13 @@ public abstract class DynamicEntryListWidgetnull, Cloth Config will follow the minecraft transparent style. + */ + @Nullable protected ResourceLocation backgroundLocation; - public DynamicEntryListWidget(Minecraft client, int width, int height, int top, int bottom, ResourceLocation backgroundLocation) { + public DynamicEntryListWidget(Minecraft client, int width, int height, int top, int bottom, @Nullable ResourceLocation backgroundLocation) { this.client = client; this.width = width; this.height = height; @@ -92,10 +95,10 @@ public DynamicEntryListWidget(Minecraft client, int width, int height, int top, /** * Get all visible children. I.e. hidden config entries are filtered out. - * + * *

Note: this isn't thread safe, since the visible children list is * updated when calling {@link #tickList()}. - * + * * @return an unmodifiable {@link List} of visible entries */ @ApiStatus.Experimental @@ -258,11 +261,11 @@ protected void clickedHeader(int int_1, int int_2) { public void tickList() { this.updateVisibleChildren(); for (E child : this.children()) { - child.tick(); + child.tick(); } } - protected void renderHeader(GuiGraphics graphics, int rowLeft, int startY, Tesselator tessellator) { + protected void renderHeader(GuiGraphics graphics, int rowLeft, int startY) { } protected void drawBackground() { @@ -272,17 +275,19 @@ protected void renderDecorations(GuiGraphics graphics, int mouseX, int mouseY) { } @Deprecated - protected void renderBackBackground(GuiGraphics graphics, BufferBuilder buffer, Tesselator tessellator) { - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); - RenderSystem.setShaderTexture(0, backgroundLocation); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - Matrix4f matrix = graphics.pose().last().pose(); - float float_2 = 32.0F; - tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - buffer.addVertex(matrix, this.left, this.bottom, 0.0F).setUv(this.left / 32.0F, ((this.bottom + (int) this.getScroll()) / 32.0F)).setColor(32, 32, 32, 255); - buffer.addVertex(matrix, this.right, this.bottom, 0.0F).setUv(this.right / 32.0F, ((this.bottom + (int) this.getScroll()) / 32.0F)).setColor(32, 32, 32, 255); - buffer.addVertex(matrix, this.right, this.top, 0.0F).setUv(this.right / 32.0F, ((this.top + (int) this.getScroll()) / 32.0F)).setColor(32, 32, 32, 255); - buffer.addVertex(matrix, this.left, this.top, 0.0F).setUv(this.left / 32.0F, ((this.top + (int) this.getScroll()) / 32.0F)).setColor(32, 32, 32, 255); + protected void renderBackBackground(GuiGraphics graphics) { + if (this.backgroundLocation != null) { + graphics.drawSpecial(source -> { + VertexConsumer buffer = source.getBuffer(RenderType.guiTextured(backgroundLocation)); + Matrix4f matrix = graphics.pose().last().pose(); + buffer.addVertex(matrix, this.left, this.bottom, 0.0F).setUv(this.left / 32.0F, ((this.bottom + (int) this.getScroll()) / 32.0F)).setColor(32, 32, 32, 255); + buffer.addVertex(matrix, this.right, this.bottom, 0.0F).setUv(this.right / 32.0F, ((this.bottom + (int) this.getScroll()) / 32.0F)).setColor(32, 32, 32, 255); + buffer.addVertex(matrix, this.right, this.top, 0.0F).setUv(this.right / 32.0F, ((this.top + (int) this.getScroll()) / 32.0F)).setColor(32, 32, 32, 255); + buffer.addVertex(matrix, this.left, this.top, 0.0F).setUv(this.left / 32.0F, ((this.top + (int) this.getScroll()) / 32.0F)).setColor(32, 32, 32, 255); + }); + } else { + graphics.blit(RenderType::guiTextured, Screen.MENU_BACKGROUND, this.left, this.top, this.right, this.bottom, this.width, this.bottom - this.top, 32, 32); + } } @Override @@ -296,44 +301,41 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { this.drawBackground(); int scrollbarPosition = this.getScrollbarPosition(); int int_4 = scrollbarPosition + 6; - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - renderBackBackground(graphics, buffer, tesselator); + renderBackBackground(graphics); int rowLeft = this.getRowLeft(); int startY = this.top + 4 - (int) this.getScroll(); if (this.renderSelection) - this.renderHeader(graphics, rowLeft, startY, tesselator); - ScissorsHandler.INSTANCE.scissor(new Rectangle(left, top, width, bottom - top)); + this.renderHeader(graphics, rowLeft, startY); + graphics.enableScissor(left, top, left + width, bottom); this.renderList(graphics, rowLeft, startY, mouseX, mouseY, delta); - ScissorsHandler.INSTANCE.removeLastScissor(); + graphics.disableScissor(); RenderSystem.disableDepthTest(); this.renderHoleBackground(graphics, 0, this.top, 255, 255); this.renderHoleBackground(graphics, this.bottom, this.height, 255, 255); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.enableBlend(); - graphics.blit(CreateWorldScreen.HEADER_SEPARATOR, this.left, this.top - 2, 0.0F, 0.0F, this.width, 2, 32, 2); - graphics.blit(CreateWorldScreen.FOOTER_SEPARATOR, this.left, this.bottom, 0.0F, 0.0F, this.width, 2, 32, 2); + graphics.blit(RenderType::guiTextured, Screen.HEADER_SEPARATOR, this.left, this.top - 2, 0.0F, 0.0F, this.width, 2, 32, 2); + graphics.blit(RenderType::guiTextured, Screen.FOOTER_SEPARATOR, this.left, this.bottom, 0.0F, 0.0F, this.width, 2, 32, 2); RenderSystem.disableBlend(); int maxScroll = this.getMaxScroll(); - renderScrollBar(graphics, tesselator, buffer, maxScroll, scrollbarPosition, int_4); + renderScrollBar(graphics, maxScroll, scrollbarPosition, int_4); this.renderDecorations(graphics, mouseX, mouseY); RenderSystem.disableBlend(); } - protected void renderScrollBar(GuiGraphics graphics, Tesselator tessellator, BufferBuilder buffer, int maxScroll, int scrollbarPositionMinX, int scrollbarPositionMaxX) { + protected void renderScrollBar(GuiGraphics graphics, int maxScroll, int scrollbarPositionMinX, int scrollbarPositionMaxX) { if (maxScroll > 0) { - int int_9 = ((this.bottom - this.top) * (this.bottom - this.top)) / this.getMaxScrollPosition(); - int_9 = Mth.clamp(int_9, 32, this.bottom - this.top - 8); - int int_10 = (int) this.getScroll() * (this.bottom - this.top - int_9) / maxScroll + this.top; - if (int_10 < this.top) { - int_10 = this.top; + int height = ((this.bottom - this.top) * (this.bottom - this.top)) / this.getMaxScrollPosition(); + height = Mth.clamp(height, 32, this.bottom - this.top - 8); + int minY = (int) this.getScroll() * (this.bottom - this.top - height) / maxScroll + this.top; + if (minY < this.top) { + minY = this.top; } - graphics.fill(scrollbarPositionMinX, this.top, scrollbarPositionMaxX, this.bottom, 0xff000000); - graphics.fill(scrollbarPositionMinX, int_10, scrollbarPositionMaxX, int_10 + int_9, 0xff808080); - graphics.fill(scrollbarPositionMinX, int_10, scrollbarPositionMaxX - 1, int_10 + int_9 - 1, 0xffc0c0c0); + graphics.blitSprite(RenderType::guiTextured, SCROLLER_BACKGROUND_SPRITE, scrollbarPositionMinX, this.top, scrollbarPositionMaxX - scrollbarPositionMinX, this.bottom - this.top); + graphics.blitSprite(RenderType::guiTextured, SCROLLER_SPRITE, scrollbarPositionMinX, minY, 6, height); } } @@ -451,7 +453,7 @@ protected E nextEntry(ScreenDirection screenDirection, Predicate predicate, @ case UP -> -1; case DOWN -> 1; }; - + if (!this.children().isEmpty() && var10000 != 0) { int j; if (entry == null) { @@ -460,7 +462,7 @@ protected E nextEntry(ScreenDirection screenDirection, Predicate predicate, @ j = this.children().indexOf(entry) + var10000; } - for(int k = j; k >= 0 && k < this.entries.size(); k += var10000) { + for (int k = j; k >= 0 && k < this.entries.size(); k += var10000) { E entry2 = this.entries.get(k); if (predicate.test(entry2)) { return entry2; @@ -588,7 +590,7 @@ public int getRowTop(int index) { if (index <= i++) { break; } - top += item.getItemHeight(); + top += item.getItemHeight(); } return top; } @@ -599,16 +601,16 @@ public boolean isFocused() { } protected void renderHoleBackground(GuiGraphics graphics, int y1, int y2, int alpha1, int alpha2) { - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - Matrix4f matrix = graphics.pose().last().pose(); - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); - RenderSystem.setShaderTexture(0, backgroundLocation); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - buffer.addVertex(matrix, this.left, y2, 0.0F).setUv(0, ((float) y2 / 32.0F)).setColor(64, 64, 64, alpha2); - buffer.addVertex(matrix, this.left + this.width, y2, 0.0F).setUv(((float) this.width / 32.0F), ((float) y2 / 32.0F)).setColor(64, 64, 64, alpha2); - buffer.addVertex(matrix, this.left + this.width, y1, 0.0F).setUv(((float) this.width / 32.0F), ((float) y1 / 32.0F)).setColor(64, 64, 64, alpha1); - buffer.addVertex(matrix, this.left, y1, 0.0F).setUv(0, ((float) y1 / 32.0F)).setColor(64, 64, 64, alpha1); + if (backgroundLocation != null) { + graphics.drawSpecial(source -> { + VertexConsumer buffer = source.getBuffer(RenderType.guiTextured(backgroundLocation)); + Matrix4f matrix = graphics.pose().last().pose(); + buffer.addVertex(matrix, this.left, y2, 0.0F).setUv(0, ((float) y2 / 32.0F)).setColor(64, 64, 64, alpha2); + buffer.addVertex(matrix, this.left + this.width, y2, 0.0F).setUv(((float) this.width / 32.0F), ((float) y2 / 32.0F)).setColor(64, 64, 64, alpha2); + buffer.addVertex(matrix, this.left + this.width, y1, 0.0F).setUv(((float) this.width / 32.0F), ((float) y1 / 32.0F)).setColor(64, 64, 64, alpha1); + buffer.addVertex(matrix, this.left, y1, 0.0F).setUv(0, ((float) y1 / 32.0F)).setColor(64, 64, 64, alpha1); + }); + } } protected E remove(int index) { diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicNewSmoothScrollingEntryListWidget.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicNewSmoothScrollingEntryListWidget.java index ef5b32ec..2b073e42 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicNewSmoothScrollingEntryListWidget.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicNewSmoothScrollingEntryListWidget.java @@ -19,9 +19,8 @@ package me.shedaniel.clothconfig2.gui.widget; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.Tesselator; import me.shedaniel.clothconfig2.ClothConfigInitializer; +import me.shedaniel.math.Color; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; import net.fabricmc.api.EnvType; @@ -29,7 +28,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.FastColor; import net.minecraft.util.Mth; import static me.shedaniel.clothconfig2.api.ScrollingContainer.clampExtension; @@ -133,9 +131,9 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { } @Override - protected void renderScrollBar(GuiGraphics graphics, Tesselator tessellator, BufferBuilder buffer, int maxScroll, int scrollbarPositionMinX, int scrollbarPositionMaxX) { + protected void renderScrollBar(GuiGraphics graphics, int maxScroll, int scrollbarPositionMinX, int scrollbarPositionMaxX) { if (!smoothScrolling) - super.renderScrollBar(graphics, tessellator, buffer, maxScroll, scrollbarPositionMinX, scrollbarPositionMaxX); + super.renderScrollBar(graphics, maxScroll, scrollbarPositionMinX, scrollbarPositionMaxX); else if (maxScroll > 0) { int height = ((this.bottom - this.top) * (this.bottom - this.top)) / this.getMaxScrollPosition(); height = Mth.clamp(height, 32, this.bottom - this.top - 8); @@ -148,9 +146,9 @@ else if (maxScroll > 0) { graphics.fill(scrollbarPositionMinX, this.top, scrollbarPositionMaxX, this.bottom, 0xff000000); graphics.fill(scrollbarPositionMinX, minY, scrollbarPositionMaxX, minY + height, - FastColor.ARGB32.color(255, bottomc, bottomc, bottomc)); + Color.ofRGBA(bottomc, bottomc, bottomc, 255).getColor()); graphics.fill(scrollbarPositionMinX, minY, scrollbarPositionMaxX - 1, minY + height - 1, - FastColor.ARGB32.color(255, topc, topc, topc)); + Color.ofRGBA(topc, topc, topc, 255).getColor()); } } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicSmoothScrollingEntryListWidget.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicSmoothScrollingEntryListWidget.java index 344dbba2..af705431 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicSmoothScrollingEntryListWidget.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicSmoothScrollingEntryListWidget.java @@ -19,11 +19,10 @@ package me.shedaniel.clothconfig2.gui.widget; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.Tesselator; import me.shedaniel.clothconfig2.ClothConfigInitializer; import me.shedaniel.clothconfig2.api.animator.NumberAnimator; import me.shedaniel.clothconfig2.api.animator.ValueAnimator; +import me.shedaniel.math.Color; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; import net.fabricmc.api.EnvType; @@ -31,7 +30,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.FastColor; import net.minecraft.util.Mth; import static me.shedaniel.clothconfig2.api.scroll.ScrollingContainer.clampExtension; @@ -130,9 +128,9 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { } @Override - protected void renderScrollBar(GuiGraphics graphics, Tesselator tessellator, BufferBuilder buffer, int maxScroll, int scrollbarPositionMinX, int scrollbarPositionMaxX) { + protected void renderScrollBar(GuiGraphics graphics, int maxScroll, int scrollbarPositionMinX, int scrollbarPositionMaxX) { if (!smoothScrolling) - super.renderScrollBar(graphics, tessellator, buffer, maxScroll, scrollbarPositionMinX, scrollbarPositionMaxX); + super.renderScrollBar(graphics, maxScroll, scrollbarPositionMinX, scrollbarPositionMaxX); else if (maxScroll > 0) { int height = ((this.bottom - this.top) * (this.bottom - this.top)) / this.getMaxScrollPosition(); height = Mth.clamp(height, 32, this.bottom - this.top - 8); @@ -145,9 +143,9 @@ else if (maxScroll > 0) { graphics.fill(scrollbarPositionMinX, this.top, scrollbarPositionMaxX, this.bottom, 0xff000000); graphics.fill(scrollbarPositionMinX, minY, scrollbarPositionMaxX, minY + height, - FastColor.ARGB32.color(255, bottomc, bottomc, bottomc)); + Color.ofRGB(bottomc, bottomc, bottomc).getColor()); graphics.fill(scrollbarPositionMinX, minY, scrollbarPositionMaxX - 1, minY + height - 1, - FastColor.ARGB32.color(255, topc, topc, topc)); + Color.ofRGB(topc, topc, topc).getColor()); } } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/impl/ScissorsHandlerImpl.java b/common/src/main/java/me/shedaniel/clothconfig2/impl/ScissorsHandlerImpl.java deleted file mode 100644 index 5bf32f5d..00000000 --- a/common/src/main/java/me/shedaniel/clothconfig2/impl/ScissorsHandlerImpl.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * This file is part of Cloth Config. - * Copyright (C) 2020 - 2021 shedaniel - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package me.shedaniel.clothconfig2.impl; - -import com.google.common.collect.Lists; -import com.mojang.blaze3d.platform.GlStateManager; -import com.mojang.blaze3d.platform.Window; -import me.shedaniel.clothconfig2.api.ScissorsHandler; -import me.shedaniel.clothconfig2.api.ScissorsScreen; -import me.shedaniel.math.Rectangle; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.Minecraft; -import org.jetbrains.annotations.ApiStatus; - -import java.util.Collections; -import java.util.List; - -@Environment(EnvType.CLIENT) -@ApiStatus.Internal -public final class ScissorsHandlerImpl implements ScissorsHandler { - @ApiStatus.Internal - public static final ScissorsHandler INSTANCE = new ScissorsHandlerImpl(); - - // TODO: should this be reimplemented? - /*static { - Executor.runIf(() -> FabricLoader.getInstance().isModLoaded("notenoughcrashes"), () -> () -> { - try { - Class.forName("fudge.notenoughcrashes.api.NotEnoughCrashesApi").getDeclaredMethod("onEveryCrash", Runnable.class).invoke(null, (Runnable) () -> { - try { - ScissorsHandler.INSTANCE.clearScissors(); - } catch (Throwable t) { - ClothConfigInitializer.LOGGER.error("[ClothConfig] Failed clear scissors on game crash!", t); - } - }); - } catch (Throwable throwable) { - throwable.printStackTrace(); - } - }); - }*/ - - private final List scissorsAreas; - - public ScissorsHandlerImpl() { - this.scissorsAreas = Lists.newArrayList(); - } - - @Override - public void clearScissors() { - scissorsAreas.clear(); - applyScissors(); - } - - @Override - public List getScissorsAreas() { - return Collections.unmodifiableList(scissorsAreas); - } - - @Override - public void scissor(Rectangle rectangle) { - scissorsAreas.add(rectangle); - applyScissors(); - } - - @Override - public void removeLastScissor() { - if (!scissorsAreas.isEmpty()) - scissorsAreas.remove(scissorsAreas.size() - 1); - applyScissors(); - } - - @Override - public void applyScissors() { - if (!scissorsAreas.isEmpty()) { - Rectangle r = scissorsAreas.get(0).clone(); - for (int i = 1; i < scissorsAreas.size(); i++) { - Rectangle r1 = scissorsAreas.get(i); - if (r.intersects(r1)) { - r.setBounds(r.intersection(r1)); - } else { - if (Minecraft.getInstance().screen instanceof ScissorsScreen) - _applyScissor(((ScissorsScreen) Minecraft.getInstance().screen).handleScissor(new Rectangle())); - else _applyScissor(new Rectangle()); - return; - } - } - r.setBounds(Math.min(r.x, r.x + r.width), Math.min(r.y, r.y + r.height), Math.abs(r.width), Math.abs(r.height)); - if (Minecraft.getInstance().screen instanceof ScissorsScreen) - _applyScissor(((ScissorsScreen) Minecraft.getInstance().screen).handleScissor(r)); - else _applyScissor(r); - } else { - if (Minecraft.getInstance().screen instanceof ScissorsScreen) - _applyScissor(((ScissorsScreen) Minecraft.getInstance().screen).handleScissor(null)); - else _applyScissor(null); - } - } - - public void _applyScissor(Rectangle r) { - if (r != null) { - GlStateManager._enableScissorTest(); - if (r.isEmpty()) { - GlStateManager._scissorBox(0, 0, 0, 0); - } else { - Window window = Minecraft.getInstance().getWindow(); - double scaleFactor = window.getGuiScale(); - GlStateManager._scissorBox((int) (r.x * scaleFactor), (int) ((window.getGuiScaledHeight() - r.height - r.y) * scaleFactor), (int) (r.width * scaleFactor), (int) (r.height * scaleFactor)); - } - } else { - GlStateManager._disableScissorTest(); - } - } -} diff --git a/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownMenuBuilder.java b/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownMenuBuilder.java index 79ac96c5..310bcfd1 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownMenuBuilder.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownMenuBuilder.java @@ -191,7 +191,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, int x, int y, i textFieldWidget.setTextColor(getPreferredTextColor()); textFieldWidget.render(graphics, mouseX, mouseY, delta); ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); - ItemStack stack = hasConfigError() ? BARRIER : new ItemStack(BuiltInRegistries.ITEM.get(getValue())); + ItemStack stack = hasConfigError() ? BARRIER : new ItemStack(BuiltInRegistries.ITEM.getValue(getValue())); graphics.renderItem(stack, x + width - 18, y + 2); } }; @@ -208,7 +208,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, int x, int y, i textFieldWidget.setTextColor(getPreferredTextColor()); textFieldWidget.render(graphics, mouseX, mouseY, delta); ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); - ItemStack stack = hasConfigError() ? BARRIER : new ItemStack(BuiltInRegistries.BLOCK.get(getValue())); + ItemStack stack = hasConfigError() ? BARRIER : new ItemStack(BuiltInRegistries.BLOCK.getValue(getValue())); graphics.renderItem(stack, x + width - 18, y + 2); } }; @@ -372,7 +372,7 @@ public static SelectionCellCreator ofItemIdentifier(int cellHe return new DefaultSelectionCellCreator() { @Override public DropdownBoxEntry.SelectionCellElement create(ResourceLocation selection) { - ItemStack s = new ItemStack(BuiltInRegistries.ITEM.get(selection)); + ItemStack s = new ItemStack(BuiltInRegistries.ITEM.getValue(selection)); return new DropdownBoxEntry.DefaultSelectionCellElement(selection, toTextFunction) { @Override public void render(GuiGraphics graphics, int mouseX, int mouseY, int x, int y, int width, int height, float delta) { @@ -421,7 +421,7 @@ public static SelectionCellCreator ofBlockIdentifier(int cellH return new DefaultSelectionCellCreator() { @Override public DropdownBoxEntry.SelectionCellElement create(ResourceLocation selection) { - ItemStack s = new ItemStack(BuiltInRegistries.BLOCK.get(selection)); + ItemStack s = new ItemStack(BuiltInRegistries.BLOCK.getValue(selection)); return new DropdownBoxEntry.DefaultSelectionCellElement(selection, toTextFunction) { @Override public void render(GuiGraphics graphics, int mouseX, int mouseY, int x, int y, int width, int height, float delta) { diff --git a/fabric/build.gradle b/fabric/build.gradle index 7da7ed05..b938a8e6 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -111,7 +111,7 @@ publishing { unifiedPublishing { project { displayName = "[Fabric $rootProject.supported_version] v$project.version" - releaseType = "release" + releaseType = "beta" gameVersions = [] gameLoaders = ["fabric"] @@ -121,7 +121,7 @@ unifiedPublishing { curseforge { token = project.hasProperty("curse_api_key") ? project.property("curse_api_key") : System.getenv("curse_api_key") id = project.curseforge_id - gameVersions.addAll "1.21", "Java 21" + gameVersions.addAll "1.21.2-Snapshot", "Java 21" } } diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 060e1586..5dfbfb7b 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "cloth-config", - "name": "Cloth Config v15", + "name": "Cloth Config v16", "description": "An API for config screens.", "version": "${version}", "authors": [ @@ -27,7 +27,7 @@ ], "depends": { "fabricloader": ">=0.14.0", - "minecraft": ">=1.21-" + "minecraft": ">=1.21.2-" }, "accessWidener": "cloth-config.accessWidener", "custom": { diff --git a/gradle.properties b/gradle.properties index 593509ff..945c357d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,21 +1,21 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -minecraft_version=1.21 -supported_version=1.21 +minecraft_version=24w36a +supported_version=1.21.2 (24w36a) archives_base_name=cloth-config archives_base_name_snapshot=cloth-config-snapshot -base_version=15.0 +base_version=16.0 maven_group=me.shedaniel.cloth jankson_version=1.2.0 toml4j_version=0.7.2 snakeyaml_version=1.27 -fabric_loader_version=0.16.0 -fabric_api_version=0.102.0+1.21 -mod_menu_version=11.0.0 +fabric_loader_version=0.16.5 +fabric_api_version=0.103.2+1.21.2 +mod_menu_version=12.0.0-alpha.1 forge_version=51.0.33 neoforge_version=21.0.167 diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 6bcc0632..deb2df73 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -9,7 +9,7 @@ license = "GNU LGPLv3" [[mods]] modId = "cloth_config" version = "${version}" -displayName = "Cloth Config v15 API" +displayName = "Cloth Config v16 API" description = ''' An API for config screens. ''' diff --git a/settings.gradle b/settings.gradle index a482eb80..5f295fa9 100755 --- a/settings.gradle +++ b/settings.gradle @@ -14,7 +14,7 @@ if (JavaVersion.current().ordinal() + 1 < 21) { include("common") include("fabric") -include("forge") -include("neoforge") +//include("forge") +//include("neoforge") rootProject.name = 'cloth-config'