diff --git a/README.md b/README.md index 83a41dd..68c482f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # SongPlayer A Fabric mod for Minecraft that plays songs with noteblocks. -The current version is for Minecraft 1.20.4. +The current version is for Minecraft 1.20.5 - 1.20.6. # How to install You can grab the mod jar from releases section. diff --git a/build.gradle b/build.gradle index 14f6f46..46a0781 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,15 @@ plugins { - id 'fabric-loom' version '1.0-SNAPSHOT' + id 'fabric-loom' version '1.6-SNAPSHOT' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - -archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group +base { + archivesName = project.archives_base_name +} + repositories { // Add repositories to retrieve artifacts from in here. // You should only use this when depending on other mods because @@ -27,8 +27,6 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. - // You may need to force-disable transitiveness on them. } processResources { @@ -40,8 +38,7 @@ processResources { } tasks.withType(JavaCompile).configureEach { - // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. - it.options.release = 17 + it.options.release = 21 } java { @@ -49,18 +46,22 @@ java { // if it is present. // If you remove this line, sources will not be generated. withSourcesJar() + + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } jar { from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} + rename { "${it}_${project.base.archivesName.get()}"} } } // configure the maven publication publishing { publications { - mavenJava(MavenPublication) { + create("mavenJava", MavenPublication) { + artifactId = project.archives_base_name from components.java } } diff --git a/gradle.properties b/gradle.properties index 194608e..d232237 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,15 +4,15 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.20.4 - yarn_mappings=1.20.3+build.1 - loader_version=0.15.0 + minecraft_version=1.20.6 + yarn_mappings=1.20.6+build.1 + loader_version=0.15.10 # Mod Properties - mod_version = 3.1.3 + mod_version = 3.1.4 maven_group = com.github.hhhzzzsss archives_base_name = song-player # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.91.1+1.20.4 + fabric_version=0.97.8+1.20.6 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f398c33..20db9ad 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-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java b/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java index 953b483..6635032 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/CommandProcessor.java @@ -10,6 +10,8 @@ import com.github.hhhzzzsss.songplayer.song.Song; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.minecraft.command.CommandSource; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.util.Hand; @@ -1030,7 +1032,7 @@ public class CommandProcessor { return true; } String name = String.join(" ", Arrays.copyOfRange(split, 1, split.length)); - songPlayerNBT.putString(SongItemUtils.DISPLAY_NAME_KEY, name); + NbtComponent.set(DataComponentTypes.CUSTOM_DATA, stack, nbt -> nbt.getCompound(SongItemUtils.SONG_ITEM_KEY).putString(SongItemUtils.DISPLAY_NAME_KEY, name)); SongItemUtils.addSongItemDisplay(stack); MC.player.setStackInHand(Hand.MAIN_HAND, stack); MC.interactionManager.clickCreativeStack(MC.player.getStackInHand(Hand.MAIN_HAND), 36 + MC.player.getInventory().selectedSlot); diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/Util.java b/src/main/java/com/github/hhhzzzsss/songplayer/Util.java index eb2453e..121c6d1 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/Util.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/Util.java @@ -3,6 +3,8 @@ package com.github.hhhzzzsss.songplayer; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.minecraft.command.CommandSource; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.LoreComponent; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtList; import net.minecraft.nbt.NbtString; @@ -222,14 +224,10 @@ public class Util { } public static void setItemName(ItemStack stack, Text text) { - stack.getOrCreateSubNbt(ItemStack.DISPLAY_KEY).putString(ItemStack.NAME_KEY, Text.Serialization.toJsonString(text)); + stack.set(DataComponentTypes.CUSTOM_NAME, text); } public static void setItemLore(ItemStack stack, Text... loreLines) { - NbtList lore = new NbtList(); - for (Text line : loreLines) { - lore.add(NbtString.of(Text.Serialization.toJsonString(line))); - } - stack.getOrCreateSubNbt(ItemStack.DISPLAY_KEY).put(ItemStack.LORE_KEY, lore); + stack.set(DataComponentTypes.LORE, new LoreComponent(List.of(loreLines))); } } diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemConfirmationScreen.java b/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemConfirmationScreen.java index 12c273e..8814357 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemConfirmationScreen.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemConfirmationScreen.java @@ -54,7 +54,7 @@ public class SongItemConfirmationScreen extends Screen { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { - this.renderBackground(context, mouseX, mouseY, delta); + super.render(context, mouseX, mouseY, delta); context.drawCenteredTextWithShadow(textRenderer, this.title, this.width / 2, 40, 0xFFFFFF); @@ -86,8 +86,6 @@ public class SongItemConfirmationScreen extends Screen { else { unloadedText.drawCenterWithShadow(context, this.width / 2, 60); } - - super.render(context, mouseX, mouseY, delta); } public String getNumberColor(double number) { diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemCreatorThread.java b/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemCreatorThread.java index d084db0..91fc017 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemCreatorThread.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemCreatorThread.java @@ -3,6 +3,8 @@ package com.github.hhhzzzsss.songplayer.item; import com.github.hhhzzzsss.songplayer.SongPlayer; import com.github.hhhzzzsss.songplayer.conversion.SPConverter; import com.github.hhhzzzsss.songplayer.song.SongLoaderThread; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.CustomModelDataComponent; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.text.Text; @@ -39,7 +41,7 @@ public class SongItemCreatorThread extends SongLoaderThread { ItemStack newStack; if (stack.isEmpty()) { newStack = Items.PAPER.getDefaultStack(); - newStack.getOrCreateNbt().putInt("CustomModelData", 751642938); + newStack.set(DataComponentTypes.CUSTOM_MODEL_DATA, new CustomModelDataComponent(751642938)); } else { newStack = stack.copy(); diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemUtils.java b/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemUtils.java index 72b8cc0..f3cf9de 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemUtils.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/item/SongItemUtils.java @@ -1,6 +1,8 @@ package com.github.hhhzzzsss.songplayer.item; import com.github.hhhzzzsss.songplayer.Util; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.NbtComponent; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; @@ -18,10 +20,10 @@ public class SongItemUtils { public static ItemStack createSongItem(ItemStack stack, byte[] songData, String filename, String displayName) { NbtCompound songPlayerNbt = new NbtCompound(); - stack.setSubNbt(SONG_ITEM_KEY, songPlayerNbt); songPlayerNbt.putString(SONG_DATA_KEY, Base64.getEncoder().encodeToString(songData)); songPlayerNbt.putString(FILE_NAME_KEY, filename); songPlayerNbt.putString(DISPLAY_NAME_KEY, displayName); + NbtComponent.set(DataComponentTypes.CUSTOM_DATA, stack, nbt -> nbt.put(SONG_ITEM_KEY, songPlayerNbt)); addSongItemDisplay(stack); return stack; } @@ -43,7 +45,12 @@ public class SongItemUtils { } public static NbtCompound getSongItemTag(ItemStack stack) { - return stack.getSubNbt(SONG_ITEM_KEY); + NbtCompound nbt = stack.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT).copyNbt(); + if (nbt.contains(SONG_ITEM_KEY, NbtElement.COMPOUND_TYPE)) { + return (NbtCompound)nbt.get(SONG_ITEM_KEY); + } else { + return null; + } } public static boolean isSongItem(ItemStack stack) { diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/mixin/InGameHudMixin.java b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/InGameHudMixin.java index 9f3e533..a6ac6cc 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/mixin/InGameHudMixin.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/mixin/InGameHudMixin.java @@ -3,7 +3,6 @@ package com.github.hhhzzzsss.songplayer.mixin; import com.github.hhhzzzsss.songplayer.playing.ProgressDisplay; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; -import net.minecraft.client.util.math.MatrixStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -12,18 +11,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(InGameHud.class) public class InGameHudMixin { - @Shadow - private int scaledWidth; - - @Shadow - private int scaledHeight; - @Shadow private int heldItemTooltipFade; - @Inject(method = "render", - at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;enableBlend()V", ordinal = 3)) - private void onRender(DrawContext context, float tickDelta, CallbackInfo ci) { - ProgressDisplay.getInstance().onRenderHUD(context, scaledWidth, scaledHeight, heldItemTooltipFade); + @Inject(at = @At("TAIL"), method = "renderHeldItemTooltip(Lnet/minecraft/client/gui/DrawContext;)V") + private void onRenderHeldItemTooltip(DrawContext context, CallbackInfo ci) { + ProgressDisplay.getInstance().onRenderHUD(context, heldItemTooltipFade); } } diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/playing/ProgressDisplay.java b/src/main/java/com/github/hhhzzzsss/songplayer/playing/ProgressDisplay.java index 973c8b2..b3a1fb5 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/playing/ProgressDisplay.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/playing/ProgressDisplay.java @@ -29,16 +29,16 @@ public class ProgressDisplay { fade = 100; } - public void onRenderHUD(DrawContext context, int scaledWidth, int scaledHeight, int heldItemTooltipFade) { + public void onRenderHUD(DrawContext context, int heldItemTooltipFade) { if (fade <= 0) { return; } int bottomTextWidth = SongPlayer.MC.textRenderer.getWidth(bottomText); int topTextWidth = SongPlayer.MC.textRenderer.getWidth(topText); - int bottomTextX = (scaledWidth - bottomTextWidth) / 2; - int topTextX = (scaledWidth - topTextWidth) / 2; - int bottomTextY = scaledHeight - 59; + int bottomTextX = (SongPlayer.MC.getWindow().getScaledWidth() - bottomTextWidth) / 2; + int topTextX = (SongPlayer.MC.getWindow().getScaledWidth() - topTextWidth) / 2; + int bottomTextY = SongPlayer.MC.getWindow().getScaledHeight() - 59; if (!SongPlayer.MC.interactionManager.hasStatusBars()) { bottomTextY += 14; } diff --git a/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java b/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java index cbb5d16..0ffbbea 100644 --- a/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java +++ b/src/main/java/com/github/hhhzzzsss/songplayer/playing/SongHandler.java @@ -8,8 +8,11 @@ import com.github.hhhzzzsss.songplayer.mixin.ClientPlayerInteractionManagerAcces import com.github.hhhzzzsss.songplayer.song.*; import net.minecraft.block.Block; import net.minecraft.client.world.ClientWorld; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.BlockStateComponent; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import net.minecraft.text.MutableText; @@ -26,6 +29,7 @@ import net.minecraft.world.GameMode; import java.io.IOException; import java.nio.file.Path; import java.util.LinkedList; +import java.util.Map; public class SongHandler { private static SongHandler instance = null; @@ -457,16 +461,11 @@ public class SongHandler { ((ClientPlayerInteractionManagerAccessor) SongPlayer.MC.interactionManager).invokeSyncSelectedSlot(); int instrument = id/25; int note = id%25; - NbtCompound nbt = new NbtCompound(); - nbt.putString("id", "minecraft:note_block"); - nbt.putByte("Count", (byte) 1); - NbtCompound tag = new NbtCompound(); - NbtCompound bsTag = new NbtCompound(); - bsTag.putString("instrument", instrumentNames[instrument]); - bsTag.putString("note", Integer.toString(note)); - tag.put("BlockStateTag", bsTag); - nbt.put("tag", tag); - ItemStack noteblockStack = ItemStack.fromNbt(nbt); + ItemStack noteblockStack = Items.NOTE_BLOCK.getDefaultStack(); + noteblockStack.set(DataComponentTypes.BLOCK_STATE, new BlockStateComponent(Map.of( + "instrument", instrumentNames[instrument], + "note", Integer.toString(note) + ))); inventory.main.set(slot, noteblockStack); SongPlayer.MC.interactionManager.clickCreativeStack(noteblockStack, 36 + slot); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8b1d77f..72e74e7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -28,7 +28,7 @@ "depends": { "fabricloader": ">=0.14.11", "fabric": "*", - "minecraft": "~1.20.3", + "minecraft": "~1.20.5", "java": ">=17" }, "suggests": {