Skip to content

Commit

Permalink
fix errors for 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNavaStar committed Oct 23, 2024
1 parent 7c7ac4c commit 982e76b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
6 changes: 1 addition & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,18 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Quilt
modCompileOnly "org.quiltmc:quilt-loader:0.26.4"

// Adventure
modImplementation "net.kyori:adventure-platform-fabric:${project.adventure_version}"

// Config
shadow implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-toml:${project.jackson_version}")

// SQL
shadow implementation("com.zaxxer:HikariCP:${project.hikari_version}")
shadow implementation("org.jdbi:jdbi3-core:${project.jdbi_version}")
shadow implementation("org.xerial:sqlite-jdbc:${project.sqlite_version}")
shadow implementation("org.mariadb.jdbc:mariadb-java-client:${project.mariadb_version}")
shadow implementation("org.postgresql:postgresql:${project.postgres_version}")

// Extra
compileOnly "org.projectlombok:lombok:1.18.34"
annotationProcessor "org.projectlombok:lombok:1.18.34"
Expand All @@ -86,6 +81,7 @@ shadowJar {
relocate 'waffle', 'me.mrnavastar.sqlib.libs.waffle'
relocate 'org.checkerframework', 'me.mrnavastar.sqlib.libs.org.checkerframework'
relocate 'org.jdbi', 'me.mrnavastar.sqlib.libs.org.jdbi'
relocate 'me.mrnavastar.r', 'me.mrnavastar.sqlib.libs.me.mrnavastar.r'
//relocate 'org.sqlite', 'me.mrnavastar.sqlib.libs.org.sqlite'
//relocate 'org.mariadb', 'me.mrnavastar.sqlib.libs.org.mariadb'
//relocate 'org.postgresql', 'me.mrnavastar.sqlib.libs.org.postgresql'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import me.mrnavastar.sqlib.impl.SQLPrimitive;
import me.mrnavastar.sqlib.impl.SoundParser;
import me.mrnavastar.sqlib.impl.TextParser;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.StringNbtReader;
Expand All @@ -19,7 +20,7 @@ public class MinecraftTypes {

public static final SQLibType<Text> TEXT = new SQLibType<>(SQLPrimitive.STRING, TextParser::textToString, TextParser::stringToText);
public static final SQLibType<Identifier> IDENTIFIER = new SQLibType<>(SQLPrimitive.STRING, Identifier::toString, Identifier::tryParse);
public static final SQLibType<SoundEvent> SOUND = new SQLibType<>(IDENTIFIER, SoundEvent::getId, SoundEvent::of);
public static final SQLibType<SoundEvent> SOUND = new SQLibType<>(IDENTIFIER, SoundParser::getId, SoundEvent::of);

public static final SQLibType<NbtElement> NBT = new SQLibType<>(SQLPrimitive.STRING, NbtElement::toString, v -> {
try {
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/me/mrnavastar/sqlib/impl/SoundParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package me.mrnavastar.sqlib.impl;

import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;

import java.lang.reflect.Field;

// This class is used for backwards compatibility as 1.21.2 changed SoundEvent to a record
public class SoundParser {

private static Field id = null;

static {
try {
id = SoundEvent.class.getDeclaredField("comp_3319");
} catch (NoSuchFieldException ignore) {}

// DEV
try {
id = SoundEvent.class.getDeclaredField("id");
} catch (NoSuchFieldException ignore) {}

id.setAccessible(true);
}

public static Identifier getId(SoundEvent event) {
try {
return (Identifier) id.get(event);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
6 changes: 2 additions & 4 deletions src/testMod/java/me/mrnavastar/sqlib/TestMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import lombok.SneakyThrows;
import me.mrnavastar.easyeula.EasyEula;
import me.mrnavastar.sqlib.api.DataContainer;
import me.mrnavastar.sqlib.api.database.SQLite;
import me.mrnavastar.sqlib.api.types.AdventureTypes;
import me.mrnavastar.sqlib.api.types.JavaTypes;
import me.mrnavastar.sqlib.api.types.MinecraftTypes;
import me.mrnavastar.sqlib.api.types.GsonTypes;
import me.mrnavastar.sqlib.api.DataStore;
import me.mrnavastar.sqlib.impl.SoundParser;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand All @@ -26,7 +25,6 @@
import net.minecraft.util.math.Vec3i;

import java.awt.*;
import java.io.File;
import java.util.Arrays;
import java.util.Date;
import java.util.UUID;
Expand Down Expand Up @@ -173,7 +171,7 @@ private void testAllTransactions() {

SoundEvent soundEvent = SoundEvents.BLOCK_BARREL_OPEN;
container.put(MinecraftTypes.SOUND, "sound", soundEvent);
assertEquals(soundEvent.getId(), container.get(MinecraftTypes.SOUND, "sound").orElseThrow().getId());
assertEquals(SoundParser.getId(soundEvent), SoundParser.getId(container.get(MinecraftTypes.SOUND, "sound").orElseThrow()));

// Test Adventure Key
Key key = Key.key("cool:guys");
Expand Down

0 comments on commit 982e76b

Please sign in to comment.