Download data to the correct directory and remove redundancy.

This commit is contained in:
Articdive 2021-05-25 10:42:39 +02:00
parent 36d2834b18
commit 042311d5e3
No known key found for this signature in database
GPG Key ID: B069585F0F7D90DE
5 changed files with 39 additions and 110 deletions

4
.gitignore vendored
View File

@ -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

View File

@ -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
}
}
}

View File

@ -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"))
}

View File

@ -1,3 +1,4 @@
mcVersion = 1.16.5
asmVersion=9.0
mixinVersion=0.8.1
hephaistosVersion=v1.1.8

View File

@ -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;