From 7bd37b85ff37184e19f2736c059d1b1542aa8786 Mon Sep 17 00:00:00 2001 From: enjarai Date: Sun, 19 May 2024 14:14:57 +0200 Subject: [PATCH] Actual update woah crazy --- CHANGELOG.md | 3 +- gradle.properties | 10 ++-- .../dev/enjarai/blahajtotem/BlahajTotem.java | 3 +- .../particle/BlahajParticleEffect.java | 46 +++++++++---------- .../blahajtotem/particle/ModParticles.java | 3 +- 5 files changed, 31 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6b3061..a71387b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1 @@ -- Changed the color of totem particles depending on the shark type used. -- Added an icelandic translation (Thanks @VipelyRS) \ No newline at end of file +- Updated to 1.20.6. \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 735dfd7..a13772c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,14 +4,14 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.10 -loader_version=0.15.6 +minecraft_version=1.20.6 +yarn_mappings=1.20.6+build.1 +loader_version=0.15.11 # Mod Properties -mod_version=1.3.0 +mod_version=1.3.1 maven_group=dev.enjarai.blahajtotem archives_base_name=blahaj-totem # Dependencies -fabric_version=0.89.3+1.20.1 +fabric_version=0.98.0+1.20.6 diff --git a/src/main/java/dev/enjarai/blahajtotem/BlahajTotem.java b/src/main/java/dev/enjarai/blahajtotem/BlahajTotem.java index ba75294..2244794 100644 --- a/src/main/java/dev/enjarai/blahajtotem/BlahajTotem.java +++ b/src/main/java/dev/enjarai/blahajtotem/BlahajTotem.java @@ -5,6 +5,7 @@ import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; import net.minecraft.client.item.ModelPredicateProviderRegistry; +import net.minecraft.component.DataComponentTypes; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.Identifier; @@ -76,7 +77,7 @@ public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { @Nullable public static BlahajType getShorkType(ItemStack stack) { - if (stack.isOf(Items.TOTEM_OF_UNDYING) && stack.hasCustomName()) { + if (stack.isOf(Items.TOTEM_OF_UNDYING) && stack.contains(DataComponentTypes.CUSTOM_NAME)) { var name = Arrays.asList(stack.getName().getString().toLowerCase(Locale.ROOT).split("[ \\-_]")); var variant = VARIANTS.stream().filter(v -> name.contains(v.name())).reduce((v1, v2) -> v2.name().length() > v1.name().length() ? v2 : v1); diff --git a/src/main/java/dev/enjarai/blahajtotem/particle/BlahajParticleEffect.java b/src/main/java/dev/enjarai/blahajtotem/particle/BlahajParticleEffect.java index 4f7192e..564edfd 100644 --- a/src/main/java/dev/enjarai/blahajtotem/particle/BlahajParticleEffect.java +++ b/src/main/java/dev/enjarai/blahajtotem/particle/BlahajParticleEffect.java @@ -1,41 +1,37 @@ package dev.enjarai.blahajtotem.particle; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import dev.enjarai.blahajtotem.BlahajTotem; import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleType; -import net.minecraft.registry.Registries; -public record BlahajParticleEffect(ParticleType type, int[] colors) implements ParticleEffect { - @SuppressWarnings("deprecation") - public static final ParticleEffect.Factory PARAMETERS_FACTORY = new ParticleEffect.Factory<>() { - @Override - public BlahajParticleEffect read(ParticleType type, StringReader reader) throws CommandSyntaxException { - return new BlahajParticleEffect(type, new int[0]); // This doesn't actually need to work with commands, so dummy impl it is - } - - @Override - public BlahajParticleEffect read(ParticleType type, PacketByteBuf buf) { - return new BlahajParticleEffect(type, buf.readIntArray()); - } - }; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.stream.IntStream; - @Override - public ParticleType getType() { - return type; +public record BlahajParticleEffect(ParticleType type, int[] colors) implements ParticleEffect { + public static MapCodec createCodec(ParticleType type) { + return Codec.INT_STREAM.xmap( + intStream -> new BlahajParticleEffect(type, intStream.toArray()), + effect -> IntStream.of(effect.colors) + ).fieldOf("colors"); } - @Override - public void write(PacketByteBuf buf) { - buf.writeIntArray(colors); + public static PacketCodec createPacketCodec(ParticleType type) { + return PacketCodec.tuple( + PacketCodecs.collection(ArrayList::new, PacketCodecs.INTEGER, 32), effect -> Arrays.stream(effect.colors).boxed().toList(), + list -> new BlahajParticleEffect(type, list.stream().mapToInt(i -> i).toArray()) + ); } @Override - public String asString() { - return Registries.PARTICLE_TYPE.getId(getType()) + ""; + public ParticleType getType() { + return type; } public static int[] getColorsForShork(ItemStack shorkStack) { diff --git a/src/main/java/dev/enjarai/blahajtotem/particle/ModParticles.java b/src/main/java/dev/enjarai/blahajtotem/particle/ModParticles.java index 7e7430c..85b3db0 100644 --- a/src/main/java/dev/enjarai/blahajtotem/particle/ModParticles.java +++ b/src/main/java/dev/enjarai/blahajtotem/particle/ModParticles.java @@ -8,7 +8,8 @@ import net.minecraft.registry.Registry; public class ModParticles { - public static final ParticleType BLAHAJ_OF_UNDYING = FabricParticleTypes.complex(BlahajParticleEffect.PARAMETERS_FACTORY); + public static final ParticleType BLAHAJ_OF_UNDYING = + FabricParticleTypes.complex(BlahajParticleEffect::createCodec, BlahajParticleEffect::createPacketCodec); public static void register() { Registry.register(Registries.PARTICLE_TYPE, BlahajTotem.id("blahaj_of_undying"), BLAHAJ_OF_UNDYING);