diff options
-rw-r--r-- | build.gradle.kts | 16 | ||||
-rw-r--r-- | settings.gradle.kts | 5 | ||||
-rw-r--r-- | src/main/java/dev/isxander/yacl3/gui/YACLScreen.java | 4 | ||||
-rw-r--r-- | src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java | 26 | ||||
-rw-r--r-- | src/main/java/dev/isxander/yacl3/mixin/ContainerEventHandlerMixin.java | 8 | ||||
-rw-r--r-- | src/main/java/dev/isxander/yacl3/mixin/TabNavigationBarAccessor.java | 18 | ||||
-rw-r--r-- | src/main/resources/yacl.accesswidener | 5 |
7 files changed, 45 insertions, 37 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index 8804ceb..14b6130 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,8 +11,7 @@ plugins { } val loader = loom.platform.get().name.lowercase() -val isCommon = stonecutter.current.project.endsWith("common") -val isFabric = loader == "fabric" && !isCommon // common uses fabric platform +val isFabric = loader == "fabric" val isNeoforge = loader == "neoforge" val isForge = loader == "forge" val isForgeLike = isNeoforge || isForge @@ -31,7 +30,7 @@ base { } java.toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) + //languageVersion.set(JavaLanguageVersion.of(17)) } stonecutter.expression { @@ -76,10 +75,6 @@ loom { } } - mixin { - useLegacyMixinAp.set(false) - } - createRemapConfigurations(testmod) } @@ -99,12 +94,7 @@ repositories { } dependencies { - fun Dependency?.jij(): Dependency? { - if (!isCommon) { - include(this!!) - } - return this - } + fun Dependency?.jij(): Dependency? = include(this!!) minecraft("com.mojang:minecraft:${if (mcVersion.contains("beta")) "1.20.5-pre1" else mcVersion}") diff --git a/settings.gradle.kts b/settings.gradle.kts index fed4fd6..f924ec3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,13 +20,10 @@ extensions.configure<StonecutterSettings> { kotlinController(true) centralScript("build.gradle.kts") shared { - fun mc(mcVersion: String, name: String = mcVersion, common: Boolean = true, loaders: Iterable<String>) { + fun mc(mcVersion: String, name: String = mcVersion, loaders: Iterable<String>) { for (loader in loaders) { vers("$name-$loader", mcVersion) } - if (common) { - vers("$name-common", mcVersion) - } } mc("1.20.4", loaders = listOf("fabric", "neoforge")) diff --git a/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java b/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java index e88c144..ec70d60 100644 --- a/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java +++ b/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java @@ -43,7 +43,7 @@ public class YACLScreen extends Screen { private final Screen parent; public final TabManager tabManager = new TabManager(this::addRenderableWidget, this::removeWidget); - public TabNavigationBar tabNavigationBar; + public ScrollableNavigationBar tabNavigationBar; public ScreenRectangle tabArea; public Component saveButtonMessage; @@ -67,7 +67,7 @@ public class YACLScreen extends Screen { tabArea = new ScreenRectangle(0, 24 - 1, this.width, this.height - 24 + 1); int currentTab = tabNavigationBar != null - ? tabNavigationBar.tabs.indexOf(tabManager.getCurrentTab()) + ? tabNavigationBar.getTabs().indexOf(tabManager.getCurrentTab()) : 0; if (currentTab == -1) currentTab = 0; diff --git a/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java b/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java index 5829202..f458557 100644 --- a/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java +++ b/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java @@ -23,11 +23,14 @@ public class ScrollableNavigationBar extends TabNavigationBar { private int scrollOffset; private int maxScrollOffset; + private final TabNavigationBarAccessor accessor; + public ScrollableNavigationBar(int width, TabManager tabManager, Iterable<? extends Tab> tabs) { super(width, tabManager, ImmutableList.copyOf(tabs)); + this.accessor = (TabNavigationBarAccessor) this; // add tab tooltips to the tab buttons - for (TabButton tabButton : this.tabButtons) { + for (TabButton tabButton : accessor.getTabButtons()) { if (tabButton.tab() instanceof TabExt tab) { tabButton.setTooltip(tab.getTooltip()); } @@ -36,20 +39,21 @@ public class ScrollableNavigationBar extends TabNavigationBar { @Override public void arrangeElements() { - int noScrollWidth = this.width - NAVBAR_MARGIN*2; + ImmutableList<TabButton> tabButtons = accessor.getTabButtons(); + int noScrollWidth = accessor.getWidth() - NAVBAR_MARGIN*2; int allTabsWidth = 0; // first pass: set the width of each tab button - for (TabButton tabButton : this.tabButtons) { + for (TabButton tabButton : tabButtons) { int buttonWidth = font.width(tabButton.getMessage()) + 20; allTabsWidth += buttonWidth; tabButton.setWidth(buttonWidth); } if (allTabsWidth < noScrollWidth) { - int equalWidth = noScrollWidth / this.tabButtons.size(); - var smallTabs = this.tabButtons.stream().filter(btn -> btn.getWidth() < equalWidth).toList(); - var bigTabs = this.tabButtons.stream().filter(btn -> btn.getWidth() >= equalWidth).toList(); + int equalWidth = noScrollWidth / tabButtons.size(); + var smallTabs = tabButtons.stream().filter(btn -> btn.getWidth() < equalWidth).toList(); + var bigTabs = tabButtons.stream().filter(btn -> btn.getWidth() >= equalWidth).toList(); int leftoverWidth = noScrollWidth - bigTabs.stream().mapToInt(AbstractWidget::getWidth).sum(); int equalWidthForSmallTabs = leftoverWidth / smallTabs.size(); for (TabButton tabButton : smallTabs) { @@ -64,7 +68,7 @@ public class ScrollableNavigationBar extends TabNavigationBar { layout.setY(0); scrollOffset = 0; - layout.setX(Math.max((this.width - allTabsWidth) / 2, NAVBAR_MARGIN)); + layout.setX(Math.max((accessor.getWidth() - allTabsWidth) / 2, NAVBAR_MARGIN)); this.maxScrollOffset = Math.max(0, allTabsWidth - noScrollWidth); } @@ -113,8 +117,12 @@ public class ScrollableNavigationBar extends TabNavigationBar { protected void ensureVisible(TabButton tabButton) { if (tabButton.getX() < NAVBAR_MARGIN) { this.setScrollOffset(this.scrollOffset - (NAVBAR_MARGIN - tabButton.getX())); - } else if (tabButton.getX() + tabButton.getWidth() > this.width - NAVBAR_MARGIN) { - this.setScrollOffset(this.scrollOffset + (tabButton.getX() + tabButton.getWidth() - (this.width - NAVBAR_MARGIN))); + } else if (tabButton.getX() + tabButton.getWidth() > accessor.getWidth() - NAVBAR_MARGIN) { + this.setScrollOffset(this.scrollOffset + (tabButton.getX() + tabButton.getWidth() - (accessor.getWidth() - NAVBAR_MARGIN))); } } + + public ImmutableList<Tab> getTabs() { + return accessor.getTabs(); + } } diff --git a/src/main/java/dev/isxander/yacl3/mixin/ContainerEventHandlerMixin.java b/src/main/java/dev/isxander/yacl3/mixin/ContainerEventHandlerMixin.java index bd5ada0..f22af36 100644 --- a/src/main/java/dev/isxander/yacl3/mixin/ContainerEventHandlerMixin.java +++ b/src/main/java/dev/isxander/yacl3/mixin/ContainerEventHandlerMixin.java @@ -1,7 +1,9 @@ -/*? if !forge {*/ package dev.isxander.yacl3.mixin; import net.minecraft.client.gui.components.events.ContainerEventHandler; +import org.spongepowered.asm.mixin.Mixin; + +/*? if !forge {*/ import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.components.tabs.TabNavigationBar; import net.minecraft.client.gui.navigation.FocusNavigationEvent; @@ -9,13 +11,11 @@ import net.minecraft.client.gui.navigation.ScreenAxis; import net.minecraft.client.gui.navigation.ScreenDirection; import net.minecraft.client.gui.navigation.ScreenRectangle; import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import java.util.List; - @Mixin(ContainerEventHandler.class) public interface ContainerEventHandlerMixin { // This mixin is used to prevent the tab bar from being focused when navigating left or right @@ -30,7 +30,7 @@ public interface ContainerEventHandlerMixin { } } /*?} else {*//* -@Mixin(targets = {}) +@Mixin(ContainerEventHandler.class) public class ContainerEventHandlerMixin { } diff --git a/src/main/java/dev/isxander/yacl3/mixin/TabNavigationBarAccessor.java b/src/main/java/dev/isxander/yacl3/mixin/TabNavigationBarAccessor.java index 388407b..f0da81d 100644 --- a/src/main/java/dev/isxander/yacl3/mixin/TabNavigationBarAccessor.java +++ b/src/main/java/dev/isxander/yacl3/mixin/TabNavigationBarAccessor.java @@ -1,8 +1,13 @@ package dev.isxander.yacl3.mixin; +import com.google.common.collect.ImmutableList; +import net.minecraft.client.gui.components.TabButton; +import net.minecraft.client.gui.components.tabs.Tab; +import net.minecraft.client.gui.components.tabs.TabManager; import net.minecraft.client.gui.components.tabs.TabNavigationBar; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(TabNavigationBar.class) public interface TabNavigationBarAccessor { @@ -13,4 +18,17 @@ public interface TabNavigationBarAccessor { @Accessor net.minecraft.client.gui.layouts.GridLayout getLayout(); /*?}*/ + + @Accessor + int getWidth(); + + @Accessor + TabManager getTabManager(); + + @Accessor + ImmutableList<Tab> getTabs(); + + @Accessor + ImmutableList<TabButton> getTabButtons(); + } diff --git a/src/main/resources/yacl.accesswidener b/src/main/resources/yacl.accesswidener index 7c0e2ca..e7bf3a4 100644 --- a/src/main/resources/yacl.accesswidener +++ b/src/main/resources/yacl.accesswidener @@ -4,9 +4,4 @@ extendable method net/minecraft/client/gui/components/AbstractSelectionList chil extendable method net/minecraft/client/gui/components/AbstractSelectionList getEntryAtPosition (DD)Lnet/minecraft/client/gui/components/AbstractSelectionList$Entry; accessible class net/minecraft/client/gui/components/AbstractSelectionList$Entry accessible method net/minecraft/client/gui/components/tabs/TabNavigationBar <init> (ILnet/minecraft/client/gui/components/tabs/TabManager;Ljava/lang/Iterable;)V -accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar layout Lnet/minecraft/client/gui/layouts/GridLayout; -accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar width I -accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar tabManager Lnet/minecraft/client/gui/components/tabs/TabManager; -accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar tabs Lcom/google/common/collect/ImmutableList; -accessible field net/minecraft/client/gui/components/tabs/TabNavigationBar tabButtons Lcom/google/common/collect/ImmutableList; accessible method net/minecraft/client/gui/components/Tooltip <init> (Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/Component;)V |