From 510b43172ce71f01636110a3e134a2ee919bda6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Schweiger?= Date: Wed, 22 Nov 2023 15:04:41 +0100 Subject: [PATCH 01/10] Add support for DropdownBoxEntry in NestedListListEntry --- .../gui/entries/BaseListCell.java | 6 ++++ .../gui/entries/BaseListEntry.java | 15 +++++++++ .../gui/entries/DropdownBoxEntry.java | 32 +++++++++++-------- .../gui/entries/MultiElementListEntry.java | 2 +- .../gui/entries/NestedListListEntry.java | 12 +++++++ 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListCell.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListCell.java index da1ff9e7..f5b7295f 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListCell.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/BaseListCell.java @@ -53,6 +53,12 @@ public void setErrorSupplier(Supplier> errorSupplier) { public abstract void render(GuiGraphics graphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta); + public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) {} + + public int getMorePossibleHeight() { + return 0; + } + public void updateSelected(boolean isSelected) {} public boolean isRequiresRestart() { 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 85d36f59..b9676cc6 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 @@ -310,6 +310,21 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth } } + @Override + public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + super.lateRender(graphics, mouseX, mouseY, delta); + BaseListCell focused = !isExpanded() || getFocused() == null || !(getFocused() instanceof BaseListCell) ? null : (BaseListCell) getFocused(); + if(focused != null) { + focused.lateRender(graphics, mouseX, mouseY, delta); + } + } + + @Override + public int getMorePossibleHeight() { + BaseListCell focused = !isExpanded() || getFocused() == null || !(getFocused() instanceof BaseListCell) ? null : (BaseListCell) getFocused(); + return focused != null ? focused.getMorePossibleHeight() : 0; + } + @Override public void updateSelected(boolean isSelected) { for (C cell : cells) { 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 85c6f341..f6b07ca0 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 @@ -76,7 +76,7 @@ public DropdownBoxEntry(Component fieldName, @NotNull Component resetButtonKey, this.resetButton = Button.builder(resetButtonKey, widget -> { selectionElement.topRenderer.setValue(defaultValue.get()); }).bounds(0, 0, Minecraft.getInstance().font.width(resetButtonKey) + 6, 20).build(); - this.selectionElement = new SelectionElement<>(this, new Rectangle(0, 0, 150, 20), new DefaultDropdownMenuElement<>(selections == null ? ImmutableList.of() : ImmutableList.copyOf(selections)), topRenderer, cellCreator); + this.selectionElement = new SelectionElement<>(this, new Rectangle(0, 0, fieldName.getString().isBlank() ? 300 : 150, 20), new DefaultDropdownMenuElement<>(selections == null ? ImmutableList.of() : ImmutableList.copyOf(selections)), topRenderer, cellCreator); } @Override @@ -88,6 +88,7 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth this.selectionElement.active = isEditable(); this.selectionElement.bounds.y = y; Component displayedFieldName = getDisplayedFieldName(); + boolean hasName = !displayedFieldName.getString().isBlank(); if (Minecraft.getInstance().font.isBidirectional()) { graphics.drawString(Minecraft.getInstance().font, displayedFieldName.getVisualOrderText(), window.getGuiScaledWidth() - x - Minecraft.getInstance().font.width(displayedFieldName), y + 6, getPreferredTextColor()); this.resetButton.setX(x); @@ -95,9 +96,9 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth } else { graphics.drawString(Minecraft.getInstance().font, displayedFieldName.getVisualOrderText(), x, y + 6, getPreferredTextColor()); this.resetButton.setX(x + entryWidth - resetButton.getWidth()); - this.selectionElement.bounds.x = x + entryWidth - 150 + 1; + this.selectionElement.bounds.x = x + (hasName ? entryWidth - 150 : 0) + 1; } - this.selectionElement.bounds.width = 150 - resetButton.getWidth() - 4; + this.selectionElement.bounds.width = (hasName ? 150 : entryWidth) - resetButton.getWidth() - 4; resetButton.render(graphics, mouseX, mouseY, delta); selectionElement.render(graphics, mouseX, mouseY, delta); } @@ -253,6 +254,10 @@ public SelectionCellCreator getCellCreator() { return cellCreator; } + public int getCellWidth() { + return getCellCreator().getCellWidth() > 0 ? getCellCreator().getCellWidth() : getEntry().selectionElement.bounds.width; + } + @NotNull public final DropdownBoxEntry getEntry() { return entry; @@ -408,18 +413,19 @@ private void updatePosition(float delta) { @Override public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { int last10Height = getHeight(); - int cWidth = getCellCreator().getCellWidth(); - graphics.fill(lastRectangle.x, lastRectangle.y + lastRectangle.height, lastRectangle.x + cWidth, lastRectangle.y + lastRectangle.height + last10Height + 1, isExpanded() ? -1 : -6250336); - graphics.fill(lastRectangle.x + 1, lastRectangle.y + lastRectangle.height + 1, lastRectangle.x + cWidth - 1, lastRectangle.y + lastRectangle.height + last10Height, -16777216); + int cWidth = getCellWidth(); graphics.pose().pushPose(); graphics.pose().translate(0, 0, 300f); + graphics.fill(lastRectangle.x, lastRectangle.y + lastRectangle.height, lastRectangle.x + cWidth, lastRectangle.y + lastRectangle.height + last10Height + 1, isExpanded() ? 0xFFFFFFFF : -6250336); + graphics.fill(lastRectangle.x + 1, lastRectangle.y + lastRectangle.height + 1, lastRectangle.x + cWidth - 1, lastRectangle.y + lastRectangle.height + last10Height, 0xFF000000); + graphics.pose().translate(0, 0, 300f); ScissorsHandler.INSTANCE.scissor(new Rectangle(lastRectangle.x, lastRectangle.y + lastRectangle.height + 1, cWidth - 6, last10Height - 1)); 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) { - graphics.fill(lastRectangle.x + 1, (int) yy, lastRectangle.x + getCellCreator().getCellWidth(), (int) yy + getCellCreator().getCellHeight(), 0xFF000000); - cell.render(graphics, mouseX, mouseY, lastRectangle.x, (int) yy, getMaxScrollPosition() > 6 ? getCellCreator().getCellWidth() - 6 : getCellCreator().getCellWidth(), getCellCreator().getCellHeight(), delta); + graphics.fill(lastRectangle.x + 1, (int) yy, lastRectangle.x + cWidth, (int) yy + getCellCreator().getCellHeight(), 0xFF000000); + cell.render(graphics, mouseX, mouseY, lastRectangle.x, (int) yy, getMaxScrollPosition() > 6 ? cWidth - 6 : cWidth, getCellCreator().getCellHeight(), delta); } else cell.dontRender(graphics, delta); yy += getCellCreator().getCellHeight(); @@ -429,12 +435,12 @@ public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta if (currentElements.isEmpty()) { Font textRenderer = Minecraft.getInstance().font; Component text = Component.translatable("text.cloth-config.dropdown.value.unknown"); - graphics.drawString(textRenderer, text.getVisualOrderText(), (int) (lastRectangle.x + getCellCreator().getCellWidth() / 2f - textRenderer.width(text) / 2f), lastRectangle.y + lastRectangle.height + 3, -1); + graphics.drawString(textRenderer, text.getVisualOrderText(), (int) (lastRectangle.x + cWidth / 2f - textRenderer.width(text) / 2f), lastRectangle.y + lastRectangle.height + 3, -1); } if (getMaxScrollPosition() > 6) { RenderSystem.setShader(GameRenderer::getPositionTexColorShader); - int scrollbarPositionMinX = lastRectangle.x + getCellCreator().getCellWidth() - 6; + int scrollbarPositionMinX = lastRectangle.x + cWidth - 6; int scrollbarPositionMaxX = scrollbarPositionMinX + 6; int height = (int) (((last10Height) * (last10Height)) / this.getMaxScrollPosition()); height = Mth.clamp(height, 32, last10Height - 8); @@ -472,7 +478,7 @@ public int getHeight() { @Override public boolean isMouseOver(double mouseX, double mouseY) { - return isExpanded() && mouseX >= lastRectangle.x && mouseX <= lastRectangle.x + getCellCreator().getCellWidth() && mouseY >= lastRectangle.y + lastRectangle.height && mouseY <= lastRectangle.y + lastRectangle.height + getHeight() + 1; + return isExpanded() && mouseX >= lastRectangle.x && mouseX <= lastRectangle.x + getCellWidth() && mouseY >= lastRectangle.y + lastRectangle.height && mouseY <= lastRectangle.y + lastRectangle.height + getHeight() + 1; } @Override @@ -507,7 +513,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amountX, doubl } protected void updateScrollingState(double double_1, double double_2, int int_1) { - this.scrolling = isExpanded() && lastRectangle != null && int_1 == 0 && double_1 >= (double) lastRectangle.x + getCellCreator().getCellWidth() - 6 && double_1 < (double) (lastRectangle.x + getCellCreator().getCellWidth()); + this.scrolling = isExpanded() && lastRectangle != null && int_1 == 0 && double_1 >= (double) lastRectangle.x + getCellWidth() - 6 && double_1 < (double) (lastRectangle.x + getCellWidth()); } @Override @@ -550,7 +556,7 @@ public static abstract class SelectionCellCreator { public abstract int getDropBoxMaxHeight(); public int getCellWidth() { - return 132; + return -1; } } 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 22da29ce..7e73e1c5 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 @@ -58,7 +58,7 @@ public MultiElementListEntry(Component categoryName, T object, List.CategoryLabelWidget(); + this.widget = new MultiElementListEntry.CategoryLabelWidget(); this.children = Lists.newArrayList(widget); this.children.addAll(entries); this.setReferenceProviderEntries((List) entries); diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/NestedListListEntry.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/NestedListListEntry.java index b513c7f5..0352d45c 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/NestedListListEntry.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/NestedListListEntry.java @@ -112,6 +112,18 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth nestedEntry.render(graphics, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); } + @Override + public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + nestedEntry.setParent((DynamicEntryListWidget) listListEntry.getParent()); + nestedEntry.setScreen(listListEntry.getConfigScreen()); + nestedEntry.lateRender(graphics, mouseX, mouseY, delta); + } + + @Override + public int getMorePossibleHeight() { + return nestedEntry.getMorePossibleHeight(); + } + @Override public List children() { return Collections.singletonList(nestedEntry); From 422b6f0e913a286d49820269a4c2fdec4db28aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Schweiger?= Date: Wed, 22 Nov 2023 15:06:02 +0100 Subject: [PATCH 02/10] Add builder for Block and Item list config options --- .../clothconfig2/api/ConfigEntryBuilder.java | 30 ++++ .../impl/ConfigEntryBuilderImpl.java | 5 + .../impl/builders/DropdownListBuilder.java | 149 ++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100644 common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownListBuilder.java diff --git a/common/src/main/java/me/shedaniel/clothconfig2/api/ConfigEntryBuilder.java b/common/src/main/java/me/shedaniel/clothconfig2/api/ConfigEntryBuilder.java index f572a791..0989e87f 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/api/ConfigEntryBuilder.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/api/ConfigEntryBuilder.java @@ -31,8 +31,12 @@ import net.fabricmc.api.Environment; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextColor; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; import java.util.List; import java.util.function.Function; @@ -155,4 +159,30 @@ default DropdownMenuBuilder startStringDropdownMenu(Component fieldNameK default DropdownMenuBuilder startStringDropdownMenu(Component fieldNameKey, String value, Function toTextFunction) { return startDropdownMenu(fieldNameKey, TopCellElementBuilder.of(value, s -> s, toTextFunction), new DefaultSelectionCellCreator<>()); } + + DropdownListBuilder startDropdownList(Component fieldNameKey, List value, Function> topCellCreator, SelectionCellCreator cellCreator); + + default DropdownListBuilder startItemIdentifierList(Component fieldNameKey, List value) { + DropdownListBuilder entry = startDropdownList(fieldNameKey, value, element -> DropdownMenuBuilder.TopCellElementBuilder.ofItemIdentifier(BuiltInRegistries.ITEM.get(element)), DropdownMenuBuilder.CellCreatorBuilder.ofItemIdentifier()); + entry.setSelections(BuiltInRegistries.ITEM.keySet()); + return entry; + } + + default DropdownListBuilder startBlockIdentifierList(Component fieldNameKey, List value) { + DropdownListBuilder entry = startDropdownList(fieldNameKey, value, element -> DropdownMenuBuilder.TopCellElementBuilder.ofBlockIdentifier(BuiltInRegistries.BLOCK.get(element)), DropdownMenuBuilder.CellCreatorBuilder.ofBlockIdentifier()); + entry.setSelections(BuiltInRegistries.BLOCK.keySet()); + return entry; + } + + default DropdownListBuilder startItemObjectList(Component fieldNameKey, List value) { + DropdownListBuilder entry = startDropdownList(fieldNameKey, value, element -> DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(element), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()); + entry.setSelections(BuiltInRegistries.ITEM); + return entry; + } + + default DropdownListBuilder startBlockObjectList(Component fieldNameKey, List value) { + DropdownListBuilder entry = startDropdownList(fieldNameKey, value, element -> DropdownMenuBuilder.TopCellElementBuilder.ofBlockObject(element), DropdownMenuBuilder.CellCreatorBuilder.ofBlockObject()); + entry.setSelections(BuiltInRegistries.BLOCK); + return entry; + } } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigEntryBuilderImpl.java b/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigEntryBuilderImpl.java index 85ece43f..1709b2a3 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigEntryBuilderImpl.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigEntryBuilderImpl.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.UUID; +import java.util.function.Function; @Environment(EnvType.CLIENT) public class ConfigEntryBuilderImpl implements ConfigEntryBuilder { @@ -176,4 +177,8 @@ public DropdownMenuBuilder startDropdownMenu(Component fieldNameKey, Sele return new DropdownMenuBuilder<>(resetButtonKey, fieldNameKey, topCellElement, cellCreator); } + @Override + public DropdownListBuilder startDropdownList(Component fieldNameKey, List value, Function> topCellCreator, SelectionCellCreator cellCreator) { + return new DropdownListBuilder<>(resetButtonKey, fieldNameKey, value, topCellCreator, cellCreator); + } } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownListBuilder.java b/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownListBuilder.java new file mode 100644 index 00000000..b789d54d --- /dev/null +++ b/common/src/main/java/me/shedaniel/clothconfig2/impl/builders/DropdownListBuilder.java @@ -0,0 +1,149 @@ +/* + * 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.builders; + +import me.shedaniel.clothconfig2.gui.entries.DropdownBoxEntry; +import me.shedaniel.clothconfig2.gui.entries.DropdownBoxEntry.SelectionCellCreator; +import me.shedaniel.clothconfig2.gui.entries.DropdownBoxEntry.SelectionTopCellElement; +import me.shedaniel.clothconfig2.gui.entries.NestedListListEntry; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; + +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; + +@Environment(EnvType.CLIENT) +public class DropdownListBuilder extends FieldBuilder, NestedListListEntry>, DropdownListBuilder> { + protected List value; + protected Supplier defaultEntryValue = null; + protected Function> topCellCreator; + protected SelectionCellCreator cellCreator; + protected Supplier> tooltipSupplier = () -> Optional.empty(); + protected Consumer> saveConsumer = null; + protected Iterable selections = Collections.emptyList(); + protected boolean suggestionMode = true; + + public DropdownListBuilder(Component resetButtonKey, Component fieldNameKey, List value, Function> topCellCreator, SelectionCellCreator cellCreator) { + super(resetButtonKey, fieldNameKey); + this.value = value; + this.topCellCreator = Objects.requireNonNull(topCellCreator); + this.cellCreator = Objects.requireNonNull(cellCreator); + } + + public DropdownListBuilder setSelections(Iterable selections) { + this.selections = selections; + return this; + } + + public DropdownListBuilder setDefaultValue(Supplier> defaultValue) { + this.defaultValue = defaultValue; + return this; + } + + public DropdownListBuilder setDefaultValue(List defaultValue) { + this.defaultValue = () -> Objects.requireNonNull(defaultValue); + return this; + } + + public DropdownListBuilder setDefaultEntryValue(Supplier defaultEntryValue) { + this.defaultEntryValue = defaultEntryValue; + return this; + } + + public DropdownListBuilder setDefaultEntryValue(T defaultEntryValue) { + this.defaultEntryValue = () -> Objects.requireNonNull(defaultEntryValue); + return this; + } + + public DropdownListBuilder setSaveConsumer(Consumer> saveConsumer) { + this.saveConsumer = saveConsumer; + return this; + } + + public DropdownListBuilder setTooltipSupplier(Supplier> tooltipSupplier) { + this.tooltipSupplier = tooltipSupplier; + return this; + } + + public DropdownListBuilder setTooltip(Optional tooltip) { + this.tooltipSupplier = () -> tooltip; + return this; + } + + public DropdownListBuilder setTooltip(Component... tooltip) { + this.tooltipSupplier = () -> Optional.ofNullable(tooltip); + return this; + } + + public DropdownListBuilder requireRestart() { + requireRestart(true); + return this; + } + + public DropdownListBuilder setErrorSupplier(Function, Optional> errorSupplier) { + this.errorSupplier = errorSupplier; + return this; + } + + public DropdownListBuilder setSuggestionMode(boolean suggestionMode) { + this.suggestionMode = suggestionMode; + return this; + } + + public boolean isSuggestionMode() { + return suggestionMode; + } + + @NotNull + @Override + public NestedListListEntry> build() { + NestedListListEntry> listEntry = new NestedListListEntry>( + getFieldNameKey(), + value, + false, + tooltipSupplier, + saveConsumer, + defaultValue, + getResetButtonKey(), + true, + false, + (entryValue, list) -> { + Supplier defaultValue = () -> entryValue; + if(entryValue == null) defaultValue = defaultEntryValue; + DropdownBoxEntry entry = new DropdownBoxEntry(CommonComponents.EMPTY, getResetButtonKey(), null, isRequireRestart(), defaultValue, null, selections, topCellCreator.apply(entryValue), cellCreator); + entry.setSuggestionMode(suggestionMode); + return entry; + }); + if (errorSupplier != null) + listEntry.setErrorSupplier(() -> errorSupplier.apply(listEntry.getValue())); + + + return finishBuilding(listEntry); + } +} From c4f4b54b2da1b4ddcdbcef2c60af9d0e97780971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Schweiger?= Date: Wed, 22 Nov 2023 15:42:21 +0100 Subject: [PATCH 03/10] Fix #112 --- .../gui/entries/DropdownBoxEntry.java | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) 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 f6b07ca0..41f06f26 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 @@ -66,6 +66,7 @@ public class DropdownBoxEntry extends TooltipListEntry { protected SelectionElement selectionElement; @NotNull private final Supplier defaultValue; private boolean suggestionMode = true; + protected boolean dontReFocus = false; @ApiStatus.Internal @Deprecated @@ -172,13 +173,22 @@ public boolean mouseScrolled(double double_1, double double_2, double amountX, d return selectionElement.mouseScrolled(double_1, double_2, amountX, amountY); } + @Override + public boolean mouseClicked(double double_1, double double_2, int int_1) { + boolean b = super.mouseClicked(double_1, double_2, int_1); + if (dontReFocus) { + setFocused(null); + dontReFocus = false; + } + return b; + } + public static class SelectionElement extends AbstractContainerEventHandler implements Renderable { protected Rectangle bounds; protected boolean active; protected SelectionTopCellElement topRenderer; protected DropdownBoxEntry entry; protected DropdownMenuElement menu; - protected boolean dontReFocus = false; public SelectionElement(DropdownBoxEntry entry, Rectangle bounds, DropdownMenuElement menu, SelectionTopCellElement topRenderer, SelectionCellCreator cellCreator) { this.bounds = bounds; @@ -231,17 +241,6 @@ public R getValue() { public List children() { return Lists.newArrayList(topRenderer, menu); } - - @Override - public boolean mouseClicked(double double_1, double double_2, int int_1) { - dontReFocus = false; - boolean b = super.mouseClicked(double_1, double_2, int_1); - if (dontReFocus) { - setFocused(null); - dontReFocus = false; - } - return b; - } } public static abstract class DropdownMenuElement extends AbstractContainerEventHandler { @@ -421,7 +420,7 @@ public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta graphics.pose().translate(0, 0, 300f); ScissorsHandler.INSTANCE.scissor(new Rectangle(lastRectangle.x, lastRectangle.y + lastRectangle.height + 1, cWidth - 6, last10Height - 1)); - double yy = lastRectangle.y + lastRectangle.height - scroll; + double yy = lastRectangle.y + lastRectangle.height - scroll + 1; for (SelectionCellElement cell : currentElements) { if (yy + getCellCreator().getCellHeight() >= lastRectangle.y + lastRectangle.height && yy <= lastRectangle.y + lastRectangle.height + last10Height + 1) { graphics.fill(lastRectangle.x + 1, (int) yy, lastRectangle.x + cWidth, (int) yy + getCellCreator().getCellHeight(), 0xFF000000); @@ -521,7 +520,19 @@ public boolean mouseClicked(double double_1, double double_2, int int_1) { if (!isExpanded()) return false; updateScrollingState(double_1, double_2, int_1); - return super.mouseClicked(double_1, double_2, int_1) || scrolling; + + if(!isMouseOver(double_1, double_2)) { + getEntry().dontReFocus = true; + getEntry().setFocused(null); + return true; + } else { + boolean elementClicked = super.mouseClicked(double_1, double_2, int_1); + if(elementClicked) { + getEntry().dontReFocus = true; + getEntry().setFocused(null); + } + return elementClicked || scrolling; + } } public void offset(double value, boolean animated) { @@ -660,8 +671,8 @@ public boolean mouseClicked(double mouseX, double mouseY, int int_1) { boolean b = rendering && mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height; if (b) { getEntry().selectionElement.topRenderer.setValue(r); - getEntry().selectionElement.setFocused(null); - getEntry().selectionElement.dontReFocus = true; + getEntry().setFocused(null); + getEntry().dontReFocus = true; return true; } return false; From 3a6d56d606f99de67c5b94e56e44a3bc4aa989da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Schweiger?= Date: Wed, 22 Nov 2023 16:57:18 +0100 Subject: [PATCH 04/10] Ensure default ofItem/Block... helper methods do not override automatic menu dropdown width --- .../impl/builders/DropdownMenuBuilder.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 0b6bd4fb..7be9aba2 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 @@ -361,11 +361,11 @@ public int getDropBoxMaxHeight() { } public static SelectionCellCreator ofItemIdentifier() { - return ofItemIdentifier(20, 146, 7); + return ofItemIdentifier(20, -1, 7); } public static SelectionCellCreator ofItemIdentifier(int maxItems) { - return ofItemIdentifier(20, 146, maxItems); + return ofItemIdentifier(20, -1, maxItems); } public static SelectionCellCreator ofItemIdentifier(int cellHeight, int cellWidth, int maxItems) { @@ -410,11 +410,11 @@ public int getDropBoxMaxHeight() { public static SelectionCellCreator ofBlockIdentifier() { - return ofBlockIdentifier(20, 146, 7); + return ofBlockIdentifier(20, -1, 7); } public static SelectionCellCreator ofBlockIdentifier(int maxItems) { - return ofBlockIdentifier(20, 146, maxItems); + return ofBlockIdentifier(20, -1, maxItems); } public static SelectionCellCreator ofBlockIdentifier(int cellHeight, int cellWidth, int maxItems) { @@ -458,11 +458,11 @@ public int getDropBoxMaxHeight() { } public static SelectionCellCreator ofItemObject() { - return ofItemObject(20, 146, 7); + return ofItemObject(20, -1, 7); } public static SelectionCellCreator ofItemObject(int maxItems) { - return ofItemObject(20, 146, maxItems); + return ofItemObject(20, -1, maxItems); } public static SelectionCellCreator ofItemObject(int cellHeight, int cellWidth, int maxItems) { @@ -506,11 +506,11 @@ public int getDropBoxMaxHeight() { } public static SelectionCellCreator ofBlockObject() { - return ofBlockObject(20, 146, 7); + return ofBlockObject(20, -1, 7); } public static SelectionCellCreator ofBlockObject(int maxItems) { - return ofBlockObject(20, 146, maxItems); + return ofBlockObject(20, -1, maxItems); } public static SelectionCellCreator ofBlockObject(int cellHeight, int cellWidth, int maxItems) { From cfefa1d619e7deb65cbaf1fc2a2be0fc81ba00df Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 29 Feb 2024 23:29:15 +0900 Subject: [PATCH 05/10] Update to 24w09a --- .github/workflows/publish.yml | 1 + build.gradle | 2 +- common/build.gradle | 2 +- .../autoconfig/example/ExampleConfig.java | 2 +- .../autoconfig/gui/ConfigScreenProvider.java | 4 +-- .../clothconfig2/ClothConfigDemo.java | 7 ++-- .../clothconfig2/api/TabbedConfigScreen.java | 2 ++ .../gui/AbstractConfigScreen.java | 2 +- .../gui/AbstractTabbedConfigScreen.java | 14 ++++++++ .../clothconfig2/gui/ClothConfigScreen.java | 15 +++++--- .../gui/GlobalizedClothConfigScreen.java | 33 ++++++++++++------ .../gui/widget/DynamicEntryListWidget.java | 9 +++-- .../clothconfig2/impl/ConfigBuilderImpl.java | 4 +-- .../clothconfig2/impl/ConfigCategoryImpl.java | 2 -- .../gui/vertical_footer_separator.png | Bin 0 -> 547 bytes .../gui/vertical_header_separator.png | Bin 0 -> 547 bytes fabric/build.gradle | 17 +++++---- fabric/src/main/resources/fabric.mod.json | 4 +-- forge/src/main/resources/META-INF/mods.toml | 2 +- gradle.properties | 12 +++---- .../src/main/resources/META-INF/mods.toml | 4 +-- settings.gradle | 4 +-- 22 files changed, 93 insertions(+), 49 deletions(-) create mode 100644 common/src/main/resources/assets/cloth-config2/textures/gui/vertical_footer_separator.png create mode 100644 common/src/main/resources/assets/cloth-config2/textures/gui/vertical_header_separator.png diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4385b64f..d5b93712 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,6 +19,7 @@ on: - v11 - v12 - v13 + - v14 jobs: build: diff --git a/build.gradle b/build.gradle index a4199d5b..fed93ef8 100755 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false id "me.shedaniel.unified-publishing" version "0.1.+" apply false id "maven-publish" id "org.cadixdev.licenser" version "0.6.1" apply false diff --git a/common/build.gradle b/common/build.gradle index 53cd8cad..aa79ed78 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -31,7 +31,7 @@ dependencies { } architectury { - common("fabric", "forge", "neoforge") + common("fabric") } task sourcesJar(type: Jar, dependsOn: classes) { diff --git a/common/src/main/java/me/shedaniel/autoconfig/example/ExampleConfig.java b/common/src/main/java/me/shedaniel/autoconfig/example/ExampleConfig.java index d4c38be4..c518e2af 100644 --- a/common/src/main/java/me/shedaniel/autoconfig/example/ExampleConfig.java +++ b/common/src/main/java/me/shedaniel/autoconfig/example/ExampleConfig.java @@ -32,7 +32,7 @@ @SuppressWarnings({"unused", "FieldMayBeFinal"}) @ApiStatus.Internal @Config(name = "autoconfig1u_example") -@Config.Gui.Background("minecraft:textures/block/oak_planks.png") +@Config.Gui.Background(Config.Gui.Background.TRANSPARENT) @Config.Gui.CategoryBackground(category = "b", background = "minecraft:textures/block/stone.png") public class ExampleConfig extends PartitioningSerializer.GlobalData { @ConfigEntry.Category("a") diff --git a/common/src/main/java/me/shedaniel/autoconfig/gui/ConfigScreenProvider.java b/common/src/main/java/me/shedaniel/autoconfig/gui/ConfigScreenProvider.java index fc62e1b9..399688a9 100644 --- a/common/src/main/java/me/shedaniel/autoconfig/gui/ConfigScreenProvider.java +++ b/common/src/main/java/me/shedaniel/autoconfig/gui/ConfigScreenProvider.java @@ -100,9 +100,9 @@ public Screen get() { String bg = configClass.getAnnotation(Config.Gui.Background.class).value(); ResourceLocation bgId = ResourceLocation.tryParse(bg); if (TRANSPARENT_BACKGROUND.equals(bgId)) - builder.transparentBackground(); + builder.transparentBackground().setDefaultBackgroundTexture(null); else - builder.setDefaultBackgroundTexture(bgId); + builder.solidBackground().setDefaultBackgroundTexture(bgId); } Map categoryBackgrounds = diff --git a/common/src/main/java/me/shedaniel/clothconfig2/ClothConfigDemo.java b/common/src/main/java/me/shedaniel/clothconfig2/ClothConfigDemo.java index 2876674d..a9b51590 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/ClothConfigDemo.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/ClothConfigDemo.java @@ -28,6 +28,7 @@ import me.shedaniel.clothconfig2.impl.builders.SubCategoryBuilder; import net.minecraft.ChatFormatting; import net.minecraft.Util; +import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; @@ -84,7 +85,6 @@ enum DependencyDemoEnum { } ConfigBuilder builder = ConfigBuilder.create().setTitle(Component.translatable("title.cloth-config.config")); - builder.setDefaultBackgroundTexture(new ResourceLocation("minecraft:textures/block/oak_planks.png")); builder.setGlobalized(true); builder.setGlobalizedExpanded(false); ConfigEntryBuilder entryBuilder = builder.entryBuilder(); @@ -204,7 +204,10 @@ enum DependencyDemoEnum { testing.addEntry(entryBuilder.startTextDescription( Component.translatable("text.cloth-config.testing.1", - Component.literal("ClothConfig").withStyle(s -> s.withBold(true).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new HoverEvent.ItemStackInfo(Util.make(new ItemStack(Items.PINK_WOOL), stack -> stack.setHoverName(Component.literal("(\u30FB\u2200\u30FB)")).enchant(Enchantments.BLOCK_EFFICIENCY, 10)))))), + Component.literal("ClothConfig").withStyle(s -> s.withBold(true).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new HoverEvent.ItemStackInfo(Util.make(new ItemStack(Items.PINK_WOOL), stack -> { + stack.set(DataComponents.CUSTOM_NAME, Component.literal("(\u30FB\u2200\u30FB)")); + stack.enchant(Enchantments.EFFICIENCY, 10); + }))))), Component.translatable("text.cloth-config.testing.2").withStyle(s -> s.withColor(ChatFormatting.BLUE).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("https://shedaniel.gitbook.io/cloth-config/"))).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://shedaniel.gitbook.io/cloth-config/"))), Component.translatable("text.cloth-config.testing.3").withStyle(s -> s.withColor(ChatFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, Utils.getConfigFolder().getParent().resolve("options.txt").toString()))) ) diff --git a/common/src/main/java/me/shedaniel/clothconfig2/api/TabbedConfigScreen.java b/common/src/main/java/me/shedaniel/clothconfig2/api/TabbedConfigScreen.java index cbaa9888..380058cb 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/api/TabbedConfigScreen.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/api/TabbedConfigScreen.java @@ -25,5 +25,7 @@ public interface TabbedConfigScreen extends ConfigScreen { void registerCategoryBackground(String text, ResourceLocation identifier); + void registerCategoryTransparency(String text, boolean transparent); + Component getSelectedCategory(); } 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 e2966882..b3ca8ca1 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/AbstractConfigScreen.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/AbstractConfigScreen.java @@ -137,7 +137,7 @@ public void setAlwaysShowTabs(boolean alwaysShowTabs) { } public boolean isTransparentBackground() { - return transparentBackground && Minecraft.getInstance().level != null; + return transparentBackground; } @ApiStatus.Internal diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/AbstractTabbedConfigScreen.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/AbstractTabbedConfigScreen.java index d64bb9e3..6b11e33e 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/AbstractTabbedConfigScreen.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/AbstractTabbedConfigScreen.java @@ -28,6 +28,7 @@ import java.util.Map; public abstract class AbstractTabbedConfigScreen extends AbstractConfigScreen implements TabbedConfigScreen { + private final Map categoryTransparentBackground = Maps.newHashMap(); private final Map categoryBackgroundLocation = Maps.newHashMap(); protected AbstractTabbedConfigScreen(Screen parent, Component title, ResourceLocation backgroundLocation) { @@ -39,6 +40,19 @@ public final void registerCategoryBackground(String text, ResourceLocation ident this.categoryBackgroundLocation.put(text, identifier); } + @Override + public void registerCategoryTransparency(String text, boolean transparent) { + this.categoryTransparentBackground.put(text, transparent); + } + + @Override + public boolean isTransparentBackground() { + Component selectedCategory = getSelectedCategory(); + if (categoryTransparentBackground.containsKey(selectedCategory.getString())) + return categoryTransparentBackground.get(selectedCategory.getString()); + return super.isTransparentBackground(); + } + @Override public ResourceLocation getBackgroundLocation() { Component selectedCategory = getSelectedCategory(); 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 59a30189..27422c5d 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigScreen.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigScreen.java @@ -99,6 +99,7 @@ public ClothConfigScreen(Screen parent, Component title, Map 0d; buttonRightTab.active = tabsScroller.scrollAmount < getTabsMaximumScrolled() - width + 40; } - if (isTransparentBackground()) { - graphics.fillGradient(0, 0, this.width, this.height, -1072689136, -804253680); + if (!isTransparentBackground()) { + renderMenuBackground(graphics); } else { - renderDirtBackground(graphics); + if (this.minecraft.level == null) { + this.renderPanorama(graphics, delta); + } + renderBlurredBackground(delta); + renderMenuBackground(graphics); } listWidget.render(graphics, mouseX, mouseY, delta); ScissorsHandler.INSTANCE.scissor(new Rectangle(listWidget.left, listWidget.top, listWidget.width, listWidget.bottom - listWidget.top)); @@ -425,7 +430,9 @@ protected void renderBackBackground(GuiGraphics graphics, BufferBuilder buffer, if (!screen.isTransparentBackground()) super.renderBackBackground(graphics, buffer, tessellator); else { - graphics.fillGradient(left, top, right, bottom, 0x68000000, 0x68000000); + RenderSystem.enableBlend(); + graphics.blit(new ResourceLocation("textures/gui/menu_list_background.png"), this.left, this.top, this.right, this.bottom, this.width, this.bottom - this.top, 32, 32); + RenderSystem.disableBlend(); } } 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 450e32e0..9fadc8d2 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/GlobalizedClothConfigScreen.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/GlobalizedClothConfigScreen.java @@ -30,6 +30,7 @@ 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; @@ -43,6 +44,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.resources.sounds.SimpleSoundInstance; @@ -213,12 +215,17 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { requestingReferenceRebuilding = false; } int sliderPosition = getSideSliderPosition(); - ScissorsHandler.INSTANCE.scissor(new Rectangle(sliderPosition, 0, width - sliderPosition, height)); - if (isTransparentBackground()) { - graphics.fillGradient(14, 0, width, height, -1072689136, -804253680); - } else { - renderDirtBackground(graphics); + if (!isTransparentBackground()) { + ScissorsHandler.INSTANCE.scissor(new Rectangle(sliderPosition, 0, width - sliderPosition, 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); + renderMenuBackground(graphics); + ScissorsHandler.INSTANCE.scissor(new Rectangle(sliderPosition, 0, width - sliderPosition, height)); } listWidget.width = width - sliderPosition; listWidget.setLeftPos(sliderPosition); @@ -235,8 +242,14 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { sideSlider.updatePosition(delta); sideScroller.updatePosition(delta); if (isTransparentBackground()) { - graphics.fillGradient(0, 0, sliderPosition, height, -1240461296, -972025840); - graphics.fillGradient(0, 0, sliderPosition - 14, height, 1744830464, 1744830464); + RenderSystem.enableBlend(); + graphics.blit(new ResourceLocation("textures/gui/menu_list_background.png"), 0, 0, sliderPosition, height, sliderPosition, height, 32, 32); + graphics.blit(new ResourceLocation("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); + if (sliderPosition - 14 - 1 > 0) { + graphics.blit(DynamicEntryListWidget.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.getBuilder(); @@ -255,14 +268,11 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { buffer.vertex(sliderPosition - 14, 0, 0.0D).uv((sliderPosition - 14) / 32.0F, sideScroller.scrollAmountInt() / 32.0F).color(32, 32, 32, 255).endVertex(); buffer.vertex(0, 0, 0.0D).uv(0, sideScroller.scrollAmountInt() / 32.0F).color(32, 32, 32, 255).endVertex(); tesselator.end(); - } - { + Matrix4f matrix = graphics.pose().last().pose(); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.setShader(GameRenderer::getPositionColorShader); - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.getBuilder(); int shadeColor = isTransparentBackground() ? 120 : 160; buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); buffer.vertex(matrix, sliderPosition + 4, 0, 100.0F).color(0, 0, 0, 0).endVertex(); @@ -373,6 +383,7 @@ public int getItemHeight() { public ComponentPath nextFocusPath(FocusNavigationEvent focusNavigationEvent) { return null; } + @Override public Object getValue() { return null; 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 f68ca030..54d378b2 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 @@ -40,6 +40,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.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -53,6 +54,8 @@ @Environment(EnvType.CLIENT) public abstract class DynamicEntryListWidget> extends AbstractContainerEventHandler implements Renderable, NarratableEntry { + public static final ResourceLocation VERTICAL_HEADER_SEPARATOR = new ResourceLocation("cloth-config2:textures/gui/vertical_header_separator.png"); + public static final ResourceLocation VERTICAL_FOOTER_SEPARATOR = new ResourceLocation("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(); @@ -308,8 +311,10 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { 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); - graphics.fillGradient(this.left, this.top, this.right, this.top + 4, 0xff000000, 0); - graphics.fillGradient(this.left, this.bottom - 4, this.right, this.bottom, 0, 0xff000000); + 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); + RenderSystem.disableBlend(); int maxScroll = this.getMaxScroll(); renderScrollBar(graphics, tesselator, buffer, maxScroll, scrollbarPosition, int_4); diff --git a/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigBuilderImpl.java b/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigBuilderImpl.java index 94042a00..777a9c26 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigBuilderImpl.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigBuilderImpl.java @@ -49,8 +49,8 @@ public class ConfigBuilderImpl implements ConfigBuilder { private boolean tabsSmoothScroll = true; private boolean listSmoothScroll = true; private boolean doesConfirmSave = true; - private boolean transparentBackground = false; - private ResourceLocation defaultBackground = Screen.BACKGROUND_LOCATION; + private boolean transparentBackground = true; + private ResourceLocation defaultBackground = new ResourceLocation("textures/block/dirt.png"); private Consumer afterInitConsumer = screen -> {}; private final Map categoryMap = Maps.newLinkedHashMap(); private String fallbackCategory = null; diff --git a/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigCategoryImpl.java b/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigCategoryImpl.java index d49da7a7..a5712825 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigCategoryImpl.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigCategoryImpl.java @@ -68,8 +68,6 @@ public ConfigCategory addEntry(AbstractConfigListEntry entry) { @Override public ConfigCategory setCategoryBackground(ResourceLocation identifier) { - if (builder.hasTransparentBackground()) - throw new IllegalStateException("Cannot set category background if screen is using transparent background."); background = identifier; return this; } diff --git a/common/src/main/resources/assets/cloth-config2/textures/gui/vertical_footer_separator.png b/common/src/main/resources/assets/cloth-config2/textures/gui/vertical_footer_separator.png new file mode 100644 index 0000000000000000000000000000000000000000..78700e3147e2d7cfb98612137036c33250acb667 GIT binary patch literal 547 zcmeAS@N?(olHy`uVBq!ia0vp^OhBx_!3HEPF0GUVQjEnx?oJHr&dIz4aspB#JkxxA z8MJ_G4hAMhAqHlU5+Gz~&tzZ$vl$rFfHVUG^8!YM>;fjZEYkvJI9mav(B;Ux3qV66 zGeaUuB7A+UlJj%*5>xV%QuQiw3qT4OY$~jP%-qzHM1_jnoV;SI3R@+x3M(KRB&@Hb z09I0xZL1XF8=&BvUzDm~re~mMpk&9TprBw=l#*r@P?Wt5Z@Sn2DRmzV36 z8|&p4rRy77T3YHG80i}s=>k>g7FXt#Bv$C=6)QswftllyTAW;zSx}OhpQivaH!&%{ zw8U0P31kr*K-^i9nTD__uNdkrpa=CqGWv#k2KsQbfm&@qqE`MznW;dVLFU^T+JIG} zh(YbK(Fa+M;fjZEYkvJI9mav(B;Ux3qV66 zGeaUuB7A+UlJj%*5>xV%QuQiw3qT4OY$~jP%-qzHM1_jnoV;SI3R@+x3M(KRB&@Hb z09I0xZL1XF8=&BvUzDm~re~mMpk&9TprBw=l#*r@P?Wt5Z@Sn2DRmzV36 z8|&p4rRy77T3YHG80i}s=>k>g7FXt#Bv$C=6)QswftllyTAW;zSx}OhpQivaH!&%{ zw8U0P31kr*K-^i9nTD__uNdkrpa=CqGWv#k2KsQbfm&@qqE`MznW;dVLFU^T+JIG} zh(YbK(Fa+M=0.14.0", - "minecraft": ">=1.20-" + "minecraft": ">=1.20.5-" }, "accessWidener": "cloth-config.accessWidener", "custom": { diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 73812cce..bfca6c6d 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -9,7 +9,7 @@ license = "GNU LGPLv3" [[mods]] modId = "cloth_config" version = "${version}" -displayName = "Cloth Config v13 API" +displayName = "Cloth Config v14 API" description = ''' An API for config screens. ''' diff --git a/gradle.properties b/gradle.properties index 509de6a0..2c415ff4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,21 +1,21 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -minecraft_version=1.20.4 -supported_version=1.20.4 +minecraft_version=24w09a +supported_version=1.20.5 (24w09a) archives_base_name=cloth-config archives_base_name_snapshot=cloth-config-snapshot -base_version=13.0 +base_version=14.0 maven_group=me.shedaniel.cloth jankson_version=1.2.0 toml4j_version=0.7.2 snakeyaml_version=1.27 -fabric_loader_version=0.15.1 -fabric_api_version=0.91.2+1.20.4 -mod_menu_version=9.0.0-pre.1 +fabric_loader_version=0.15.7 +fabric_api_version=0.96.4+1.20.5 +mod_menu_version=9.0.0 forge_version=49.0.3 neoforge_version=20.4.3-beta diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/mods.toml index 462a2667..ef2bca97 100644 --- a/neoforge/src/main/resources/META-INF/mods.toml +++ b/neoforge/src/main/resources/META-INF/mods.toml @@ -9,7 +9,7 @@ license = "GNU LGPLv3" [[mods]] modId = "cloth_config" version = "${version}" -displayName = "Cloth Config v13 API" +displayName = "Cloth Config v14 API" description = ''' An API for config screens. ''' @@ -17,6 +17,6 @@ An API for config screens. [[dependencies.cloth_config]] modId = "neoforge" type = "required" -versionRange = "[20.2,)" +versionRange = "[20.5,)" ordering = "NONE" side = "BOTH" diff --git a/settings.gradle b/settings.gradle index 90092fbc..06238f13 100755 --- a/settings.gradle +++ b/settings.gradle @@ -10,7 +10,7 @@ pluginManagement { include("common") include("fabric") -include("forge") -include("neoforge") +//include("forge") +//include("neoforge") rootProject.name = 'cloth-config' From da76be50dbf993b4e32677f8f471974a3d2d4158 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 2 Apr 2024 20:54:52 +0900 Subject: [PATCH 06/10] Update to 24w14potato --- .github/workflows/publish.yml | 1 + fabric/build.gradle | 6 +++--- gradle.properties | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d5b93712..c8dbbc6d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -20,6 +20,7 @@ on: - v12 - v13 - v14 + - v14-24w14potato jobs: build: diff --git a/fabric/build.gradle b/fabric/build.gradle index f19b061c..fa49b507 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -55,9 +55,9 @@ dependencies { modCompileOnly("com.terraformersmc:modmenu:${mod_menu_version}") { transitive(false) } -// modLocalRuntime("com.terraformersmc:modmenu:${mod_menu_version}") { -// transitive(false) -// } + modLocalRuntime("com.terraformersmc:modmenu:${mod_menu_version}") { + transitive(false) + } common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false } diff --git a/gradle.properties b/gradle.properties index 2c415ff4..7242a21d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -minecraft_version=24w09a -supported_version=1.20.5 (24w09a) +minecraft_version=24w14potato +supported_version=24w14potato April Fools archives_base_name=cloth-config archives_base_name_snapshot=cloth-config-snapshot @@ -13,9 +13,9 @@ jankson_version=1.2.0 toml4j_version=0.7.2 snakeyaml_version=1.27 -fabric_loader_version=0.15.7 -fabric_api_version=0.96.4+1.20.5 -mod_menu_version=9.0.0 +fabric_loader_version=0.15.9 +fabric_api_version=0.96.14+24w14potato +mod_menu_version=10.0.0-alpha.1 forge_version=49.0.3 neoforge_version=20.4.3-beta From ae59ec02f3638225ce9ec4339389d8fba3349d12 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 9 Apr 2024 20:08:34 +0900 Subject: [PATCH 07/10] Update to 24w14a --- .github/workflows/publish.yml | 6 +++--- build.gradle | 12 ++++++++++-- common/build.gradle | 4 ++-- fabric/build.gradle | 2 +- forge/build.gradle | 2 +- gradle.properties | 9 +++++---- gradle/wrapper/gradle-wrapper.properties | 2 +- neoforge/build.gradle | 7 ++++--- .../me/shedaniel/clothconfig/ClothConfigForge.java | 3 --- .../shedaniel/clothconfig/ClothConfigForgeDemo.java | 6 +++--- .../META-INF/{mods.toml => neoforge.mods.toml} | 2 +- settings.gradle | 6 +++++- 12 files changed, 36 insertions(+), 25 deletions(-) rename neoforge/src/main/resources/META-INF/{mods.toml => neoforge.mods.toml} (92%) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c8dbbc6d..e1b9cc4c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -27,10 +27,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Set up JDK 17 - uses: actions/setup-java@v1 + - name: Set up JDK 21 + uses: actions/setup-java@v2 with: - java-version: 17 + java-version: 21 - name: Upload to Maven run: ./gradlew publish modPublish --stacktrace if: | diff --git a/build.gradle b/build.gradle index fed93ef8..57ab32ef 100755 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false id "me.shedaniel.unified-publishing" version "0.1.+" apply false id "maven-publish" id "org.cadixdev.licenser" version "0.6.1" apply false @@ -19,6 +19,14 @@ subprojects { repositories { maven { url "https://maven.neoforged.net/releases/" } + if (rootProject.neoforge_pr != "") { + maven { + url "https://prmaven.neoforged.net/NeoForge/pr$rootProject.neoforge_pr" + content { + includeModule("net.neoforged", "neoforge") + } + } + } } } @@ -40,7 +48,7 @@ allprojects { // The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too // JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. // We'll use that if it's available, but otherwise we'll use the older option. - options.release = 17 + options.release = 21 } license { diff --git a/common/build.gradle b/common/build.gradle index aa79ed78..e983a819 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.github.johnrengelman.shadow" version "7.0.0" + id "com.github.johnrengelman.shadow" version "8.1.1" id "maven-publish" } @@ -31,7 +31,7 @@ dependencies { } architectury { - common("fabric") + common("fabric", "neoforge") } task sourcesJar(type: Jar, dependsOn: classes) { diff --git a/fabric/build.gradle b/fabric/build.gradle index fa49b507..3c1054b4 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.github.johnrengelman.shadow" version "7.0.0" + id "com.github.johnrengelman.shadow" version "8.1.1" id "me.shedaniel.unified-publishing" id "maven-publish" } diff --git a/forge/build.gradle b/forge/build.gradle index 4d560715..c8b0d5fb 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.github.johnrengelman.shadow" version "7.0.0" + id "com.github.johnrengelman.shadow" version "8.1.1" id "me.shedaniel.unified-publishing" id "maven-publish" } diff --git a/gradle.properties b/gradle.properties index 7242a21d..93f6e794 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -minecraft_version=24w14potato -supported_version=24w14potato April Fools +minecraft_version=24w14a +supported_version=1.20.5 (24w14a) archives_base_name=cloth-config archives_base_name_snapshot=cloth-config-snapshot @@ -14,11 +14,12 @@ toml4j_version=0.7.2 snakeyaml_version=1.27 fabric_loader_version=0.15.9 -fabric_api_version=0.96.14+24w14potato +fabric_api_version=0.96.14+1.20.5 mod_menu_version=10.0.0-alpha.1 forge_version=49.0.3 -neoforge_version=20.4.3-beta +neoforge_version=20.5.0-alpha.24w14a.20240408.221956 +neoforge_pr=787 curseforge_id=348521 modrinth_id=9s6osm5g diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4b8cf416..f9014382 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 32c28817..496bbc85 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.github.johnrengelman.shadow" version "7.0.0" + id "com.github.johnrengelman.shadow" version "8.1.1" id "me.shedaniel.unified-publishing" id "maven-publish" } @@ -49,10 +49,10 @@ dependencies { } processResources { - filesMatching("META-INF/mods.toml") { + filesMatching("META-INF/neoforge.mods.toml") { expand "version": project.version } - inputs.property "META-INF/mods.toml", project.version + inputs.property "META-INF/neoforge.mods.toml", project.version } shadowJar { @@ -96,6 +96,7 @@ publishing { } unifiedPublishing { + if (rootProject.neoforge_pr != "") return project { displayName = "[NeoForge $rootProject.supported_version] v$project.version" releaseType = "release" diff --git a/neoforge/src/main/java/me/shedaniel/clothconfig/ClothConfigForge.java b/neoforge/src/main/java/me/shedaniel/clothconfig/ClothConfigForge.java index fa36c392..638b7ccb 100644 --- a/neoforge/src/main/java/me/shedaniel/clothconfig/ClothConfigForge.java +++ b/neoforge/src/main/java/me/shedaniel/clothconfig/ClothConfigForge.java @@ -22,14 +22,11 @@ import me.shedaniel.clothconfig2.ClothConfigInitializer; import net.neoforged.api.distmarker.Dist; import net.neoforged.fml.DistExecutor; -import net.neoforged.fml.IExtensionPoint; -import net.neoforged.fml.ModLoadingContext; import net.neoforged.fml.common.Mod; @Mod(ClothConfigInitializer.MOD_ID) public class ClothConfigForge { public ClothConfigForge() { - ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> IExtensionPoint.DisplayTest.IGNORESERVERONLY, (a, b) -> true)); DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> ClothConfigForgeDemo::registerModsPage); } } diff --git a/neoforge/src/main/java/me/shedaniel/clothconfig/ClothConfigForgeDemo.java b/neoforge/src/main/java/me/shedaniel/clothconfig/ClothConfigForgeDemo.java index fc234b83..dc5b1841 100644 --- a/neoforge/src/main/java/me/shedaniel/clothconfig/ClothConfigForgeDemo.java +++ b/neoforge/src/main/java/me/shedaniel/clothconfig/ClothConfigForgeDemo.java @@ -21,12 +21,12 @@ import me.shedaniel.clothconfig2.ClothConfigDemo; import net.neoforged.fml.ModLoadingContext; -import net.neoforged.neoforge.client.ConfigScreenHandler; +import net.neoforged.neoforge.client.gui.IConfigScreenFactory; public class ClothConfigForgeDemo { public static void registerModsPage() { - ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> { + ModLoadingContext.get().registerExtensionPoint(IConfigScreenFactory.class, () -> (client, parent) -> { return ClothConfigDemo.getConfigBuilderWithDemo().setParentScreen(parent).build(); - })); + }); } } diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml similarity index 92% rename from neoforge/src/main/resources/META-INF/mods.toml rename to neoforge/src/main/resources/META-INF/neoforge.mods.toml index ef2bca97..6c5fe2d2 100644 --- a/neoforge/src/main/resources/META-INF/mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -17,6 +17,6 @@ An API for config screens. [[dependencies.cloth_config]] modId = "neoforge" type = "required" -versionRange = "[20.5,)" +versionRange = "[20.5.0-alpha.24w14a,)" ordering = "NONE" side = "BOTH" diff --git a/settings.gradle b/settings.gradle index 06238f13..c0332d0c 100755 --- a/settings.gradle +++ b/settings.gradle @@ -8,9 +8,13 @@ pluginManagement { } } +if (JavaVersion.current().ordinal() + 1 < 21) { + throw new IllegalStateException("Please run gradle with Java 21+!") +} + include("common") include("fabric") //include("forge") -//include("neoforge") +include("neoforge") rootProject.name = 'cloth-config' From 4db6991104e8df5f60be0c3fc1ac3e1afc2265ed Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 9 Apr 2024 20:14:21 +0900 Subject: [PATCH 08/10] Use Temurin J21 --- .github/workflows/publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e1b9cc4c..ed08cee5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -31,6 +31,7 @@ jobs: uses: actions/setup-java@v2 with: java-version: 21 + distribution: 'temurin' - name: Upload to Maven run: ./gradlew publish modPublish --stacktrace if: | From 474a0dd67316fcd8b220ccead5a63a80117d5269 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 24 Apr 2024 23:02:09 +0900 Subject: [PATCH 09/10] Update to 1.20.5 --- fabric/build.gradle | 4 ++-- gradle.properties | 14 +++++++------- neoforge/build.gradle | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fabric/build.gradle b/fabric/build.gradle index 3c1054b4..5a321b2b 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 = "beta" + releaseType = "release" 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.20.5-Snapshot", "Java 17" + gameVersions.addAll "1.20.5", "Java 21" } } diff --git a/gradle.properties b/gradle.properties index 93f6e794..4157b325 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,8 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -minecraft_version=24w14a -supported_version=1.20.5 (24w14a) +minecraft_version=1.20.5 +supported_version=1.20.5 archives_base_name=cloth-config archives_base_name_snapshot=cloth-config-snapshot @@ -13,13 +13,13 @@ jankson_version=1.2.0 toml4j_version=0.7.2 snakeyaml_version=1.27 -fabric_loader_version=0.15.9 -fabric_api_version=0.96.14+1.20.5 -mod_menu_version=10.0.0-alpha.1 +fabric_loader_version=0.15.10 +fabric_api_version=0.97.6+1.20.5 +mod_menu_version=10.0.0-beta.1 forge_version=49.0.3 -neoforge_version=20.5.0-alpha.24w14a.20240408.221956 -neoforge_pr=787 +neoforge_version=20.5.0-beta +neoforge_pr= curseforge_id=348521 modrinth_id=9s6osm5g diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 496bbc85..198a2a7c 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -100,7 +100,7 @@ unifiedPublishing { project { displayName = "[NeoForge $rootProject.supported_version] v$project.version" releaseType = "release" - gameVersions = ["1.20.3", "1.20.4"] + gameVersions = ["1.20.5"] gameLoaders = ["neoforge"] mainPublication remapJar @@ -109,7 +109,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 "Java 17" + gameVersions.addAll "Java 21" } } From f361c5e75298956cc98607c33ca729dc73479fea Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Thu, 13 Jun 2024 19:32:47 +0200 Subject: [PATCH 10/10] Port to 1.21 (#260) * Port to 1.21 * Remove AW/AT required, mark as v15 * Update to 1.20.1 --------- Co-authored-by: shedaniel --- .github/workflows/publish.yml | 1 + .../autoconfig/gui/ConfigScreenProvider.java | 4 +- .../clothconfig2/ClothConfigDemo.java | 4 +- .../gui/AbstractConfigScreen.java | 14 +++-- .../clothconfig2/gui/ClothConfigScreen.java | 30 +++++------ .../gui/GlobalizedClothConfigScreen.java | 51 +++++++++---------- .../gui/entries/BaseListEntry.java | 2 +- .../gui/entries/DropdownBoxEntry.java | 20 ++++---- .../gui/entries/MultiElementListEntry.java | 2 +- .../gui/entries/SubCategoryListEntry.java | 2 +- .../gui/widget/DynamicEntryListWidget.java | 31 +++++------ .../clothconfig2/impl/ConfigBuilderImpl.java | 2 +- .../impl/builders/DropdownMenuBuilder.java | 10 ++-- fabric/build.gradle | 2 +- fabric/src/main/resources/fabric.mod.json | 4 +- gradle.properties | 14 ++--- neoforge/build.gradle | 4 +- .../clothconfig/ClothConfigForge.java | 7 +-- .../resources/META-INF/neoforge.mods.toml | 2 +- 19 files changed, 98 insertions(+), 108 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ed08cee5..0d15aed3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,6 +21,7 @@ on: - v13 - v14 - v14-24w14potato + - v15 jobs: build: diff --git a/common/src/main/java/me/shedaniel/autoconfig/gui/ConfigScreenProvider.java b/common/src/main/java/me/shedaniel/autoconfig/gui/ConfigScreenProvider.java index 399688a9..f7da1693 100644 --- a/common/src/main/java/me/shedaniel/autoconfig/gui/ConfigScreenProvider.java +++ b/common/src/main/java/me/shedaniel/autoconfig/gui/ConfigScreenProvider.java @@ -45,7 +45,7 @@ @Environment(EnvType.CLIENT) public class ConfigScreenProvider implements Supplier { - private static final ResourceLocation TRANSPARENT_BACKGROUND = new ResourceLocation(Config.Gui.Background.TRANSPARENT); + private static final ResourceLocation TRANSPARENT_BACKGROUND = ResourceLocation.parse(Config.Gui.Background.TRANSPARENT); private final ConfigManager manager; private final GuiRegistryAccess registry; @@ -110,7 +110,7 @@ public Screen get() { .collect( toMap( Config.Gui.CategoryBackground::category, - ann -> new ResourceLocation(ann.background()) + ann -> ResourceLocation.parse(ann.background()) ) ); diff --git a/common/src/main/java/me/shedaniel/clothconfig2/ClothConfigDemo.java b/common/src/main/java/me/shedaniel/clothconfig2/ClothConfigDemo.java index a9b51590..8e79a5ea 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/ClothConfigDemo.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/ClothConfigDemo.java @@ -30,6 +30,8 @@ import net.minecraft.Util; import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.data.registries.VanillaRegistries; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.HoverEvent; @@ -206,7 +208,7 @@ enum DependencyDemoEnum { Component.translatable("text.cloth-config.testing.1", Component.literal("ClothConfig").withStyle(s -> s.withBold(true).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new HoverEvent.ItemStackInfo(Util.make(new ItemStack(Items.PINK_WOOL), stack -> { stack.set(DataComponents.CUSTOM_NAME, Component.literal("(\u30FB\u2200\u30FB)")); - stack.enchant(Enchantments.EFFICIENCY, 10); + stack.enchant(VanillaRegistries.createLookup().lookupOrThrow(Registries.ENCHANTMENT).getOrThrow(Enchantments.EFFICIENCY), 10); }))))), Component.translatable("text.cloth-config.testing.2").withStyle(s -> s.withColor(ChatFormatting.BLUE).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("https://shedaniel.gitbook.io/cloth-config/"))).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://shedaniel.gitbook.io/cloth-config/"))), Component.translatable("text.cloth-config.testing.3").withStyle(s -> s.withColor(ChatFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, Utils.getConfigFolder().getParent().resolve("options.txt").toString()))) 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 b3ca8ca1..f87c46d0 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/AbstractConfigScreen.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/AbstractConfigScreen.java @@ -54,7 +54,7 @@ import java.util.function.Consumer; public abstract class AbstractConfigScreen extends Screen implements ConfigScreen { - protected static final ResourceLocation CONFIG_TEX = new ResourceLocation("cloth-config2", "textures/gui/cloth_config.png"); + protected static final ResourceLocation CONFIG_TEX = ResourceLocation.fromNamespaceAndPath("cloth-config2", "textures/gui/cloth_config.png"); private final ResourceLocation backgroundLocation; protected boolean confirmSave; protected final Screen parent; @@ -378,16 +378,14 @@ protected void overlayBackground(Matrix4f matrix, Rectangle rect, int red, int g if (isTransparentBackground()) return; Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.getBuilder(); + 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.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - buffer.vertex(matrix, rect.getMinX(), rect.getMaxY(), 0.0F).uv(rect.getMinX() / 32.0F, rect.getMaxY() / 32.0F).color(red, green, blue, endAlpha).endVertex(); - buffer.vertex(matrix, rect.getMaxX(), rect.getMaxY(), 0.0F).uv(rect.getMaxX() / 32.0F, rect.getMaxY() / 32.0F).color(red, green, blue, endAlpha).endVertex(); - buffer.vertex(matrix, rect.getMaxX(), rect.getMinY(), 0.0F).uv(rect.getMaxX() / 32.0F, rect.getMinY() / 32.0F).color(red, green, blue, startAlpha).endVertex(); - buffer.vertex(matrix, rect.getMinX(), rect.getMinY(), 0.0F).uv(rect.getMinX() / 32.0F, rect.getMinY() / 32.0F).color(red, green, blue, startAlpha).endVertex(); - tesselator.end(); + 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 27422c5d..33f2b2ef 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigScreen.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigScreen.java @@ -313,17 +313,15 @@ private void drawTabsShades(Matrix4f matrix, int lightColor, int darkColor) { RenderSystem.blendFuncSeparate(770, 771, 0, 1); RenderSystem.setShader(GameRenderer::getPositionTexColorShader); Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.getBuilder(); - buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - buffer.vertex(matrix, tabsBounds.getMinX() + 20, tabsBounds.getMinY() + 4, 0.0F).uv(0, 1f).color(0, 0, 0, lightColor).endVertex(); - buffer.vertex(matrix, tabsBounds.getMaxX() - 20, tabsBounds.getMinY() + 4, 0.0F).uv(1f, 1f).color(0, 0, 0, lightColor).endVertex(); - buffer.vertex(matrix, tabsBounds.getMaxX() - 20, tabsBounds.getMinY(), 0.0F).uv(1f, 0).color(0, 0, 0, darkColor).endVertex(); - buffer.vertex(matrix, tabsBounds.getMinX() + 20, tabsBounds.getMinY(), 0.0F).uv(0, 0).color(0, 0, 0, darkColor).endVertex(); - buffer.vertex(matrix, tabsBounds.getMinX() + 20, tabsBounds.getMaxY(), 0.0F).uv(0, 1f).color(0, 0, 0, darkColor).endVertex(); - buffer.vertex(matrix, tabsBounds.getMaxX() - 20, tabsBounds.getMaxY(), 0.0F).uv(1f, 1f).color(0, 0, 0, darkColor).endVertex(); - buffer.vertex(matrix, tabsBounds.getMaxX() - 20, tabsBounds.getMaxY() - 4, 0.0F).uv(1f, 0).color(0, 0, 0, lightColor).endVertex(); - buffer.vertex(matrix, tabsBounds.getMinX() + 20, tabsBounds.getMaxY() - 4, 0.0F).uv(0, 0).color(0, 0, 0, lightColor).endVertex(); - tesselator.end(); + BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); + 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); + buffer.addVertex(matrix, tabsBounds.getMinX() + 20, tabsBounds.getMinY(), 0.0F).setUv(0, 0).setColor(0, 0, 0, darkColor); + buffer.addVertex(matrix, tabsBounds.getMinX() + 20, tabsBounds.getMaxY(), 0.0F).setUv(0, 1f).setColor(0, 0, 0, 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(); } @@ -397,10 +395,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.vertex(matrix4f, (float) xEnd, (float) yStart, (float) i).color(g, h, l, f).endVertex(); - bufferBuilder.vertex(matrix4f, (float) xStart, (float) yStart, (float) i).color(g, h, l, f).endVertex(); - bufferBuilder.vertex(matrix4f, (float) xStart, (float) yEnd, (float) i).color(n, o, p, m).endVertex(); - bufferBuilder.vertex(matrix4f, (float) xEnd, (float) yEnd, (float) i).color(n, o, p, m).endVertex(); + 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); } @Override @@ -431,7 +429,7 @@ protected void renderBackBackground(GuiGraphics graphics, BufferBuilder buffer, super.renderBackBackground(graphics, buffer, tessellator); else { RenderSystem.enableBlend(); - graphics.blit(new ResourceLocation("textures/gui/menu_list_background.png"), this.left, this.top, this.right, this.bottom, this.width, this.bottom - this.top, 32, 32); + 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(); } } 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 9fadc8d2..682d53f9 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/GlobalizedClothConfigScreen.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/GlobalizedClothConfigScreen.java @@ -205,7 +205,6 @@ private void buildReferenceFor(AbstractConfigEntry entry, int layer) { } } - @SuppressWarnings("deprecation") @Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { this.lastHoveredReference = null; @@ -243,8 +242,8 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { sideScroller.updatePosition(delta); if (isTransparentBackground()) { RenderSystem.enableBlend(); - graphics.blit(new ResourceLocation("textures/gui/menu_list_background.png"), 0, 0, sliderPosition, height, sliderPosition, height, 32, 32); - graphics.blit(new ResourceLocation("textures/gui/menu_list_background.png"), 0, 0, sliderPosition - 14, height, sliderPosition - 14, height, 32, 32); + 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); if (sliderPosition - 14 - 1 > 0) { graphics.blit(DynamicEntryListWidget.VERTICAL_HEADER_SEPARATOR, sliderPosition - 14 - 1, 0, 0.0F, 0.0F, 1, this.height, 2, 32); @@ -252,49 +251,45 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { RenderSystem.disableBlend(); } else { Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.getBuilder(); + 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.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - buffer.vertex(sliderPosition - 14, height, 0.0D).uv(0, height / 32.0F).color(68, 68, 68, 255).endVertex(); - buffer.vertex(sliderPosition, height, 0.0D).uv(14 / 32.0F, height / 32.0F).color(68, 68, 68, 255).endVertex(); - buffer.vertex(sliderPosition, 0, 0.0D).uv(14 / 32.0F, 0).color(68, 68, 68, 255).endVertex(); - buffer.vertex(sliderPosition - 14, 0, 0.0D).uv(0, 0).color(68, 68, 68, 255).endVertex(); + 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.vertex(0, height, 0.0D).uv(0, (height + sideScroller.scrollAmountInt()) / 32.0F).color(32, 32, 32, 255).endVertex(); - buffer.vertex(sliderPosition - 14, height, 0.0D).uv((sliderPosition - 14) / 32.0F, (height + sideScroller.scrollAmountInt()) / 32.0F).color(32, 32, 32, 255).endVertex(); - buffer.vertex(sliderPosition - 14, 0, 0.0D).uv((sliderPosition - 14) / 32.0F, sideScroller.scrollAmountInt() / 32.0F).color(32, 32, 32, 255).endVertex(); - buffer.vertex(0, 0, 0.0D).uv(0, sideScroller.scrollAmountInt() / 32.0F).color(32, 32, 32, 255).endVertex(); - tesselator.end(); + 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.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - buffer.vertex(matrix, sliderPosition + 4, 0, 100.0F).color(0, 0, 0, 0).endVertex(); - buffer.vertex(matrix, sliderPosition, 0, 100.0F).color(0, 0, 0, shadeColor).endVertex(); - buffer.vertex(matrix, sliderPosition, height, 100.0F).color(0, 0, 0, shadeColor).endVertex(); - buffer.vertex(matrix, sliderPosition + 4, height, 100.0F).color(0, 0, 0, 0).endVertex(); - tesselator.end(); + 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.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - buffer.vertex(matrix, sliderPosition - 14, 0, 100.0F).color(0, 0, 0, shadeColor).endVertex(); - buffer.vertex(matrix, sliderPosition - 14 - 4, 0, 100.0F).color(0, 0, 0, 0).endVertex(); - buffer.vertex(matrix, sliderPosition - 14 - 4, height, 100.0F).color(0, 0, 0, 0).endVertex(); - buffer.vertex(matrix, sliderPosition - 14, height, 100.0F).color(0, 0, 0, shadeColor).endVertex(); - tesselator.end(); + 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(); } Rectangle slideArrowBounds = new Rectangle(sliderPosition - 14, 0, 14, height); { - MultiBufferSource.BufferSource immediate = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder()); + 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); - immediate.endBatch(); + graphics.flush(); Rectangle scrollerBounds = sideScroller.getBounds(); if (!scrollerBounds.isEmpty()) { 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 85d36f59..8d98d830 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 @@ -58,7 +58,7 @@ @Environment(EnvType.CLIENT) public abstract class BaseListEntry> extends TooltipListEntry> implements Expandable { - protected static final ResourceLocation CONFIG_TEX = new ResourceLocation("cloth-config2", "textures/gui/cloth_config.png"); + protected static final ResourceLocation CONFIG_TEX = ResourceLocation.fromNamespaceAndPath("cloth-config2", "textures/gui/cloth_config.png"); @NotNull protected final List cells; @NotNull protected final List widgets; @NotNull protected final List narratables; 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 85c6f341..1ddfc731 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 @@ -446,21 +446,19 @@ public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta int topc = new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height).contains(PointHelper.ofMouse()) ? 222 : 172; Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.getBuilder(); + BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); // Bottom - buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - buffer.vertex(scrollbarPositionMinX, minY + height, 0.0D).color(bottomc, bottomc, bottomc, 255).endVertex(); - buffer.vertex(scrollbarPositionMaxX, minY + height, 0.0D).color(bottomc, bottomc, bottomc, 255).endVertex(); - buffer.vertex(scrollbarPositionMaxX, minY, 0.0D).color(bottomc, bottomc, bottomc, 255).endVertex(); - buffer.vertex(scrollbarPositionMinX, minY, 0.0D).color(bottomc, bottomc, bottomc, 255).endVertex(); + 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.vertex(scrollbarPositionMinX, (minY + height - 1), 0.0D).color(topc, topc, topc, 255).endVertex(); - buffer.vertex((scrollbarPositionMaxX - 1), (minY + height - 1), 0.0D).color(topc, topc, topc, 255).endVertex(); - buffer.vertex((scrollbarPositionMaxX - 1), minY, 0.0D).color(topc, topc, topc, 255).endVertex(); - buffer.vertex(scrollbarPositionMinX, minY, 0.0D).color(topc, topc, topc, 255).endVertex(); - tesselator.end(); + 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.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 22da29ce..f7fc1571 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 @@ -45,7 +45,7 @@ @Environment(EnvType.CLIENT) public class MultiElementListEntry extends TooltipListEntry implements Expandable { - private static final ResourceLocation CONFIG_TEX = new ResourceLocation("cloth-config2", "textures/gui/cloth_config.png"); + 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; 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 d6951650..4355c499 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 @@ -46,7 +46,7 @@ @Environment(EnvType.CLIENT) public class SubCategoryListEntry extends TooltipListEntry> implements Expandable { - private static final ResourceLocation CONFIG_TEX = new ResourceLocation("cloth-config2", "textures/gui/cloth_config.png"); + 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 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 54d378b2..1428bd71 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 @@ -54,8 +54,8 @@ @Environment(EnvType.CLIENT) public abstract class DynamicEntryListWidget> extends AbstractContainerEventHandler implements Renderable, NarratableEntry { - public static final ResourceLocation VERTICAL_HEADER_SEPARATOR = new ResourceLocation("cloth-config2:textures/gui/vertical_header_separator.png"); - public static final ResourceLocation VERTICAL_FOOTER_SEPARATOR = new ResourceLocation("cloth-config2:textures/gui/vertical_footer_separator.png"); + 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(); @@ -278,12 +278,11 @@ protected void renderBackBackground(GuiGraphics graphics, BufferBuilder buffer, RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); Matrix4f matrix = graphics.pose().last().pose(); float float_2 = 32.0F; - buffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - buffer.vertex(matrix, this.left, this.bottom, 0.0F).uv(this.left / 32.0F, ((this.bottom + (int) this.getScroll()) / 32.0F)).color(32, 32, 32, 255).endVertex(); - buffer.vertex(matrix, this.right, this.bottom, 0.0F).uv(this.right / 32.0F, ((this.bottom + (int) this.getScroll()) / 32.0F)).color(32, 32, 32, 255).endVertex(); - buffer.vertex(matrix, this.right, this.top, 0.0F).uv(this.right / 32.0F, ((this.top + (int) this.getScroll()) / 32.0F)).color(32, 32, 32, 255).endVertex(); - buffer.vertex(matrix, this.left, this.top, 0.0F).uv(this.left / 32.0F, ((this.top + (int) this.getScroll()) / 32.0F)).color(32, 32, 32, 255).endVertex(); - tessellator.end(); + 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); } @Override @@ -298,7 +297,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { int scrollbarPosition = this.getScrollbarPosition(); int int_4 = scrollbarPosition + 6; Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.getBuilder(); + BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); renderBackBackground(graphics, buffer, tesselator); int rowLeft = this.getRowLeft(); int startY = this.top + 4 - (int) this.getScroll(); @@ -544,7 +543,7 @@ public boolean isMouseOver(double double_1, double double_2) { protected void renderList(GuiGraphics graphics, int startX, int startY, int mouseX, int mouseY, float delta) { Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.getBuilder(); + BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); hoveredItem = this.isMouseOver(mouseX, mouseY) ? this.getItemAtPosition(mouseX, mouseY) : null; @@ -601,17 +600,15 @@ public boolean isFocused() { protected void renderHoleBackground(GuiGraphics graphics, int y1, int y2, int alpha1, int alpha2) { Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.getBuilder(); + 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.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - buffer.vertex(matrix, this.left, y2, 0.0F).uv(0, ((float) y2 / 32.0F)).color(64, 64, 64, alpha2).endVertex(); - buffer.vertex(matrix, this.left + this.width, y2, 0.0F).uv(((float) this.width / 32.0F), ((float) y2 / 32.0F)).color(64, 64, 64, alpha2).endVertex(); - buffer.vertex(matrix, this.left + this.width, y1, 0.0F).uv(((float) this.width / 32.0F), ((float) y1 / 32.0F)).color(64, 64, 64, alpha1).endVertex(); - buffer.vertex(matrix, this.left, y1, 0.0F).uv(0, ((float) y1 / 32.0F)).color(64, 64, 64, alpha1).endVertex(); - tesselator.end(); + 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/impl/ConfigBuilderImpl.java b/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigBuilderImpl.java index 777a9c26..e6f6999f 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigBuilderImpl.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/impl/ConfigBuilderImpl.java @@ -50,7 +50,7 @@ public class ConfigBuilderImpl implements ConfigBuilder { private boolean listSmoothScroll = true; private boolean doesConfirmSave = true; private boolean transparentBackground = true; - private ResourceLocation defaultBackground = new ResourceLocation("textures/block/dirt.png"); + private ResourceLocation defaultBackground = ResourceLocation.withDefaultNamespace("textures/block/dirt.png"); private Consumer afterInitConsumer = screen -> {}; private final Map categoryMap = Maps.newLinkedHashMap(); private String fallbackCategory = null; 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 0b6bd4fb..79ac96c5 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 @@ -133,14 +133,14 @@ public DropdownBoxEntry build() { public static class TopCellElementBuilder { public static final Function IDENTIFIER_FUNCTION = str -> { try { - return new ResourceLocation(str); + return ResourceLocation.parse(str); } catch (NumberFormatException e) { return null; } }; public static final Function ITEM_IDENTIFIER_FUNCTION = str -> { try { - ResourceLocation identifier = new ResourceLocation(str); + ResourceLocation identifier = ResourceLocation.parse(str); if (BuiltInRegistries.ITEM.getOptional(identifier).isPresent()) return identifier; } catch (Exception ignored) { @@ -149,7 +149,7 @@ public static class TopCellElementBuilder { }; public static final Function BLOCK_IDENTIFIER_FUNCTION = str -> { try { - ResourceLocation identifier = new ResourceLocation(str); + ResourceLocation identifier = ResourceLocation.parse(str); if (BuiltInRegistries.BLOCK.getOptional(identifier).isPresent()) return identifier; } catch (Exception ignored) { @@ -158,14 +158,14 @@ public static class TopCellElementBuilder { }; public static final Function ITEM_FUNCTION = str -> { try { - return BuiltInRegistries.ITEM.getOptional(new ResourceLocation(str)).orElse(null); + return BuiltInRegistries.ITEM.getOptional(ResourceLocation.parse(str)).orElse(null); } catch (Exception ignored) { } return null; }; public static final Function BLOCK_FUNCTION = str -> { try { - return BuiltInRegistries.BLOCK.getOptional(new ResourceLocation(str)).orElse(null); + return BuiltInRegistries.BLOCK.getOptional(ResourceLocation.parse(str)).orElse(null); } catch (Exception ignored) { } return null; diff --git a/fabric/build.gradle b/fabric/build.gradle index 5a321b2b..7da7ed05 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -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.20.5", "Java 21" + gameVersions.addAll "1.21", "Java 21" } } diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index dcdf8a7f..060e1586 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 v14", + "name": "Cloth Config v15", "description": "An API for config screens.", "version": "${version}", "authors": [ @@ -27,7 +27,7 @@ ], "depends": { "fabricloader": ">=0.14.0", - "minecraft": ">=1.20.5-" + "minecraft": ">=1.21-" }, "accessWidener": "cloth-config.accessWidener", "custom": { diff --git a/gradle.properties b/gradle.properties index 4157b325..23581ea6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,24 +1,24 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -minecraft_version=1.20.5 -supported_version=1.20.5 +minecraft_version=1.21 +supported_version=1.21 archives_base_name=cloth-config archives_base_name_snapshot=cloth-config-snapshot -base_version=14.0 +base_version=15.0 maven_group=me.shedaniel.cloth jankson_version=1.2.0 toml4j_version=0.7.2 snakeyaml_version=1.27 -fabric_loader_version=0.15.10 -fabric_api_version=0.97.6+1.20.5 -mod_menu_version=10.0.0-beta.1 +fabric_loader_version=0.15.11 +fabric_api_version=0.100.1+1.21 +mod_menu_version=11.0.0-beta.1 forge_version=49.0.3 -neoforge_version=20.5.0-beta +neoforge_version=21.0.0-beta neoforge_pr= curseforge_id=348521 diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 198a2a7c..18e9b855 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -32,7 +32,7 @@ dependencies { neoForge "net.neoforged:neoforge:${rootProject.neoforge_version}" - modLocalRuntime("me.shedaniel.cloth:basic-math:0.6.1") + compileOnly("me.shedaniel.cloth:basic-math:0.6.1") forgeRuntimeLibrary(shadowCommon("me.shedaniel.cloth:basic-math:0.6.1")) modLocalRuntime("blue.endless:jankson:${rootProject.jankson_version}") @@ -100,7 +100,7 @@ unifiedPublishing { project { displayName = "[NeoForge $rootProject.supported_version] v$project.version" releaseType = "release" - gameVersions = ["1.20.5"] + gameVersions = ["1.21"] gameLoaders = ["neoforge"] mainPublication remapJar diff --git a/neoforge/src/main/java/me/shedaniel/clothconfig/ClothConfigForge.java b/neoforge/src/main/java/me/shedaniel/clothconfig/ClothConfigForge.java index 638b7ccb..2b20c0b7 100644 --- a/neoforge/src/main/java/me/shedaniel/clothconfig/ClothConfigForge.java +++ b/neoforge/src/main/java/me/shedaniel/clothconfig/ClothConfigForge.java @@ -20,13 +20,14 @@ package me.shedaniel.clothconfig; import me.shedaniel.clothconfig2.ClothConfigInitializer; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.fml.DistExecutor; import net.neoforged.fml.common.Mod; +import net.neoforged.fml.loading.FMLEnvironment; @Mod(ClothConfigInitializer.MOD_ID) public class ClothConfigForge { public ClothConfigForge() { - DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> ClothConfigForgeDemo::registerModsPage); + if (FMLEnvironment.dist.isClient()) { + ClothConfigForgeDemo.registerModsPage(); + } } } diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 6c5fe2d2..4052842d 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 v14 API" +displayName = "Cloth Config v15 API" description = ''' An API for config screens. '''