Add support for 1.20.5-1.20.6

This commit is contained in:
hhhzzzsss 2024-05-02 08:59:39 -05:00
parent 06f3497c95
commit 51e365c30f
13 changed files with 56 additions and 57 deletions

View file

@ -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.

View file

@ -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
}
}

View file

@ -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

View file

@ -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

View file

@ -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);

View file

@ -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)));
}
}

View file

@ -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) {

View file

@ -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();

View file

@ -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) {

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -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);
}

View file

@ -28,7 +28,7 @@
"depends": {
"fabricloader": ">=0.14.11",
"fabric": "*",
"minecraft": "~1.20.3",
"minecraft": "~1.20.5",
"java": ">=17"
},
"suggests": {