From 29ed502aeaa892ae06497f8dbf941b28bc715b6b Mon Sep 17 00:00:00 2001 From: Alexander Medvedev Date: Thu, 26 Dec 2024 22:10:12 +0100 Subject: [PATCH] extractor: extract entities --- assets/entities.json | 1 + extractor/gradle.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- extractor/gradlew | 5 +- extractor/gradlew.bat | 2 +- .../kotlin/de/snowii/extractor/Extractor.kt | 2 +- .../snowii/extractor/extractors/Entities.kt | 42 ++++ .../de/snowii/extractor/extractors/Tests.kt | 217 +++++++++--------- 8 files changed, 155 insertions(+), 118 deletions(-) create mode 100644 assets/entities.json create mode 100644 extractor/src/main/kotlin/de/snowii/extractor/extractors/Entities.kt diff --git a/assets/entities.json b/assets/entities.json new file mode 100644 index 000000000..ac4995f5d --- /dev/null +++ b/assets/entities.json @@ -0,0 +1 @@ +{"acacia_boat":{"id":0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"acacia_chest_boat":{"id":1,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"allay":{"id":2,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.35,0.6]},"area_effect_cloud":{"id":3,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[6.0,0.5]},"armadillo":{"id":4,"max_health":12.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.7,0.65]},"armor_stand":{"id":5,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.5,1.975]},"arrow":{"id":6,"attackable":false,"summonable":true,"fire_immune":false,"dimension":[0.5,0.5]},"axolotl":{"id":7,"max_health":14.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.75,0.42]},"bamboo_chest_raft":{"id":8,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"bamboo_raft":{"id":9,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"bat":{"id":10,"max_health":6.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.5,0.9]},"bee":{"id":11,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.7,0.6]},"birch_boat":{"id":12,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"birch_chest_boat":{"id":13,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"blaze":{"id":14,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[0.6,1.8]},"block_display":{"id":15,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.0,0.0]},"bogged":{"id":16,"max_health":16.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.99]},"breeze":{"id":17,"max_health":30.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.77]},"breeze_wind_charge":{"id":18,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.3125,0.3125]},"camel":{"id":19,"max_health":32.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.7,2.375]},"cat":{"id":20,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,0.7]},"cave_spider":{"id":21,"max_health":12.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.7,0.5]},"cherry_boat":{"id":22,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"cherry_chest_boat":{"id":23,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"chest_minecart":{"id":24,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.98,0.7]},"chicken":{"id":25,"max_health":4.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.4,0.7]},"cod":{"id":26,"max_health":3.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.5,0.3]},"command_block_minecart":{"id":27,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.98,0.7]},"cow":{"id":28,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.9,1.4]},"creaking":{"id":29,"max_health":1.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.9,2.7]},"creeper":{"id":30,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.7]},"dark_oak_boat":{"id":31,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"dark_oak_chest_boat":{"id":32,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"dolphin":{"id":33,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.9,0.6]},"donkey":{"id":34,"max_health":53.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.3964844,1.5]},"dragon_fireball":{"id":35,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.0,1.0]},"drowned":{"id":36,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"egg":{"id":37,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.25,0.25]},"elder_guardian":{"id":38,"max_health":80.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.9975,1.9975]},"enderman":{"id":39,"max_health":40.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,2.9]},"endermite":{"id":40,"max_health":8.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.4,0.3]},"ender_dragon":{"id":41,"max_health":200.0,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[16.0,8.0]},"ender_pearl":{"id":42,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.25,0.25]},"end_crystal":{"id":43,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[2.0,2.0]},"evoker":{"id":44,"max_health":24.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"evoker_fangs":{"id":45,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.5,0.8]},"experience_bottle":{"id":46,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.25,0.25]},"experience_orb":{"id":47,"attackable":false,"summonable":true,"fire_immune":false,"dimension":[0.5,0.5]},"eye_of_ender":{"id":48,"attackable":false,"summonable":true,"fire_immune":false,"dimension":[0.25,0.25]},"falling_block":{"id":49,"attackable":false,"summonable":true,"fire_immune":false,"dimension":[0.98,0.98]},"fireball":{"id":50,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.0,1.0]},"firework_rocket":{"id":51,"attackable":false,"summonable":true,"fire_immune":false,"dimension":[0.25,0.25]},"fox":{"id":52,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,0.7]},"frog":{"id":53,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.5,0.5]},"furnace_minecart":{"id":54,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.98,0.7]},"ghast":{"id":55,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[4.0,4.0]},"giant":{"id":56,"max_health":100.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[3.6,12.0]},"glow_item_frame":{"id":57,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.5,0.5]},"glow_squid":{"id":58,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.8,0.8]},"goat":{"id":59,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.9,1.3]},"guardian":{"id":60,"max_health":30.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.85,0.85]},"hoglin":{"id":61,"max_health":40.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.3964844,1.4]},"hopper_minecart":{"id":62,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.98,0.7]},"horse":{"id":63,"max_health":53.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.3964844,1.6]},"husk":{"id":64,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"illusioner":{"id":65,"max_health":32.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"interaction":{"id":66,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.0,0.0]},"iron_golem":{"id":67,"max_health":100.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.4,2.7]},"item":{"id":68,"attackable":false,"summonable":true,"fire_immune":false,"dimension":[0.25,0.25]},"item_display":{"id":69,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.0,0.0]},"item_frame":{"id":70,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.5,0.5]},"jungle_boat":{"id":71,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"jungle_chest_boat":{"id":72,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"leash_knot":{"id":73,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.375,0.5]},"lightning_bolt":{"id":74,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.0,0.0]},"llama":{"id":75,"max_health":53.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.9,1.87]},"llama_spit":{"id":76,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.25,0.25]},"magma_cube":{"id":77,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[0.52,0.52]},"mangrove_boat":{"id":78,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"mangrove_chest_boat":{"id":79,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"marker":{"id":80,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.0,0.0]},"minecart":{"id":81,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.98,0.7]},"mooshroom":{"id":82,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.9,1.4]},"mule":{"id":83,"max_health":53.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.3964844,1.6]},"oak_boat":{"id":84,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"oak_chest_boat":{"id":85,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"ocelot":{"id":86,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,0.7]},"ominous_item_spawner":{"id":87,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.25,0.25]},"painting":{"id":88,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.5,0.5]},"pale_oak_boat":{"id":89,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"pale_oak_chest_boat":{"id":90,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"panda":{"id":91,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.3,1.25]},"parrot":{"id":92,"max_health":6.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.5,0.9]},"phantom":{"id":93,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.9,0.5]},"pig":{"id":94,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.9,0.9]},"piglin":{"id":95,"max_health":16.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"piglin_brute":{"id":96,"max_health":50.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"pillager":{"id":97,"max_health":24.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"polar_bear":{"id":98,"max_health":30.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.4,1.4]},"potion":{"id":99,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.25,0.25]},"pufferfish":{"id":100,"max_health":3.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.7,0.7]},"rabbit":{"id":101,"max_health":3.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.4,0.5]},"ravager":{"id":102,"max_health":100.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.95,2.2]},"salmon":{"id":103,"max_health":3.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.7,0.4]},"sheep":{"id":104,"max_health":8.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.9,1.3]},"shulker":{"id":105,"max_health":30.0,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[1.0,1.0]},"shulker_bullet":{"id":106,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.3125,0.3125]},"silverfish":{"id":107,"max_health":8.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.4,0.3]},"skeleton":{"id":108,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.99]},"skeleton_horse":{"id":109,"max_health":15.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.3964844,1.6]},"slime":{"id":110,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.52,0.52]},"small_fireball":{"id":111,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.3125,0.3125]},"sniffer":{"id":112,"max_health":14.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.9,1.75]},"snowball":{"id":113,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.25,0.25]},"snow_golem":{"id":114,"max_health":4.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.7,1.9]},"spawner_minecart":{"id":115,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.98,0.7]},"spectral_arrow":{"id":116,"attackable":false,"summonable":true,"fire_immune":false,"dimension":[0.5,0.5]},"spider":{"id":117,"max_health":16.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.4,0.9]},"spruce_boat":{"id":118,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"spruce_chest_boat":{"id":119,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.375,0.5625]},"squid":{"id":120,"max_health":10.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.8,0.8]},"stray":{"id":121,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.99]},"strider":{"id":122,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[0.9,1.7]},"tadpole":{"id":123,"max_health":6.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.4,0.3]},"text_display":{"id":124,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.0,0.0]},"tnt":{"id":125,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[0.98,0.98]},"tnt_minecart":{"id":126,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.98,0.7]},"trader_llama":{"id":127,"max_health":53.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.9,1.87]},"trident":{"id":128,"attackable":false,"summonable":true,"fire_immune":false,"dimension":[0.5,0.5]},"tropical_fish":{"id":129,"max_health":3.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.5,0.4]},"turtle":{"id":130,"max_health":30.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.2,0.4]},"vex":{"id":131,"max_health":14.0,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[0.4,0.8]},"villager":{"id":132,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"vindicator":{"id":133,"max_health":24.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"wandering_trader":{"id":134,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"warden":{"id":135,"max_health":500.0,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[0.9,2.9]},"wind_charge":{"id":136,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.3125,0.3125]},"witch":{"id":137,"max_health":26.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"wither":{"id":138,"max_health":300.0,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[0.9,3.5]},"wither_skeleton":{"id":139,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[0.7,2.4]},"wither_skull":{"id":140,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.3125,0.3125]},"wolf":{"id":141,"max_health":8.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,0.85]},"zoglin":{"id":142,"max_health":40.0,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[1.3964844,1.4]},"zombie":{"id":143,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"zombie_horse":{"id":144,"max_health":15.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[1.3964844,1.6]},"zombie_villager":{"id":145,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":false,"dimension":[0.6,1.95]},"zombified_piglin":{"id":146,"max_health":20.0,"attackable":true,"summonable":true,"fire_immune":true,"dimension":[0.6,1.95]},"fishing_bobber":{"id":148,"attackable":true,"summonable":false,"fire_immune":false,"dimension":[0.25,0.25]}} \ No newline at end of file diff --git a/extractor/gradle.properties b/extractor/gradle.properties index 5b4def5d9..880c97721 100644 --- a/extractor/gradle.properties +++ b/extractor/gradle.properties @@ -11,4 +11,4 @@ kotlin_loader_version=1.13.0+kotlin.2.1.0 mod_version=1.0-SNAPSHOT maven_group=de.snowii archives_base_name=extractor -fabric_version=0.112.1+1.21.4 +fabric_version=0.113.0+1.21.4 diff --git a/extractor/gradle/wrapper/gradle-wrapper.properties b/extractor/gradle/wrapper/gradle-wrapper.properties index e2847c820..cea7a793a 100644 --- a/extractor/gradle/wrapper/gradle-wrapper.properties +++ b/extractor/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/extractor/gradlew b/extractor/gradlew index f5feea6d6..057afac53 100755 --- a/extractor/gradlew +++ b/extractor/gradlew @@ -86,8 +86,7 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s -' "$PWD" ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -203,7 +202,7 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +DEFAULT_JVM_OPTS='-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m"' # Collect all arguments for the java command: # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, diff --git a/extractor/gradlew.bat b/extractor/gradlew.bat index 9b42019c7..6a90cee9b 100644 --- a/extractor/gradlew.bat +++ b/extractor/gradlew.bat @@ -36,7 +36,7 @@ set APP_HOME=%DIRNAME% for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" +set DEFAULT_JVM_OPTS=-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/extractor/src/main/kotlin/de/snowii/extractor/Extractor.kt b/extractor/src/main/kotlin/de/snowii/extractor/Extractor.kt index d16e89b6d..2f47fe63c 100644 --- a/extractor/src/main/kotlin/de/snowii/extractor/Extractor.kt +++ b/extractor/src/main/kotlin/de/snowii/extractor/Extractor.kt @@ -1,6 +1,5 @@ package de.snowii.extractor -import com.google.gson.Gson import com.google.gson.GsonBuilder import com.google.gson.JsonElement import de.snowii.extractor.extractors.* @@ -31,6 +30,7 @@ class Extractor : ModInitializer { Packets(), Screens(), Tags(), + Entities(), Items(), Blocks(), Tests(), diff --git a/extractor/src/main/kotlin/de/snowii/extractor/extractors/Entities.kt b/extractor/src/main/kotlin/de/snowii/extractor/extractors/Entities.kt new file mode 100644 index 000000000..475047118 --- /dev/null +++ b/extractor/src/main/kotlin/de/snowii/extractor/extractors/Entities.kt @@ -0,0 +1,42 @@ +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.entity.LivingEntity +import net.minecraft.entity.SpawnReason +import net.minecraft.registry.Registries +import net.minecraft.server.MinecraftServer + +class Entities : Extractor.Extractor { + override fun fileName(): String { + return "entities.json" + } + + override fun extract(server: MinecraftServer): JsonElement { + val entitiesJson = JsonObject() + for (entityType in Registries.ENTITY_TYPE) { + val entity = entityType.create(server.overworld!!, SpawnReason.NATURAL) ?: continue + val entityJson = JsonObject() + entityJson.addProperty("id", Registries.ENTITY_TYPE.getRawId(entityType)) + if (entity is LivingEntity) { + entityJson.addProperty("max_health", entity.maxHealth) + + } + entityJson.addProperty("attackable", entity.isAttackable) + entityJson.addProperty("summonable", entityType.isSummonable) + entityJson.addProperty("fire_immune", entityType.isFireImmune) + val dimension = JsonArray() + dimension.add(entityType.dimensions.width) + dimension.add(entityType.dimensions.height) + entityJson.add("dimension", dimension) + + entitiesJson.add( + Registries.ENTITY_TYPE.getId(entityType).path, entityJson + ) + } + + return entitiesJson + } +} diff --git a/extractor/src/main/kotlin/de/snowii/extractor/extractors/Tests.kt b/extractor/src/main/kotlin/de/snowii/extractor/extractors/Tests.kt index ac81ec76c..e75a1797d 100644 --- a/extractor/src/main/kotlin/de/snowii/extractor/extractors/Tests.kt +++ b/extractor/src/main/kotlin/de/snowii/extractor/extractors/Tests.kt @@ -1,8 +1,5 @@ - package de.snowii.extractor.extractors -import com.google.gson.Gson -import com.google.gson.GsonBuilder import com.google.gson.JsonArray import com.google.gson.JsonElement import de.snowii.extractor.Extractor @@ -11,129 +8,127 @@ import net.minecraft.block.BlockState import net.minecraft.block.Blocks import net.minecraft.registry.BuiltinRegistries import net.minecraft.registry.RegistryKeys -import net.minecraft.registry.RegistryWrapper -import net.minecraft.registry.RegistryWrapper.WrapperLookup -import net.minecraft.registry.entry.RegistryEntry.Reference import net.minecraft.server.MinecraftServer -import net.minecraft.util.math.noise.DoublePerlinNoiseSampler.NoiseParameters import net.minecraft.util.math.ChunkPos -import net.minecraft.world.gen.chunk.AquiferSampler -import net.minecraft.world.gen.chunk.Blender -import net.minecraft.world.gen.chunk.ChunkGeneratorSettings -import net.minecraft.world.gen.chunk.ChunkNoiseSampler -import net.minecraft.world.gen.chunk.GenerationShapeConfig -import net.minecraft.world.gen.densityfunction.DensityFunction.NoisePos; -import net.minecraft.world.gen.densityfunction.DensityFunction.EachApplier; +import net.minecraft.world.gen.chunk.* +import net.minecraft.world.gen.densityfunction.DensityFunction.EachApplier +import net.minecraft.world.gen.densityfunction.DensityFunction.NoisePos import net.minecraft.world.gen.densityfunction.DensityFunctionTypes import net.minecraft.world.gen.noise.NoiseConfig - -import java.lang.reflect.Method -import java.util.Arrays -import kotlin.reflect.full.createType -import kotlin.reflect.full.declaredFunctions -import kotlin.reflect.jvm.javaMethod import kotlin.reflect.KFunction +import kotlin.reflect.full.declaredFunctions class Tests : Extractor.Extractor { override fun fileName(): String = "chunk.json" - private fun createFluidLevelSampler(settings: ChunkGeneratorSettings): AquiferSampler.FluidLevelSampler { - val fluidLevel = AquiferSampler.FluidLevel(-54, Blocks.LAVA.getDefaultState()); - val i = settings.seaLevel(); - val fluidLevel2 = AquiferSampler.FluidLevel(i, settings.defaultFluid()); - return AquiferSampler.FluidLevelSampler {_, y, _ -> if (y < Math.min(-54, i)) fluidLevel else fluidLevel2}; - } - - private fun get_index(config: GenerationShapeConfig, x: Int, y: Int, z: Int): Int { - if (x < 0 || y < 0 || z < 0) { - System.err.println("Bad local pos"); - System.exit(1); - } - return config.height() * 16 * x + 16 * y + z - } - - // This is basically just what NoiseChunkGenerator is doing - private fun populate_noise(start_x: Int, start_z: Int, sampler: ChunkNoiseSampler, config: GenerationShapeConfig, settings: ChunkGeneratorSettings): IntArray? { - val result = IntArray(16 * 16 * config.height()) - - for (method: KFunction<*> in sampler::class.declaredFunctions) { - if (method.name.equals("sampleBlockState")) { - sampler.sampleStartDensity() - val k = config.horizontalCellBlockCount() - val l = config.verticalCellBlockCount() - - val m = 16 / k - val n = 16 / k + private fun createFluidLevelSampler(settings: ChunkGeneratorSettings): AquiferSampler.FluidLevelSampler { + val fluidLevel = AquiferSampler.FluidLevel(-54, Blocks.LAVA.defaultState) + val i = settings.seaLevel() + val fluidLevel2 = AquiferSampler.FluidLevel(i, settings.defaultFluid()) + return AquiferSampler.FluidLevelSampler { _, y, _ -> if (y < Math.min(-54, i)) fluidLevel else fluidLevel2 } + } - val cellHeight = config.height() / l - val minimumCellY = config.minimumY() / l + private fun get_index(config: GenerationShapeConfig, x: Int, y: Int, z: Int): Int { + if (x < 0 || y < 0 || z < 0) { + System.err.println("Bad local pos") + System.exit(1) + } + return config.height() * 16 * x + 16 * y + z + } - for (o in 0.. in sampler::class.declaredFunctions) { + if (method.name.equals("sampleBlockState")) { + sampler.sampleStartDensity() + val k = config.horizontalCellBlockCount() + val l = config.verticalCellBlockCount() + + val m = 16 / k + val n = 16 / k + + val cellHeight = config.height() / l + val minimumCellY = config.minimumY() / l + + for (o in 0.. + val seed = 0L + val chunk_pos = ChunkPos(7, 4) + + val lookup = BuiltinRegistries.createWrapperLookup() + val wrapper = lookup.getOrThrow(RegistryKeys.CHUNK_GENERATOR_SETTINGS) + val noise_params = lookup.getOrThrow(RegistryKeys.NOISE_PARAMETERS) + + val ref = wrapper.getOrThrow(ChunkGeneratorSettings.OVERWORLD) + val settings = ref.value() + val config = NoiseConfig.create(settings, noise_params, seed) + + // Overworld shape config + val shape = GenerationShapeConfig(-64, 384, 1, 2) + val test_sampler = + ChunkNoiseSampler( + 16 / shape.horizontalCellBlockCount(), config, chunk_pos.startX, chunk_pos.startZ, + shape, object : DensityFunctionTypes.Beardifying { + override fun maxValue(): Double = 0.0 + override fun minValue(): Double = 0.0 + override fun sample(pos: NoisePos): Double = 0.0 + override fun fill(densities: DoubleArray, applier: EachApplier) { + densities.fill(0.0) + } + }, settings, createFluidLevelSampler(settings), Blender.getNoBlending() + ) + + val data = populate_noise(chunk_pos.startX, chunk_pos.startZ, test_sampler, shape, settings) + data?.forEach { state -> topLevelJson.add(state) }