From 857a3406a514e3bc434e8344bd62e9b9504bf967 Mon Sep 17 00:00:00 2001 From: NotRyken <127091011+NotRyken@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:28:02 +0800 Subject: [PATCH] Update to mc1.21.3 --- common/build.gradle | 17 +++++++++ .../scotsguy/nowplaying/NowPlaying.java | 4 +- .../nowplaying/gui/toast/NowPlayingToast.java | 32 +++++++++++----- ...derer.java => MixinLevelEventHandler.java} | 26 +++++++------ .../nowplaying/mixin/MixinToastInstance.java | 9 ++--- .../main/resources/now-playing.mixins.json | 2 +- gradle.properties | 38 ++++++++++--------- gradle/wrapper/gradle-wrapper.properties | 2 +- 8 files changed, 82 insertions(+), 48 deletions(-) rename common/src/main/java/com/github/scotsguy/nowplaying/mixin/{MixinLevelRenderer.java => MixinLevelEventHandler.java} (80%) diff --git a/common/build.gradle b/common/build.gradle index 43bda32..4021dd0 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -3,7 +3,24 @@ plugins { id("net.neoforged.moddev") } +// Vanilla depends on ASM 9.3, MDG makes that a 'strict' version constraint, +// but Mixin and MixinExtras needs newer ASM so we override that here. +configurations.configureEach { + resolutionStrategy.eachDependency { details -> + if (details.requested.group == "org.ow2.asm") { + details.useVersion(asm_version) + details.because("Mixin requires new ASM") + } + } +} + dependencies { + compileOnly "org.ow2.asm:asm:${asm_version}" + compileOnly "org.ow2.asm:asm-analysis:${asm_version}" + compileOnly "org.ow2.asm:asm-commons:${asm_version}" + compileOnly "org.ow2.asm:asm-tree:${asm_version}" + compileOnly "org.ow2.asm:asm-util:${asm_version}" + compileOnly("org.spongepowered:mixin:${mixin_version}") compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:${mixinextras_version}")) diff --git a/common/src/main/java/com/github/scotsguy/nowplaying/NowPlaying.java b/common/src/main/java/com/github/scotsguy/nowplaying/NowPlaying.java index 470c239..eac4c37 100644 --- a/common/src/main/java/com/github/scotsguy/nowplaying/NowPlaying.java +++ b/common/src/main/java/com/github/scotsguy/nowplaying/NowPlaying.java @@ -82,7 +82,7 @@ public static void display(Component name, Item disc, Config.Options.Style style switch(style) { case Toast -> { - mc.getToasts().addToast(new NowPlayingToast(name, new ItemStack(disc), + mc.getToastManager().addToast(new NowPlayingToast(name, new ItemStack(disc), options.toastTime * 1000L, options.toastScale)); if (options.narrate) mc.getNarrator().sayNow(message); } @@ -91,7 +91,7 @@ public static void display(Component name, Item disc, Config.Options.Style style mc.gui.setOverlayMessage(message, true); ((GuiAccessor)mc.gui).setOverlayMessageTime(options.hotbarTime * 20); } else if (options.fallbackToast) { - mc.getToasts().addToast(new NowPlayingToast(name, new ItemStack(disc), + mc.getToastManager().addToast(new NowPlayingToast(name, new ItemStack(disc), options.toastTime * 1000L, options.toastScale)); } if (options.narrate) mc.getNarrator().sayNow(message); diff --git a/common/src/main/java/com/github/scotsguy/nowplaying/gui/toast/NowPlayingToast.java b/common/src/main/java/com/github/scotsguy/nowplaying/gui/toast/NowPlayingToast.java index 22a8937..1e0e991 100644 --- a/common/src/main/java/com/github/scotsguy/nowplaying/gui/toast/NowPlayingToast.java +++ b/common/src/main/java/com/github/scotsguy/nowplaying/gui/toast/NowPlayingToast.java @@ -24,9 +24,11 @@ import com.github.scotsguy.nowplaying.config.Config; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.toasts.Toast; -import net.minecraft.client.gui.components.toasts.ToastComponent; +import net.minecraft.client.gui.components.toasts.ToastManager; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.FormattedCharSequence; @@ -44,6 +46,8 @@ public class NowPlayingToast implements Toast { private final ItemStack itemStack; private final long displayTime; private final float scale; + private Toast.Visibility wantedVisibility; + private long startTime; private static final int TEXT_LEFT_MARGIN = 30; private static final int TEXT_RIGHT_MARGIN = 7; @@ -56,7 +60,18 @@ public NowPlayingToast(Component description, ItemStack itemStack, long displayT } @Override - public @NotNull Visibility render(@NotNull GuiGraphics graphics, @NotNull ToastComponent toast, long startTime) { + public @NotNull Visibility getWantedVisibility() { + return wantedVisibility; + } + + @Override + public void update(@NotNull ToastManager toastManager, long l) { + this.wantedVisibility = startTime >= this.displayTime ? Visibility.HIDE : Visibility.SHOW; + } + + @Override + public void render(@NotNull GuiGraphics graphics, @NotNull Font font, long startTime) { + this.startTime = startTime; if (scale != 1.0F) { graphics.pose().pushPose(); graphics.pose().translate(160 * (1 - scale), 0.0F, 0.0F); @@ -70,7 +85,7 @@ public NowPlayingToast(Component description, ItemStack itemStack, long displayT if (width == 160 && textLines.size() <= 1) { // Text fits, draw the whole toast from the texture - graphics.blitSprite(BACKGROUND_SPRITE, 0, 0, width, height); + graphics.blitSprite(RenderType::guiTextured, BACKGROUND_SPRITE, 0, 0, width, height); } else { // Stretch toast by drawing the sprite multiple times height = height + Math.max(0, textLines.size() - (Config.get().options.simpleToast ? 2 : 1)) * 12; @@ -107,21 +122,18 @@ public NowPlayingToast(Component description, ItemStack itemStack, long displayT graphics.renderFakeItem(itemStack, 9, (height / 2) - (16 / 2)); if (scale != 1.0F) graphics.pose().popPose(); - return startTime >= this.displayTime ? Visibility.HIDE : Visibility.SHOW; } private void renderBackgroundRow(GuiGraphics graphics, int i, int vOffset, int y, int vHeight) { int uWidth = vOffset == 0 ? 20 : 5; int n = Math.min(60, i - uWidth); - graphics.blitSprite(BACKGROUND_SPRITE, 160, 32, 0, vOffset, 0, y, uWidth, vHeight); - + graphics.blitSprite(RenderType::guiTextured, BACKGROUND_SPRITE, 160, 32, 0, vOffset, 0, y, uWidth, vHeight); + for (int o = uWidth; o < i - n; o += 64) { - graphics.blitSprite(BACKGROUND_SPRITE, 160, 32, 32, vOffset, o, y, Math.min(64, i - o - n), vHeight); + graphics.blitSprite(RenderType::guiTextured, BACKGROUND_SPRITE, 160, 32, 32, vOffset, o, y, Math.min(64, i - o - n), vHeight); } - graphics.blitSprite(BACKGROUND_SPRITE, 160, 32, 160 - n, vOffset, i - n, y, n, vHeight); + graphics.blitSprite(RenderType::guiTextured, BACKGROUND_SPRITE, 160, 32, 160 - n, vOffset, i - n, y, n, vHeight); } } - - diff --git a/common/src/main/java/com/github/scotsguy/nowplaying/mixin/MixinLevelRenderer.java b/common/src/main/java/com/github/scotsguy/nowplaying/mixin/MixinLevelEventHandler.java similarity index 80% rename from common/src/main/java/com/github/scotsguy/nowplaying/mixin/MixinLevelRenderer.java rename to common/src/main/java/com/github/scotsguy/nowplaying/mixin/MixinLevelEventHandler.java index 5212d53..60004c2 100644 --- a/common/src/main/java/com/github/scotsguy/nowplaying/mixin/MixinLevelRenderer.java +++ b/common/src/main/java/com/github/scotsguy/nowplaying/mixin/MixinLevelEventHandler.java @@ -28,8 +28,8 @@ import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.client.gui.Gui; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.LevelEventHandler; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; @@ -38,7 +38,8 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.item.JukeboxSong; -import org.jetbrains.annotations.Nullable; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -46,12 +47,11 @@ import java.util.Optional; -@Mixin(LevelRenderer.class) -public class MixinLevelRenderer { - +@Mixin(LevelEventHandler.class) +public class MixinLevelEventHandler { + @Shadow - @Nullable - private ClientLevel level; + private @Final Level level; @WrapOperation( method = "playJukeboxSong", @@ -71,9 +71,13 @@ private void display(Gui instance, Component text, Operation original, if (level == null) return defaultDisc; Item disc = null; - Optional> itemRegistry = level.registryAccess().registry(Registries.ITEM); - if (itemRegistry.isPresent()) disc = itemRegistry.get().get(ResourceLocation.parse( - sound.getLocation().toString().replaceAll("\\.", "_"))); + Optional>> itemRegistry = + level.registryAccess().get(Registries.ITEM); + if (itemRegistry.isPresent()) { + Optional> discRef = itemRegistry.get().value().get( + ResourceLocation.parse(sound.location().toString().replaceAll("\\.", "_"))); + if (discRef.isPresent()) disc = discRef.get().value(); + } if (disc == null || disc.equals(Items.AIR)) disc = defaultDisc; return disc; diff --git a/common/src/main/java/com/github/scotsguy/nowplaying/mixin/MixinToastInstance.java b/common/src/main/java/com/github/scotsguy/nowplaying/mixin/MixinToastInstance.java index e571e74..b0733be 100644 --- a/common/src/main/java/com/github/scotsguy/nowplaying/mixin/MixinToastInstance.java +++ b/common/src/main/java/com/github/scotsguy/nowplaying/mixin/MixinToastInstance.java @@ -33,14 +33,13 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -@Mixin(targets = "net.minecraft.client.gui.components.toasts.ToastComponent$ToastInstance") -public class MixinToastInstance { - @Final +@Mixin(targets = "net.minecraft.client.gui.components.toasts.ToastManager$ToastInstance") +public class MixinToastInstance { @Shadow - private T toast; + private @Final Toast toast; @WrapOperation( - method = "render", + method = "update", at = @At( value = "INVOKE", target = "Lnet/minecraft/client/gui/components/toasts/Toast$Visibility;playSound(Lnet/minecraft/client/sounds/SoundManager;)V" diff --git a/common/src/main/resources/now-playing.mixins.json b/common/src/main/resources/now-playing.mixins.json index 3086e7a..0de43cb 100644 --- a/common/src/main/resources/now-playing.mixins.json +++ b/common/src/main/resources/now-playing.mixins.json @@ -7,7 +7,7 @@ "mixins": [ ], "client": [ - "MixinLevelRenderer", + "MixinLevelEventHandler", "MixinMinecraft", "MixinToastInstance", "GuiAccessor" diff --git a/gradle.properties b/gradle.properties index 4a20372..030f3e4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ # Neo/Forge version ranges: https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html # Project -mod_version=1.5.11+1.21 +mod_version=1.5.11+1.21.3 mod_group=com.github.scotsguy mod_id=now-playing mod_name=Now Playing @@ -24,35 +24,35 @@ java_versions_fabric=>=21 java_versions_neoforge=[21,) # Minecraft -minecraft_version=1.21 -minecraft_versions_fabric=>1.20.6 <1.22 -minecraft_versions_neoforge=(1.20.6, 1.22) +minecraft_version=1.21.3 +minecraft_versions_fabric=>1.21.1 <1.22 +minecraft_versions_neoforge=(1.21.1, 1.22) # Parchment https://parchmentmc.org/docs/getting-started#choose-a-version parchment_minecraft_version=1.21 -parchment_version=2024.07.28 +parchment_version=2024.11.10 # Fabric https://fabricmc.net/develop -fabric_loader_version=0.16.5 +fabric_loader_version=0.16.9 fabric_loader_versions=>=0.15.0 -fabric_api_version=0.102.0+1.21 +fabric_api_version=0.108.0+1.21.3 fabric_api_versions=* # NeoForge https://projects.neoforged.net/neoforged/neoforge neoforge_loader_versions=[1,) -neoforge_version=21.0.167 -neoforge_versions=[21.0.143, 22) +neoforge_version=21.3.33-beta +neoforge_versions=[21.2.0, 22) # NeoForm https://projects.neoforged.net/neoforged/neoform -neoform_version=1.21-20240613.152323 +neoform_version=1.21.3-20241023.131943 # Cloth Config https://modrinth.com/mod/9s6osm5g/versions -clothconfig_version=15.0.140 +clothconfig_version=16.0.141 clothconfig_versions_fabric=>=15 clothconfig_versions_neoforge=[15,) # ModMenu https://modrinth.com/mod/mOgUt4GM/versions -modmenu_version=11.0.2 -modmenu_versions_fabric=>10 +modmenu_version=12.0.0-beta.1 +modmenu_versions_fabric=>11 # GitHub, Modrinth, CurseForge releases # Plural properties expect CSV lists @@ -64,12 +64,12 @@ curseforge_id=398652 release_type=release # Fabric release_mod_loaders_fabric=fabric,quilt -release_game_versions_fabric=1.21,1.21.1 +release_game_versions_fabric=1.21.2,1.21.3 release_required_dep_ids_fabric_mr=P7dR8mSH,mOgUt4GM,9s6osm5g release_required_dep_ids_fabric_cf=fabric-api,modmenu,cloth-config # NeoForge release_mod_loaders_neoforge=neoforge -release_game_versions_neoforge=1.21,1.21.1 +release_game_versions_neoforge=1.21.2,1.21.3 release_required_dep_ids_neoforge_mr=9s6osm5g release_required_dep_ids_neoforge_cf=cloth-config @@ -77,12 +77,14 @@ release_required_dep_ids_neoforge_cf=cloth-config mixin_version=0.8.7 # MixinExtras https://github.com/LlamaLad7/MixinExtras/releases mixinextras_version=0.4.1 +# ASM https://mvnrepository.com/artifact/org.ow2.asm/asm +asm_version=9.7 # Plugins # Fabric Loom https://mvnrepository.com/artifact/net.fabricmc/fabric-loom -loom_version=1.7.4 +loom_version=1.8.12 # ModDev https://plugins.gradle.org/plugin/net.neoforged.moddev -moddev_version=1.0.19 +moddev_version=2.0.44-beta # Minotaur https://plugins.gradle.org/plugin/com.modrinth.minotaur minotaur_version=2.8.7 # CurseForgeGradle https://plugins.gradle.org/plugin/net.darkhax.curseforgegradle @@ -90,7 +92,7 @@ curseforgegradle_version=1.1.25 # github-release https://plugins.gradle.org/plugin/com.github.breadmoirai.github-release githubrelease_version=2.5.2 # grgit-service https://github.com/ajoberstar/grgit/releases -grgitservice_version=5.2.2 +grgitservice_version=5.3.0 # licenser https://plugins.gradle.org/plugin/org.cadixdev.licenser licenser_version=0.6.1 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a441313..94113f2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME