diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ec8ed143..882dff7a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,6 +23,7 @@ on: - v14-24w14potato - v15 - v16 + - v17 jobs: build: diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigTabButton.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigTabButton.java index a62a7aa2..a2213708 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigTabButton.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/ClothConfigTabButton.java @@ -73,8 +73,8 @@ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float del } @Override - protected boolean clicked(double double_1, double double_2) { - return visible && active && isMouseOver(double_1, double_2); + protected boolean isValidClickButton(int i) { + return visible && active && super.isValidClickButton(i); } @Override diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/AbstractListListEntry.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/AbstractListListEntry.java index f47145eb..754c4758 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/AbstractListListEntry.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/entries/AbstractListListEntry.java @@ -19,6 +19,7 @@ package me.shedaniel.clothconfig2.gui.entries; +import me.shedaniel.math.Rectangle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.network.chat.Component; @@ -98,6 +99,7 @@ public boolean isEdited() { @ApiStatus.Internal public static abstract class AbstractListCell, OUTER_SELF extends AbstractListListEntry> extends BaseListCell { protected final OUTER_SELF listListEntry; + protected final Rectangle cellBounds = new Rectangle(); public AbstractListCell(@Nullable T value, OUTER_SELF listListEntry) { this.listListEntry = listListEntry; @@ -105,6 +107,20 @@ public AbstractListCell(@Nullable T value, OUTER_SELF listListEntry) { } public abstract T getValue(); + + @Override + public void updateBounds(boolean expanded, int x, int y, int entryWidth, int entryHeight) { + if (expanded) { + this.cellBounds.setBounds(x, y, entryWidth, entryHeight); + } else { + this.cellBounds.setBounds(0, 0, 0, 0); + } + } + + @Override + public boolean isMouseOver(double mouseX, double mouseY) { + return cellBounds.contains(mouseX, mouseY); + } } } 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..5d91c416 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,8 @@ 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 updateBounds(boolean expanded, int x, int y, int entryWidth, int entryHeight) {} + 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 0f940625..674f3ee5 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 @@ -306,6 +306,13 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth int yy = y + 24; for (BaseListCell cell : cells) { cell.render(graphics, -1, yy, x + 14, entryWidth - 14, cell.getCellHeight(), mouseX, mouseY, getParent().getFocused() != null && getParent().getFocused().equals(this) && getFocused() != null && getFocused().equals(cell), delta); + cell.updateBounds(true, x + 14, yy, entryWidth - 14, cell.getCellHeight()); + yy += cell.getCellHeight(); + } + } else { + int yy = y + 24; + for (BaseListCell cell : cells) { + cell.updateBounds(false, x + 14, yy, entryWidth - 14, cell.getCellHeight()); yy += cell.getCellHeight(); } } @@ -327,6 +334,20 @@ public boolean insertInFront() { return insertInFront; } + @Override + public boolean isMouseOver(double mouseX, double mouseY) { + if (super.isMouseOver(mouseX, mouseY)) return true; + if (isExpanded()) { + for (BaseListCell cell : cells) { + if (cell.isMouseOver(mouseX, mouseY)) { + return true; + } + } + } + + return false; + } + public class ListLabelWidget implements GuiEventListener { protected Rectangle rectangle = new Rectangle(); @@ -375,6 +396,11 @@ public void setFocused(boolean bl) { public boolean isFocused() { return false; } + + @Override + public boolean isMouseOver(double mouseX, double mouseY) { + return rectangle.contains(mouseX, mouseY) && !resetWidget.isMouseOver(mouseX, mouseY); + } } } 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 3cf7df71..2417203b 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 @@ -165,6 +165,11 @@ public boolean mouseScrolled(double double_1, double double_2, double amountX, d return selectionElement.mouseScrolled(double_1, double_2, amountX, amountY); } + @Override + public boolean isMouseOver(double mouseX, double mouseY) { + return super.isMouseOver(mouseX, mouseY) || selectionElement.isMouseOver(mouseX, mouseY); + } + public static class SelectionElement extends AbstractContainerEventHandler implements Renderable { protected Rectangle bounds; protected boolean active; @@ -189,6 +194,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { graphics.fill(bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height, topRenderer.isSelected ? -1 : -6250336); graphics.fill(bounds.x + 1, bounds.y + 1, bounds.x + bounds.width - 1, bounds.y + bounds.height - 1, -16777216); topRenderer.render(graphics, mouseX, mouseY, bounds.x, bounds.y, bounds.width, bounds.height, delta); + topRenderer.updateBounds(bounds); if (menu.isExpanded()) menu.render(graphics, mouseX, mouseY, bounds, delta); } @@ -235,6 +241,11 @@ public boolean mouseClicked(double double_1, double double_2, int int_1) { } return b; } + + @Override + public boolean isMouseOver(double mouseX, double mouseY) { + return bounds.contains(mouseX, mouseY) || (menu.isExpanded() && menu.isMouseOver(mouseX, mouseY)); + } } public static abstract class DropdownMenuElement extends AbstractContainerEventHandler { @@ -413,9 +424,12 @@ public void lateRender(GuiGraphics graphics, int mouseX, int mouseY, float delta 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.bounds.setBounds(lastRectangle.x, (int) yy, getMaxScrollPosition() > 6 ? getCellCreator().getCellWidth() - 6 : getCellCreator().getCellWidth(), getCellCreator().getCellHeight()); cell.render(graphics, mouseX, mouseY, lastRectangle.x, (int) yy, getMaxScrollPosition() > 6 ? getCellCreator().getCellWidth() - 6 : getCellCreator().getCellWidth(), getCellCreator().getCellHeight(), delta); - } else + } else { + cell.bounds.setBounds(0, 0, 0, 0); cell.dontRender(graphics, delta); + } yy += getCellCreator().getCellHeight(); } graphics.disableScissor(); @@ -557,6 +571,7 @@ public int getDropBoxMaxHeight() { } public static abstract class SelectionCellElement extends AbstractContainerEventHandler { + @Deprecated final Rectangle bounds = new Rectangle(); @SuppressWarnings("NotNullFieldNotInitialized") @Deprecated @NotNull private DropdownBoxEntry entry; @NotNull @@ -573,6 +588,11 @@ public final DropdownBoxEntry getEntry() { @Nullable public abstract R getSelection(); + + @Override + public boolean isMouseOver(double d, double e) { + return bounds.contains(d, e); + } } public static class DefaultSelectionCellElement extends SelectionCellElement { @@ -638,6 +658,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int int_1) { } public static abstract class SelectionTopCellElement extends AbstractContainerEventHandler { + @Deprecated private final Rectangle bounds = new Rectangle(); @Deprecated private DropdownBoxEntry entry; protected boolean isSelected = false; @@ -689,6 +710,15 @@ public void selectFirstRecommendation() { } public abstract void render(GuiGraphics graphics, int mouseX, int mouseY, int x, int y, int width, int height, float delta); + + private void updateBounds(Rectangle bounds) { + this.bounds.setBounds(bounds); + } + + @Override + public boolean isMouseOver(double mouseX, double mouseY) { + return this.bounds.contains(mouseX, mouseY); + } } public static class DefaultSelectionTopCellElement extends SelectionTopCellElement { 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 dccc39e6..757af77f 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 @@ -123,13 +123,32 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth if (isExpanded()) { int yy = y + 24; for (AbstractConfigListEntry entry : entries) { + entry.setBounds(new Rectangle(x, yy, entryWidth, entry.getItemHeight())); entry.render(graphics, -1, yy, x + 14, entryWidth - 14, entry.getItemHeight(), mouseX, mouseY, isHovered, delta); yy += entry.getItemHeight(); yy += Math.max(0, entry.getMorePossibleHeight()); } + } else { + for (AbstractConfigListEntry entry : entries) { + entry.setBounds(new Rectangle()); + } } } + @Override + public boolean isMouseOver(double mouseX, double mouseY) { + if (super.isMouseOver(mouseX, mouseY)) return true; + if (isExpanded()) { + for (AbstractConfigListEntry entry : entries) { + if (entry.isMouseOver(mouseX, mouseY)) { + return true; + } + } + } + + return false; + } + @Override public Rectangle getEntryArea(int x, int y, int entryWidth, int entryHeight) { widget.rectangle.x = x - 15; 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..57889191 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 @@ -26,6 +26,7 @@ import me.shedaniel.clothconfig2.api.ReferenceProvider; import me.shedaniel.clothconfig2.gui.entries.NestedListListEntry.NestedListCell; import me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget; +import me.shedaniel.math.Rectangle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.GuiGraphics; @@ -112,6 +113,16 @@ 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 updateBounds(boolean expanded, int x, int y, int entryWidth, int entryHeight) { + super.updateBounds(expanded, x, y, entryWidth, entryHeight); + if (expanded) { + nestedEntry.setBounds(new Rectangle(x, y, entryWidth, nestedEntry.getItemHeight())); + } else { + nestedEntry.setBounds(new Rectangle()); + } + } + @Override public List children() { return Collections.singletonList(nestedEntry); @@ -155,5 +166,10 @@ public NarrationPriority narrationPriority() { public void updateNarration(NarrationElementOutput narrationElementOutput) { } + + @Override + public boolean isMouseOver(double mouseX, double mouseY) { + return super.isMouseOver(mouseX, mouseY) || nestedEntry.isMouseOver(mouseX, mouseY); + } } } 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 d8395768..711228d4 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 @@ -137,9 +137,14 @@ public void render(GuiGraphics graphics, int index, int y, int x, int entryWidth if (isExpanded()) { int yy = y + 24; for (AbstractConfigListEntry entry : filteredEntries()) { + entry.setBounds(new Rectangle(x + 14, yy, entryWidth - 14, entry.getItemHeight())); entry.render(graphics, -1, yy, x + 14, entryWidth - 14, entry.getItemHeight(), mouseX, mouseY, isHovered && getFocused() == entry, delta); yy += entry.getItemHeight(); } + } else { + for (AbstractConfigListEntry entry : entries) { + entry.setBounds(new Rectangle()); + } } } @@ -285,6 +290,20 @@ public Optional getError() { return Optional.ofNullable(error); } + @Override + public boolean isMouseOver(double mouseX, double mouseY) { + if (super.isMouseOver(mouseX, mouseY)) return true; + if (isExpanded()) { + for (AbstractConfigListEntry entry : entries) { + if (entry.isMouseOver(mouseX, mouseY)) { + return true; + } + } + } + + return false; + } + public class CategoryLabelWidget implements GuiEventListener, NarratableEntry { private final Rectangle rectangle = new Rectangle(); private boolean isHovered; @@ -317,6 +336,11 @@ public NarrationPriority narrationPriority() { public void updateNarration(NarrationElementOutput narrationElementOutput) { narrationElementOutput.add(NarratedElementType.TITLE, getFieldName()); } + + @Override + public boolean isMouseOver(double mouseX, double mouseY) { + return rectangle.contains(mouseX, mouseY); + } } } diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicEntryListWidget.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/DynamicEntryListWidget.java index 43ed8cda..ecf52802 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 @@ -26,6 +26,7 @@ import me.shedaniel.clothconfig2.api.HideableWidget; import me.shedaniel.clothconfig2.api.Requirement; import me.shedaniel.clothconfig2.api.TickableWidget; +import me.shedaniel.math.Rectangle; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -576,6 +577,7 @@ protected void renderList(GuiGraphics graphics, int startX, int startY, int mous } protected void renderItem(GuiGraphics graphics, E item, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { + item.setBounds(new Rectangle(x, y, entryWidth, entryHeight)); item.render(graphics, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); } @@ -636,6 +638,7 @@ private SmoothScrollingSettings() {} @Environment(EnvType.CLIENT) public abstract static class Entry> implements GuiEventListener, TickableWidget, HideableWidget, DisableableWidget { @Deprecated DynamicEntryListWidget parent; + @Deprecated final Rectangle bounds = new Rectangle(); @Nullable private NarratableEntry lastNarratable; @Nullable @@ -651,7 +654,7 @@ public Entry() { public abstract void render(GuiGraphics graphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isHovered, float delta); public boolean isMouseOver(double double_1, double double_2) { - return Objects.equals(this.parent.getItemAtPosition(double_1, double_2), this); + return this.bounds.contains(double_1, double_2); } public DynamicEntryListWidget getParent() { @@ -662,6 +665,11 @@ public void setParent(DynamicEntryListWidget parent) { this.parent = parent; } + @Deprecated + public void setBounds(Rectangle bounds) { + this.bounds.setBounds(bounds); + } + @Override public boolean isEnabled() { return isDisplayed() && enabled; diff --git a/fabric/build.gradle b/fabric/build.gradle index d4c84c9f..845fd31b 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.21.2-Snapshot", "Java 21", "1.21.2" + gameVersions.addAll "1.21.4-Snapshot", "Java 21", "1.21.4" } } diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 5dfbfb7b..7367e9f4 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 v16", + "name": "Cloth Config v17", "description": "An API for config screens.", "version": "${version}", "authors": [ @@ -27,7 +27,7 @@ ], "depends": { "fabricloader": ">=0.14.0", - "minecraft": ">=1.21.2-" + "minecraft": ">=1.21.4-" }, "accessWidener": "cloth-config.accessWidener", "custom": { diff --git a/gradle.properties b/gradle.properties index 780c726f..b259cb02 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,24 +1,24 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -minecraft_version=1.21.2 -supported_version=1.21.2 +minecraft_version=1.21.4 +supported_version=1.21.4 archives_base_name=cloth-config archives_base_name_snapshot=cloth-config-snapshot -base_version=16.0 +base_version=17.0 maven_group=me.shedaniel.cloth jankson_version=1.2.0 toml4j_version=0.7.2 snakeyaml_version=1.27 -fabric_loader_version=0.16.7 -fabric_api_version=0.106.1+1.21.2 -mod_menu_version=12.0.0-beta.1 +fabric_loader_version=0.16.9 +fabric_api_version=0.111.0+1.21.4 +mod_menu_version=13.0.0-beta.1 forge_version=51.0.33 -neoforge_version=21.2.0-beta +neoforge_version=21.4.9-beta neoforge_pr= curseforge_id=348521 diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 945e63dc..c32e6b57 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.21.2"] + gameVersions = ["1.21.4"] gameLoaders = ["neoforge"] mainPublication remapJar diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 8e9e6368..19782029 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 v16 API" +displayName = "Cloth Config v17 API" description = ''' An API for config screens. ''' @@ -17,6 +17,6 @@ An API for config screens. [[dependencies.cloth_config]] modId = "neoforge" type = "required" -versionRange = "[21.2.0-beta,)" +versionRange = "[21.4.0-beta,)" ordering = "NONE" side = "BOTH"