mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-28 11:01:35 +01:00
Fix generator, use namespace instead of mojang field name
This commit is contained in:
parent
2dceab7743
commit
1915722d02
@ -14,29 +14,24 @@ application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
//maven { url "https://repo.minestom.net/repository/maven-public/" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.google.code.gson:gson:2.8.6'
|
implementation 'com.google.code.gson:gson:2.8.7'
|
||||||
implementation 'org.jetbrains:annotations:20.1.0'
|
implementation 'org.jetbrains:annotations:21.0.1'
|
||||||
implementation 'com.squareup:javapoet:1.13.0'
|
implementation 'com.squareup:javapoet:1.13.0'
|
||||||
// Logging
|
// Logging
|
||||||
implementation 'org.apache.logging.log4j:log4j-core:2.14.0'
|
implementation 'org.apache.logging.log4j:log4j-core:2.14.1'
|
||||||
// SLF4J is the base logger for most libraries, therefore we can hook it into log4j2.
|
// SLF4J is the base logger for most libraries, therefore we can hook it into log4j2.
|
||||||
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.0'
|
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.1'
|
||||||
// This is the data Minestom uses. from https://github.com/Minestom/MinestomDataGenerator
|
// Contains the json files
|
||||||
//implementation "net.minestom:minestom-data-full:${rootProject.properties.get("mcVersion")}"
|
implementation 'com.github.Minestom:MinestomDataGenerator:-SNAPSHOT'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
run {
|
run {
|
||||||
// Update version
|
// Update version
|
||||||
setArgs(List.of(
|
setArgs(List.of(
|
||||||
// Point to gradle.properties "mcVersion"
|
|
||||||
rootProject.properties.get("mcVersion"),
|
|
||||||
// If the source is 'classes' it will load from the dependency "net.minestom:minestom-data-customizable:version"
|
|
||||||
"resources",
|
|
||||||
// Points to src/autogenerated/java
|
// Points to src/autogenerated/java
|
||||||
project.rootProject.projectDir.getPath() + "${File.separatorChar}src${File.separatorChar}autogenerated${File.separatorChar}java"
|
project.rootProject.projectDir.getPath() + "${File.separatorChar}src${File.separatorChar}autogenerated${File.separatorChar}java"
|
||||||
) as List<String>
|
) as List<String>
|
||||||
|
@ -14,71 +14,41 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class Generators {
|
public class Generators {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(Generators.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(Generators.class);
|
||||||
|
|
||||||
public static void main(String[] args) throws FileNotFoundException {
|
public static void main(String[] args) {
|
||||||
if (args.length < 3) {
|
if (args.length != 1) {
|
||||||
LOGGER.error("Usage: <MC version> <source folder | 'resources'> <target folder>");
|
LOGGER.error("Usage: <target folder>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String targetVersion = args[0].replace(".", "_");
|
File outputFolder = new File(args[0]);
|
||||||
boolean resourceMode = false;
|
|
||||||
if (args[1].equals("resources")) {
|
|
||||||
resourceMode = true;
|
|
||||||
}
|
|
||||||
File inputFolder = new File(args[1]); // This will be ignored if resourceMode = true
|
|
||||||
File outputFolder = new File(args[2]);
|
|
||||||
// Generate blocks
|
// Generate blocks
|
||||||
new BlockGenerator(Generators.class.getResourceAsStream("/blocks.json"), outputFolder).generate();
|
new BlockGenerator(resource("blocks.json"), outputFolder).generate();
|
||||||
// Generate fluids
|
// Generate fluids
|
||||||
new FluidGenerator(
|
new FluidGenerator(resource("fluids.json"), outputFolder).generate();
|
||||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_fluids.json") : new FileInputStream(new File(inputFolder, targetVersion + "_fluids.json")),
|
|
||||||
outputFolder
|
|
||||||
).generate();
|
|
||||||
// Generate entities
|
// Generate entities
|
||||||
new EntityTypeGenerator(
|
new EntityTypeGenerator(resource("entities.json"), outputFolder).generate();
|
||||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_entities.json") : new FileInputStream(new File(inputFolder, targetVersion + "_entities.json")),
|
|
||||||
outputFolder
|
|
||||||
).generate();
|
|
||||||
// Generate items
|
// Generate items
|
||||||
new MaterialGenerator(
|
new MaterialGenerator(resource("items.json"), outputFolder).generate();
|
||||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_items.json") : new FileInputStream(new File(inputFolder, targetVersion + "_items.json")),
|
|
||||||
outputFolder
|
|
||||||
).generate();
|
|
||||||
// Generate enchantments
|
// Generate enchantments
|
||||||
new EnchantmentGenerator(
|
new EnchantmentGenerator(resource("enchantments.json"), outputFolder).generate();
|
||||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_enchantments.json") : new FileInputStream(new File(inputFolder, targetVersion + "_enchantments.json")),
|
|
||||||
outputFolder
|
|
||||||
).generate();
|
|
||||||
// TODO: Generate attributes
|
// TODO: Generate attributes
|
||||||
// new AttributeGenerator(
|
// new AttributeGenerator(
|
||||||
// new File(inputFolder, targetVersion + "_attributes.json"),
|
// new File(inputFolder, targetVersion + "_attributes.json"),
|
||||||
// outputFolder
|
// outputFolder
|
||||||
// ).generate();
|
// ).generate();
|
||||||
// Generate potion effects
|
// Generate potion effects
|
||||||
new PotionEffectGenerator(
|
new PotionEffectGenerator(resource("potion_effects.json"), outputFolder).generate();
|
||||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_potion_effects.json") : new FileInputStream(new File(inputFolder, targetVersion + "_potion_effects.json")),
|
|
||||||
outputFolder
|
|
||||||
).generate();
|
|
||||||
// Generate potions
|
// Generate potions
|
||||||
new PotionTypeGenerator(
|
new PotionTypeGenerator(resource("potions.json"), outputFolder).generate();
|
||||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_potions.json") : new FileInputStream(new File(inputFolder, targetVersion + "_potions.json")),
|
|
||||||
outputFolder
|
|
||||||
).generate();
|
|
||||||
// Generate particles
|
// Generate particles
|
||||||
new ParticleGenerator(
|
new ParticleGenerator(resource("particles.json"), outputFolder).generate();
|
||||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_particles.json") : new FileInputStream(new File(inputFolder, targetVersion + "_particles.json")),
|
|
||||||
outputFolder
|
|
||||||
).generate();
|
|
||||||
// Generate sounds
|
// Generate sounds
|
||||||
new SoundEventGenerator(
|
new SoundEventGenerator(resource("sounds.json"), outputFolder).generate();
|
||||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_sounds.json") : new FileInputStream(new File(inputFolder, targetVersion + "_sounds.json")),
|
|
||||||
outputFolder
|
|
||||||
).generate();
|
|
||||||
// TODO: Generate villager professions
|
// TODO: Generate villager professions
|
||||||
// new VillagerProfessionGenerator(
|
// new VillagerProfessionGenerator(
|
||||||
// new File(inputFolder, targetVersion + "_villager_professions.json"),
|
// new File(inputFolder, targetVersion + "_villager_professions.json"),
|
||||||
@ -90,10 +60,11 @@ public class Generators {
|
|||||||
// outputFolder
|
// outputFolder
|
||||||
// ).generate();
|
// ).generate();
|
||||||
// Generate statistics
|
// Generate statistics
|
||||||
new StatisticGenerator(
|
new StatisticGenerator(resource("custom_statistics.json"), outputFolder).generate();
|
||||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_custom_statistics.json") : new FileInputStream(new File(inputFolder, targetVersion + "_custom_statistics.json")),
|
|
||||||
outputFolder
|
|
||||||
).generate();
|
|
||||||
LOGGER.info("Finished generating code");
|
LOGGER.info("Finished generating code");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static InputStream resource(String name) {
|
||||||
|
return Generators.class.getResourceAsStream("/" + name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public abstract class MinestomCodeGenerator {
|
public abstract class MinestomCodeGenerator {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(MinestomCodeGenerator.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(MinestomCodeGenerator.class);
|
||||||
@ -26,4 +27,8 @@ public abstract class MinestomCodeGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static String toConstant(String namespace) {
|
||||||
|
return namespace.replace("minecraft:", "").toUpperCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ public final class EntityTypeGenerator extends MinestomCodeGenerator {
|
|||||||
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
||||||
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
||||||
|
|
||||||
JsonArray entities = GSON.fromJson(new InputStreamReader(entitiesFile), JsonArray.class);
|
JsonObject entities = GSON.fromJson(new InputStreamReader(entitiesFile), JsonObject.class);
|
||||||
ClassName entityClassName = ClassName.get("net.minestom.server.entity", "EntityType");
|
ClassName entityClassName = ClassName.get("net.minestom.server.entity", "EntityType");
|
||||||
|
|
||||||
// Particle
|
// Particle
|
||||||
@ -376,13 +376,14 @@ public final class EntityTypeGenerator extends MinestomCodeGenerator {
|
|||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
// Use data
|
// Use data
|
||||||
for (JsonElement e : entities) {
|
entities.entrySet().forEach(entry -> {
|
||||||
JsonObject entity = e.getAsJsonObject();
|
final String entityNamespace = entry.getKey();
|
||||||
|
final String entityConstant = toConstant(entityNamespace);
|
||||||
|
|
||||||
String entityName = entity.get("name").getAsString();
|
JsonObject entity = entry.getValue().getAsJsonObject();
|
||||||
|
|
||||||
// Get metaClass (this is a little complicated)
|
// Get metaClass (this is a little complicated)
|
||||||
String metaClassName = NameUtil.convertSnakeCaseToCamelCase(entityName.toLowerCase());
|
String metaClassName = NameUtil.convertSnakeCaseToCamelCase(entityConstant.toLowerCase());
|
||||||
switch (metaClassName) {
|
switch (metaClassName) {
|
||||||
// These are cases where the entity name doesn't fully match up to the meta name.
|
// These are cases where the entity name doesn't fully match up to the meta name.
|
||||||
// UPDATE: Handle new entity names that don't match up to their meta name.
|
// UPDATE: Handle new entity names that don't match up to their meta name.
|
||||||
@ -408,18 +409,18 @@ public final class EntityTypeGenerator extends MinestomCodeGenerator {
|
|||||||
String packageName = metadata.get(metaClassName);
|
String packageName = metadata.get(metaClassName);
|
||||||
String className = metaClassName + "Meta";
|
String className = metaClassName + "Meta";
|
||||||
if (packageName == null) {
|
if (packageName == null) {
|
||||||
LOGGER.error("The Entity metadata for " + entity.get("id").getAsString() + " is not implemented!");
|
LOGGER.error("The Entity metadata for " + entityNamespace + " is not implemented!");
|
||||||
LOGGER.error("The metadata has been defaulted to EntityMeta.");
|
LOGGER.error("The metadata has been defaulted to EntityMeta.");
|
||||||
packageName = "net.minestom.server.entity.metadata";
|
packageName = "net.minestom.server.entity.metadata";
|
||||||
className = "EntityMeta";
|
className = "EntityMeta";
|
||||||
}
|
}
|
||||||
|
|
||||||
entityClass.addEnumConstant(
|
entityClass.addEnumConstant(
|
||||||
entityName,
|
entityConstant,
|
||||||
TypeSpec.anonymousClassBuilder(
|
TypeSpec.anonymousClassBuilder(
|
||||||
"$T.from($S), $L, $L, $T::new, $T.$N",
|
"$T.from($S), $L, $L, $T::new, $T.$N",
|
||||||
namespaceIDClassName,
|
namespaceIDClassName,
|
||||||
entity.get("id").getAsString(),
|
entityNamespace,
|
||||||
entity.get("width").getAsDouble(),
|
entity.get("width").getAsDouble(),
|
||||||
entity.get("height").getAsDouble(),
|
entity.get("height").getAsDouble(),
|
||||||
ClassName.get(packageName, className),
|
ClassName.get(packageName, className),
|
||||||
@ -427,7 +428,7 @@ public final class EntityTypeGenerator extends MinestomCodeGenerator {
|
|||||||
entity.get("packetType").getAsString().toUpperCase()
|
entity.get("packetType").getAsString().toUpperCase()
|
||||||
).build()
|
).build()
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
// Write files to outputFolder
|
// Write files to outputFolder
|
||||||
writeFiles(
|
writeFiles(
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package net.minestom.codegen.fluid;
|
package net.minestom.codegen.fluid;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.squareup.javapoet.*;
|
import com.squareup.javapoet.*;
|
||||||
import net.minestom.codegen.MinestomCodeGenerator;
|
import net.minestom.codegen.MinestomCodeGenerator;
|
||||||
@ -41,7 +39,7 @@ public final class FluidGenerator extends MinestomCodeGenerator {
|
|||||||
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
||||||
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
||||||
|
|
||||||
JsonArray fluids = GSON.fromJson(new InputStreamReader(fluidsFile), JsonArray.class);
|
JsonObject fluids = GSON.fromJson(new InputStreamReader(fluidsFile), JsonObject.class);
|
||||||
ClassName fluidClassName = ClassName.get("net.minestom.server.fluid", "Fluid");
|
ClassName fluidClassName = ClassName.get("net.minestom.server.fluid", "Fluid");
|
||||||
|
|
||||||
// Particle
|
// Particle
|
||||||
@ -122,18 +120,15 @@ public final class FluidGenerator extends MinestomCodeGenerator {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Use data
|
// Use data
|
||||||
for (JsonElement f : fluids) {
|
fluids.entrySet().forEach(entry -> {
|
||||||
JsonObject fluid = f.getAsJsonObject();
|
final String fluidName = entry.getKey();
|
||||||
|
fluidClass.addEnumConstant(toConstant(fluidName), TypeSpec.anonymousClassBuilder(
|
||||||
String fluidName = fluid.get("name").getAsString();
|
"$T.from($S)",
|
||||||
|
namespaceIDClassName,
|
||||||
fluidClass.addEnumConstant(fluidName, TypeSpec.anonymousClassBuilder(
|
fluidName
|
||||||
"$T.from($S)",
|
|
||||||
namespaceIDClassName,
|
|
||||||
fluid.get("id").getAsString()
|
|
||||||
).build()
|
).build()
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
// Write files to outputFolder
|
// Write files to outputFolder
|
||||||
writeFiles(
|
writeFiles(
|
||||||
|
@ -41,7 +41,7 @@ public final class EnchantmentGenerator extends MinestomCodeGenerator {
|
|||||||
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
||||||
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
||||||
|
|
||||||
JsonArray enchantments = GSON.fromJson(new InputStreamReader(enchantmentsFile), JsonArray.class);
|
JsonObject enchantments = GSON.fromJson(new InputStreamReader(enchantmentsFile), JsonObject.class);
|
||||||
ClassName enchantmentClassName = ClassName.get("net.minestom.server.item", "Enchantment");
|
ClassName enchantmentClassName = ClassName.get("net.minestom.server.item", "Enchantment");
|
||||||
|
|
||||||
// Enchantment
|
// Enchantment
|
||||||
@ -121,17 +121,16 @@ public final class EnchantmentGenerator extends MinestomCodeGenerator {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Use data
|
// Use data
|
||||||
for (JsonElement e : enchantments) {
|
enchantments.entrySet().forEach(entry -> {
|
||||||
JsonObject enchantment = e.getAsJsonObject();
|
final String enchantmentNamespace = entry.getKey();
|
||||||
|
final String enchantmentConstant = toConstant(enchantmentNamespace);
|
||||||
String enchantmentName = enchantment.get("name").getAsString();
|
enchantmentClass.addEnumConstant(enchantmentConstant, TypeSpec.anonymousClassBuilder(
|
||||||
enchantmentClass.addEnumConstant(enchantmentName, TypeSpec.anonymousClassBuilder(
|
"$T.from($S)",
|
||||||
"$T.from($S)",
|
namespaceIDClassName,
|
||||||
namespaceIDClassName,
|
enchantmentNamespace
|
||||||
enchantment.get("id").getAsString()
|
|
||||||
).build()
|
).build()
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
|
|
||||||
// Write files to outputFolder
|
// Write files to outputFolder
|
||||||
|
@ -40,11 +40,12 @@ public final class MaterialGenerator extends MinestomCodeGenerator {
|
|||||||
}
|
}
|
||||||
// Important classes we use alot
|
// Important classes we use alot
|
||||||
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
||||||
|
ClassName blockClassName = ClassName.get("net.minestom.server.instance.block", "Block");
|
||||||
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
||||||
ClassName blockCN = ClassName.get("net.minestom.server.instance.block", "Block");
|
ClassName blockCN = ClassName.get("net.minestom.server.instance.block", "Block");
|
||||||
ParameterizedTypeName blocksCNSupplier = ParameterizedTypeName.get(ClassName.get(Supplier.class), blockCN);
|
ParameterizedTypeName blocksCNSupplier = ParameterizedTypeName.get(ClassName.get(Supplier.class), blockCN);
|
||||||
|
|
||||||
JsonArray items = GSON.fromJson(new InputStreamReader(itemsFile), JsonArray.class);
|
JsonObject items = GSON.fromJson(new InputStreamReader(itemsFile), JsonObject.class);
|
||||||
ClassName itemClassName = ClassName.get("net.minestom.server.item", "Material");
|
ClassName itemClassName = ClassName.get("net.minestom.server.item", "Material");
|
||||||
|
|
||||||
// Item
|
// Item
|
||||||
@ -232,26 +233,28 @@ public final class MaterialGenerator extends MinestomCodeGenerator {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Use data
|
// Use data
|
||||||
for (JsonElement i : items) {
|
items.entrySet().forEach(entry -> {
|
||||||
JsonObject item = i.getAsJsonObject();
|
final String itemNamespace = entry.getKey();
|
||||||
|
final String itemConstant = toConstant(itemNamespace);
|
||||||
|
|
||||||
|
JsonObject item = entry.getValue().getAsJsonObject();
|
||||||
|
|
||||||
String itemName = item.get("name").getAsString();
|
|
||||||
TypeSpec.Builder enumConst;
|
TypeSpec.Builder enumConst;
|
||||||
if (!(item.get("blockId").getAsString().equals("minecraft:air"))) {
|
if (!(item.get("blockId").getAsString().equals("minecraft:air"))) {
|
||||||
enumConst = TypeSpec.anonymousClassBuilder(
|
enumConst = TypeSpec.anonymousClassBuilder(
|
||||||
"$T.from($S), (byte) $L, () -> $T.getBlock($S)",
|
"$T.from($S), (byte) $L, () -> $T.$L",
|
||||||
namespaceIDClassName,
|
namespaceIDClassName,
|
||||||
item.get("id").getAsString(),
|
itemNamespace,
|
||||||
item.get("maxStackSize").getAsInt(),
|
item.get("maxStackSize").getAsInt(),
|
||||||
// Supplier
|
// Supplier
|
||||||
registriesClassName,
|
blockClassName,
|
||||||
item.get("blockId").getAsString()
|
toConstant(item.get("blockId").getAsString())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
enumConst = TypeSpec.anonymousClassBuilder(
|
enumConst = TypeSpec.anonymousClassBuilder(
|
||||||
"$T.from($S), (byte) $L, () -> null",
|
"$T.from($S), (byte) $L, () -> null",
|
||||||
namespaceIDClassName,
|
namespaceIDClassName,
|
||||||
item.get("id").getAsString(),
|
itemNamespace,
|
||||||
item.get("maxStackSize").getAsInt()
|
item.get("maxStackSize").getAsInt()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -326,8 +329,8 @@ public final class MaterialGenerator extends MinestomCodeGenerator {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
itemClass.addEnumConstant(itemName, enumConst.build());
|
itemClass.addEnumConstant(itemConstant, enumConst.build());
|
||||||
}
|
});
|
||||||
|
|
||||||
// Write files to outputFolder
|
// Write files to outputFolder
|
||||||
writeFiles(
|
writeFiles(
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package net.minestom.codegen.particle;
|
package net.minestom.codegen.particle;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.squareup.javapoet.*;
|
import com.squareup.javapoet.*;
|
||||||
import net.minestom.codegen.MinestomCodeGenerator;
|
import net.minestom.codegen.MinestomCodeGenerator;
|
||||||
@ -41,7 +39,7 @@ public final class ParticleGenerator extends MinestomCodeGenerator {
|
|||||||
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
||||||
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
||||||
|
|
||||||
JsonArray particles = GSON.fromJson(new InputStreamReader(particlesFile), JsonArray.class);
|
JsonObject particles = GSON.fromJson(new InputStreamReader(particlesFile), JsonObject.class);
|
||||||
ClassName particleClassName = ClassName.get("net.minestom.server.particle", "Particle");
|
ClassName particleClassName = ClassName.get("net.minestom.server.particle", "Particle");
|
||||||
|
|
||||||
// Particle
|
// Particle
|
||||||
@ -121,17 +119,15 @@ public final class ParticleGenerator extends MinestomCodeGenerator {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Use data
|
// Use data
|
||||||
for (JsonElement p : particles) {
|
particles.entrySet().forEach(entry -> {
|
||||||
JsonObject particle = p.getAsJsonObject();
|
final String particleNamespace = entry.getKey();
|
||||||
|
final String particleConstant = toConstant(particleNamespace);
|
||||||
String particleName = particle.get("name").getAsString();
|
particleClass.addEnumConstant(particleConstant, TypeSpec.anonymousClassBuilder(
|
||||||
|
|
||||||
particleClass.addEnumConstant(particleName, TypeSpec.anonymousClassBuilder(
|
|
||||||
"$T.from($S)",
|
"$T.from($S)",
|
||||||
namespaceIDClassName,
|
namespaceIDClassName,
|
||||||
particle.get("id").getAsString()
|
particleNamespace
|
||||||
).build());
|
).build());
|
||||||
}
|
});
|
||||||
|
|
||||||
// Write files to outputFolder
|
// Write files to outputFolder
|
||||||
writeFiles(
|
writeFiles(
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package net.minestom.codegen.potion;
|
package net.minestom.codegen.potion;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.squareup.javapoet.*;
|
import com.squareup.javapoet.*;
|
||||||
import net.minestom.codegen.MinestomCodeGenerator;
|
import net.minestom.codegen.MinestomCodeGenerator;
|
||||||
@ -41,7 +39,7 @@ public final class PotionEffectGenerator extends MinestomCodeGenerator {
|
|||||||
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
||||||
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
||||||
|
|
||||||
JsonArray potionEffects = GSON.fromJson(new InputStreamReader(potionEffectsFile), JsonArray.class);
|
JsonObject potionEffects = GSON.fromJson(new InputStreamReader(potionEffectsFile), JsonObject.class);
|
||||||
ClassName potionEffectClassName = ClassName.get("net.minestom.server.potion", "PotionEffect");
|
ClassName potionEffectClassName = ClassName.get("net.minestom.server.potion", "PotionEffect");
|
||||||
|
|
||||||
// Particle
|
// Particle
|
||||||
@ -121,18 +119,16 @@ public final class PotionEffectGenerator extends MinestomCodeGenerator {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Use data
|
// Use data
|
||||||
for (JsonElement pe : potionEffects) {
|
potionEffects.entrySet().forEach(entry -> {
|
||||||
JsonObject potionEffect = pe.getAsJsonObject();
|
final String potionEffectNamespace = entry.getKey();
|
||||||
|
final String potionEffectConstant = toConstant(potionEffectNamespace);
|
||||||
String potionEffectName = potionEffect.get("name").getAsString();
|
potionEffectClass.addEnumConstant(potionEffectConstant, TypeSpec.anonymousClassBuilder(
|
||||||
|
"$T.from($S)",
|
||||||
potionEffectClass.addEnumConstant(potionEffectName, TypeSpec.anonymousClassBuilder(
|
namespaceIDClassName,
|
||||||
"$T.from($S)",
|
potionEffectNamespace
|
||||||
namespaceIDClassName,
|
|
||||||
potionEffect.get("id").getAsString()
|
|
||||||
).build()
|
).build()
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
// Write files to outputFolder
|
// Write files to outputFolder
|
||||||
writeFiles(
|
writeFiles(
|
||||||
|
@ -41,7 +41,7 @@ public final class PotionTypeGenerator extends MinestomCodeGenerator {
|
|||||||
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
||||||
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
||||||
|
|
||||||
JsonArray potions = GSON.fromJson(new InputStreamReader(potionsFile), JsonArray.class);
|
JsonObject potions = GSON.fromJson(new InputStreamReader(potionsFile), JsonObject.class);
|
||||||
ClassName potionTypeClassName = ClassName.get("net.minestom.server.potion", "PotionType");
|
ClassName potionTypeClassName = ClassName.get("net.minestom.server.potion", "PotionType");
|
||||||
|
|
||||||
// Particle
|
// Particle
|
||||||
@ -121,18 +121,16 @@ public final class PotionTypeGenerator extends MinestomCodeGenerator {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Use data
|
// Use data
|
||||||
for (JsonElement p : potions) {
|
potions.entrySet().forEach(entry -> {
|
||||||
JsonObject potion = p.getAsJsonObject();
|
final String potionNamespace = entry.getKey();
|
||||||
|
final String potionConstant = toConstant(potionNamespace);
|
||||||
String potionName = potion.get("name").getAsString();
|
potionTypeClass.addEnumConstant(potionConstant, TypeSpec.anonymousClassBuilder(
|
||||||
|
"$T.from($S)",
|
||||||
potionTypeClass.addEnumConstant(potionName, TypeSpec.anonymousClassBuilder(
|
namespaceIDClassName,
|
||||||
"$T.from($S)",
|
potionNamespace
|
||||||
namespaceIDClassName,
|
|
||||||
potion.get("id").getAsString()
|
|
||||||
).build()
|
).build()
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
// Write files to outputFolder
|
// Write files to outputFolder
|
||||||
writeFiles(
|
writeFiles(
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package net.minestom.codegen.sound;
|
package net.minestom.codegen.sound;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.squareup.javapoet.*;
|
import com.squareup.javapoet.*;
|
||||||
import net.minestom.codegen.MinestomCodeGenerator;
|
import net.minestom.codegen.MinestomCodeGenerator;
|
||||||
@ -41,7 +39,7 @@ public final class SoundEventGenerator extends MinestomCodeGenerator {
|
|||||||
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
||||||
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
||||||
|
|
||||||
JsonArray sounds = GSON.fromJson(new InputStreamReader(soundsFile), JsonArray.class);
|
JsonObject sounds = GSON.fromJson(new InputStreamReader(soundsFile), JsonObject.class);
|
||||||
ClassName soundClassName = ClassName.get("net.minestom.server.sound", "SoundEvent");
|
ClassName soundClassName = ClassName.get("net.minestom.server.sound", "SoundEvent");
|
||||||
// Sound
|
// Sound
|
||||||
TypeSpec.Builder soundClass = TypeSpec.enumBuilder(soundClassName)
|
TypeSpec.Builder soundClass = TypeSpec.enumBuilder(soundClassName)
|
||||||
@ -121,17 +119,16 @@ public final class SoundEventGenerator extends MinestomCodeGenerator {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Use data
|
// Use data
|
||||||
for (JsonElement s : sounds) {
|
sounds.entrySet().forEach(entry -> {
|
||||||
JsonObject sound = s.getAsJsonObject();
|
final String soundNamespace = entry.getKey();
|
||||||
|
final String soundConstant = toConstant(soundNamespace).replace(".", "_");
|
||||||
String soundName = sound.get("name").getAsString();
|
soundClass.addEnumConstant(soundConstant, TypeSpec.anonymousClassBuilder(
|
||||||
soundClass.addEnumConstant(soundName, TypeSpec.anonymousClassBuilder(
|
"$T.from($S)",
|
||||||
"$T.from($S)",
|
namespaceIDClassName,
|
||||||
namespaceIDClassName,
|
soundNamespace
|
||||||
sound.get("id").getAsString()
|
|
||||||
).build()
|
).build()
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
// Write files to outputFolder
|
// Write files to outputFolder
|
||||||
writeFiles(
|
writeFiles(
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package net.minestom.codegen.statistics;
|
package net.minestom.codegen.statistics;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.squareup.javapoet.*;
|
import com.squareup.javapoet.*;
|
||||||
import net.minestom.codegen.MinestomCodeGenerator;
|
import net.minestom.codegen.MinestomCodeGenerator;
|
||||||
@ -41,7 +39,7 @@ public final class StatisticGenerator extends MinestomCodeGenerator {
|
|||||||
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
||||||
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
|
||||||
|
|
||||||
JsonArray statistics = GSON.fromJson(new InputStreamReader(statisticsFile), JsonArray.class);
|
JsonObject statistics = GSON.fromJson(new InputStreamReader(statisticsFile), JsonObject.class);
|
||||||
ClassName statisticClassName = ClassName.get("net.minestom.server.statistic", "StatisticType");
|
ClassName statisticClassName = ClassName.get("net.minestom.server.statistic", "StatisticType");
|
||||||
|
|
||||||
// Particle
|
// Particle
|
||||||
@ -121,18 +119,16 @@ public final class StatisticGenerator extends MinestomCodeGenerator {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Use data
|
// Use data
|
||||||
for (JsonElement s : statistics) {
|
statistics.entrySet().forEach(entry -> {
|
||||||
JsonObject statistic = s.getAsJsonObject();
|
final String statisticNamespace = entry.getKey();
|
||||||
|
final String statisticConstant = toConstant(statisticNamespace);
|
||||||
String statisticName = statistic.get("name").getAsString();
|
statisticClass.addEnumConstant(statisticConstant, TypeSpec.anonymousClassBuilder(
|
||||||
|
"$T.from($S)",
|
||||||
statisticClass.addEnumConstant(statisticName, TypeSpec.anonymousClassBuilder(
|
namespaceIDClassName,
|
||||||
"$T.from($S)",
|
statisticNamespace
|
||||||
namespaceIDClassName,
|
|
||||||
statistic.get("id").getAsString()
|
|
||||||
).build()
|
).build()
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
// Write files to outputFolder
|
// Write files to outputFolder
|
||||||
writeFiles(
|
writeFiles(
|
||||||
|
@ -11,11 +11,11 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
* AUTOGENERATED by EnchantmentGenerator
|
* AUTOGENERATED by EnchantmentGenerator
|
||||||
*/
|
*/
|
||||||
public enum Enchantment implements Keyed {
|
public enum Enchantment implements Keyed {
|
||||||
ALL_DAMAGE_PROTECTION(NamespaceID.from("minecraft:protection")),
|
PROTECTION(NamespaceID.from("minecraft:protection")),
|
||||||
|
|
||||||
FIRE_PROTECTION(NamespaceID.from("minecraft:fire_protection")),
|
FIRE_PROTECTION(NamespaceID.from("minecraft:fire_protection")),
|
||||||
|
|
||||||
FALL_PROTECTION(NamespaceID.from("minecraft:feather_falling")),
|
FEATHER_FALLING(NamespaceID.from("minecraft:feather_falling")),
|
||||||
|
|
||||||
BLAST_PROTECTION(NamespaceID.from("minecraft:blast_protection")),
|
BLAST_PROTECTION(NamespaceID.from("minecraft:blast_protection")),
|
||||||
|
|
||||||
@ -45,29 +45,29 @@ public enum Enchantment implements Keyed {
|
|||||||
|
|
||||||
FIRE_ASPECT(NamespaceID.from("minecraft:fire_aspect")),
|
FIRE_ASPECT(NamespaceID.from("minecraft:fire_aspect")),
|
||||||
|
|
||||||
MOB_LOOTING(NamespaceID.from("minecraft:looting")),
|
LOOTING(NamespaceID.from("minecraft:looting")),
|
||||||
|
|
||||||
SWEEPING_EDGE(NamespaceID.from("minecraft:sweeping")),
|
SWEEPING(NamespaceID.from("minecraft:sweeping")),
|
||||||
|
|
||||||
BLOCK_EFFICIENCY(NamespaceID.from("minecraft:efficiency")),
|
EFFICIENCY(NamespaceID.from("minecraft:efficiency")),
|
||||||
|
|
||||||
SILK_TOUCH(NamespaceID.from("minecraft:silk_touch")),
|
SILK_TOUCH(NamespaceID.from("minecraft:silk_touch")),
|
||||||
|
|
||||||
UNBREAKING(NamespaceID.from("minecraft:unbreaking")),
|
UNBREAKING(NamespaceID.from("minecraft:unbreaking")),
|
||||||
|
|
||||||
BLOCK_FORTUNE(NamespaceID.from("minecraft:fortune")),
|
FORTUNE(NamespaceID.from("minecraft:fortune")),
|
||||||
|
|
||||||
POWER_ARROWS(NamespaceID.from("minecraft:power")),
|
POWER(NamespaceID.from("minecraft:power")),
|
||||||
|
|
||||||
PUNCH_ARROWS(NamespaceID.from("minecraft:punch")),
|
PUNCH(NamespaceID.from("minecraft:punch")),
|
||||||
|
|
||||||
FLAMING_ARROWS(NamespaceID.from("minecraft:flame")),
|
FLAME(NamespaceID.from("minecraft:flame")),
|
||||||
|
|
||||||
INFINITY_ARROWS(NamespaceID.from("minecraft:infinity")),
|
INFINITY(NamespaceID.from("minecraft:infinity")),
|
||||||
|
|
||||||
FISHING_LUCK(NamespaceID.from("minecraft:luck_of_the_sea")),
|
LUCK_OF_THE_SEA(NamespaceID.from("minecraft:luck_of_the_sea")),
|
||||||
|
|
||||||
FISHING_SPEED(NamespaceID.from("minecraft:lure")),
|
LURE(NamespaceID.from("minecraft:lure")),
|
||||||
|
|
||||||
LOYALTY(NamespaceID.from("minecraft:loyalty")),
|
LOYALTY(NamespaceID.from("minecraft:loyalty")),
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -11,27 +11,27 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
* AUTOGENERATED by PotionEffectGenerator
|
* AUTOGENERATED by PotionEffectGenerator
|
||||||
*/
|
*/
|
||||||
public enum PotionEffect implements Keyed {
|
public enum PotionEffect implements Keyed {
|
||||||
MOVEMENT_SPEED(NamespaceID.from("minecraft:speed")),
|
SPEED(NamespaceID.from("minecraft:speed")),
|
||||||
|
|
||||||
MOVEMENT_SLOWDOWN(NamespaceID.from("minecraft:slowness")),
|
SLOWNESS(NamespaceID.from("minecraft:slowness")),
|
||||||
|
|
||||||
DIG_SPEED(NamespaceID.from("minecraft:haste")),
|
HASTE(NamespaceID.from("minecraft:haste")),
|
||||||
|
|
||||||
DIG_SLOWDOWN(NamespaceID.from("minecraft:mining_fatigue")),
|
MINING_FATIGUE(NamespaceID.from("minecraft:mining_fatigue")),
|
||||||
|
|
||||||
DAMAGE_BOOST(NamespaceID.from("minecraft:strength")),
|
STRENGTH(NamespaceID.from("minecraft:strength")),
|
||||||
|
|
||||||
HEAL(NamespaceID.from("minecraft:instant_health")),
|
INSTANT_HEALTH(NamespaceID.from("minecraft:instant_health")),
|
||||||
|
|
||||||
HARM(NamespaceID.from("minecraft:instant_damage")),
|
INSTANT_DAMAGE(NamespaceID.from("minecraft:instant_damage")),
|
||||||
|
|
||||||
JUMP(NamespaceID.from("minecraft:jump_boost")),
|
JUMP_BOOST(NamespaceID.from("minecraft:jump_boost")),
|
||||||
|
|
||||||
CONFUSION(NamespaceID.from("minecraft:nausea")),
|
NAUSEA(NamespaceID.from("minecraft:nausea")),
|
||||||
|
|
||||||
REGENERATION(NamespaceID.from("minecraft:regeneration")),
|
REGENERATION(NamespaceID.from("minecraft:regeneration")),
|
||||||
|
|
||||||
DAMAGE_RESISTANCE(NamespaceID.from("minecraft:resistance")),
|
RESISTANCE(NamespaceID.from("minecraft:resistance")),
|
||||||
|
|
||||||
FIRE_RESISTANCE(NamespaceID.from("minecraft:fire_resistance")),
|
FIRE_RESISTANCE(NamespaceID.from("minecraft:fire_resistance")),
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -21,7 +21,7 @@ public enum StatisticType implements Keyed {
|
|||||||
|
|
||||||
TIME_SINCE_REST(NamespaceID.from("minecraft:time_since_rest")),
|
TIME_SINCE_REST(NamespaceID.from("minecraft:time_since_rest")),
|
||||||
|
|
||||||
CROUCH_TIME(NamespaceID.from("minecraft:sneak_time")),
|
SNEAK_TIME(NamespaceID.from("minecraft:sneak_time")),
|
||||||
|
|
||||||
WALK_ONE_CM(NamespaceID.from("minecraft:walk_one_cm")),
|
WALK_ONE_CM(NamespaceID.from("minecraft:walk_one_cm")),
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user