Update to Minecraft 1.20.5, switch to java 21, and a couple general code improvements

This commit is contained in:
Semmieboy YT 2024-04-24 12:30:41 +02:00
parent f0145d093d
commit 620f06930d
10 changed files with 31 additions and 53 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<Note> capturedNotes = new ArrayList<>();
for(Note note : song.uniqueNotes) {
ArrayList<BlockPos> availableBlocks = noteblocksForInstrument.get(note.instrument);
ArrayList<BlockPos> 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<Block, Integer> 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<BlockPos, Integer> 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;

View File

@ -22,7 +22,7 @@ public class SongListWidget extends EntryListWidget<SongListWidget.SongEntry> {
}
@Override
protected int getScrollbarPositionX() {
protected int getScrollbarX() {
return width - 12;
}

View File

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

View File

@ -27,7 +27,7 @@
],
"depends": {
"fabric": "*",
"minecraft": "1.20.*",
"minecraft": "1.20.5",
"cloth-config": "*"
}
}