From 042311d5e31a180a1841e1e05e8a0e76eefffb23 Mon Sep 17 00:00:00 2001 From: Articdive <13535885+Articdive@users.noreply.github.com> Date: Tue, 25 May 2021 10:42:39 +0200 Subject: [PATCH] Download data to the correct directory and remove redundancy. --- .gitignore | 4 +- build.gradle | 45 +++++---- code-generators/build.gradle | 97 ++----------------- gradle.properties | 1 + .../server/instance/block/BlockImpl.java | 2 +- 5 files changed, 39 insertions(+), 110 deletions(-) diff --git a/.gitignore b/.gitignore index eca70347d..953a582c9 100644 --- a/.gitignore +++ b/.gitignore @@ -59,5 +59,5 @@ gradle-app.setting # When compiling we get a docs folder **/docs -# The data for generation is included in this folder -code-generators/data/ +# The data for generation and the resources is included in this folder +src/main/resources diff --git a/build.gradle b/build.gradle index 3772a1dfc..058de24d9 100644 --- a/build.gradle +++ b/build.gradle @@ -219,9 +219,26 @@ configurations.all { exclude group: "org.checkerframework", module: "checker-qual" } +processResources { + dependsOn("downloadResources") +} + +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + } + } +} + +def mcVersionUnderscored = mcVersion.replace('.', '_') +def dataDest = new File(project.projectDir, "/src/main/resources/minecraft_data/") +def dataDestTags = new File(project.projectDir, "/src/main/resources/minecraft_data/tags") +def dataDestLootTable = new File(project.projectDir, "/src/main/resources/minecraft_data/loot_tables") + // UPDATE: Update the data to the required version -task downloadData(type: Download) { - String mainURL = "https://raw.githubusercontent.com/Minestom/MinestomDataGenerator/master/Minestom-data/1.16.5/1_16_5_"; +task downloadResources(type: Download) { + String mainURL = "https://raw.githubusercontent.com/Minestom/MinestomDataGenerator/master/Minestom-data/$mcVersion/${mcVersionUnderscored}_" src([ // attributes.json "${mainURL}attributes.json", @@ -258,12 +275,14 @@ task downloadData(type: Download) { // villager_types.json "${mainURL}villager_types.json" ]) - dest new File(processResources.destinationDir, "/minecraft_data/") + dest dataDest overwrite true + dependsOn("downloadLootTables") + dependsOn("downloadTags") } task downloadTags(type: Download) { - String mainURL = "https://raw.githubusercontent.com/Minestom/MinestomDataGenerator/master/Minestom-data/1.16.5/1_16_5_tags/1_16_5_"; + String mainURL = "https://raw.githubusercontent.com/Minestom/MinestomDataGenerator/master/Minestom-data/$mcVersion/${mcVersionUnderscored}_tags/${mcVersionUnderscored}_" src([ // block_tags.json "${mainURL}block_tags.json", @@ -274,12 +293,12 @@ task downloadTags(type: Download) { // item_tags.json "${mainURL}item_tags.json", ]) - dest new File(processResources.destinationDir, "/minecraft_data/tags/") + dest dataDestTags overwrite true } task downloadLootTables(type: Download) { - String mainURL = "https://raw.githubusercontent.com/Minestom/MinestomDataGenerator/master/Minestom-data/1.16.5/1_16_5_loot_tables/1_16_5_"; + String mainURL = "https://raw.githubusercontent.com/Minestom/MinestomDataGenerator/master/Minestom-data/$mcVersion/${mcVersionUnderscored}_loot_tables/${mcVersionUnderscored}_" src([ // block_loot_tables.json.json "${mainURL}block_loot_tables.json", @@ -290,18 +309,6 @@ task downloadLootTables(type: Download) { // gameplay_loot_tables.json "${mainURL}gameplay_loot_tables.json", ]) - dest new File(processResources.destinationDir, "/minecraft_data/loot_tables/") + dest dataDestLootTable overwrite true -} - -processResources { - dependsOn(downloadData, downloadTags, downloadLootTables) -} - -publishing { - publications { - mavenJava(MavenPublication) { - from components.java - } - } } \ No newline at end of file diff --git a/code-generators/build.gradle b/code-generators/build.gradle index 576ee9f12..e6630f1e8 100644 --- a/code-generators/build.gradle +++ b/code-generators/build.gradle @@ -10,12 +10,6 @@ version '1.0' sourceCompatibility = 1.11 -def mcVersion = "1.16.5" -def mcVersionUnderscored = mcVersion.replace('.', '_') -def dataDest = new File(project.projectDir, "/data/") -def dataDestTags = new File(project.projectDir, "/data/tags/") -def dataDestLootTable = new File(project.projectDir, "/data/loot_tables/") - application { mainClass.set("net.minestom.codegen.Generators") } @@ -33,91 +27,18 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-reflect:${project.kotlinVersion}" } -// UPDATE: Update the data to the required version and run the code generator. -task downloadData(type: Download) { - String mainURL = "https://raw.githubusercontent.com/Minestom/MinestomDataGenerator/master/Minestom-data/$mcVersion/${mcVersionUnderscored}_" - src([ - // attributes.json - "${mainURL}attributes.json", - // biomes.json - "${mainURL}biomes.json", - // block_entities - "${mainURL}block_entities.json", - // block_properties - "${mainURL}block_properties.json", - // blocks.json - "${mainURL}blocks.json", - // custom_statistics.json - "${mainURL}custom_statistics.json", - // dimension_types.json - "${mainURL}dimension_types.json", - // enchantments.json - "${mainURL}enchantments.json", - // fluids.json - "${mainURL}fluids.json", - // items.json - "${mainURL}items.json", - // map_colors.json - "${mainURL}map_colors.json", - // particles.json - "${mainURL}particles.json", - // potion_effects.json - "${mainURL}potion_effects.json", - // potions.json - "${mainURL}potions.json", - // sounds.json - "${mainURL}sounds.json", - // villager_professions.json - "${mainURL}villager_professions.json", - // villager_types.json - "${mainURL}villager_types.json" - ]) - dest dataDest - overwrite true - dependsOn("downloadLootTables") - dependsOn("downloadTags") -} - -task downloadTags(type: Download) { - String mainURL = "https://raw.githubusercontent.com/Minestom/MinestomDataGenerator/master/Minestom-data/$mcVersion/${mcVersionUnderscored}_tags/${mcVersionUnderscored}_" - src([ - // block_tags.json - "${mainURL}block_tags.json", - // entity_type_tags.json - "${mainURL}entity_type_tags.json", - // fluid_tags.json - "${mainURL}fluid_tags.json", - // item_tags.json - "${mainURL}item_tags.json", - ]) - dest dataDestTags - overwrite true -} - -task downloadLootTables(type: Download) { - String mainURL = "https://raw.githubusercontent.com/Minestom/MinestomDataGenerator/master/Minestom-data/$mcVersion/${mcVersionUnderscored}_loot_tables/${mcVersionUnderscored}_" - src([ - // block_loot_tables.json.json - "${mainURL}block_loot_tables.json", - // chest_loot_tables.json - "${mainURL}chest_loot_tables.json", - // entity_loot_tables.json - "${mainURL}entity_loot_tables.json", - // gameplay_loot_tables.json - "${mainURL}gameplay_loot_tables.json", - ]) - dest dataDestLootTable - overwrite true -} - run { // Update version setArgs( - List.of( - mcVersion, - dataDest.getAbsolutePath(), - project.rootProject.projectDir.getPath() + "${File.separatorChar}src${File.separatorChar}autogenerated${File.separatorChar}java") + [ + // Point to gradle.properties "mcVersion" + project.rootProject.properties["mcVersion"], + // Points to src/main/resources/minecraft_data + project.rootProject.projectDir.getPath() + "${File.separatorChar}src${File.separatorChar}main${File.separatorChar}resources${File.separatorChar}minecraft_data", + // Points to src/autogenerated/java + project.rootProject.projectDir.getPath() + "${File.separatorChar}src${File.separatorChar}autogenerated${File.separatorChar}java" + ] ) - dependsOn(downloadData) + dependsOn(project.rootProject.tasks.getByName("downloadResources")) } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 34ba796b2..f5426723a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,4 @@ +mcVersion = 1.16.5 asmVersion=9.0 mixinVersion=0.8.1 hephaistosVersion=v1.1.8 diff --git a/src/main/java/net/minestom/server/instance/block/BlockImpl.java b/src/main/java/net/minestom/server/instance/block/BlockImpl.java index 6e7cd8b46..742ad35f3 100644 --- a/src/main/java/net/minestom/server/instance/block/BlockImpl.java +++ b/src/main/java/net/minestom/server/instance/block/BlockImpl.java @@ -234,7 +234,7 @@ class BlockImpl implements Block { */ private static void loadBlockData() { // E.G. 1_16_5_blocks.json - InputStream blocksIS = BlockImpl.class.getResourceAsStream("/minestom_data/" + MinecraftServer.VERSION_NAME_UNDERSCORED + "_blocks.json"); + InputStream blocksIS = BlockImpl.class.getResourceAsStream("/minecraft_data/" + MinecraftServer.VERSION_NAME_UNDERSCORED + "_blocks.json"); if (blocksIS == null) { LOGGER.error("Failed to find blocks.json"); return;