From 123b2d756b5dbd8840fc082b7c35633a9b09b031 Mon Sep 17 00:00:00 2001 From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Wed, 27 Dec 2023 15:46:30 -0500 Subject: [PATCH] v1.5 1.20.4 support --- build.gradle.kts | 2 +- nms/build.gradle.kts | 2 +- .../biomevisuals/nms/ApiEntityConverter.java | 20 +++++++++++-------- .../nms/ParticleDataSerializerImpl.java | 4 ++-- .../biomevisuals/nms/hooks/RegistryHook.java | 10 +++++++--- plugin/build.gradle.kts | 2 +- plugin/src/main/resources/plugin.yml | 2 +- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0993843..2e17c67 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } group = "com.owen1212055" -version = "1.4.2" +version = "1.5" repositories { mavenCentral() diff --git a/nms/build.gradle.kts b/nms/build.gradle.kts index cf7a408..1d90eb2 100644 --- a/nms/build.gradle.kts +++ b/nms/build.gradle.kts @@ -13,7 +13,7 @@ repositories { } dependencies { - paperDevBundle("1.19.4-R0.1-SNAPSHOT") + paperDevBundle("1.20.4-R0.1-SNAPSHOT") implementation("xyz.jpenilla", "reflection-remapper", "0.1.0-SNAPSHOT") implementation(project(":api")) { diff --git a/nms/src/main/java/com/owen1212055/biomevisuals/nms/ApiEntityConverter.java b/nms/src/main/java/com/owen1212055/biomevisuals/nms/ApiEntityConverter.java index fe17863..f92ddfa 100644 --- a/nms/src/main/java/com/owen1212055/biomevisuals/nms/ApiEntityConverter.java +++ b/nms/src/main/java/com/owen1212055/biomevisuals/nms/ApiEntityConverter.java @@ -7,8 +7,11 @@ import com.mojang.serialization.JsonOps; import com.owen1212055.biomevisuals.api.types.biome.effect.*; import net.minecraft.core.Holder; +import net.minecraft.core.RegistryAccess; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.level.biome.AmbientAdditionsSettings; @@ -16,14 +19,15 @@ import net.minecraft.world.level.biome.AmbientParticleSettings; import org.bukkit.Registry; import org.bukkit.Sound; -import org.bukkit.craftbukkit.v1_19_R3.CraftParticle; -import org.bukkit.craftbukkit.v1_19_R3.CraftSound; -import org.bukkit.craftbukkit.v1_19_R3.util.CraftNamespacedKey; +import org.bukkit.craftbukkit.v1_20_R3.CraftParticle; +import org.bukkit.craftbukkit.v1_20_R3.CraftSound; +import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey; import java.lang.reflect.Field; import java.util.Objects; public class ApiEntityConverter { + private static final RegistryOps BUILTIN_CONTEXT_OPS = RegistryOps.create(JsonOps.INSTANCE, RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY)); private static final Field probabilityField; @@ -37,7 +41,7 @@ public class ApiEntityConverter { } public static JsonElement serialize(AdditionSound sound) { - AmbientAdditionsSettings settings = new AmbientAdditionsSettings(Holder.direct(CraftSound.getSoundEffect(sound.getSoundEvent())), sound.getTickChance()); + AmbientAdditionsSettings settings = new AmbientAdditionsSettings(Holder.direct(CraftSound.bukkitToMinecraft(sound.getSoundEvent())), sound.getTickChance()); return encode(AmbientAdditionsSettings.CODEC, settings); } @@ -78,7 +82,7 @@ public static AmbientSound deserializeAmbientSound(JsonElement ambientSound) { } public static JsonElement serialize(MoodSound moodSound) { - AmbientMoodSettings settings = new AmbientMoodSettings(Holder.direct(CraftSound.getSoundEffect(moodSound.getSoundEvent())), moodSound.getTickDelay(), moodSound.getBlockSearchExtent(), moodSound.getSoundPositionOffset()); + AmbientMoodSettings settings = new AmbientMoodSettings(Holder.direct(CraftSound.bukkitToMinecraft(moodSound.getSoundEvent())), moodSound.getTickDelay(), moodSound.getBlockSearchExtent(), moodSound.getSoundPositionOffset()); return encode(AmbientMoodSettings.CODEC, settings); } @@ -90,7 +94,7 @@ public static MoodSound deserializeMoodSound(JsonElement moodSound) { } public static JsonElement serialize(Music music) { - net.minecraft.sounds.Music nmsMusic = new net.minecraft.sounds.Music(Holder.direct(CraftSound.getSoundEffect(music.getSoundEvent())), music.getMinDelay(), music.getMaxDelay(), music.replaceCurrentMusic()); + net.minecraft.sounds.Music nmsMusic = new net.minecraft.sounds.Music(Holder.direct(CraftSound.bukkitToMinecraft(music.getSoundEvent())), music.getMinDelay(), music.getMaxDelay(), music.replaceCurrentMusic()); return encode(net.minecraft.sounds.Music.CODEC, nmsMusic); } @@ -108,10 +112,10 @@ private static Sound nmsSoundEventToBukkit(SoundEvent soundEvent) { } private static JsonElement encode(Codec type, T object) { - return type.encode(object, JsonOps.INSTANCE, JsonOps.INSTANCE.empty()).get().orThrow(); + return type.encode(object, BUILTIN_CONTEXT_OPS, BUILTIN_CONTEXT_OPS.empty()).get().orThrow(); } private static T decode(Codec type, JsonElement object) { - return type.decode(JsonOps.INSTANCE, object).map(Pair::getFirst).result().orElseThrow(); + return type.decode(BUILTIN_CONTEXT_OPS, object).map(Pair::getFirst).result().orElseThrow(); } } diff --git a/nms/src/main/java/com/owen1212055/biomevisuals/nms/ParticleDataSerializerImpl.java b/nms/src/main/java/com/owen1212055/biomevisuals/nms/ParticleDataSerializerImpl.java index e6f0110..8cbc7ef 100644 --- a/nms/src/main/java/com/owen1212055/biomevisuals/nms/ParticleDataSerializerImpl.java +++ b/nms/src/main/java/com/owen1212055/biomevisuals/nms/ParticleDataSerializerImpl.java @@ -5,11 +5,11 @@ import com.owen1212055.biomevisuals.api.types.biome.effect.ParticleDataSerializer; import net.minecraft.core.particles.ParticleTypes; import org.bukkit.Particle; -import org.bukkit.craftbukkit.v1_19_R3.CraftParticle; +import org.bukkit.craftbukkit.v1_20_R3.CraftParticle; public class ParticleDataSerializerImpl implements ParticleDataSerializer { @Override public JsonObject serialize(Particle particle, Object data) { - return (JsonObject) ParticleTypes.CODEC.encode(CraftParticle.toNMS(particle, data), JsonOps.INSTANCE, JsonOps.INSTANCE.empty()).get().orThrow(); + return (JsonObject) ParticleTypes.CODEC.encode(CraftParticle.createParticleParam(particle, data), JsonOps.INSTANCE, JsonOps.INSTANCE.empty()).get().orThrow(); } } diff --git a/nms/src/main/java/com/owen1212055/biomevisuals/nms/hooks/RegistryHook.java b/nms/src/main/java/com/owen1212055/biomevisuals/nms/hooks/RegistryHook.java index 379cdc6..3b00938 100644 --- a/nms/src/main/java/com/owen1212055/biomevisuals/nms/hooks/RegistryHook.java +++ b/nms/src/main/java/com/owen1212055/biomevisuals/nms/hooks/RegistryHook.java @@ -17,6 +17,10 @@ import com.owen1212055.biomevisuals.nms.UnsafeUtils; import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistrySynchronization; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.nbt.NbtOps; +import net.minecraft.nbt.Tag; +import net.minecraft.resources.RegistryOps; import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.slf4j.Logger; @@ -28,7 +32,7 @@ import static java.util.Map.Entry; public class RegistryHook { - + private static final RegistryOps BUILTIN_CONTEXT_OPS = RegistryOps.create(JsonOps.INSTANCE, RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY)); private static Logger LOGGER; // Custom codec that wraps around the pre-existing codec. @@ -43,7 +47,7 @@ public static void injectCodec(Logger logger) throws Exception { @Override public DataResult encode(RegistryAccess input, DynamicOps ops, T prefix) { - DataResult result = CAPTURED_CODEC.encode(input, JsonOps.INSTANCE, JsonOps.INSTANCE.empty()); + DataResult result = CAPTURED_CODEC.encode(input, BUILTIN_CONTEXT_OPS, BUILTIN_CONTEXT_OPS.empty()); Optional> optionalError = result.error(); if (optionalError.isPresent()) { LOGGER.warn("Failed to encode to JSON: " + optionalError.get().message()); @@ -63,7 +67,7 @@ public DataResult encode(RegistryAccess input, DynamicOps ops, T prefi } // Decode it back into NMS type from json - DataResult> dataresult = CAPTURED_CODEC.decode(JsonOps.INSTANCE, mainRegistry); + DataResult> dataresult = CAPTURED_CODEC.decode(BUILTIN_CONTEXT_OPS, mainRegistry); // Fail? if (dataresult.error().isPresent()) { LOGGER.warn("Failed to encode hooked data: {}", dataresult.error().get().message()); diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 9ff3e19..dbee984 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -32,7 +32,7 @@ tasks { } runServer { - minecraftVersion("1.19.4") + minecraftVersion("1.20.4") } } diff --git a/plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml index ecdf85a..544831f 100644 --- a/plugin/src/main/resources/plugin.yml +++ b/plugin/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BiomeVisuals -version: '1.4.2' +version: '1.5' main: com.owen1212055.biomevisuals.Main api-version: 1.19 authors: [ Owen1212055 ]