mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-14 12:11:27 +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 {
|
||||
//maven { url "https://repo.minestom.net/repository/maven-public/" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
implementation 'org.jetbrains:annotations:20.1.0'
|
||||
implementation 'com.google.code.gson:gson:2.8.7'
|
||||
implementation 'org.jetbrains:annotations:21.0.1'
|
||||
implementation 'com.squareup:javapoet:1.13.0'
|
||||
// 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.
|
||||
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.0'
|
||||
// This is the data Minestom uses. from https://github.com/Minestom/MinestomDataGenerator
|
||||
//implementation "net.minestom:minestom-data-full:${rootProject.properties.get("mcVersion")}"
|
||||
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.1'
|
||||
// Contains the json files
|
||||
implementation 'com.github.Minestom:MinestomDataGenerator:-SNAPSHOT'
|
||||
}
|
||||
|
||||
|
||||
run {
|
||||
// Update version
|
||||
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
|
||||
project.rootProject.projectDir.getPath() + "${File.separatorChar}src${File.separatorChar}autogenerated${File.separatorChar}java"
|
||||
) as List<String>
|
||||
|
@ -14,71 +14,41 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class Generators {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Generators.class);
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
if (args.length < 3) {
|
||||
LOGGER.error("Usage: <MC version> <source folder | 'resources'> <target folder>");
|
||||
public static void main(String[] args) {
|
||||
if (args.length != 1) {
|
||||
LOGGER.error("Usage: <target folder>");
|
||||
return;
|
||||
}
|
||||
String targetVersion = args[0].replace(".", "_");
|
||||
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]);
|
||||
File outputFolder = new File(args[0]);
|
||||
// Generate blocks
|
||||
new BlockGenerator(Generators.class.getResourceAsStream("/blocks.json"), outputFolder).generate();
|
||||
new BlockGenerator(resource("blocks.json"), outputFolder).generate();
|
||||
// Generate fluids
|
||||
new FluidGenerator(
|
||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_fluids.json") : new FileInputStream(new File(inputFolder, targetVersion + "_fluids.json")),
|
||||
outputFolder
|
||||
).generate();
|
||||
new FluidGenerator(resource("fluids.json"), outputFolder).generate();
|
||||
// Generate entities
|
||||
new EntityTypeGenerator(
|
||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_entities.json") : new FileInputStream(new File(inputFolder, targetVersion + "_entities.json")),
|
||||
outputFolder
|
||||
).generate();
|
||||
new EntityTypeGenerator(resource("entities.json"), outputFolder).generate();
|
||||
// Generate items
|
||||
new MaterialGenerator(
|
||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_items.json") : new FileInputStream(new File(inputFolder, targetVersion + "_items.json")),
|
||||
outputFolder
|
||||
).generate();
|
||||
new MaterialGenerator(resource("items.json"), outputFolder).generate();
|
||||
// Generate enchantments
|
||||
new EnchantmentGenerator(
|
||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_enchantments.json") : new FileInputStream(new File(inputFolder, targetVersion + "_enchantments.json")),
|
||||
outputFolder
|
||||
).generate();
|
||||
new EnchantmentGenerator(resource("enchantments.json"), outputFolder).generate();
|
||||
// TODO: Generate attributes
|
||||
// new AttributeGenerator(
|
||||
// new File(inputFolder, targetVersion + "_attributes.json"),
|
||||
// outputFolder
|
||||
// ).generate();
|
||||
// Generate potion effects
|
||||
new PotionEffectGenerator(
|
||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_potion_effects.json") : new FileInputStream(new File(inputFolder, targetVersion + "_potion_effects.json")),
|
||||
outputFolder
|
||||
).generate();
|
||||
new PotionEffectGenerator(resource("potion_effects.json"), outputFolder).generate();
|
||||
// Generate potions
|
||||
new PotionTypeGenerator(
|
||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_potions.json") : new FileInputStream(new File(inputFolder, targetVersion + "_potions.json")),
|
||||
outputFolder
|
||||
).generate();
|
||||
new PotionTypeGenerator(resource("potions.json"), outputFolder).generate();
|
||||
// Generate particles
|
||||
new ParticleGenerator(
|
||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_particles.json") : new FileInputStream(new File(inputFolder, targetVersion + "_particles.json")),
|
||||
outputFolder
|
||||
).generate();
|
||||
new ParticleGenerator(resource("particles.json"), outputFolder).generate();
|
||||
// Generate sounds
|
||||
new SoundEventGenerator(
|
||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_sounds.json") : new FileInputStream(new File(inputFolder, targetVersion + "_sounds.json")),
|
||||
outputFolder
|
||||
).generate();
|
||||
new SoundEventGenerator(resource("sounds.json"), outputFolder).generate();
|
||||
// TODO: Generate villager professions
|
||||
// new VillagerProfessionGenerator(
|
||||
// new File(inputFolder, targetVersion + "_villager_professions.json"),
|
||||
@ -90,10 +60,11 @@ public class Generators {
|
||||
// outputFolder
|
||||
// ).generate();
|
||||
// Generate statistics
|
||||
new StatisticGenerator(
|
||||
resourceMode ? Generators.class.getResourceAsStream("/" + targetVersion + "_custom_statistics.json") : new FileInputStream(new File(inputFolder, targetVersion + "_custom_statistics.json")),
|
||||
outputFolder
|
||||
).generate();
|
||||
new StatisticGenerator(resource("custom_statistics.json"), outputFolder).generate();
|
||||
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.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public abstract class MinestomCodeGenerator {
|
||||
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 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");
|
||||
|
||||
// Particle
|
||||
@ -376,13 +376,14 @@ public final class EntityTypeGenerator extends MinestomCodeGenerator {
|
||||
.build()
|
||||
);
|
||||
// Use data
|
||||
for (JsonElement e : entities) {
|
||||
JsonObject entity = e.getAsJsonObject();
|
||||
entities.entrySet().forEach(entry -> {
|
||||
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)
|
||||
String metaClassName = NameUtil.convertSnakeCaseToCamelCase(entityName.toLowerCase());
|
||||
String metaClassName = NameUtil.convertSnakeCaseToCamelCase(entityConstant.toLowerCase());
|
||||
switch (metaClassName) {
|
||||
// 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.
|
||||
@ -408,18 +409,18 @@ public final class EntityTypeGenerator extends MinestomCodeGenerator {
|
||||
String packageName = metadata.get(metaClassName);
|
||||
String className = metaClassName + "Meta";
|
||||
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.");
|
||||
packageName = "net.minestom.server.entity.metadata";
|
||||
className = "EntityMeta";
|
||||
}
|
||||
|
||||
entityClass.addEnumConstant(
|
||||
entityName,
|
||||
entityConstant,
|
||||
TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S), $L, $L, $T::new, $T.$N",
|
||||
namespaceIDClassName,
|
||||
entity.get("id").getAsString(),
|
||||
entityNamespace,
|
||||
entity.get("width").getAsDouble(),
|
||||
entity.get("height").getAsDouble(),
|
||||
ClassName.get(packageName, className),
|
||||
@ -427,7 +428,7 @@ public final class EntityTypeGenerator extends MinestomCodeGenerator {
|
||||
entity.get("packetType").getAsString().toUpperCase()
|
||||
).build()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Write files to outputFolder
|
||||
writeFiles(
|
||||
|
@ -1,7 +1,5 @@
|
||||
package net.minestom.codegen.fluid;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.squareup.javapoet.*;
|
||||
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 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");
|
||||
|
||||
// Particle
|
||||
@ -122,18 +120,15 @@ public final class FluidGenerator extends MinestomCodeGenerator {
|
||||
);
|
||||
|
||||
// Use data
|
||||
for (JsonElement f : fluids) {
|
||||
JsonObject fluid = f.getAsJsonObject();
|
||||
|
||||
String fluidName = fluid.get("name").getAsString();
|
||||
|
||||
fluidClass.addEnumConstant(fluidName, TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
fluid.get("id").getAsString()
|
||||
fluids.entrySet().forEach(entry -> {
|
||||
final String fluidName = entry.getKey();
|
||||
fluidClass.addEnumConstant(toConstant(fluidName), TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
fluidName
|
||||
).build()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Write files to outputFolder
|
||||
writeFiles(
|
||||
|
@ -41,7 +41,7 @@ public final class EnchantmentGenerator extends MinestomCodeGenerator {
|
||||
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
||||
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");
|
||||
|
||||
// Enchantment
|
||||
@ -121,17 +121,16 @@ public final class EnchantmentGenerator extends MinestomCodeGenerator {
|
||||
);
|
||||
|
||||
// Use data
|
||||
for (JsonElement e : enchantments) {
|
||||
JsonObject enchantment = e.getAsJsonObject();
|
||||
|
||||
String enchantmentName = enchantment.get("name").getAsString();
|
||||
enchantmentClass.addEnumConstant(enchantmentName, TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
enchantment.get("id").getAsString()
|
||||
enchantments.entrySet().forEach(entry -> {
|
||||
final String enchantmentNamespace = entry.getKey();
|
||||
final String enchantmentConstant = toConstant(enchantmentNamespace);
|
||||
enchantmentClass.addEnumConstant(enchantmentConstant, TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
enchantmentNamespace
|
||||
).build()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Write files to outputFolder
|
||||
|
@ -40,11 +40,12 @@ public final class MaterialGenerator extends MinestomCodeGenerator {
|
||||
}
|
||||
// Important classes we use alot
|
||||
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 blockCN = ClassName.get("net.minestom.server.instance.block", "Block");
|
||||
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");
|
||||
|
||||
// Item
|
||||
@ -232,26 +233,28 @@ public final class MaterialGenerator extends MinestomCodeGenerator {
|
||||
);
|
||||
|
||||
// Use data
|
||||
for (JsonElement i : items) {
|
||||
JsonObject item = i.getAsJsonObject();
|
||||
items.entrySet().forEach(entry -> {
|
||||
final String itemNamespace = entry.getKey();
|
||||
final String itemConstant = toConstant(itemNamespace);
|
||||
|
||||
JsonObject item = entry.getValue().getAsJsonObject();
|
||||
|
||||
String itemName = item.get("name").getAsString();
|
||||
TypeSpec.Builder enumConst;
|
||||
if (!(item.get("blockId").getAsString().equals("minecraft:air"))) {
|
||||
enumConst = TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S), (byte) $L, () -> $T.getBlock($S)",
|
||||
"$T.from($S), (byte) $L, () -> $T.$L",
|
||||
namespaceIDClassName,
|
||||
item.get("id").getAsString(),
|
||||
itemNamespace,
|
||||
item.get("maxStackSize").getAsInt(),
|
||||
// Supplier
|
||||
registriesClassName,
|
||||
item.get("blockId").getAsString()
|
||||
blockClassName,
|
||||
toConstant(item.get("blockId").getAsString())
|
||||
);
|
||||
} else {
|
||||
enumConst = TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S), (byte) $L, () -> null",
|
||||
namespaceIDClassName,
|
||||
item.get("id").getAsString(),
|
||||
itemNamespace,
|
||||
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
|
||||
writeFiles(
|
||||
|
@ -1,7 +1,5 @@
|
||||
package net.minestom.codegen.particle;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.squareup.javapoet.*;
|
||||
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 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");
|
||||
|
||||
// Particle
|
||||
@ -121,17 +119,15 @@ public final class ParticleGenerator extends MinestomCodeGenerator {
|
||||
);
|
||||
|
||||
// Use data
|
||||
for (JsonElement p : particles) {
|
||||
JsonObject particle = p.getAsJsonObject();
|
||||
|
||||
String particleName = particle.get("name").getAsString();
|
||||
|
||||
particleClass.addEnumConstant(particleName, TypeSpec.anonymousClassBuilder(
|
||||
particles.entrySet().forEach(entry -> {
|
||||
final String particleNamespace = entry.getKey();
|
||||
final String particleConstant = toConstant(particleNamespace);
|
||||
particleClass.addEnumConstant(particleConstant, TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
particle.get("id").getAsString()
|
||||
particleNamespace
|
||||
).build());
|
||||
}
|
||||
});
|
||||
|
||||
// Write files to outputFolder
|
||||
writeFiles(
|
||||
|
@ -1,7 +1,5 @@
|
||||
package net.minestom.codegen.potion;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.squareup.javapoet.*;
|
||||
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 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");
|
||||
|
||||
// Particle
|
||||
@ -121,18 +119,16 @@ public final class PotionEffectGenerator extends MinestomCodeGenerator {
|
||||
);
|
||||
|
||||
// Use data
|
||||
for (JsonElement pe : potionEffects) {
|
||||
JsonObject potionEffect = pe.getAsJsonObject();
|
||||
|
||||
String potionEffectName = potionEffect.get("name").getAsString();
|
||||
|
||||
potionEffectClass.addEnumConstant(potionEffectName, TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
potionEffect.get("id").getAsString()
|
||||
potionEffects.entrySet().forEach(entry -> {
|
||||
final String potionEffectNamespace = entry.getKey();
|
||||
final String potionEffectConstant = toConstant(potionEffectNamespace);
|
||||
potionEffectClass.addEnumConstant(potionEffectConstant, TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
potionEffectNamespace
|
||||
).build()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Write files to outputFolder
|
||||
writeFiles(
|
||||
|
@ -41,7 +41,7 @@ public final class PotionTypeGenerator extends MinestomCodeGenerator {
|
||||
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
|
||||
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");
|
||||
|
||||
// Particle
|
||||
@ -121,18 +121,16 @@ public final class PotionTypeGenerator extends MinestomCodeGenerator {
|
||||
);
|
||||
|
||||
// Use data
|
||||
for (JsonElement p : potions) {
|
||||
JsonObject potion = p.getAsJsonObject();
|
||||
|
||||
String potionName = potion.get("name").getAsString();
|
||||
|
||||
potionTypeClass.addEnumConstant(potionName, TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
potion.get("id").getAsString()
|
||||
potions.entrySet().forEach(entry -> {
|
||||
final String potionNamespace = entry.getKey();
|
||||
final String potionConstant = toConstant(potionNamespace);
|
||||
potionTypeClass.addEnumConstant(potionConstant, TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
potionNamespace
|
||||
).build()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Write files to outputFolder
|
||||
writeFiles(
|
||||
|
@ -1,7 +1,5 @@
|
||||
package net.minestom.codegen.sound;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.squareup.javapoet.*;
|
||||
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 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");
|
||||
// Sound
|
||||
TypeSpec.Builder soundClass = TypeSpec.enumBuilder(soundClassName)
|
||||
@ -121,17 +119,16 @@ public final class SoundEventGenerator extends MinestomCodeGenerator {
|
||||
);
|
||||
|
||||
// Use data
|
||||
for (JsonElement s : sounds) {
|
||||
JsonObject sound = s.getAsJsonObject();
|
||||
|
||||
String soundName = sound.get("name").getAsString();
|
||||
soundClass.addEnumConstant(soundName, TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
sound.get("id").getAsString()
|
||||
sounds.entrySet().forEach(entry -> {
|
||||
final String soundNamespace = entry.getKey();
|
||||
final String soundConstant = toConstant(soundNamespace).replace(".", "_");
|
||||
soundClass.addEnumConstant(soundConstant, TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
soundNamespace
|
||||
).build()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Write files to outputFolder
|
||||
writeFiles(
|
||||
|
@ -1,7 +1,5 @@
|
||||
package net.minestom.codegen.statistics;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.squareup.javapoet.*;
|
||||
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 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");
|
||||
|
||||
// Particle
|
||||
@ -121,18 +119,16 @@ public final class StatisticGenerator extends MinestomCodeGenerator {
|
||||
);
|
||||
|
||||
// Use data
|
||||
for (JsonElement s : statistics) {
|
||||
JsonObject statistic = s.getAsJsonObject();
|
||||
|
||||
String statisticName = statistic.get("name").getAsString();
|
||||
|
||||
statisticClass.addEnumConstant(statisticName, TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
statistic.get("id").getAsString()
|
||||
statistics.entrySet().forEach(entry -> {
|
||||
final String statisticNamespace = entry.getKey();
|
||||
final String statisticConstant = toConstant(statisticNamespace);
|
||||
statisticClass.addEnumConstant(statisticConstant, TypeSpec.anonymousClassBuilder(
|
||||
"$T.from($S)",
|
||||
namespaceIDClassName,
|
||||
statisticNamespace
|
||||
).build()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Write files to outputFolder
|
||||
writeFiles(
|
||||
|
@ -11,11 +11,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
* AUTOGENERATED by EnchantmentGenerator
|
||||
*/
|
||||
public enum Enchantment implements Keyed {
|
||||
ALL_DAMAGE_PROTECTION(NamespaceID.from("minecraft:protection")),
|
||||
PROTECTION(NamespaceID.from("minecraft: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")),
|
||||
|
||||
@ -45,29 +45,29 @@ public enum Enchantment implements Keyed {
|
||||
|
||||
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")),
|
||||
|
||||
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")),
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -11,27 +11,27 @@ import org.jetbrains.annotations.Nullable;
|
||||
* AUTOGENERATED by PotionEffectGenerator
|
||||
*/
|
||||
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")),
|
||||
|
||||
DAMAGE_RESISTANCE(NamespaceID.from("minecraft:resistance")),
|
||||
RESISTANCE(NamespaceID.from("minecraft: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")),
|
||||
|
||||
CROUCH_TIME(NamespaceID.from("minecraft:sneak_time")),
|
||||
SNEAK_TIME(NamespaceID.from("minecraft:sneak_time")),
|
||||
|
||||
WALK_ONE_CM(NamespaceID.from("minecraft:walk_one_cm")),
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user