From 620f06930d1337ddaede54a936644bbbbd129a7b Mon Sep 17 00:00:00 2001 From: Semmieboy YT Date: Wed, 24 Apr 2024 12:30:41 +0200 Subject: [PATCH] Update to Minecraft 1.20.5, switch to java 21, and a couple general code improvements --- build.gradle | 8 +++---- gradle.properties | 10 ++++---- gradle/wrapper/gradle-wrapper.properties | 2 +- .../semmiedev/disc_jockey/BinaryReader.java | 6 ++--- src/main/java/semmiedev/disc_jockey/Note.java | 21 ++-------------- .../semmiedev/disc_jockey/SongLoader.java | 2 +- .../semmiedev/disc_jockey/SongPlayer.java | 24 +++++++++---------- .../disc_jockey/gui/SongListWidget.java | 2 +- .../gui/screen/DiscJockeyScreen.java | 7 +----- src/main/resources/fabric.mod.json | 2 +- 10 files changed, 31 insertions(+), 53 deletions(-) diff --git a/build.gradle b/build.gradle index 4c550f9..0c76fb4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.11-SNAPSHOT' + id 'fabric-loom' version '1.6-SNAPSHOT' id 'maven-publish' } @@ -20,11 +20,11 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - include modApi("me.shedaniel.cloth:cloth-config-fabric:13.0.121") { + include modApi("me.shedaniel.cloth:cloth-config-fabric:14.0.125") { exclude(group: "net.fabricmc.fabric-api") } - modCompileOnly("com.terraformersmc:modmenu:9.0.0") + modCompileOnly("com.terraformersmc:modmenu:10.0.0-beta.1") } processResources { @@ -36,7 +36,7 @@ processResources { } } -def targetJavaVersion = 8 +def targetJavaVersion = 21 tasks.withType(JavaCompile).configureEach { // ensure that the encoding is set to UTF-8, no matter what the system default is // this fixes some edge cases with special characters not displaying correctly diff --git a/gradle.properties b/gradle.properties index 49db75c..4396846 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,13 +2,13 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.1 -loader_version=0.15.0 +minecraft_version=1.20.5 +yarn_mappings=1.20.5+build.1 +loader_version=0.15.10 # Mod Properties -mod_version=1.4.0 +mod_version=1.5.0 maven_group=semmiedev archives_base_name=disc_jockey # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.91.1+1.20.4 +fabric_version=0.97.6+1.20.5 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e750102..17655d0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/semmiedev/disc_jockey/BinaryReader.java b/src/main/java/semmiedev/disc_jockey/BinaryReader.java index ef2edd2..9b81853 100644 --- a/src/main/java/semmiedev/disc_jockey/BinaryReader.java +++ b/src/main/java/semmiedev/disc_jockey/BinaryReader.java @@ -15,7 +15,7 @@ public class BinaryReader { } public int readInt() throws IOException { - return ((ByteBuffer)((ByteBuffer)buffer.clear()).put(readBytes(Integer.BYTES)).rewind()).getInt(); + return buffer.clear().put(readBytes(Integer.BYTES)).rewind().getInt(); } public long readUInt() throws IOException { @@ -27,7 +27,7 @@ public class BinaryReader { } public short readShort() throws IOException { - return ((ByteBuffer)((ByteBuffer)buffer.clear()).put(readBytes(Short.BYTES)).rewind()).getShort(); + return buffer.clear().put(readBytes(Short.BYTES)).rewind().getShort(); } public String readString() throws IOException { @@ -35,7 +35,7 @@ public class BinaryReader { } public float readFloat() throws IOException { - return ((ByteBuffer)((ByteBuffer)buffer.clear()).put(readBytes(Float.BYTES)).rewind()).getFloat(); + return buffer.clear().put(readBytes(Float.BYTES)).rewind().getFloat(); } /*private int getStringLength() throws IOException { diff --git a/src/main/java/semmiedev/disc_jockey/Note.java b/src/main/java/semmiedev/disc_jockey/Note.java index 07839aa..b6209df 100644 --- a/src/main/java/semmiedev/disc_jockey/Note.java +++ b/src/main/java/semmiedev/disc_jockey/Note.java @@ -6,14 +6,14 @@ import net.minecraft.block.enums.Instrument; import java.util.HashMap; -public class Note { +public record Note(Instrument instrument, byte note) { public static final HashMap INSTRUMENT_BLOCKS = new HashMap<>(); public static final byte LAYER_SHIFT = Short.SIZE; public static final byte INSTRUMENT_SHIFT = Short.SIZE * 2; public static final byte NOTE_SHIFT = Short.SIZE * 2 + Byte.SIZE; - public static final Instrument[] INSTRUMENTS = new Instrument[] { + public static final Instrument[] INSTRUMENTS = new Instrument[]{ Instrument.HARP, Instrument.BASS, Instrument.BASEDRUM, @@ -50,21 +50,4 @@ public class Note { INSTRUMENT_BLOCKS.put(Instrument.BANJO, Blocks.HAY_BLOCK); INSTRUMENT_BLOCKS.put(Instrument.PLING, Blocks.GLOWSTONE); } - - public final Instrument instrument; - public final byte note; - - public Note(Instrument instrument, byte note) { - this.instrument = instrument; - this.note = note; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Note) { - Note note = (Note)obj; - return note.note == this.note && note.instrument == instrument; - } - return false; - } } diff --git a/src/main/java/semmiedev/disc_jockey/SongLoader.java b/src/main/java/semmiedev/disc_jockey/SongLoader.java index 8ef419d..5e0e44b 100644 --- a/src/main/java/semmiedev/disc_jockey/SongLoader.java +++ b/src/main/java/semmiedev/disc_jockey/SongLoader.java @@ -30,7 +30,7 @@ public class SongLoader { try { song = loadSong(file); } catch (Exception exception) { - Main.LOGGER.error("Unable to read or parse song " + file.getName(), exception); + Main.LOGGER.error("Unable to read or parse song {}", file.getName(), exception); } if (song != null) SONGS.add(song); } diff --git a/src/main/java/semmiedev/disc_jockey/SongPlayer.java b/src/main/java/semmiedev/disc_jockey/SongPlayer.java index eb78fbf..269bb90 100644 --- a/src/main/java/semmiedev/disc_jockey/SongPlayer.java +++ b/src/main/java/semmiedev/disc_jockey/SongPlayer.java @@ -297,17 +297,17 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick { // Find fitting noteblocks with the least amount of adjustments required (to reduce tuning time) ArrayList capturedNotes = new ArrayList<>(); for(Note note : song.uniqueNotes) { - ArrayList availableBlocks = noteblocksForInstrument.get(note.instrument); + ArrayList availableBlocks = noteblocksForInstrument.get(note.instrument()); if(availableBlocks == null) { // Note was mapped to "nothing". Pretend it got captured, but just ignore it capturedNotes.add(note); - getNotes(note.instrument).put(note.note, null); + getNotes(note.instrument()).put(note.note(), null); continue; } BlockPos bestBlockPos = null; int bestBlockTuningSteps = Integer.MAX_VALUE; for(BlockPos blockPos : availableBlocks) { - int wantedNote = note.note; + int wantedNote = note.note(); int currentNote = client.world.getBlockState(blockPos).get(Properties.NOTE); int tuningSteps = wantedNote >= currentNote ? wantedNote - currentNote : (25 - currentNote) + wantedNote; @@ -320,7 +320,7 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick { if(bestBlockPos != null) { capturedNotes.add(note); availableBlocks.remove(bestBlockPos); - getNotes(note.instrument).put(note.note, bestBlockPos); + getNotes(note.instrument()).put(note.note(), bestBlockPos); } // else will be a missing note } @@ -332,7 +332,7 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick { HashMap missing = new HashMap<>(); for (Note note : missingNotes) { - Instrument mappedInstrument = instrumentMap.getOrDefault(note.instrument, note.instrument); + Instrument mappedInstrument = instrumentMap.getOrDefault(note.instrument(), note.instrument()); if(mappedInstrument == null) continue; // Ignore if mapped to nothing Block block = Note.INSTRUMENT_BLOCKS.get(mappedInstrument); Integer got = missing.get(block); @@ -356,7 +356,7 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick { if(lastInteractAt != -1L) { // Paper allows 8 interacts per 300 ms (actually 9 it turns out, but lets keep it a bit lower anyway) - availableInteracts += ((System.currentTimeMillis() - lastInteractAt) / (310.0 / 8.0)); + availableInteracts += ((System.currentTimeMillis() - lastInteractAt) / (310.0f / 8.0f)); availableInteracts = Math.min(8f, Math.max(0f, availableInteracts)); }else { availableInteracts = 8f; @@ -366,17 +366,17 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick { int fullyTunedBlocks = 0; HashMap untunedNotes = new HashMap<>(); for (Note note : song.uniqueNotes) { - if(noteBlocks == null || noteBlocks.get(note.instrument) == null) + if(noteBlocks == null || noteBlocks.get(note.instrument()) == null) continue; - BlockPos blockPos = noteBlocks.get(note.instrument).get(note.note); + BlockPos blockPos = noteBlocks.get(note.instrument()).get(note.note()); if(blockPos == null) continue; BlockState blockState = world.getBlockState(blockPos); int assumedNote = notePredictions.containsKey(blockPos) ? notePredictions.get(blockPos).getLeft() : blockState.get(Properties.NOTE); if (blockState.contains(Properties.NOTE)) { - if(assumedNote == note.note && blockState.get(Properties.NOTE) == note.note) + if(assumedNote == note.note() && blockState.get(Properties.NOTE) == note.note()) fullyTunedBlocks++; - if (assumedNote != note.note) { + if (assumedNote != note.note()) { if (!canInteractWith(client.player, blockPos)) { stop(); client.inGameHud.getChatHud().addMessage(Text.translatable(Main.MOD_ID+".player.to_far").formatted(Formatting.RED)); @@ -395,7 +395,7 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick { int existingUniqueNotesCount = 0; for(Note n : song.uniqueNotes) { - if(noteBlocks.get(n.instrument).get(n.note) != null) + if(noteBlocks.get(n.instrument()).get(n.note()) != null) existingUniqueNotesCount++; } @@ -445,7 +445,7 @@ public class SongPlayer implements ClientTickEvents.StartWorldTick { lastTunedNote = untunedNotes.get(blockPos); untunedNotes.remove(blockPos); int assumedNote = notePredictions.containsKey(blockPos) ? notePredictions.get(blockPos).getLeft() : client.world.getBlockState(blockPos).get(Properties.NOTE); - notePredictions.put(blockPos, new Pair((assumedNote + 1) % 25, System.currentTimeMillis() + ping * 2 + 100)); + notePredictions.put(blockPos, new Pair<>((assumedNote + 1) % 25, System.currentTimeMillis() + ping * 2 + 100)); client.interactionManager.interactBlock(client.player, Hand.MAIN_HAND, new BlockHitResult(Vec3d.of(blockPos), Direction.UP, blockPos, false)); lastInteractAt = System.currentTimeMillis(); availableInteracts -= 1f; diff --git a/src/main/java/semmiedev/disc_jockey/gui/SongListWidget.java b/src/main/java/semmiedev/disc_jockey/gui/SongListWidget.java index cdcf875..6ce001b 100644 --- a/src/main/java/semmiedev/disc_jockey/gui/SongListWidget.java +++ b/src/main/java/semmiedev/disc_jockey/gui/SongListWidget.java @@ -22,7 +22,7 @@ public class SongListWidget extends EntryListWidget { } @Override - protected int getScrollbarPositionX() { + protected int getScrollbarX() { return width - 12; } diff --git a/src/main/java/semmiedev/disc_jockey/gui/screen/DiscJockeyScreen.java b/src/main/java/semmiedev/disc_jockey/gui/screen/DiscJockeyScreen.java index f3e2ad2..6e12489 100644 --- a/src/main/java/semmiedev/disc_jockey/gui/screen/DiscJockeyScreen.java +++ b/src/main/java/semmiedev/disc_jockey/gui/screen/DiscJockeyScreen.java @@ -89,7 +89,7 @@ public class DiscJockeyScreen extends Screen { BlocksOverlay.amountOfNoteBlocks = entry.song.uniqueNotes.size(); for (Note note : entry.song.uniqueNotes) { - ItemStack itemStack = Note.INSTRUMENT_BLOCKS.get(note.instrument).asItem().getDefaultStack(); + ItemStack itemStack = Note.INSTRUMENT_BLOCKS.get(note.instrument()).asItem().getDefaultStack(); int index = -1; for (int i = 0; i < BlocksOverlay.itemStacks.length; i++) { @@ -136,11 +136,6 @@ public class DiscJockeyScreen extends Screen { context.drawCenteredTextWithShadow(textRenderer, SELECT_SONG, width / 2, 20, 0xFFFFFF); } - @Override - public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) { - renderBackgroundTexture(context); - } - @Override public void tick() { previewButton.setMessage(Main.PREVIEWER.running ? PREVIEW_STOP : PREVIEW); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 268038f..1bea568 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,7 +27,7 @@ ], "depends": { "fabric": "*", - "minecraft": "1.20.*", + "minecraft": "1.20.5", "cloth-config": "*" } }