diff --git a/build.gradle b/build.gradle index db79275..c08cdf8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'net.fabricmc.fabric-loom-remap' version "${loom_version}" + id 'net.fabricmc.fabric-loom' version "${loom_version}" } base.archivesName = project.archives_base_name @@ -11,7 +11,7 @@ repositories { // adventure snapshots maven { - url = "https://s01.oss.sonatype.org/content/repositories/snapshots/" + url = "https://central.sonatype.com/repository/maven-snapshots/" mavenContent { snapshotsOnly() } } } @@ -19,11 +19,10 @@ repositories { dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings loom.officialMojangMappings() - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + implementation "net.fabricmc:fabric-loader:${project.loader_version}" // Fabric API - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" // LuaJ include(implementation("org.luaj:luaj-jse:3.0.1")) @@ -34,7 +33,7 @@ dependencies { include(implementation("io.leangen.geantyref:geantyref:2.0.1")) // Adventure - include(modImplementation("net.kyori:adventure-platform-fabric:6.8.0")) + include(implementation("net.kyori:adventure-platform-fabric:6.9.0-SNAPSHOT")) include(implementation("net.kyori:adventure-text-serializer-gson:4.26.1")) include(implementation("net.kyori:adventure-text-serializer-legacy:4.26.1")) } @@ -48,11 +47,10 @@ processResources { } tasks.withType(JavaCompile).configureEach { - // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. - it.options.release = 21 + it.options.release = 25 - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + sourceCompatibility = JavaVersion.VERSION_25 + targetCompatibility = JavaVersion.VERSION_25 } jar { diff --git a/gradle.properties b/gradle.properties index 81c4738..30605e2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.21.11 - loader_version=0.18.4 + minecraft_version=26.1 + loader_version=0.18.5 loom_version=1.15-SNAPSHOT # Mod Properties @@ -14,5 +14,5 @@ org.gradle.parallel=true archives_base_name = chipmunkmod # Dependencies - fabric_version=0.141.3+1.21.11 + fabric_version=0.144.3+26.1 diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/ItemCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/ItemCommand.java index 8825ff6..bb05a18 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/ItemCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/ItemCommand.java @@ -46,7 +46,7 @@ public class ItemCommand { if (player == null || connection == null) return Command.SINGLE_SUCCESS; - final ItemStack stack = getItem(context, "item").createItemStack(count, false); + final ItemStack stack = getItem(context, "item").createItemStack(count); final int slot = 36 + player.getInventory().getSelectedSlot(); connection.send(new ServerboundSetCreativeModeSlotPacket(slot, stack)); diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java index 06cdba3..259c43b 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java @@ -245,7 +245,7 @@ public class CommandCore implements Listener { final ClientPacketListener connection = client.getConnection(); if (player == null || connection == null) return; - final int distanceSquared = player.chunkPosition().distanceSquared(new ChunkPos(origin)); + final int distanceSquared = player.chunkPosition().distanceSquared(ChunkPos.containing(origin)); final int distance = (int) Math.sqrt(Math.abs(distanceSquared)); final int simulationDistance = connection.getLevel().getServerSimulationDistance(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java b/src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java index 475e5f1..79d9cdb 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java @@ -17,30 +17,33 @@ public class Instrument { public static final Instrument BIT = new Instrument(13, "bit", 54); public static final Instrument BANJO = new Instrument(14, "banjo", 54); public static final Instrument PLING = new Instrument(15, "pling", 54); - private static final Instrument[] VALUES = { HARP, BASEDRUM, SNARE, HAT, BASS, FLUTE, BELL, GUITAR, CHIME, XYLOPHONE, IRON_XYLOPHONE, COW_BELL, DIDGERIDOO, BIT, BANJO, PLING }; + public static final Instrument TRUMPET = new Instrument(15, "trumpet", 54); + public static final Instrument TRUMPET_EXPOSED = new Instrument(16, "trumpet_exposed", 54); + public static final Instrument TRUMPET_WEATHERED = new Instrument(17, "trumpet_weathered", 54); + public static final Instrument TRUMPET_OXIDIZED = new Instrument(18, "trumpet_oxidized", 54); + private static final Instrument[] VALUES = { + HARP, BASEDRUM, SNARE, HAT, BASS, FLUTE, BELL, GUITAR, CHIME, XYLOPHONE, IRON_XYLOPHONE, COW_BELL, DIDGERIDOO, + BIT, BANJO, PLING, TRUMPET, TRUMPET_EXPOSED, TRUMPET_WEATHERED, TRUMPET_OXIDIZED + }; public final int id; public final String name; public final int offset; public final String sound; - private Instrument (final int id, final String name, final int offset, final String sound) { + protected Instrument (final int id, final String name, final int offset, final String sound) { this.id = id; this.name = name; this.offset = offset; this.sound = sound; } - private Instrument (final int id, final String name, final int offset) { + protected Instrument (final int id, final String name, final int offset) { this.id = id; this.name = name; this.offset = offset; this.sound = "block.note_block." + name; } - public static Instrument of (final String sound) { - return new Instrument(-1, null, 0, sound); - } - public static Instrument fromId (final int id) { return VALUES[id]; } diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java b/src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java index 5e3a271..bb5913b 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java @@ -4,6 +4,9 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; + +import net.minecraft.resources.Identifier; +import net.minecraft.util.Util; import net.minecraft.world.phys.Vec3; public class NBSConverter { @@ -24,6 +27,10 @@ public class NBSConverter { Instrument.BIT, Instrument.BANJO, Instrument.PLING, + Instrument.TRUMPET, + Instrument.TRUMPET_EXPOSED, + Instrument.TRUMPET_WEATHERED, + Instrument.TRUMPET_OXIDIZED, }; public static Song getSongFromBytes (final byte[] bytes, final String fileName) throws IOException { @@ -32,7 +39,7 @@ public class NBSConverter { short songLength = 0; byte format = 0; - byte vanillaInstrumentCount = 0; + byte vanillaInstrumentCount = 10; // Before v1, we had 10 vanilla instruments songLength = buffer.getShort(); // If it's not 0, then it uses the old format if (songLength == 0) { format = buffer.get(); @@ -71,9 +78,9 @@ public class NBSConverter { } final ArrayList nbsNotes = new ArrayList<>(); - short tick = -1; + int tick = -1; while (true) { - final int tickJumps = buffer.getShort(); + final int tickJumps = Short.toUnsignedInt(buffer.getShort()); if (tickJumps == 0) break; tick += tickJumps; @@ -116,12 +123,12 @@ public class NBSConverter { if (buffer.hasRemaining()) { final byte customInstrumentCount = buffer.get(); for (int i = 0; i < customInstrumentCount; i++) { - final NBSCustomInstrument customInstrument = new NBSCustomInstrument(); - customInstrument.name = getString(buffer, bytes.length); - customInstrument.file = getString(buffer, bytes.length); - customInstrument.pitch = buffer.get(); - customInstrument.key = buffer.get() != 0; - customInstruments.add(customInstrument); + final String name = getString(buffer, bytes.length); + final String file = getString(buffer, bytes.length); + final byte pitch = buffer.get(); + final boolean visible = buffer.get() != 0; // "Press piano key" + + customInstruments.add(new NBSCustomInstrument(name, file, pitch, visible)); } } @@ -134,18 +141,17 @@ public class NBSConverter { for (final NBSNote note : nbsNotes) { final Instrument instrument; double key; - if (note.instrument < instrumentIndex.length) { + if (note.instrument < vanillaInstrumentCount) { + if (note.instrument >= instrumentIndex.length) continue; instrument = instrumentIndex[note.instrument]; key = (double) ((note.key * 100) + note.pitch) / 100; } else { - final int index = note.instrument - instrumentIndex.length; - + final int index = note.instrument - vanillaInstrumentCount; if (index >= customInstruments.size()) continue; - final NBSCustomInstrument customInstrument = customInstruments.get(index); - instrument = Instrument.of(customInstrument.name); + instrument = customInstrument; key = (note.key) + (customInstrument.pitch + (double) note.pitch / 100); } @@ -215,10 +221,26 @@ public class NBSConverter { public byte stereo = 100; } - private static class NBSCustomInstrument { - public String name; - public String file; - public byte pitch = 0; - public boolean key = false; + private static class NBSCustomInstrument extends Instrument { + public final byte pitch; + public final boolean visible; + + public NBSCustomInstrument(final String name, final String optionalPath, final byte pitch, final boolean visible) { + // some implementations straight up just don't save the path, so we perform conversions on name on those + final String path = optionalPath.isBlank() ? name : optionalPath; + String sound = Util.sanitizeName(path, Identifier::isAllowedInIdentifier) + .replaceFirst("\\.ogg$", "") + .replaceFirst("^minecraft/", "") + .replaceFirst("\\d+$", "") + .replace('/', '.'); + + // if there's no path, it's probably a note block sound + // this happens when you have trumpets saved in a v5 format NBS for example + if (!sound.contains(".")) sound = "block.note_block." + sound; + + super(-1, name, 0, sound); + this.pitch = pitch; + this.visible = visible; + } } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f799a41..8629e77 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -30,9 +30,9 @@ ], "depends": { - "fabricloader": ">=0.18.3", + "fabricloader": ">=0.18.5", "fabric-api": "*", - "minecraft": "1.21.11", - "java": ">=21" + "minecraft": "~26.1", + "java": ">=25" } }