From 1e1a1d712dbd1f3548f138a16d641a1be2d3faef Mon Sep 17 00:00:00 2001 From: neeleshpoli <72574589+neeleshpoli@users.noreply.github.com> Date: Thu, 28 May 2026 13:52:06 -0500 Subject: [PATCH] Extract particle parameters that need to be sent as data Update game version to 26.1.2 Update loom version to 1.16-snapshot Update fabric loader version to 0.19.2 Update kotlin loader version to 1.13.11+kotlin.2.3.21 Update fabric api version to 0.149.1+26.1.2 --- build.gradle.kts | 2 +- gradle.properties | 8 ++-- .../snowii/extractor/extractors/Particles.kt | 40 ++++++++++++++++++- src/main/resources/extractor.accesswidener | 7 +++- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c43b6f0..5c9bbed 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") version "2.3.20" - id("net.fabricmc.fabric-loom") version "1.15-SNAPSHOT" + id("net.fabricmc.fabric-loom") version "1.16-SNAPSHOT" id("maven-publish") } diff --git a/gradle.properties b/gradle.properties index 8844a93..f267183 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,11 +3,11 @@ org.gradle.jvmargs=-Xmx2G org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop/ -minecraft_version=26.1 -loader_version=0.18.4 -kotlin_loader_version=1.13.10+kotlin.2.3.20 +minecraft_version=26.1.2 +loader_version=0.19.2 +kotlin_loader_version=1.13.11+kotlin.2.3.21 # Mod Properties mod_version=1.0-SNAPSHOT maven_group=de.snowii archives_base_name=extractor -fabric_api_version=0.144.0+26.1 +fabric_api_version=0.149.1+26.1.2 diff --git a/src/main/kotlin/de/snowii/extractor/extractors/Particles.kt b/src/main/kotlin/de/snowii/extractor/extractors/Particles.kt index 774f2b4..7b1527d 100644 --- a/src/main/kotlin/de/snowii/extractor/extractors/Particles.kt +++ b/src/main/kotlin/de/snowii/extractor/extractors/Particles.kt @@ -2,9 +2,13 @@ package de.snowii.extractor.extractors import com.google.gson.JsonArray import com.google.gson.JsonElement +import com.google.gson.JsonObject import de.snowii.extractor.Extractor +import net.minecraft.core.particles.ParticleTypes +import net.minecraft.core.particles.SimpleParticleType import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.server.MinecraftServer +import java.lang.reflect.ParameterizedType class Particles : Extractor.Extractor { @@ -13,10 +17,42 @@ class Particles : Extractor.Extractor { } override fun extract(server: MinecraftServer): JsonElement { - val particlesJson = JsonArray() + val particlesJson = JsonObject() + for (particle in BuiltInRegistries.PARTICLE_TYPE) { + val fields = JsonArray() + + // Extract the fields of the particle type, using the class of the particle type + // This is done using the constructor of the particle type and reading the parameters + // SimpleParticleType does not have any fields, so we skip particles of this type + if (particle !is SimpleParticleType) { + val id = BuiltInRegistries.PARTICLE_TYPE.getKey(particle)!!.path + val particleType = ParticleTypes::class.java.getDeclaredField(id.uppercase()).genericType + + if (particleType is ParameterizedType) { + // The registry items are ParticleType, we need to get the type T using reflection + val parameterizedType = particleType as ParameterizedType? + val typeArguments = parameterizedType!!.actualTypeArguments + val typeArg = typeArguments[0] + + if (typeArg is Class<*>) { + // Based on the type T, we convert it back to a class and get the parameters using reflection + val typeClass = typeArg as Class<*>? + + for (field in typeClass?.constructors?.first()?.parameters!!) { + val name = field.name + + // Parameter 'type' is in every constructor, we do not need it for our purposes + if (name != "type") { + fields.add(name) + } + } + } + } + } + particlesJson.add( - BuiltInRegistries.PARTICLE_TYPE.getKey(particle)!!.path, + BuiltInRegistries.PARTICLE_TYPE.getKey(particle)!!.path, fields ) } diff --git a/src/main/resources/extractor.accesswidener b/src/main/resources/extractor.accesswidener index 4b5ce0f..e9703e9 100644 --- a/src/main/resources/extractor.accesswidener +++ b/src/main/resources/extractor.accesswidener @@ -32,4 +32,9 @@ accessible class net/minecraft/world/level/levelgen/DensityFunctions$Spline$Coor accessible field net/minecraft/world/level/block/FlowerPotBlock POTTED_BY_CONTENT Ljava/util/Map; # accessible field net/minecraft/entity/data/TrackedDataHandlerRegistry DATA_HANDLERS Lnet/minecraft/util/collection/Int2ObjectBiMap; -# accessible field net/minecraft/entity/data/DataTracker CLASS_TO_LAST_ID Lnet/minecraft/util/collection/Class2IntMap; \ No newline at end of file +# accessible field net/minecraft/entity/data/DataTracker CLASS_TO_LAST_ID Lnet/minecraft/util/collection/Class2IntMap; + +# For some reason, these constructors are private. We need them to be public to read the parameters from them +accessible method net/minecraft/core/particles/PowerParticleOption (Lnet/minecraft/core/particles/ParticleType;F)V +accessible method net/minecraft/core/particles/SpellParticleOption (Lnet/minecraft/core/particles/ParticleType;IF)V +accessible method net/minecraft/core/particles/ColorParticleOption (Lnet/minecraft/core/particles/ParticleType;I)V \ No newline at end of file