Skip to content

Commit

Permalink
Update to mc1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
NotRyken committed Oct 23, 2024
1 parent 2945127 commit e4de3a4
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 53 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Add Simplified Chinese translation (user111192)
- Update to mc1.21.2
10 changes: 10 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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"),
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,20 +16,21 @@
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;
import org.spongepowered.asm.mixin.injection.At;

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",
Expand All @@ -49,9 +50,13 @@ private void display(Gui instance, Component text, Operation<Void> original,
if (level == null) return defaultDisc;

Item disc = null;
Optional<Registry<Item>> itemRegistry = level.registryAccess().registry(Registries.ITEM);
if (itemRegistry.isPresent()) disc = itemRegistry.get().get(ResourceLocation.parse(
sound.getLocation().toString().replaceAll("\\.", "_")));
Optional<Holder.Reference<Registry<Item>>> itemRegistry =
level.registryAccess().get(Registries.ITEM);
if (itemRegistry.isPresent()) {
Optional<Holder.Reference<Item>> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends Toast> {
@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"
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/resources/now-playing.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"GuiAccessor"
],
"client": [
"MixinLevelRenderer",
"MixinLevelEventHandler",
"MixinMinecraft",
"MixinToastInstance"
],
Expand Down
39 changes: 19 additions & 20 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -83,19 +83,18 @@ 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
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

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e4de3a4

Please sign in to comment.