diff --git a/changelog.md b/changelog.md index 1dbf03a..69f720c 100644 --- a/changelog.md +++ b/changelog.md @@ -1 +1 @@ -- Add Simplified Chinese translation (user111192) +- Update to mc1.21.2 diff --git a/common/build.gradle b/common/build.gradle index 2f5f9c5..05c6c66 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -3,6 +3,16 @@ plugins { id("net.neoforged.moddev") } +// Workaround for NeoForge transitive deps conflict +configurations.all { + resolutionStrategy { + force "org.ow2.asm:asm:9.7" + force "org.ow2.asm:asm-commons:9.7" + force "org.ow2.asm:asm-tree:9.7" + force "org.ow2.asm:asm-util:9.7" + } +} + dependencies { compileOnly("org.spongepowered:mixin:${mixin_version}") compileOnly("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 c45dff0..eb09d20 100644 --- a/common/src/main/java/com/github/scotsguy/nowplaying/NowPlaying.java +++ b/common/src/main/java/com/github/scotsguy/nowplaying/NowPlaying.java @@ -60,7 +60,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); } @@ -69,7 +69,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/screen/ConfigScreenProvider.java b/common/src/main/java/com/github/scotsguy/nowplaying/gui/screen/ConfigScreenProvider.java index a99d481..353b8e2 100644 --- a/common/src/main/java/com/github/scotsguy/nowplaying/gui/screen/ConfigScreenProvider.java +++ b/common/src/main/java/com/github/scotsguy/nowplaying/gui/screen/ConfigScreenProvider.java @@ -1,11 +1,9 @@ package com.github.scotsguy.nowplaying.gui.screen; import net.minecraft.Util; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.MultiLineTextWidget; import net.minecraft.client.gui.screens.ConfirmLinkScreen; -import net.minecraft.client.gui.screens.options.OptionsSubScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; @@ -27,13 +25,16 @@ public static Screen getConfigScreen(Screen parent) { } } - static class BackupScreen extends OptionsSubScreen { + static class BackupScreen extends Screen { + private final Screen parent; + public BackupScreen(Screen parent) { - super(parent, Minecraft.getInstance().options, localized("screen", "title.default")); + super(localized("screen", "default")); + this.parent = parent; } @Override - protected void addOptions() { + protected void init() { MultiLineTextWidget messageWidget = new MultiLineTextWidget( width / 2 - 120, height / 2 - 40, localized("message", "install_cloth"), @@ -46,7 +47,7 @@ protected void addOptions() { (button) -> minecraft.setScreen(new ConfirmLinkScreen( (open) -> { if (open) Util.getPlatform().openUri("https://modrinth.com/mod/9s6osm5g"); - minecraft.setScreen(lastScreen); + minecraft.setScreen(parent); }, "https://modrinth.com/mod/9s6osm5g", true))) .pos(width / 2 - 120, height / 2) .size(115, 20) 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 fd4c4a3..0004c7c 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 @@ -2,9 +2,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; @@ -22,6 +24,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; @@ -34,7 +38,19 @@ 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); @@ -48,7 +64,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; @@ -85,20 +101,19 @@ 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 71% 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 a8d54de..be1a99e 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 @@ -6,8 +6,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; @@ -16,7 +16,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; @@ -24,12 +25,12 @@ import java.util.Optional; -@Mixin(LevelRenderer.class) -public class MixinLevelRenderer { +@Mixin(LevelEventHandler.class) +public class MixinLevelEventHandler { + @Final @Shadow - @Nullable - private ClientLevel level; + private Level level; @WrapOperation( method = "playJukeboxSong", @@ -49,9 +50,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 ae48c79..61604b0 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 @@ -11,14 +11,14 @@ 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; + @Final + private 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 aff919d..ead80a1 100644 --- a/common/src/main/resources/now-playing.mixins.json +++ b/common/src/main/resources/now-playing.mixins.json @@ -8,7 +8,7 @@ "GuiAccessor" ], "client": [ - "MixinLevelRenderer", + "MixinLevelEventHandler", "MixinMinecraft", "MixinToastInstance" ], diff --git a/gradle.properties b/gradle.properties index 4a6bda9..7460670 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.9 +mod_version=1.5.10 mod_group=com.github.scotsguy mod_id=now-playing mod_name=Now Playing @@ -27,35 +27,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.2 +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 # Fabric https://fabricmc.net/develop/ -fabric_loader_version=0.16.5 +fabric_loader_version=0.16.7 fabric_loader_versions=>=0.15.0 -fabric_api_version=0.102.0+1.21 +fabric_api_version=0.106.1+1.21.2 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.2.0-beta +neoforge_versions=[21.2.0-beta, 22) # NeoForm https://projects.neoforged.net/neoforged/neoform -neoform_version=1.21-20240613.152323 +neoform_version=1.21.2-20241022.151510 # Cloth Config https://modrinth.com/mod/9s6osm5g/versions -clothconfig_version=15.0.140 -clothconfig_versions_fabric=>=15 -clothconfig_versions_neoforge=[15,) +clothconfig_version=16.0.141 +clothconfig_versions_fabric=>=16 +clothconfig_versions_neoforge=[16,) # ModMenu https://modrinth.com/mod/mOgUt4GM/versions -modmenu_version=11.0.2 -modmenu_versions=>10 +modmenu_version=12.0.0-beta.1 +modmenu_versions=>11 # GitHub, Modrinth, CurseForge releases # Plural properties expect CSV lists @@ -67,12 +67,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 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 release_required_dep_ids_neoforge_mr=9s6osm5g release_required_dep_ids_neoforge_cf=cloth-config @@ -83,9 +83,9 @@ mixinextras_version=0.4.1 # Plugins # Fabric Loom https://mvnrepository.com/artifact/net.fabricmc/fabric-loom -loom_version=1.7.4 +loom_version=1.8.6 # ModDev https://plugins.gradle.org/plugin/net.neoforged.moddev -moddev_version=1.0.19 +moddev_version=1.0.21 # Minotaur https://plugins.gradle.org/plugin/com.modrinth.minotaur minotaur_version=2.8.7 # CurseForgeGradle https://plugins.gradle.org/plugin/net.darkhax.curseforgegradle @@ -93,9 +93,8 @@ 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 # Gradle org.gradle.jvmargs=-Xmx4G org.gradle.daemon=false - diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index dab2a01..ccc1a9b 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.10.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME