aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/isxander/yacl3/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/dev/isxander/yacl3/gui')
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java49
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java3
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/YACLScreen.java14
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/controllers/ColorController.java8
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/controllers/ColorPickerWidget.java16
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/controllers/LabelController.java2
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/DropdownWidget.java19
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/ItemControllerElement.java10
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/controllers/string/StringControllerElement.java7
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/image/YACLImageReloadListener.java10
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/image/impl/AnimatedDynamicTextureImage.java17
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/image/impl/DynamicTextureImage.java3
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/image/impl/ResourceTextureImage.java3
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/utils/GuiUtils.java81
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java9
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/utils/MiscUtil.java14
-rw-r--r--src/main/java/dev/isxander/yacl3/gui/utils/YACLRenderHelper.java2
17 files changed, 193 insertions, 74 deletions
diff --git a/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java b/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
index 48f2cc3..111ccdb 100644
--- a/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
+++ b/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java
@@ -2,6 +2,7 @@ package dev.isxander.yacl3.gui;
import com.mojang.blaze3d.vertex.VertexConsumer;
import dev.isxander.yacl3.api.utils.Dimension;
+import dev.isxander.yacl3.gui.utils.GuiUtils;
import dev.isxander.yacl3.gui.utils.YACLRenderHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
@@ -88,23 +89,22 @@ public abstract class AbstractWidget implements GuiEventListener, Renderable, Na
graphics.fill(x1, y1, x1 + width, y2, color);
}
- protected void fillSidewaysGradient(GuiGraphics graphics, int x1, int y1, int x2, int y2, int startColor, int endColor) {
+ protected void fillSidewaysGradient(GuiGraphics graphics, int x1, int y1, int x2, int y2, int startColor, int endColor, VertexConsumer consumer) {
//Fills a gradient, left to right
//Uses practically the same method as the GuiGraphics class, but with the x/y moved
//Has a custom "z" value in case needed for later
- VertexConsumer vertex = graphics.bufferSource().getBuffer(RenderType.gui());
Matrix4f matrix4f = graphics.pose().last().pose();
/*? if >1.20.6 {*/
- vertex.addVertex(matrix4f, x1, y1, 0).setColor(startColor);
- vertex.addVertex(matrix4f, x1, y2, 0).setColor(startColor);
- vertex.addVertex(matrix4f, x2, y2, 0).setColor(endColor);
- vertex.addVertex(matrix4f, x2, y1, 0).setColor(endColor);
+ consumer.addVertex(matrix4f, x1, y1, 0).setColor(startColor);
+ consumer.addVertex(matrix4f, x1, y2, 0).setColor(startColor);
+ consumer.addVertex(matrix4f, x2, y2, 0).setColor(endColor);
+ consumer.addVertex(matrix4f, x2, y1, 0).setColor(endColor);
/*?} else {*/
- /*vertex.vertex(matrix4f, x1, y1, 0).color(startColor).endVertex();
- vertex.vertex(matrix4f, x1, y2, 0).color(startColor).endVertex();
- vertex.vertex(matrix4f, x2, y2, 0).color(endColor).endVertex();
- vertex.vertex(matrix4f, x2, y1, 0).color(endColor).endVertex();
+ /*consumer.vertex(matrix4f, x1, y1, 0).color(startColor).endVertex();
+ consumer.vertex(matrix4f, x1, y2, 0).color(startColor).endVertex();
+ consumer.vertex(matrix4f, x2, y2, 0).color(endColor).endVertex();
+ consumer.vertex(matrix4f, x2, y1, 0).color(endColor).endVertex();
*//*?}*/
}
@@ -115,16 +115,25 @@ public abstract class AbstractWidget implements GuiEventListener, Renderable, Na
Color.cyan.getRGB(), Color.blue.getRGB(), Color.magenta.getRGB(), Color.red.getRGB()}; //all the colors in the gradient
int width = x2 - x1;
int maxColors = colors.length - 1;
- for (int color = 0; color < maxColors; color++) {
- //First checks if the final color is being rendered, if true -> uses x2 int instead of x1
- //if false -> it adds the width divided by the max colors multiplied by the current color plus one to the x1 int
- //the x2 int for the fillSidewaysGradient is the same formula, excluding the additional plus one.
- //The gradient colors is determined by the color int and the color int plus one, which is why red is in the colors array twice
- fillSidewaysGradient(graphics,
- x1 + (width / maxColors * color), y1,
- color == maxColors - 1 ? x2 : x1 + (width / maxColors * (color + 1)), y2,
- colors[color], colors[color + 1]);
- }
+
+ GuiUtils.drawSpecial(graphics, bufferSource -> {
+ VertexConsumer consumer = bufferSource.getBuffer(RenderType.gui());
+
+ for (int color = 0; color < maxColors; color++) {
+ //First checks if the final color is being rendered, if true -> uses x2 int instead of x1
+ //if false -> it adds the width divided by the max colors multiplied by the current color plus one to the x1 int
+ //the x2 int for the fillSidewaysGradient is the same formula, excluding the additional plus one.
+ //The gradient colors is determined by the color int and the color int plus one, which is why red is in the colors array twice
+ fillSidewaysGradient(
+ graphics,
+ x1 + (width / maxColors * color), y1,
+ color == maxColors - 1 ? x2 : x1 + (width / maxColors * (color + 1)), y2,
+ colors[color], colors[color + 1],
+ consumer
+ );
+ }
+ });
+
}
protected int multiplyColor(int hex, float amount) {
diff --git a/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java b/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java
index 8412cc8..cbd15fe 100644
--- a/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java
+++ b/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java
@@ -173,7 +173,8 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten
}
@Override
- protected int getRowTop(int index) {
+ /*? if >=1.21.2 {*/ public /*?} else {*/ /*protected *//*?}*/
+ int getRowTop(int index) {
int integer = getY() + 4 - (int) this.getScrollAmount() + headerHeight;
for (int i = 0; i < children().size() && i < index; i++)
integer += children().get(i).getItemHeight();
diff --git a/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java b/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
index 90bc75f..812a0a1 100644
--- a/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
+++ b/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java
@@ -2,7 +2,6 @@ package dev.isxander.yacl3.gui;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.systems.RenderSystem;
-import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Axis;
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.utils.Dimension;
@@ -25,12 +24,10 @@ import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.MultiLineLabel;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.components.tabs.TabManager;
-import net.minecraft.client.gui.components.tabs.TabNavigationBar;
import net.minecraft.client.gui.navigation.ScreenRectangle;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.tooltip.TooltipRenderUtil;
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
-import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
@@ -285,7 +282,8 @@ public class YACLScreen extends Screen {
drawY,
maxWidth,
height,
- 400
+ 400/*? if >=1.21.2 {*/,
+ null/*?}*/
);
graphics.pose().translate(0.0, 0.0, 400.0);
@@ -394,19 +392,19 @@ public class YACLScreen extends Screen {
public void renderBackground(GuiGraphics graphics) {
RenderSystem.enableBlend();
// right pane darker db
- graphics.blit(DARKER_BG, rightPaneDim.left(), rightPaneDim.top(), rightPaneDim.right() + 2, rightPaneDim.bottom() + 2, rightPaneDim.width() + 2, rightPaneDim.height() + 2, 32, 32);
-
+ GuiUtils.blitGuiTex(graphics, DARKER_BG, rightPaneDim.left(), rightPaneDim.top(), rightPaneDim.right() + 2, rightPaneDim.bottom() + 2, rightPaneDim.width() + 2, rightPaneDim.height() + 2, 32, 32);
+
// top separator for right pane
graphics.pose().pushPose();
graphics.pose().translate(0, 0, 10);
- graphics.blit(CreateWorldScreen.HEADER_SEPARATOR, rightPaneDim.left() - 1, rightPaneDim.top() - 2, 0.0F, 0.0F, rightPaneDim.width() + 1, 2, 32, 2);
+ GuiUtils.blitGuiTex(graphics, CreateWorldScreen.HEADER_SEPARATOR, rightPaneDim.left() - 1, rightPaneDim.top() - 2, 0.0F, 0.0F, rightPaneDim.width() + 1, 2, 32, 2);
graphics.pose().popPose();
// left separator for right pane
graphics.pose().pushPose();
graphics.pose().translate(rightPaneDim.left(), rightPaneDim.top() - 1, 0);
graphics.pose().rotateAround(Axis.ZP.rotationDegrees(90), 0, 0, 1);
- graphics.blit(CreateWorldScreen.FOOTER_SEPARATOR, 0, 0, 0f, 0f, rightPaneDim.height() + 1, 2, 32, 2);
+ GuiUtils.blitGuiTex(graphics, CreateWorldScreen.FOOTER_SEPARATOR, 0, 0, 0f, 0f, rightPaneDim.height() + 1, 2, 32, 2);
graphics.pose().popPose();
RenderSystem.disableBlend();
diff --git a/src/main/java/dev/isxander/yacl3/gui/controllers/ColorController.java b/src/main/java/dev/isxander/yacl3/gui/controllers/ColorController.java
index 3c0a5fc..a48bdde 100644
--- a/src/main/java/dev/isxander/yacl3/gui/controllers/ColorController.java
+++ b/src/main/java/dev/isxander/yacl3/gui/controllers/ColorController.java
@@ -260,7 +260,7 @@ public class ColorController implements IStringController<Color> {
@Override
public void unfocus() {
- if(colorPickerVisible) {
+ if (colorPickerVisible) {
removeColorPicker();
}
previewOutlineFadeTicks = 0;
@@ -271,7 +271,7 @@ public class ColorController implements IStringController<Color> {
Color outlineColor = new Color(0xFF000000);
Color highlightedColor = getHighlightedOutlineColor();
- if(!hovered && !colorPreviewHovered) {
+ if (!hovered && !colorPreviewHovered) {
previewOutlineFadeTicks = 0;
return outlineColor;
}
@@ -279,11 +279,11 @@ public class ColorController implements IStringController<Color> {
int fadeInTicks = 80;
int fadeOutTicks = fadeInTicks + 120;
- if(colorPreviewHovered) {
+ if (colorPreviewHovered) {
//white/light grey if the color preview is being hovered
previewOutlineFadeTicks = 0;
return highlightedColor;
- } else if(YACLConfig.HANDLER.instance().showColorPickerIndicator) {
+ } else if (YACLConfig.HANDLER.instance().showColorPickerIndicator) {
if(previewOutlineFadeTicks <= fadeInTicks) {
//fade to white
return getFadedColor(outlineColor, highlightedColor, previewOutlineFadeTicks, fadeInTicks);
diff --git a/src/main/java/dev/isxander/yacl3/gui/controllers/ColorPickerWidget.java b/src/main/java/dev/isxander/yacl3/gui/controllers/ColorPickerWidget.java
index efa1aec..a1828f5 100644
--- a/src/main/java/dev/isxander/yacl3/gui/controllers/ColorPickerWidget.java
+++ b/src/main/java/dev/isxander/yacl3/gui/controllers/ColorPickerWidget.java
@@ -3,9 +3,11 @@ package dev.isxander.yacl3.gui.controllers;
import dev.isxander.yacl3.api.utils.Dimension;
import dev.isxander.yacl3.api.utils.MutableDimension;
import dev.isxander.yacl3.gui.YACLScreen;
+import dev.isxander.yacl3.gui.utils.GuiUtils;
import dev.isxander.yacl3.gui.utils.YACLRenderHelper;
import dev.isxander.yacl3.platform.YACLPlatform;
import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
@@ -89,7 +91,7 @@ public class ColorPickerWidget extends ControllerPopupWidget<ColorController> {
//Background
/*? if >1.20.3 {*/
- graphics.blitSprite(COLOR_PICKER_LOCATION, colorPickerDim.x() - 5, colorPickerDim.y() - 5, colorPickerDim.width() + 10, colorPickerDim.height() + 10);
+ GuiUtils.blitSprite(graphics, COLOR_PICKER_LOCATION, colorPickerDim.x() - 5, colorPickerDim.y() - 5, colorPickerDim.width() + 10, colorPickerDim.height() + 10);
/*?} else {*/
/*graphics.blitNineSliced(COLOR_PICKER_ATLAS, colorPickerDim.x() - 5, colorPickerDim.y() - 5, colorPickerDim.width() + 10, colorPickerDim.height() + 10, 3, 236, 34, 0, 0);
*//*?}*/
@@ -100,7 +102,7 @@ public class ColorPickerWidget extends ControllerPopupWidget<ColorController> {
//transparent texture - must be rendered BEFORE the main color preview
if(controller.allowAlpha()) {
/*? if >1.20.3 {*/
- graphics.blitSprite(TRANSPARENT_TEXTURE_LOCATION, previewColorDim.x(), previewColorDim.y(), previewColorDim.width(), previewColorDim.height());
+ GuiUtils.blitSprite(graphics, TRANSPARENT_TEXTURE_LOCATION, previewColorDim.x(), previewColorDim.y(), previewColorDim.width(), previewColorDim.height());
/*?} else {*/
/*graphics.blitRepeating(COLOR_PICKER_ATLAS, previewColorDim.x(), previewColorDim.y(), previewColorDim.width(), previewColorDim.height(), 236, 0, 8, 8);
*//*?}*/
@@ -112,7 +114,9 @@ public class ColorPickerWidget extends ControllerPopupWidget<ColorController> {
//outline
graphics.fill(saturationLightDim.x() - outline, saturationLightDim.y() - outline, saturationLightDim.xLimit() + outline, saturationLightDim.yLimit() + outline, Color.black.getRGB());
//White to pending color's RGB from hue, left to right
- fillSidewaysGradient(graphics, saturationLightDim.x(), saturationLightDim.y(), saturationLightDim.xLimit(), saturationLightDim.yLimit(), 0xFFFFFFFF, (int) getRgbFromHueX());
+ GuiUtils.drawSpecial(graphics, bufferSource -> {
+ fillSidewaysGradient(graphics, saturationLightDim.x(), saturationLightDim.y(), saturationLightDim.xLimit(), saturationLightDim.yLimit(), 0xFFFFFFFF, (int) getRgbFromHueX(), bufferSource.getBuffer(RenderType.gui()));
+ });
//Transparent to black, top to bottom
graphics.fillGradient(saturationLightDim.x(), saturationLightDim.y(), saturationLightDim.xLimit(), saturationLightDim.yLimit(), 0x00000000, 0xFF000000);
//Sat/light thumb shadow
@@ -135,12 +139,14 @@ public class ColorPickerWidget extends ControllerPopupWidget<ColorController> {
graphics.fill(alphaGradientDim.x() - outline, alphaGradientDim.y() - outline, alphaGradientDim.xLimit() + outline, alphaGradientDim.yLimit() + outline, Color.black.getRGB());
//Transparent texture
/*? if >1.20.3 {*/
- graphics.blitSprite(TRANSPARENT_TEXTURE_LOCATION, alphaGradientDim.x(), alphaGradientDim.y(), alphaGradientDim.width(), sliderHeight);
+ GuiUtils.blitSprite(graphics, TRANSPARENT_TEXTURE_LOCATION, alphaGradientDim.x(), alphaGradientDim.y(), alphaGradientDim.width(), sliderHeight);
/*?} else {*/
/*graphics.blitRepeating(COLOR_PICKER_ATLAS, alphaGradientDim.x(), alphaGradientDim.y(), alphaGradientDim.width(), sliderHeight, 236, 0, 8, 8);
*//*?}*/
//Pending color to transparent
- fillSidewaysGradient(graphics, alphaGradientDim.x(), alphaGradientDim.y(), alphaGradientDim.xLimit(), alphaGradientDim.yLimit(), getRgbWithoutAlpha(), 0x00000000);
+ GuiUtils.drawSpecial(graphics, bufferSource -> {
+ fillSidewaysGradient(graphics, alphaGradientDim.x(), alphaGradientDim.y(), alphaGradientDim.xLimit(), alphaGradientDim.yLimit(), getRgbWithoutAlpha(), 0x00000000, bufferSource.getBuffer(RenderType.gui()));
+ });
//Alpha slider thumb shadow
graphics.fill(alphaThumbX - thumbWidth / 2 - 1, alphaGradientDim.y() - outline - 1, alphaThumbX + thumbWidth / 2 + 1, alphaGradientDim.yLimit() + outline + 1, 0xFF404040);
//Alpha slider thumb
diff --git a/src/main/java/dev/isxander/yacl3/gui/controllers/LabelController.java b/src/main/java/dev/isxander/yacl3/gui/controllers/LabelController.java
index fee6c19..9f38d3b 100644
--- a/src/main/java/dev/isxander/yacl3/gui/controllers/LabelController.java
+++ b/src/main/java/dev/isxander/yacl3/gui/controllers/LabelController.java
@@ -88,8 +88,6 @@ public class LabelController implements Controller<Component> {
graphics.pose().pushPose();
graphics.pose().translate(0, 0, 100);
if (isMouseOver(mouseX, mouseY)) {
- YACLScreen.renderMultilineTooltip(graphics, textRenderer, wrappedTooltip, getDimension().centerX(), getDimension().y() - 5, getDimension().yLimit() + 5, screen.width, screen.height);
-
Style style = getStyle(mouseX, mouseY);
if (style != null && style.getHoverEvent() != null) {
HoverEvent hoverEvent = style.getHoverEvent();
diff --git a/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/DropdownWidget.java b/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/DropdownWidget.java
index f799059..464571e 100644
--- a/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/DropdownWidget.java
+++ b/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/DropdownWidget.java
@@ -5,6 +5,7 @@ import dev.isxander.yacl3.api.utils.Dimension;
import dev.isxander.yacl3.api.utils.MutableDimension;
import dev.isxander.yacl3.gui.YACLScreen;
import dev.isxander.yacl3.gui.controllers.ControllerPopupWidget;
+import dev.isxander.yacl3.gui.utils.GuiUtils;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
@@ -59,26 +60,28 @@ public class DropdownWidget<T> extends ControllerPopupWidget<AbstractDropdownCon
matrices.translate(0, 0, 200);
// Background
- graphics.setColor(0.25f, 0.25f, 0.25f, 1.0f);
- graphics.blit(
+ //graphics.setColor(0.25f, 0.25f, 0.25f, 1.0f);
+ GuiUtils.blitGuiTexColor(
+ graphics,
/*? if >1.20.4 {*/
Screen.MENU_BACKGROUND,
/*?} else {*/
/*Screen.BACKGROUND_LOCATION,
*//*?}*/
- dropdownDim.x(), dropdownDim.y(), 0,
+ dropdownDim.x(), dropdownDim.y(),
0.0f, 0.0f,
dropdownDim.width(), dropdownDim.height(),
- 32, 32
+ 32, 32,
+ 0xFF3F3F3F
);
- graphics.setColor(1.0f, 1.0f, 1.0f, 1.0f);
+ //graphics.setColor(1.0f, 1.0f, 1.0f, 1.0f);
graphics.renderOutline(dropdownDim.x(), dropdownDim.y(), dropdownDim.width(), dropdownDim.height(), -1);
// Highlight the currently selected element
- graphics.setColor(0.0f, 0.0f, 0.0f, 0.5f);
+ //graphics.setColor(0.0f, 0.0f, 0.0f, 0.5f);
int y = dropdownDim.y() + 2 + entryHeight() * selectedVisibleIndex();
- graphics.fill(dropdownDim.x(), y, dropdownDim.xLimit(), y + entryHeight(), -1);
- graphics.setColor(1.0f, 1.0f, 1.0f, 1.0f);
+ graphics.fill(dropdownDim.x(), y, dropdownDim.xLimit(), y + entryHeight(), 0x7F000000);
+ //graphics.setColor(1.0f, 1.0f, 1.0f, 1.0f);
graphics.renderOutline(dropdownDim.x(), y, dropdownDim.width(), entryHeight(), -1);
// Render all visible elements
diff --git a/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/ItemControllerElement.java b/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/ItemControllerElement.java
index 2c19c13..37911de 100644
--- a/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/ItemControllerElement.java
+++ b/src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/ItemControllerElement.java
@@ -3,6 +3,7 @@ package dev.isxander.yacl3.gui.controllers.dropdown;
import dev.isxander.yacl3.api.utils.Dimension;
import dev.isxander.yacl3.gui.YACLScreen;
import dev.isxander.yacl3.gui.utils.ItemRegistryHelper;
+import dev.isxander.yacl3.gui.utils.MiscUtil;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
@@ -43,7 +44,7 @@ public class ItemControllerElement extends AbstractDropdownControllerElement<Ite
List<ResourceLocation> identifiers = ItemRegistryHelper.getMatchingItemIdentifiers(inputField).toList();
currentItem = ItemRegistryHelper.getItemFromName(inputField, null);
for (ResourceLocation identifier : identifiers) {
- matchingItems.put(identifier, BuiltInRegistries.ITEM.get(identifier));
+ matchingItems.put(identifier, MiscUtil.getFromRegistry(BuiltInRegistries.ITEM, identifier));
}
return identifiers;
}
@@ -86,6 +87,11 @@ public class ItemControllerElement extends AbstractDropdownControllerElement<Ite
if (inputFieldFocused)
return Component.literal(inputField);
- return itemController.option().pendingValue().getDescription();
+ return itemController.option().pendingValue()
+ //? if >=1.21.2 {
+ .getName();
+ //?} else {
+ /*.getDescription();
+ *///?}
}
}
diff --git a/src/main/java/dev/isxander/yacl3/gui/controllers/string/StringControllerElement.java b/src/main/java/dev/isxander/yacl3/gui/controllers/string/StringControllerElement.java
index 689d8e2..7151f89 100644
--- a/src/main/java/dev/isxander/yacl3/gui/controllers/string/StringControllerElement.java
+++ b/src/main/java/dev/isxander/yacl3/gui/controllers/string/StringControllerElement.java
@@ -1,6 +1,7 @@
package dev.isxander.yacl3.gui.controllers.string;
import com.mojang.blaze3d.platform.InputConstants;
+import dev.isxander.yacl3.api.OptionEventListener;
import dev.isxander.yacl3.api.utils.Dimension;
import dev.isxander.yacl3.gui.YACLScreen;
import dev.isxander.yacl3.gui.controllers.ControllerWidget;
@@ -39,8 +40,10 @@ public class StringControllerElement extends ControllerWidget<IStringController<
inputFieldFocused = false;
selectionLength = 0;
emptyText = Component.literal("Click to type...").withStyle(ChatFormatting.GRAY);
- control.option().addListener((opt, val) -> {
- inputField = control.getString();
+ control.option().addEventListener((opt, event) -> {
+ if (event == OptionEventListener.Event.STATE_CHANGE) {
+ inputField = control.getString();
+ }
});
setDimension(dim);
}
diff --git a/src/main/java/dev/isxander/yacl3/gui/image/YACLImageReloadListener.java b/src/main/java/dev/isxander/yacl3/gui/image/YACLImageReloadListener.java
index fb0695c..235d1d4 100644
--- a/src/main/java/dev/isxander/yacl3/gui/image/YACLImageReloadListener.java
+++ b/src/main/java/dev/isxander/yacl3/gui/image/YACLImageReloadListener.java
@@ -29,19 +29,20 @@ public class YACLImageReloadListener
public @NotNull CompletableFuture<Void> reload(
PreparationBarrier preparationBarrier,
@NotNull ResourceManager resourceManager,
- @NotNull ProfilerFiller preparationsProfiler,
+ //? if <1.21.2 {
+ /*@NotNull ProfilerFiller preparationsProfiler,
@NotNull ProfilerFiller reloadProfiler,
+ *///?}
@NotNull Executor backgroundExecutor,
@NotNull Executor gameExecutor
) {
- return prepare(resourceManager, preparationsProfiler, backgroundExecutor)
+ return prepare(resourceManager, backgroundExecutor)
.thenCompose(preparationBarrier::wait)
- .thenCompose(suppliers -> apply(suppliers, reloadProfiler, gameExecutor));
+ .thenCompose(suppliers -> apply(suppliers, gameExecutor));
}
private CompletableFuture<List<Optional<SupplierPreparation>>> prepare(
ResourceManager manager,
- ProfilerFiller profiler,
Executor executor
) {
Map<ResourceLocation, Resource> imageResources = manager.listResources(
@@ -72,7 +73,6 @@ public class YACLImageReloadListener
private CompletableFuture<Void> apply(
List<Optional<SupplierPreparation>> suppliers,
- ProfilerFiller profiler,
Executor executor
) {
return CompletableFuture.allOf(suppliers.stream()
diff --git a/src/main/java/dev/isxander/yacl3/gui/image/impl/AnimatedDynamicTextureImage.java b/src/main/java/dev/isxander/yacl3/gui/image/impl/AnimatedDynamicTextureImage.java
index 39ddb55..1dd52f2 100644
--- a/src/main/java/dev/isxander/yacl3/gui/image/impl/AnimatedDynamicTextureImage.java
+++ b/src/main/java/dev/isxander/yacl3/gui/image/impl/AnimatedDynamicTextureImage.java
@@ -7,7 +7,7 @@ import com.mojang.blaze3d.platform.NativeImage;
import com.twelvemonkeys.imageio.plugins.webp.WebPImageReaderSpi;
import dev.isxander.yacl3.debug.DebugProperties;
import dev.isxander.yacl3.gui.image.ImageRendererFactory;
-import dev.isxander.yacl3.impl.utils.YACLConstants;
+import dev.isxander.yacl3.gui.utils.GuiUtils;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
import net.minecraft.ReportedException;
@@ -16,7 +16,6 @@ import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
-import net.minecraft.util.FastColor;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
@@ -71,7 +70,8 @@ public class AnimatedDynamicTextureImage extends DynamicTextureImage {
GlStateManager._texParameter(GlConst.GL_TEXTURE_2D, GlConst.GL_TEXTURE_MIN_FILTER, GlConst.GL_LINEAR);
}
- graphics.blit(
+ GuiUtils.blitGuiTex(
+ graphics,
uniqueLocation,
0, 0,
frameWidth * currentCol, frameHeight * currentRow,
@@ -251,19 +251,16 @@ public class AnimatedDynamicTextureImage extends DynamicTextureImage {
for (int w = 0; w < bi.getWidth(); w++) {
for (int h = 0; h < bi.getHeight(); h++) {
- int rgb = bi.getRGB(w, h);
- int r = FastColor.ARGB32.red(rgb);
- int g = FastColor.ARGB32.green(rgb);
- int b = FastColor.ARGB32.blue(rgb);
- int a = FastColor.ARGB32.alpha(rgb);
+ int argb = bi.getRGB(w, h);
int col = i % cols;
int row = (int) Math.floor(i / (double)cols);
- image.setPixelRGBA(
+ GuiUtils.setPixelARGB(
+ image,
frameWidth * col + w + xOffset,
frameHeight * row + h + yOffset,
- FastColor.ABGR32.color(a, b, g, r) // NativeImage uses ABGR for some reason
+ argb
);
}
}
diff --git a/src/main/java/dev/isxander/yacl3/gui/image/impl/DynamicTextureImage.java b/src/main/java/dev/isxander/yacl3/gui/image/impl/DynamicTextureImage.java
index 2d2abb9..edfaebc 100644
--- a/src/main/java/dev/isxander/yacl3/gui/image/impl/DynamicTextureImage.java
+++ b/src/main/java/dev/isxander/yacl3/gui/image/impl/DynamicTextureImage.java
@@ -7,6 +7,7 @@ import com.mojang.blaze3d.systems.RenderSystem;
import dev.isxander.yacl3.debug.DebugProperties;
import dev.isxander.yacl3.gui.image.ImageRenderer;
import dev.isxander.yacl3.gui.image.ImageRendererFactory;
+import dev.isxander.yacl3.gui.utils.GuiUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.texture.DynamicTexture;
@@ -51,7 +52,7 @@ public class DynamicTextureImage implements ImageRenderer {
GlStateManager._texParameter(GlConst.GL_TEXTURE_2D, GlConst.GL_TEXTURE_MIN_FILTER, GlConst.GL_LINEAR);
}
- graphics.blit(uniqueLocation, 0, 0, 0, 0, this.width, this.height, this.width, this.height);
+ GuiUtils.blitGuiTex(graphics, uniqueLocation, 0, 0, 0, 0, this.width, this.height, this.width, this.height);
graphics.pose().popPose();
diff --git a/src/main/java/dev/isxander/yacl3/gui/image/impl/ResourceTextureImage.java b/src/main/java/dev/isxander/yacl3/gui/image/impl/ResourceTextureImage.java
index abbeec7..baaa4b1 100644
--- a/src/main/java/dev/isxander/yacl3/gui/image/impl/ResourceTextureImage.java
+++ b/src/main/java/dev/isxander/yacl3/gui/image/impl/ResourceTextureImage.java
@@ -5,6 +5,7 @@ import com.mojang.blaze3d.platform.GlStateManager;
import dev.isxander.yacl3.debug.DebugProperties;
import dev.isxander.yacl3.gui.image.ImageRenderer;
import dev.isxander.yacl3.gui.image.ImageRendererFactory;
+import dev.isxander.yacl3.gui.utils.GuiUtils;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
@@ -38,7 +39,7 @@ public class ResourceTextureImage implements ImageRenderer {
GlStateManager._texParameter(GlConst.GL_TEXTURE_2D, GlConst.GL_TEXTURE_MIN_FILTER, GlConst.GL_LINEAR);
}
- graphics.blit(location, 0, 0, this.u, this.v, this.width, this.height, this.textureWidth, this.textureHeight);
+ GuiUtils.blitGuiTex(graphics, location, 0, 0, this.u, this.v, this.width, this.height, this.textureWidth, this.textureHeight);
graphics.pose().popPose();
diff --git a/src/main/java/dev/isxander/yacl3/gui/utils/GuiUtils.java b/src/main/java/dev/isxander/yacl3/gui/utils/GuiUtils.java
index 2910d0f..25c4cb7 100644
--- a/src/main/java/dev/isxander/yacl3/gui/utils/GuiUtils.java
+++ b/src/main/java/dev/isxander/yacl3/gui/utils/GuiUtils.java
@@ -1,11 +1,75 @@
package dev.isxander.yacl3.gui.utils;
+import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.client.gui.Font;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.client.renderer.MultiBufferSource;
+import net.minecraft.client.renderer.RenderType;
import net.minecraft.locale.Language;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
+import net.minecraft.resources.ResourceLocation;
+
+import java.util.function.Consumer;
public class GuiUtils {
+ public static void drawSpecial(GuiGraphics graphics, Consumer<MultiBufferSource> consumer) {
+ //? if >=1.21.2 {
+ graphics.drawSpecial(consumer);
+ //?} else {
+ /*MultiBufferSource.BufferSource bufferSource = graphics.bufferSource();
+ consumer.accept(bufferSource);
+ bufferSource.endBatch();
+ *///?}
+ }
+
+ public static void blitGuiTex(GuiGraphics graphics, ResourceLocation texture, int x, int y, float u, float v, int textureWidth, int textureHeight, int width, int height) {
+ graphics.blit(
+ //? if >=1.21.2
+ RenderType::guiTextured,
+ texture,
+ x, y,
+ u, v,
+ textureWidth, textureHeight,
+ width, height
+ );
+ }
+
+ public static void blitGuiTexColor(GuiGraphics graphics, ResourceLocation texture, int x, int y, float u, float v, int textureWidth, int textureHeight, int width, int height, int color) {
+ //? if <1.21.2 {
+ /*float a = (color >> 24 & 255) / 255.0F;
+ float r = (color >> 16 & 255) / 255.0F;
+ float g = (color >> 8 & 255) / 255.0F;
+ float b = (color & 255) / 255.0F;
+ graphics.setColor(r, g, b, a);
+ *///?}
+ graphics.blit(
+ //? if >=1.21.2
+ RenderType::guiTextured,
+ texture,
+ x, y,
+ u, v,
+ textureWidth, textureHeight,
+ width, height
+ //? if >=1.21.2
+ ,color
+ );
+ //? if <1.21.2
+ /*graphics.setColor(1.0F, 1.0F, 1.0F, 1.0F);*/
+ }
+
+ //? if >1.20.1 {
+ public static void blitSprite(GuiGraphics graphics, ResourceLocation sprite, int x, int y, int width, int height) {
+ graphics.blitSprite(
+ //? if >=1.21.2
+ RenderType::guiTextured,
+ sprite,
+ x, y,
+ width, height
+ );
+ }
+ //?}
+
public static MutableComponent translatableFallback(String key, Component fallback) {
if (Language.getInstance().has(key))
return Component.translatable(key);
@@ -29,4 +93,21 @@ public class GuiUtils {
return string;
}
+
+
+ public static void setPixelARGB(NativeImage nativeImage, int x, int y, int argb) {
+ // In 1.21.2+, you set the pixel color in ARGB format, where it internally converts to ABGR.
+ // Before this, you need to directly set the pixel color in ABGR format.
+
+ //? if >=1.21.2 {
+ nativeImage.setPixel(x, y, argb);
+ //?} else {
+ /*int a = (argb >> 24) & 0xFF;
+ int r = (argb >> 16) & 0xFF;
+ int g = (argb >> 8) & 0xFF;
+ int b = argb & 0xFF;
+ int abgr = (a << 24) | (b << 16) | (g << 8) | r;
+ nativeImage.setPixelRGBA(x, y, abgr); // method name is misleading. It's actually ABGR.
+ *///?}
+ }
}
diff --git a/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java b/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java
index bb6c664..dc769bc 100644
--- a/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java
+++ b/src/main/java/dev/isxander/yacl3/gui/utils/ItemRegistryHelper.java
@@ -46,7 +46,7 @@ public final class ItemRegistryHelper {
try {
ResourceLocation itemIdentifier = YACLPlatform.parseRl(identifier.toLowerCase());
if (BuiltInRegistries.ITEM.containsKey(itemIdentifier)) {
- return BuiltInRegistries.ITEM.get(itemIdentifier);
+ return MiscUtil.getFromRegistry(BuiltInRegistries.ITEM, itemIdentifier);
}
} catch (ResourceLocationException ignored) {
}
@@ -80,14 +80,15 @@ public final class ItemRegistryHelper {
if (sep == -1) {
filterPredicate = identifier ->
identifier.getPath().contains(value)
- || BuiltInRegistries.ITEM.get(identifier).getDescription().getString().toLowerCase().contains(value.toLowerCase());
+ || MiscUtil.getFromRegistry(BuiltInRegistries.ITEM, identifier)
+ /*? if >=1.21.2 {*/ .getName() /*?} else {*/ /*.getDescription() *//*?}*/
+ .getString().toLowerCase().contains(value.toLowerCase());
} else {
String namespace = value.substring(0, sep);
String path = value.substring(sep + 1);
filterPredicate = identifier -> identifier.getNamespace().equals(namespace) && identifier.getPath().startsWith(path);
}
- return BuiltInRegistries.ITEM.holders()
- .map(holder -> holder.key().location())
+ return BuiltInRegistries.ITEM.keySet().stream()
.filter(filterPredicate)
/*
Sort items as follows based on the given "value" string's path:
diff --git a/src/main/java/dev/isxander/yacl3/gui/utils/MiscUtil.java b/src/main/java/dev/isxander/yacl3/gui/utils/MiscUtil.java
new file mode 100644
index 0000000..354b38e
--- /dev/null
+++ b/src/main/java/dev/isxander/yacl3/gui/utils/MiscUtil.java
@@ -0,0 +1,14 @@
+package dev.isxander.yacl3.gui.utils;
+
+import net.minecraft.core.Registry;
+import net.minecraft.resources.ResourceLocation;
+
+public class MiscUtil {
+ public static <T> T getFromRegistry(Registry<T> registry, ResourceLocation identifier) {
+ //? if >=1.21.2 {
+ return registry.getValue(identifier);
+ //?} else {
+ /*return registry.get(identifier);
+ *///?}
+ }
+}
diff --git a/src/main/java/dev/isxander/yacl3/gui/utils/YACLRenderHelper.java b/src/main/java/dev/isxander/yacl3/gui/utils/YACLRenderHelper.java
index aadc249..23e97c3 100644
--- a/src/main/java/dev/isxander/yacl3/gui/utils/YACLRenderHelper.java
+++ b/src/main/java/dev/isxander/yacl3/gui/utils/YACLRenderHelper.java
@@ -19,7 +19,7 @@ public class YACLRenderHelper {
public static void renderButtonTexture(GuiGraphics graphics, int x, int y, int width, int height, boolean enabled, boolean focused) {
/*? if >1.20.1 {*/
- graphics.blitSprite(SPRITES.get(enabled, focused), x, y, width, height);
+ GuiUtils.blitSprite(graphics, SPRITES.get(enabled, focused), x, y, width, height);
/*?} else {*/
/*int textureV;
if (enabled) {