Replace most enums

This commit is contained in:
TheMode 2021-07-28 14:29:28 +02:00
parent fa8bab8191
commit 13b7039721
57 changed files with 3536 additions and 4095 deletions

View File

@ -164,7 +164,7 @@ dependencies {
}
api "com.github.Minestom:DependencyGetter:v1.0.1"
implementation 'com.github.Minestom:MinestomDataGenerator:3d2d73e383'
implementation 'com.github.Minestom:MinestomDataGenerator:0e935a91e6'
// Adventure, for user-interface
api "net.kyori:adventure-api:$adventureVersion"

View File

@ -45,7 +45,10 @@ public class CodeGenerator {
// Use data
json.keySet().forEach(namespace -> {
final String constantName = namespace.replace("minecraft:", "").toUpperCase(Locale.ROOT);
final String constantName = namespace
.replace("minecraft:", "")
.replace(".", "_")
.toUpperCase(Locale.ROOT);
blockConstantsClass.addField(
FieldSpec.builder(typeClass, constantName)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)

View File

@ -1,11 +1,6 @@
package net.minestom.codegen;
import net.minestom.codegen.fluid.FluidGenerator;
import net.minestom.codegen.particle.ParticleGenerator;
import net.minestom.codegen.potion.PotionEffectGenerator;
import net.minestom.codegen.potion.PotionTypeGenerator;
import net.minestom.codegen.sound.SoundEventGenerator;
import net.minestom.codegen.statistics.StatisticGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -26,9 +21,11 @@ public class Generators {
generator.generate(resource("items.json"), "net.minestom.server.item", "Material", "MaterialLoader", "MaterialConstants");
generator.generate(resource("entities.json"), "net.minestom.server.entity", "EntityType", "EntityTypeLoader", "EntityTypeConstants");
generator.generate(resource("enchantments.json"), "net.minestom.server.item", "Enchantment", "EnchantmentLoader", "EnchantmentConstants");
if (true)
return; // TODO complete
generator.generate(resource("potion_effects.json"), "net.minestom.server.potion", "PotionEffect", "PotionEffectLoader", "PotionEffectConstants");
generator.generate(resource("potions.json"), "net.minestom.server.potion", "PotionType", "PotionTypeLoader", "PotionTypeConstants");
generator.generate(resource("particles.json"), "net.minestom.server.particle", "Particle", "ParticleLoader", "ParticleConstants");
generator.generate(resource("sounds.json"), "net.minestom.server.sound", "SoundEvent", "SoundEventLoader", "SoundEventConstants");
generator.generate(resource("custom_statistics.json"), "net.minestom.server.statistic", "StatisticType", "StatisticTypeLoader", "StatisticTypeConstants");
// Generate fluids
new FluidGenerator(resource("fluids.json"), outputFolder).generate();
@ -37,14 +34,6 @@ public class Generators {
// new File(inputFolder, targetVersion + "_attributes.json"),
// outputFolder
// ).generate();
// Generate potion effects
new PotionEffectGenerator(resource("potion_effects.json"), outputFolder).generate();
// Generate potions
new PotionTypeGenerator(resource("potions.json"), outputFolder).generate();
// Generate particles
new ParticleGenerator(resource("particles.json"), outputFolder).generate();
// Generate sounds
new SoundEventGenerator(resource("sounds.json"), outputFolder).generate();
// TODO: Generate villager professions
// new VillagerProfessionGenerator(
// new File(inputFolder, targetVersion + "_villager_professions.json"),
@ -55,8 +44,6 @@ public class Generators {
// new File(inputFolder, targetVersion + "_villager_types.json"),
// outputFolder
// ).generate();
// Generate statistics
new StatisticGenerator(resource("custom_statistics.json"), outputFolder).generate();
LOGGER.info("Finished generating code");
}

View File

@ -1,143 +0,0 @@
package net.minestom.codegen.particle;
import com.google.gson.JsonObject;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
public final class ParticleGenerator extends MinestomCodeGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(ParticleGenerator.class);
private final InputStream particlesFile;
private final File outputFolder;
public ParticleGenerator(@Nullable InputStream particlesFile, @NotNull File outputFolder) {
this.particlesFile = particlesFile;
this.outputFolder = outputFolder;
}
@Override
public void generate() {
if (particlesFile == null) {
LOGGER.error("Failed to find particles.json.");
LOGGER.error("Stopped code generation for particles.");
return;
}
if (!outputFolder.exists() && !outputFolder.mkdirs()) {
LOGGER.error("Output folder for code generation does not exist and could not be created.");
return;
}
// Important classes we use alot
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
JsonObject particles = GSON.fromJson(new InputStreamReader(particlesFile), JsonObject.class);
ClassName particleClassName = ClassName.get("net.minestom.server.particle", "Particle");
// Particle
TypeSpec.Builder particleClass = TypeSpec.enumBuilder(particleClassName)
.addSuperinterface(ClassName.get("net.kyori.adventure.key", "Keyed"))
.addModifiers(Modifier.PUBLIC).addJavadoc("AUTOGENERATED by " + getClass().getSimpleName());
particleClass.addField(
FieldSpec.builder(namespaceIDClassName, "id")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).addAnnotation(NotNull.class).build()
);
// static field
particleClass.addField(
FieldSpec.builder(ArrayTypeName.of(particleClassName), "VALUES")
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
.initializer("values()")
.build()
);
particleClass.addMethod(
MethodSpec.constructorBuilder()
.addParameter(ParameterSpec.builder(namespaceIDClassName, "id").addAnnotation(NotNull.class).build())
.addStatement("this.id = id")
.addStatement("$T.particles.put(id, this)", registriesClassName)
.build()
);
// Override key method (adventure)
particleClass.addMethod(
MethodSpec.methodBuilder("key")
.returns(ClassName.get("net.kyori.adventure.key", "Key"))
.addAnnotation(Override.class)
.addAnnotation(NotNull.class)
.addStatement("return this.id")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getId method
particleClass.addMethod(
MethodSpec.methodBuilder("getId")
.returns(TypeName.SHORT)
.addStatement("return (short) ordinal()")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getNamespaceID method
particleClass.addMethod(
MethodSpec.methodBuilder("getNamespaceID")
.returns(namespaceIDClassName)
.addAnnotation(NotNull.class)
.addStatement("return this.id")
.addModifiers(Modifier.PUBLIC)
.build()
);
// fromId Method
particleClass.addMethod(
MethodSpec.methodBuilder("fromId")
.returns(particleClassName)
.addAnnotation(Nullable.class)
.addParameter(TypeName.SHORT, "id")
.beginControlFlow("if(id >= 0 && id < VALUES.length)")
.addStatement("return VALUES[id]")
.endControlFlow()
.addStatement("return null")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.build()
);
// toString method
particleClass.addMethod(
MethodSpec.methodBuilder("toString")
.addAnnotation(NotNull.class)
.addAnnotation(Override.class)
.returns(String.class)
// this resolves to [Namespace]
.addStatement("return \"[\" + this.id + \"]\"")
.addModifiers(Modifier.PUBLIC)
.build()
);
// Use data
particles.entrySet().forEach(entry -> {
final String particleNamespace = entry.getKey();
final String particleConstant = toConstant(particleNamespace);
particleClass.addEnumConstant(particleConstant, TypeSpec.anonymousClassBuilder(
"$T.from($S)",
namespaceIDClassName,
particleNamespace
).build());
});
// Write files to outputFolder
writeFiles(
Collections.singletonList(
JavaFile.builder("net.minestom.server.particle", particleClass.build())
.indent(" ")
.skipJavaLangImports(true)
.build()
),
outputFolder
);
}
}

View File

@ -1,144 +0,0 @@
package net.minestom.codegen.potion;
import com.google.gson.JsonObject;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
public final class PotionEffectGenerator extends MinestomCodeGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(PotionEffectGenerator.class);
private final InputStream potionEffectsFile;
private final File outputFolder;
public PotionEffectGenerator(@Nullable InputStream potionEffectsFile, @NotNull File outputFolder) {
this.potionEffectsFile = potionEffectsFile;
this.outputFolder = outputFolder;
}
@Override
public void generate() {
if (potionEffectsFile == null) {
LOGGER.error("Failed to find potionEffects.json.");
LOGGER.error("Stopped code generation for potion effects.");
return;
}
if (!outputFolder.exists() && !outputFolder.mkdirs()) {
LOGGER.error("Output folder for code generation does not exist and could not be created.");
return;
}
// Important classes we use alot
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
JsonObject potionEffects = GSON.fromJson(new InputStreamReader(potionEffectsFile), JsonObject.class);
ClassName potionEffectClassName = ClassName.get("net.minestom.server.potion", "PotionEffect");
// Particle
TypeSpec.Builder potionEffectClass = TypeSpec.enumBuilder(potionEffectClassName)
.addSuperinterface(ClassName.get("net.kyori.adventure.key", "Keyed"))
.addModifiers(Modifier.PUBLIC).addJavadoc("AUTOGENERATED by " + getClass().getSimpleName());
potionEffectClass.addField(
FieldSpec.builder(namespaceIDClassName, "id")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).addAnnotation(NotNull.class).build()
);
// static field
potionEffectClass.addField(
FieldSpec.builder(ArrayTypeName.of(potionEffectClassName), "VALUES")
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
.initializer("values()")
.build()
);
potionEffectClass.addMethod(
MethodSpec.constructorBuilder()
.addParameter(ParameterSpec.builder(namespaceIDClassName, "id").addAnnotation(NotNull.class).build())
.addStatement("this.id = id")
.addStatement("$T.potionEffects.put(id, this)", registriesClassName)
.build()
);
// Override key method (adventure)
potionEffectClass.addMethod(
MethodSpec.methodBuilder("key")
.returns(ClassName.get("net.kyori.adventure.key", "Key"))
.addAnnotation(Override.class)
.addAnnotation(NotNull.class)
.addStatement("return this.id")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getId method
potionEffectClass.addMethod(
MethodSpec.methodBuilder("getId")
.returns(TypeName.SHORT)
.addStatement("return (short) (ordinal() + 1)")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getNamespaceID method
potionEffectClass.addMethod(
MethodSpec.methodBuilder("getNamespaceID")
.returns(namespaceIDClassName)
.addAnnotation(NotNull.class)
.addStatement("return this.id")
.addModifiers(Modifier.PUBLIC)
.build()
);
// fromId Method
potionEffectClass.addMethod(
MethodSpec.methodBuilder("fromId")
.returns(potionEffectClassName)
.addAnnotation(Nullable.class)
.addParameter(TypeName.SHORT, "id")
.beginControlFlow("if(id >= 1 && id < VALUES.length + 1)")
.addStatement("return VALUES[id - 1]")
.endControlFlow()
.addStatement("return null")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.build()
);
// toString method
potionEffectClass.addMethod(
MethodSpec.methodBuilder("toString")
.addAnnotation(NotNull.class)
.addAnnotation(Override.class)
.returns(String.class)
// this resolves to [Namespace]
.addStatement("return \"[\" + this.id + \"]\"")
.addModifiers(Modifier.PUBLIC)
.build()
);
// Use data
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(
Collections.singletonList(
JavaFile.builder("net.minestom.server.potion", potionEffectClass.build())
.indent(" ")
.skipJavaLangImports(true)
.build()
),
outputFolder
);
}
}

View File

@ -1,146 +0,0 @@
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;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
public final class PotionTypeGenerator extends MinestomCodeGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(PotionTypeGenerator.class);
private final InputStream potionsFile;
private final File outputFolder;
public PotionTypeGenerator(@Nullable InputStream potionsFile, @NotNull File outputFolder) {
this.potionsFile = potionsFile;
this.outputFolder = outputFolder;
}
@Override
public void generate() {
if (potionsFile == null) {
LOGGER.error("Failed to find potions.json.");
LOGGER.error("Stopped code generation for potions.");
return;
}
if (!outputFolder.exists() && !outputFolder.mkdirs()) {
LOGGER.error("Output folder for code generation does not exist and could not be created.");
return;
}
// Important classes we use alot
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
JsonObject potions = GSON.fromJson(new InputStreamReader(potionsFile), JsonObject.class);
ClassName potionTypeClassName = ClassName.get("net.minestom.server.potion", "PotionType");
// Particle
TypeSpec.Builder potionTypeClass = TypeSpec.enumBuilder(potionTypeClassName)
.addSuperinterface(ClassName.get("net.kyori.adventure.key", "Keyed"))
.addModifiers(Modifier.PUBLIC).addJavadoc("AUTOGENERATED by " + getClass().getSimpleName());
potionTypeClass.addField(
FieldSpec.builder(namespaceIDClassName, "id")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).addAnnotation(NotNull.class).build()
);
// static field
potionTypeClass.addField(
FieldSpec.builder(ArrayTypeName.of(potionTypeClassName), "VALUES")
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
.initializer("values()")
.build()
);
potionTypeClass.addMethod(
MethodSpec.constructorBuilder()
.addParameter(ParameterSpec.builder(namespaceIDClassName, "id").addAnnotation(NotNull.class).build())
.addStatement("this.id = id")
.addStatement("$T.potionTypes.put(id, this)", registriesClassName)
.build()
);
// Override key method (adventure)
potionTypeClass.addMethod(
MethodSpec.methodBuilder("key")
.returns(ClassName.get("net.kyori.adventure.key", "Key"))
.addAnnotation(Override.class)
.addAnnotation(NotNull.class)
.addStatement("return this.id")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getId method
potionTypeClass.addMethod(
MethodSpec.methodBuilder("getId")
.returns(TypeName.SHORT)
.addStatement("return (short) ordinal()")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getNamespaceID method
potionTypeClass.addMethod(
MethodSpec.methodBuilder("getNamespaceID")
.returns(namespaceIDClassName)
.addAnnotation(NotNull.class)
.addStatement("return this.id")
.addModifiers(Modifier.PUBLIC)
.build()
);
// fromId Method
potionTypeClass.addMethod(
MethodSpec.methodBuilder("fromId")
.returns(potionTypeClassName)
.addAnnotation(Nullable.class)
.addParameter(TypeName.SHORT, "id")
.beginControlFlow("if(id >= 0 && id < VALUES.length)")
.addStatement("return VALUES[id]")
.endControlFlow()
.addStatement("return null")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.build()
);
// toString method
potionTypeClass.addMethod(
MethodSpec.methodBuilder("toString")
.addAnnotation(NotNull.class)
.addAnnotation(Override.class)
.returns(String.class)
// this resolves to [Namespace]
.addStatement("return \"[\" + this.id + \"]\"")
.addModifiers(Modifier.PUBLIC)
.build()
);
// Use data
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(
Collections.singletonList(
JavaFile.builder("net.minestom.server.potion", potionTypeClass.build())
.indent(" ")
.skipJavaLangImports(true)
.build()
),
outputFolder
);
}
}

View File

@ -1,144 +0,0 @@
package net.minestom.codegen.sound;
import com.google.gson.JsonObject;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
public final class SoundEventGenerator extends MinestomCodeGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(SoundEventGenerator.class);
private final InputStream soundsFile;
private final File outputFolder;
public SoundEventGenerator(@Nullable InputStream itemsFile, @NotNull File outputFolder) {
this.soundsFile = itemsFile;
this.outputFolder = outputFolder;
}
@Override
public void generate() {
if (soundsFile == null) {
LOGGER.error("Failed to find sounds.json.");
LOGGER.error("Stopped code generation for sounds.");
return;
}
if (!outputFolder.exists() && !outputFolder.mkdirs()) {
LOGGER.error("Output folder for code generation does not exist and could not be created.");
return;
}
// Important classes we use alot
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
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)
.addSuperinterface(ClassName.get("net.kyori.adventure.key", "Keyed"))
.addSuperinterface(ClassName.get("net.kyori.adventure.sound", "Sound", "Type"))
.addModifiers(Modifier.PUBLIC).addJavadoc("AUTOGENERATED by " + getClass().getSimpleName());
soundClass.addField(
FieldSpec.builder(namespaceIDClassName, "id")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).addAnnotation(NotNull.class).build()
);
// static field
soundClass.addField(
FieldSpec.builder(ArrayTypeName.of(soundClassName), "VALUES")
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
.initializer("values()")
.build()
);
soundClass.addMethod(
MethodSpec.constructorBuilder()
.addParameter(ParameterSpec.builder(namespaceIDClassName, "id").addAnnotation(NotNull.class).build())
.addStatement("this.id = id")
.addStatement("$T.soundEvents.put(id, this)", registriesClassName)
.build()
);
// Override key method (adventure)
soundClass.addMethod(
MethodSpec.methodBuilder("key")
.returns(ClassName.get("net.kyori.adventure.key", "Key"))
.addAnnotation(Override.class)
.addAnnotation(NotNull.class)
.addStatement("return this.id")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getId method
soundClass.addMethod(
MethodSpec.methodBuilder("getId")
.returns(TypeName.SHORT)
.addStatement("return (short) ordinal()")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getNamespaceID method
soundClass.addMethod(
MethodSpec.methodBuilder("getNamespaceID")
.returns(namespaceIDClassName)
.addAnnotation(NotNull.class)
.addStatement("return this.id")
.addModifiers(Modifier.PUBLIC)
.build()
);
// fromId Method
soundClass.addMethod(
MethodSpec.methodBuilder("fromId")
.returns(soundClassName)
.addAnnotation(Nullable.class)
.addParameter(TypeName.SHORT, "id")
.beginControlFlow("if(id >= 0 && id < VALUES.length)")
.addStatement("return VALUES[id]")
.endControlFlow()
.addStatement("return null")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.build()
);
// toString method
soundClass.addMethod(
MethodSpec.methodBuilder("toString")
.addAnnotation(NotNull.class)
.addAnnotation(Override.class)
.returns(String.class)
// this resolves to [Namespace]
.addStatement("return \"[\" + this.id + \"]\"")
.addModifiers(Modifier.PUBLIC)
.build()
);
// Use data
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(
Collections.singletonList(
JavaFile.builder("net.minestom.server.sound", soundClass.build())
.indent(" ")
.skipJavaLangImports(true)
.build()
),
outputFolder
);
}
}

View File

@ -1,144 +0,0 @@
package net.minestom.codegen.statistics;
import com.google.gson.JsonObject;
import com.squareup.javapoet.*;
import net.minestom.codegen.MinestomCodeGenerator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.lang.model.element.Modifier;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
public final class StatisticGenerator extends MinestomCodeGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(StatisticGenerator.class);
private final InputStream statisticsFile;
private final File outputFolder;
public StatisticGenerator(@Nullable InputStream statisticsFile, @NotNull File outputFolder) {
this.statisticsFile = statisticsFile;
this.outputFolder = outputFolder;
}
@Override
public void generate() {
if (statisticsFile == null) {
LOGGER.error("Failed to find statistics.json.");
LOGGER.error("Stopped code generation for statistics.");
return;
}
if (!outputFolder.exists() && !outputFolder.mkdirs()) {
LOGGER.error("Output folder for code generation does not exist and could not be created.");
return;
}
// Important classes we use alot
ClassName namespaceIDClassName = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName registriesClassName = ClassName.get("net.minestom.server.registry", "Registries");
JsonObject statistics = GSON.fromJson(new InputStreamReader(statisticsFile), JsonObject.class);
ClassName statisticClassName = ClassName.get("net.minestom.server.statistic", "StatisticType");
// Particle
TypeSpec.Builder statisticClass = TypeSpec.enumBuilder(statisticClassName)
.addSuperinterface(ClassName.get("net.kyori.adventure.key", "Keyed"))
.addModifiers(Modifier.PUBLIC).addJavadoc("AUTOGENERATED by " + getClass().getSimpleName());
statisticClass.addField(
FieldSpec.builder(namespaceIDClassName, "id")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).addAnnotation(NotNull.class).build()
);
// static field
statisticClass.addField(
FieldSpec.builder(ArrayTypeName.of(statisticClassName), "VALUES")
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
.initializer("values()")
.build()
);
statisticClass.addMethod(
MethodSpec.constructorBuilder()
.addParameter(ParameterSpec.builder(namespaceIDClassName, "id").addAnnotation(NotNull.class).build())
.addStatement("this.id = id")
.addStatement("$T.statisticTypes.put(id, this)", registriesClassName)
.build()
);
// Override key method (adventure)
statisticClass.addMethod(
MethodSpec.methodBuilder("key")
.returns(ClassName.get("net.kyori.adventure.key", "Key"))
.addAnnotation(Override.class)
.addAnnotation(NotNull.class)
.addStatement("return this.id")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getId method
statisticClass.addMethod(
MethodSpec.methodBuilder("getId")
.returns(TypeName.SHORT)
.addStatement("return (short) ordinal()")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getNamespaceID method
statisticClass.addMethod(
MethodSpec.methodBuilder("getNamespaceID")
.returns(namespaceIDClassName)
.addAnnotation(NotNull.class)
.addStatement("return this.id")
.addModifiers(Modifier.PUBLIC)
.build()
);
// fromId Method
statisticClass.addMethod(
MethodSpec.methodBuilder("fromId")
.returns(statisticClassName)
.addAnnotation(Nullable.class)
.addParameter(TypeName.SHORT, "id")
.beginControlFlow("if(id >= 0 && id < VALUES.length)")
.addStatement("return VALUES[id]")
.endControlFlow()
.addStatement("return null")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.build()
);
// toString method
statisticClass.addMethod(
MethodSpec.methodBuilder("toString")
.addAnnotation(NotNull.class)
.addAnnotation(Override.class)
.returns(String.class)
// this resolves to [Namespace]
.addStatement("return \"[\" + this.id + \"]\"")
.addModifiers(Modifier.PUBLIC)
.build()
);
// Use data
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(
Collections.singletonList(
JavaFile.builder("net.minestom.server.statistic", statisticClass.build())
.indent(" ")
.skipJavaLangImports(true)
.build()
),
outputFolder
);
}
}

View File

@ -1,21 +0,0 @@
package net.minestom.codegen.util;
public final class NameUtil {
private NameUtil() {
}
public static String convertSnakeCaseToCamelCase(String snakeCase) {
StringBuilder sb = new StringBuilder(snakeCase);
for (int i = 0; i < sb.length(); i++) {
if (sb.charAt(i) == '_') {
sb.deleteCharAt(i);
sb.replace(i, i + 1, String.valueOf(Character.toUpperCase(sb.charAt(i))));
}
}
// Capitalize first letter.
sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
return sb.toString();
}
}

View File

@ -1,230 +0,0 @@
package net.minestom.server.particle;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.Keyed;
import net.minestom.server.registry.Registries;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* AUTOGENERATED by ParticleGenerator
*/
public enum Particle implements Keyed {
AMBIENT_ENTITY_EFFECT(NamespaceID.from("minecraft:ambient_entity_effect")),
ANGRY_VILLAGER(NamespaceID.from("minecraft:angry_villager")),
BARRIER(NamespaceID.from("minecraft:barrier")),
LIGHT(NamespaceID.from("minecraft:light")),
BLOCK(NamespaceID.from("minecraft:block")),
BUBBLE(NamespaceID.from("minecraft:bubble")),
CLOUD(NamespaceID.from("minecraft:cloud")),
CRIT(NamespaceID.from("minecraft:crit")),
DAMAGE_INDICATOR(NamespaceID.from("minecraft:damage_indicator")),
DRAGON_BREATH(NamespaceID.from("minecraft:dragon_breath")),
DRIPPING_LAVA(NamespaceID.from("minecraft:dripping_lava")),
FALLING_LAVA(NamespaceID.from("minecraft:falling_lava")),
LANDING_LAVA(NamespaceID.from("minecraft:landing_lava")),
DRIPPING_WATER(NamespaceID.from("minecraft:dripping_water")),
FALLING_WATER(NamespaceID.from("minecraft:falling_water")),
DUST(NamespaceID.from("minecraft:dust")),
DUST_COLOR_TRANSITION(NamespaceID.from("minecraft:dust_color_transition")),
EFFECT(NamespaceID.from("minecraft:effect")),
ELDER_GUARDIAN(NamespaceID.from("minecraft:elder_guardian")),
ENCHANTED_HIT(NamespaceID.from("minecraft:enchanted_hit")),
ENCHANT(NamespaceID.from("minecraft:enchant")),
END_ROD(NamespaceID.from("minecraft:end_rod")),
ENTITY_EFFECT(NamespaceID.from("minecraft:entity_effect")),
EXPLOSION_EMITTER(NamespaceID.from("minecraft:explosion_emitter")),
EXPLOSION(NamespaceID.from("minecraft:explosion")),
FALLING_DUST(NamespaceID.from("minecraft:falling_dust")),
FIREWORK(NamespaceID.from("minecraft:firework")),
FISHING(NamespaceID.from("minecraft:fishing")),
FLAME(NamespaceID.from("minecraft:flame")),
SOUL_FIRE_FLAME(NamespaceID.from("minecraft:soul_fire_flame")),
SOUL(NamespaceID.from("minecraft:soul")),
FLASH(NamespaceID.from("minecraft:flash")),
HAPPY_VILLAGER(NamespaceID.from("minecraft:happy_villager")),
COMPOSTER(NamespaceID.from("minecraft:composter")),
HEART(NamespaceID.from("minecraft:heart")),
INSTANT_EFFECT(NamespaceID.from("minecraft:instant_effect")),
ITEM(NamespaceID.from("minecraft:item")),
VIBRATION(NamespaceID.from("minecraft:vibration")),
ITEM_SLIME(NamespaceID.from("minecraft:item_slime")),
ITEM_SNOWBALL(NamespaceID.from("minecraft:item_snowball")),
LARGE_SMOKE(NamespaceID.from("minecraft:large_smoke")),
LAVA(NamespaceID.from("minecraft:lava")),
MYCELIUM(NamespaceID.from("minecraft:mycelium")),
NOTE(NamespaceID.from("minecraft:note")),
POOF(NamespaceID.from("minecraft:poof")),
PORTAL(NamespaceID.from("minecraft:portal")),
RAIN(NamespaceID.from("minecraft:rain")),
SMOKE(NamespaceID.from("minecraft:smoke")),
SNEEZE(NamespaceID.from("minecraft:sneeze")),
SPIT(NamespaceID.from("minecraft:spit")),
SQUID_INK(NamespaceID.from("minecraft:squid_ink")),
SWEEP_ATTACK(NamespaceID.from("minecraft:sweep_attack")),
TOTEM_OF_UNDYING(NamespaceID.from("minecraft:totem_of_undying")),
UNDERWATER(NamespaceID.from("minecraft:underwater")),
SPLASH(NamespaceID.from("minecraft:splash")),
WITCH(NamespaceID.from("minecraft:witch")),
BUBBLE_POP(NamespaceID.from("minecraft:bubble_pop")),
CURRENT_DOWN(NamespaceID.from("minecraft:current_down")),
BUBBLE_COLUMN_UP(NamespaceID.from("minecraft:bubble_column_up")),
NAUTILUS(NamespaceID.from("minecraft:nautilus")),
DOLPHIN(NamespaceID.from("minecraft:dolphin")),
CAMPFIRE_COSY_SMOKE(NamespaceID.from("minecraft:campfire_cosy_smoke")),
CAMPFIRE_SIGNAL_SMOKE(NamespaceID.from("minecraft:campfire_signal_smoke")),
DRIPPING_HONEY(NamespaceID.from("minecraft:dripping_honey")),
FALLING_HONEY(NamespaceID.from("minecraft:falling_honey")),
LANDING_HONEY(NamespaceID.from("minecraft:landing_honey")),
FALLING_NECTAR(NamespaceID.from("minecraft:falling_nectar")),
FALLING_SPORE_BLOSSOM(NamespaceID.from("minecraft:falling_spore_blossom")),
ASH(NamespaceID.from("minecraft:ash")),
CRIMSON_SPORE(NamespaceID.from("minecraft:crimson_spore")),
WARPED_SPORE(NamespaceID.from("minecraft:warped_spore")),
SPORE_BLOSSOM_AIR(NamespaceID.from("minecraft:spore_blossom_air")),
DRIPPING_OBSIDIAN_TEAR(NamespaceID.from("minecraft:dripping_obsidian_tear")),
FALLING_OBSIDIAN_TEAR(NamespaceID.from("minecraft:falling_obsidian_tear")),
LANDING_OBSIDIAN_TEAR(NamespaceID.from("minecraft:landing_obsidian_tear")),
REVERSE_PORTAL(NamespaceID.from("minecraft:reverse_portal")),
WHITE_ASH(NamespaceID.from("minecraft:white_ash")),
SMALL_FLAME(NamespaceID.from("minecraft:small_flame")),
SNOWFLAKE(NamespaceID.from("minecraft:snowflake")),
DRIPPING_DRIPSTONE_LAVA(NamespaceID.from("minecraft:dripping_dripstone_lava")),
FALLING_DRIPSTONE_LAVA(NamespaceID.from("minecraft:falling_dripstone_lava")),
DRIPPING_DRIPSTONE_WATER(NamespaceID.from("minecraft:dripping_dripstone_water")),
FALLING_DRIPSTONE_WATER(NamespaceID.from("minecraft:falling_dripstone_water")),
GLOW_SQUID_INK(NamespaceID.from("minecraft:glow_squid_ink")),
GLOW(NamespaceID.from("minecraft:glow")),
WAX_ON(NamespaceID.from("minecraft:wax_on")),
WAX_OFF(NamespaceID.from("minecraft:wax_off")),
ELECTRIC_SPARK(NamespaceID.from("minecraft:electric_spark")),
SCRAPE(NamespaceID.from("minecraft:scrape"));
private static final Particle[] VALUES = values();
@NotNull
private final NamespaceID id;
Particle(@NotNull NamespaceID id) {
this.id = id;
Registries.particles.put(id, this);
}
@Override
@NotNull
public Key key() {
return this.id;
}
public short getId() {
return (short) ordinal();
}
@NotNull
public NamespaceID getNamespaceID() {
return this.id;
}
@Nullable
public static Particle fromId(short id) {
if(id >= 0 && id < VALUES.length) {
return VALUES[id];
}
return null;
}
@NotNull
@Override
public String toString() {
return "[" + this.id + "]";
}
}

View File

@ -0,0 +1,185 @@
package net.minestom.server.particle;
/**
* Code autogenerated, do not edit!
*/
@SuppressWarnings("unused")
interface ParticleConstants {
Particle AMBIENT_ENTITY_EFFECT = ParticleLoader.get("minecraft:ambient_entity_effect");
Particle ANGRY_VILLAGER = ParticleLoader.get("minecraft:angry_villager");
Particle BARRIER = ParticleLoader.get("minecraft:barrier");
Particle LIGHT = ParticleLoader.get("minecraft:light");
Particle BLOCK = ParticleLoader.get("minecraft:block");
Particle BUBBLE = ParticleLoader.get("minecraft:bubble");
Particle CLOUD = ParticleLoader.get("minecraft:cloud");
Particle CRIT = ParticleLoader.get("minecraft:crit");
Particle DAMAGE_INDICATOR = ParticleLoader.get("minecraft:damage_indicator");
Particle DRAGON_BREATH = ParticleLoader.get("minecraft:dragon_breath");
Particle DRIPPING_LAVA = ParticleLoader.get("minecraft:dripping_lava");
Particle FALLING_LAVA = ParticleLoader.get("minecraft:falling_lava");
Particle LANDING_LAVA = ParticleLoader.get("minecraft:landing_lava");
Particle DRIPPING_WATER = ParticleLoader.get("minecraft:dripping_water");
Particle FALLING_WATER = ParticleLoader.get("minecraft:falling_water");
Particle DUST = ParticleLoader.get("minecraft:dust");
Particle DUST_COLOR_TRANSITION = ParticleLoader.get("minecraft:dust_color_transition");
Particle EFFECT = ParticleLoader.get("minecraft:effect");
Particle ELDER_GUARDIAN = ParticleLoader.get("minecraft:elder_guardian");
Particle ENCHANTED_HIT = ParticleLoader.get("minecraft:enchanted_hit");
Particle ENCHANT = ParticleLoader.get("minecraft:enchant");
Particle END_ROD = ParticleLoader.get("minecraft:end_rod");
Particle ENTITY_EFFECT = ParticleLoader.get("minecraft:entity_effect");
Particle EXPLOSION_EMITTER = ParticleLoader.get("minecraft:explosion_emitter");
Particle EXPLOSION = ParticleLoader.get("minecraft:explosion");
Particle FALLING_DUST = ParticleLoader.get("minecraft:falling_dust");
Particle FIREWORK = ParticleLoader.get("minecraft:firework");
Particle FISHING = ParticleLoader.get("minecraft:fishing");
Particle FLAME = ParticleLoader.get("minecraft:flame");
Particle SOUL_FIRE_FLAME = ParticleLoader.get("minecraft:soul_fire_flame");
Particle SOUL = ParticleLoader.get("minecraft:soul");
Particle FLASH = ParticleLoader.get("minecraft:flash");
Particle HAPPY_VILLAGER = ParticleLoader.get("minecraft:happy_villager");
Particle COMPOSTER = ParticleLoader.get("minecraft:composter");
Particle HEART = ParticleLoader.get("minecraft:heart");
Particle INSTANT_EFFECT = ParticleLoader.get("minecraft:instant_effect");
Particle ITEM = ParticleLoader.get("minecraft:item");
Particle VIBRATION = ParticleLoader.get("minecraft:vibration");
Particle ITEM_SLIME = ParticleLoader.get("minecraft:item_slime");
Particle ITEM_SNOWBALL = ParticleLoader.get("minecraft:item_snowball");
Particle LARGE_SMOKE = ParticleLoader.get("minecraft:large_smoke");
Particle LAVA = ParticleLoader.get("minecraft:lava");
Particle MYCELIUM = ParticleLoader.get("minecraft:mycelium");
Particle NOTE = ParticleLoader.get("minecraft:note");
Particle POOF = ParticleLoader.get("minecraft:poof");
Particle PORTAL = ParticleLoader.get("minecraft:portal");
Particle RAIN = ParticleLoader.get("minecraft:rain");
Particle SMOKE = ParticleLoader.get("minecraft:smoke");
Particle SNEEZE = ParticleLoader.get("minecraft:sneeze");
Particle SPIT = ParticleLoader.get("minecraft:spit");
Particle SQUID_INK = ParticleLoader.get("minecraft:squid_ink");
Particle SWEEP_ATTACK = ParticleLoader.get("minecraft:sweep_attack");
Particle TOTEM_OF_UNDYING = ParticleLoader.get("minecraft:totem_of_undying");
Particle UNDERWATER = ParticleLoader.get("minecraft:underwater");
Particle SPLASH = ParticleLoader.get("minecraft:splash");
Particle WITCH = ParticleLoader.get("minecraft:witch");
Particle BUBBLE_POP = ParticleLoader.get("minecraft:bubble_pop");
Particle CURRENT_DOWN = ParticleLoader.get("minecraft:current_down");
Particle BUBBLE_COLUMN_UP = ParticleLoader.get("minecraft:bubble_column_up");
Particle NAUTILUS = ParticleLoader.get("minecraft:nautilus");
Particle DOLPHIN = ParticleLoader.get("minecraft:dolphin");
Particle CAMPFIRE_COSY_SMOKE = ParticleLoader.get("minecraft:campfire_cosy_smoke");
Particle CAMPFIRE_SIGNAL_SMOKE = ParticleLoader.get("minecraft:campfire_signal_smoke");
Particle DRIPPING_HONEY = ParticleLoader.get("minecraft:dripping_honey");
Particle FALLING_HONEY = ParticleLoader.get("minecraft:falling_honey");
Particle LANDING_HONEY = ParticleLoader.get("minecraft:landing_honey");
Particle FALLING_NECTAR = ParticleLoader.get("minecraft:falling_nectar");
Particle FALLING_SPORE_BLOSSOM = ParticleLoader.get("minecraft:falling_spore_blossom");
Particle ASH = ParticleLoader.get("minecraft:ash");
Particle CRIMSON_SPORE = ParticleLoader.get("minecraft:crimson_spore");
Particle WARPED_SPORE = ParticleLoader.get("minecraft:warped_spore");
Particle SPORE_BLOSSOM_AIR = ParticleLoader.get("minecraft:spore_blossom_air");
Particle DRIPPING_OBSIDIAN_TEAR = ParticleLoader.get("minecraft:dripping_obsidian_tear");
Particle FALLING_OBSIDIAN_TEAR = ParticleLoader.get("minecraft:falling_obsidian_tear");
Particle LANDING_OBSIDIAN_TEAR = ParticleLoader.get("minecraft:landing_obsidian_tear");
Particle REVERSE_PORTAL = ParticleLoader.get("minecraft:reverse_portal");
Particle WHITE_ASH = ParticleLoader.get("minecraft:white_ash");
Particle SMALL_FLAME = ParticleLoader.get("minecraft:small_flame");
Particle SNOWFLAKE = ParticleLoader.get("minecraft:snowflake");
Particle DRIPPING_DRIPSTONE_LAVA = ParticleLoader.get("minecraft:dripping_dripstone_lava");
Particle FALLING_DRIPSTONE_LAVA = ParticleLoader.get("minecraft:falling_dripstone_lava");
Particle DRIPPING_DRIPSTONE_WATER = ParticleLoader.get("minecraft:dripping_dripstone_water");
Particle FALLING_DRIPSTONE_WATER = ParticleLoader.get("minecraft:falling_dripstone_water");
Particle GLOW_SQUID_INK = ParticleLoader.get("minecraft:glow_squid_ink");
Particle GLOW = ParticleLoader.get("minecraft:glow");
Particle WAX_ON = ParticleLoader.get("minecraft:wax_on");
Particle WAX_OFF = ParticleLoader.get("minecraft:wax_off");
Particle ELECTRIC_SPARK = ParticleLoader.get("minecraft:electric_spark");
Particle SCRAPE = ParticleLoader.get("minecraft:scrape");
}

View File

@ -1,116 +0,0 @@
package net.minestom.server.potion;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.Keyed;
import net.minestom.server.registry.Registries;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* AUTOGENERATED by PotionEffectGenerator
*/
public enum PotionEffect implements Keyed {
SPEED(NamespaceID.from("minecraft:speed")),
SLOWNESS(NamespaceID.from("minecraft:slowness")),
HASTE(NamespaceID.from("minecraft:haste")),
MINING_FATIGUE(NamespaceID.from("minecraft:mining_fatigue")),
STRENGTH(NamespaceID.from("minecraft:strength")),
INSTANT_HEALTH(NamespaceID.from("minecraft:instant_health")),
INSTANT_DAMAGE(NamespaceID.from("minecraft:instant_damage")),
JUMP_BOOST(NamespaceID.from("minecraft:jump_boost")),
NAUSEA(NamespaceID.from("minecraft:nausea")),
REGENERATION(NamespaceID.from("minecraft:regeneration")),
RESISTANCE(NamespaceID.from("minecraft:resistance")),
FIRE_RESISTANCE(NamespaceID.from("minecraft:fire_resistance")),
WATER_BREATHING(NamespaceID.from("minecraft:water_breathing")),
INVISIBILITY(NamespaceID.from("minecraft:invisibility")),
BLINDNESS(NamespaceID.from("minecraft:blindness")),
NIGHT_VISION(NamespaceID.from("minecraft:night_vision")),
HUNGER(NamespaceID.from("minecraft:hunger")),
WEAKNESS(NamespaceID.from("minecraft:weakness")),
POISON(NamespaceID.from("minecraft:poison")),
WITHER(NamespaceID.from("minecraft:wither")),
HEALTH_BOOST(NamespaceID.from("minecraft:health_boost")),
ABSORPTION(NamespaceID.from("minecraft:absorption")),
SATURATION(NamespaceID.from("minecraft:saturation")),
GLOWING(NamespaceID.from("minecraft:glowing")),
LEVITATION(NamespaceID.from("minecraft:levitation")),
LUCK(NamespaceID.from("minecraft:luck")),
UNLUCK(NamespaceID.from("minecraft:unluck")),
SLOW_FALLING(NamespaceID.from("minecraft:slow_falling")),
CONDUIT_POWER(NamespaceID.from("minecraft:conduit_power")),
DOLPHINS_GRACE(NamespaceID.from("minecraft:dolphins_grace")),
BAD_OMEN(NamespaceID.from("minecraft:bad_omen")),
HERO_OF_THE_VILLAGE(NamespaceID.from("minecraft:hero_of_the_village"));
private static final PotionEffect[] VALUES = values();
@NotNull
private final NamespaceID id;
PotionEffect(@NotNull NamespaceID id) {
this.id = id;
Registries.potionEffects.put(id, this);
}
@Override
@NotNull
public Key key() {
return this.id;
}
public short getId() {
return (short) (ordinal() + 1);
}
@NotNull
public NamespaceID getNamespaceID() {
return this.id;
}
@Nullable
public static PotionEffect fromId(short id) {
if(id >= 1 && id < VALUES.length + 1) {
return VALUES[id - 1];
}
return null;
}
@NotNull
@Override
public String toString() {
return "[" + this.id + "]";
}
}

View File

@ -0,0 +1,71 @@
package net.minestom.server.potion;
/**
* Code autogenerated, do not edit!
*/
@SuppressWarnings("unused")
interface PotionEffectConstants {
PotionEffect SPEED = PotionEffectLoader.get("minecraft:speed");
PotionEffect SLOWNESS = PotionEffectLoader.get("minecraft:slowness");
PotionEffect HASTE = PotionEffectLoader.get("minecraft:haste");
PotionEffect MINING_FATIGUE = PotionEffectLoader.get("minecraft:mining_fatigue");
PotionEffect STRENGTH = PotionEffectLoader.get("minecraft:strength");
PotionEffect INSTANT_HEALTH = PotionEffectLoader.get("minecraft:instant_health");
PotionEffect INSTANT_DAMAGE = PotionEffectLoader.get("minecraft:instant_damage");
PotionEffect JUMP_BOOST = PotionEffectLoader.get("minecraft:jump_boost");
PotionEffect NAUSEA = PotionEffectLoader.get("minecraft:nausea");
PotionEffect REGENERATION = PotionEffectLoader.get("minecraft:regeneration");
PotionEffect RESISTANCE = PotionEffectLoader.get("minecraft:resistance");
PotionEffect FIRE_RESISTANCE = PotionEffectLoader.get("minecraft:fire_resistance");
PotionEffect WATER_BREATHING = PotionEffectLoader.get("minecraft:water_breathing");
PotionEffect INVISIBILITY = PotionEffectLoader.get("minecraft:invisibility");
PotionEffect BLINDNESS = PotionEffectLoader.get("minecraft:blindness");
PotionEffect NIGHT_VISION = PotionEffectLoader.get("minecraft:night_vision");
PotionEffect HUNGER = PotionEffectLoader.get("minecraft:hunger");
PotionEffect WEAKNESS = PotionEffectLoader.get("minecraft:weakness");
PotionEffect POISON = PotionEffectLoader.get("minecraft:poison");
PotionEffect WITHER = PotionEffectLoader.get("minecraft:wither");
PotionEffect HEALTH_BOOST = PotionEffectLoader.get("minecraft:health_boost");
PotionEffect ABSORPTION = PotionEffectLoader.get("minecraft:absorption");
PotionEffect SATURATION = PotionEffectLoader.get("minecraft:saturation");
PotionEffect GLOWING = PotionEffectLoader.get("minecraft:glowing");
PotionEffect LEVITATION = PotionEffectLoader.get("minecraft:levitation");
PotionEffect LUCK = PotionEffectLoader.get("minecraft:luck");
PotionEffect UNLUCK = PotionEffectLoader.get("minecraft:unluck");
PotionEffect SLOW_FALLING = PotionEffectLoader.get("minecraft:slow_falling");
PotionEffect CONDUIT_POWER = PotionEffectLoader.get("minecraft:conduit_power");
PotionEffect DOLPHINS_GRACE = PotionEffectLoader.get("minecraft:dolphins_grace");
PotionEffect BAD_OMEN = PotionEffectLoader.get("minecraft:bad_omen");
PotionEffect HERO_OF_THE_VILLAGE = PotionEffectLoader.get("minecraft:hero_of_the_village");
}

View File

@ -1,138 +0,0 @@
package net.minestom.server.potion;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.Keyed;
import net.minestom.server.registry.Registries;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* AUTOGENERATED by PotionTypeGenerator
*/
public enum PotionType implements Keyed {
EMPTY(NamespaceID.from("minecraft:empty")),
WATER(NamespaceID.from("minecraft:water")),
MUNDANE(NamespaceID.from("minecraft:mundane")),
THICK(NamespaceID.from("minecraft:thick")),
AWKWARD(NamespaceID.from("minecraft:awkward")),
NIGHT_VISION(NamespaceID.from("minecraft:night_vision")),
LONG_NIGHT_VISION(NamespaceID.from("minecraft:long_night_vision")),
INVISIBILITY(NamespaceID.from("minecraft:invisibility")),
LONG_INVISIBILITY(NamespaceID.from("minecraft:long_invisibility")),
LEAPING(NamespaceID.from("minecraft:leaping")),
LONG_LEAPING(NamespaceID.from("minecraft:long_leaping")),
STRONG_LEAPING(NamespaceID.from("minecraft:strong_leaping")),
FIRE_RESISTANCE(NamespaceID.from("minecraft:fire_resistance")),
LONG_FIRE_RESISTANCE(NamespaceID.from("minecraft:long_fire_resistance")),
SWIFTNESS(NamespaceID.from("minecraft:swiftness")),
LONG_SWIFTNESS(NamespaceID.from("minecraft:long_swiftness")),
STRONG_SWIFTNESS(NamespaceID.from("minecraft:strong_swiftness")),
SLOWNESS(NamespaceID.from("minecraft:slowness")),
LONG_SLOWNESS(NamespaceID.from("minecraft:long_slowness")),
STRONG_SLOWNESS(NamespaceID.from("minecraft:strong_slowness")),
TURTLE_MASTER(NamespaceID.from("minecraft:turtle_master")),
LONG_TURTLE_MASTER(NamespaceID.from("minecraft:long_turtle_master")),
STRONG_TURTLE_MASTER(NamespaceID.from("minecraft:strong_turtle_master")),
WATER_BREATHING(NamespaceID.from("minecraft:water_breathing")),
LONG_WATER_BREATHING(NamespaceID.from("minecraft:long_water_breathing")),
HEALING(NamespaceID.from("minecraft:healing")),
STRONG_HEALING(NamespaceID.from("minecraft:strong_healing")),
HARMING(NamespaceID.from("minecraft:harming")),
STRONG_HARMING(NamespaceID.from("minecraft:strong_harming")),
POISON(NamespaceID.from("minecraft:poison")),
LONG_POISON(NamespaceID.from("minecraft:long_poison")),
STRONG_POISON(NamespaceID.from("minecraft:strong_poison")),
REGENERATION(NamespaceID.from("minecraft:regeneration")),
LONG_REGENERATION(NamespaceID.from("minecraft:long_regeneration")),
STRONG_REGENERATION(NamespaceID.from("minecraft:strong_regeneration")),
STRENGTH(NamespaceID.from("minecraft:strength")),
LONG_STRENGTH(NamespaceID.from("minecraft:long_strength")),
STRONG_STRENGTH(NamespaceID.from("minecraft:strong_strength")),
WEAKNESS(NamespaceID.from("minecraft:weakness")),
LONG_WEAKNESS(NamespaceID.from("minecraft:long_weakness")),
LUCK(NamespaceID.from("minecraft:luck")),
SLOW_FALLING(NamespaceID.from("minecraft:slow_falling")),
LONG_SLOW_FALLING(NamespaceID.from("minecraft:long_slow_falling"));
private static final PotionType[] VALUES = values();
@NotNull
private final NamespaceID id;
PotionType(@NotNull NamespaceID id) {
this.id = id;
Registries.potionTypes.put(id, this);
}
@Override
@NotNull
public Key key() {
return this.id;
}
public short getId() {
return (short) ordinal();
}
@NotNull
public NamespaceID getNamespaceID() {
return this.id;
}
@Nullable
public static PotionType fromId(short id) {
if(id >= 0 && id < VALUES.length) {
return VALUES[id];
}
return null;
}
@NotNull
@Override
public String toString() {
return "[" + this.id + "]";
}
}

View File

@ -0,0 +1,93 @@
package net.minestom.server.potion;
/**
* Code autogenerated, do not edit!
*/
@SuppressWarnings("unused")
interface PotionTypeConstants {
PotionType EMPTY = PotionTypeLoader.get("minecraft:empty");
PotionType WATER = PotionTypeLoader.get("minecraft:water");
PotionType MUNDANE = PotionTypeLoader.get("minecraft:mundane");
PotionType THICK = PotionTypeLoader.get("minecraft:thick");
PotionType AWKWARD = PotionTypeLoader.get("minecraft:awkward");
PotionType NIGHT_VISION = PotionTypeLoader.get("minecraft:night_vision");
PotionType LONG_NIGHT_VISION = PotionTypeLoader.get("minecraft:long_night_vision");
PotionType INVISIBILITY = PotionTypeLoader.get("minecraft:invisibility");
PotionType LONG_INVISIBILITY = PotionTypeLoader.get("minecraft:long_invisibility");
PotionType LEAPING = PotionTypeLoader.get("minecraft:leaping");
PotionType LONG_LEAPING = PotionTypeLoader.get("minecraft:long_leaping");
PotionType STRONG_LEAPING = PotionTypeLoader.get("minecraft:strong_leaping");
PotionType FIRE_RESISTANCE = PotionTypeLoader.get("minecraft:fire_resistance");
PotionType LONG_FIRE_RESISTANCE = PotionTypeLoader.get("minecraft:long_fire_resistance");
PotionType SWIFTNESS = PotionTypeLoader.get("minecraft:swiftness");
PotionType LONG_SWIFTNESS = PotionTypeLoader.get("minecraft:long_swiftness");
PotionType STRONG_SWIFTNESS = PotionTypeLoader.get("minecraft:strong_swiftness");
PotionType SLOWNESS = PotionTypeLoader.get("minecraft:slowness");
PotionType LONG_SLOWNESS = PotionTypeLoader.get("minecraft:long_slowness");
PotionType STRONG_SLOWNESS = PotionTypeLoader.get("minecraft:strong_slowness");
PotionType TURTLE_MASTER = PotionTypeLoader.get("minecraft:turtle_master");
PotionType LONG_TURTLE_MASTER = PotionTypeLoader.get("minecraft:long_turtle_master");
PotionType STRONG_TURTLE_MASTER = PotionTypeLoader.get("minecraft:strong_turtle_master");
PotionType WATER_BREATHING = PotionTypeLoader.get("minecraft:water_breathing");
PotionType LONG_WATER_BREATHING = PotionTypeLoader.get("minecraft:long_water_breathing");
PotionType HEALING = PotionTypeLoader.get("minecraft:healing");
PotionType STRONG_HEALING = PotionTypeLoader.get("minecraft:strong_healing");
PotionType HARMING = PotionTypeLoader.get("minecraft:harming");
PotionType STRONG_HARMING = PotionTypeLoader.get("minecraft:strong_harming");
PotionType POISON = PotionTypeLoader.get("minecraft:poison");
PotionType LONG_POISON = PotionTypeLoader.get("minecraft:long_poison");
PotionType STRONG_POISON = PotionTypeLoader.get("minecraft:strong_poison");
PotionType REGENERATION = PotionTypeLoader.get("minecraft:regeneration");
PotionType LONG_REGENERATION = PotionTypeLoader.get("minecraft:long_regeneration");
PotionType STRONG_REGENERATION = PotionTypeLoader.get("minecraft:strong_regeneration");
PotionType STRENGTH = PotionTypeLoader.get("minecraft:strength");
PotionType LONG_STRENGTH = PotionTypeLoader.get("minecraft:long_strength");
PotionType STRONG_STRENGTH = PotionTypeLoader.get("minecraft:strong_strength");
PotionType WEAKNESS = PotionTypeLoader.get("minecraft:weakness");
PotionType LONG_WEAKNESS = PotionTypeLoader.get("minecraft:long_weakness");
PotionType LUCK = PotionTypeLoader.get("minecraft:luck");
PotionType SLOW_FALLING = PotionTypeLoader.get("minecraft:slow_falling");
PotionType LONG_SLOW_FALLING = PotionTypeLoader.get("minecraft:long_slow_falling");
}

View File

@ -3,14 +3,8 @@ package net.minestom.server.registry;
import net.kyori.adventure.key.Key;
import net.minestom.server.fluid.Fluid;
import net.minestom.server.particle.Particle;
import net.minestom.server.potion.PotionEffect;
import net.minestom.server.potion.PotionType;
import net.minestom.server.sound.SoundEvent;
import net.minestom.server.statistic.StatisticType;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
@ -19,162 +13,12 @@ import java.util.HashMap;
*/
public final class Registries {
/**
* Should only be used for internal code, please use the get* methods.
*/
@Deprecated
public static final HashMap<NamespaceID, Particle> particles = new HashMap<>();
/**
* Should only be used for internal code, please use the get* methods.
*/
@Deprecated
public static final HashMap<NamespaceID, PotionType> potionTypes = new HashMap<>();
/**
* Should only be used for internal code, please use the get* methods.
*/
@Deprecated
public static final HashMap<NamespaceID, PotionEffect> potionEffects = new HashMap<>();
/**
* Should only be used for internal code, please use the get* methods.
*/
@Deprecated
public static final HashMap<NamespaceID, SoundEvent> soundEvents = new HashMap<>();
/**
* Should only be used for internal code, please use the get* methods.
*/
@Deprecated
public static final HashMap<NamespaceID, StatisticType> statisticTypes = new HashMap<>();
/**
* Should only be used for internal code, please use the get* methods.
*/
@Deprecated
public static final HashMap<NamespaceID, Fluid> fluids = new HashMap<>();
/**
* Returns the corresponding Particle matching the given id. Returns null if none match.
*/
@Nullable
public static Particle getParticle(String id) {
return getParticle(NamespaceID.from(id));
}
/**
* Returns the corresponding Particle matching the given id. Returns null if none match.
*/
@Nullable
public static Particle getParticle(NamespaceID id) {
return particles.get(id);
}
/**
* Returns the corresponding Particle matching the given key. Returns null if none match.
*/
@Nullable
public static Particle getParticle(Key key) {
return getParticle(NamespaceID.from(key));
}
/**
* Returns the corresponding PotionType matching the given id. Returns null if none match.
*/
@Nullable
public static PotionType getPotionType(String id) {
return getPotionType(NamespaceID.from(id));
}
/**
* Returns the corresponding PotionType matching the given id. Returns null if none match.
*/
@Nullable
public static PotionType getPotionType(NamespaceID id) {
return potionTypes.get(id);
}
/**
* Returns the corresponding PotionType matching the given key. Returns null if none match.
*/
@Nullable
public static PotionType getPotionType(Key key) {
return getPotionType(NamespaceID.from(key));
}
/**
* Returns the corresponding PotionEffect matching the given id. Returns null if none match.
*/
@Nullable
public static PotionEffect getPotionEffect(String id) {
return getPotionEffect(NamespaceID.from(id));
}
/**
* Returns the corresponding PotionEffect matching the given id. Returns null if none match.
*/
@Nullable
public static PotionEffect getPotionEffect(NamespaceID id) {
return potionEffects.get(id);
}
/**
* Returns the corresponding PotionEffect matching the given key. Returns null if none match.
*/
@Nullable
public static PotionEffect getPotionEffect(Key key) {
return getPotionEffect(NamespaceID.from(key));
}
/**
* Returns the corresponding SoundEvent matching the given id. Returns null if none match.
*/
@Nullable
public static SoundEvent getSoundEvent(String id) {
return getSoundEvent(NamespaceID.from(id));
}
/**
* Returns the corresponding SoundEvent matching the given id. Returns null if none match.
*/
@Nullable
public static SoundEvent getSoundEvent(NamespaceID id) {
return soundEvents.get(id);
}
/**
* Returns the corresponding SoundEvent matching the given key. Returns null if none match.
*/
@Nullable
public static SoundEvent getSoundEvent(Key key) {
return getSoundEvent(NamespaceID.from(key));
}
/**
* Returns the corresponding StatisticType matching the given id. Returns null if none match.
*/
@Nullable
public static StatisticType getStatisticType(String id) {
return getStatisticType(NamespaceID.from(id));
}
/**
* Returns the corresponding StatisticType matching the given id. Returns null if none match.
*/
@Nullable
public static StatisticType getStatisticType(NamespaceID id) {
return statisticTypes.get(id);
}
/**
* Returns the corresponding StatisticType matching the given key. Returns null if none match.
*/
@Nullable
public static StatisticType getStatisticType(Key key) {
return getStatisticType(NamespaceID.from(key));
}
/**
* Returns the corresponding Fluid matching the given id. Returns 'EMPTY' if none match.
*/

File diff suppressed because it is too large Load Diff

View File

@ -1,202 +0,0 @@
package net.minestom.server.statistic;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.Keyed;
import net.minestom.server.registry.Registries;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* AUTOGENERATED by StatisticGenerator
*/
public enum StatisticType implements Keyed {
LEAVE_GAME(NamespaceID.from("minecraft:leave_game")),
PLAY_TIME(NamespaceID.from("minecraft:play_time")),
TOTAL_WORLD_TIME(NamespaceID.from("minecraft:total_world_time")),
TIME_SINCE_DEATH(NamespaceID.from("minecraft:time_since_death")),
TIME_SINCE_REST(NamespaceID.from("minecraft:time_since_rest")),
SNEAK_TIME(NamespaceID.from("minecraft:sneak_time")),
WALK_ONE_CM(NamespaceID.from("minecraft:walk_one_cm")),
CROUCH_ONE_CM(NamespaceID.from("minecraft:crouch_one_cm")),
SPRINT_ONE_CM(NamespaceID.from("minecraft:sprint_one_cm")),
WALK_ON_WATER_ONE_CM(NamespaceID.from("minecraft:walk_on_water_one_cm")),
FALL_ONE_CM(NamespaceID.from("minecraft:fall_one_cm")),
CLIMB_ONE_CM(NamespaceID.from("minecraft:climb_one_cm")),
FLY_ONE_CM(NamespaceID.from("minecraft:fly_one_cm")),
WALK_UNDER_WATER_ONE_CM(NamespaceID.from("minecraft:walk_under_water_one_cm")),
MINECART_ONE_CM(NamespaceID.from("minecraft:minecart_one_cm")),
BOAT_ONE_CM(NamespaceID.from("minecraft:boat_one_cm")),
PIG_ONE_CM(NamespaceID.from("minecraft:pig_one_cm")),
HORSE_ONE_CM(NamespaceID.from("minecraft:horse_one_cm")),
AVIATE_ONE_CM(NamespaceID.from("minecraft:aviate_one_cm")),
SWIM_ONE_CM(NamespaceID.from("minecraft:swim_one_cm")),
STRIDER_ONE_CM(NamespaceID.from("minecraft:strider_one_cm")),
JUMP(NamespaceID.from("minecraft:jump")),
DROP(NamespaceID.from("minecraft:drop")),
DAMAGE_DEALT(NamespaceID.from("minecraft:damage_dealt")),
DAMAGE_DEALT_ABSORBED(NamespaceID.from("minecraft:damage_dealt_absorbed")),
DAMAGE_DEALT_RESISTED(NamespaceID.from("minecraft:damage_dealt_resisted")),
DAMAGE_TAKEN(NamespaceID.from("minecraft:damage_taken")),
DAMAGE_BLOCKED_BY_SHIELD(NamespaceID.from("minecraft:damage_blocked_by_shield")),
DAMAGE_ABSORBED(NamespaceID.from("minecraft:damage_absorbed")),
DAMAGE_RESISTED(NamespaceID.from("minecraft:damage_resisted")),
DEATHS(NamespaceID.from("minecraft:deaths")),
MOB_KILLS(NamespaceID.from("minecraft:mob_kills")),
ANIMALS_BRED(NamespaceID.from("minecraft:animals_bred")),
PLAYER_KILLS(NamespaceID.from("minecraft:player_kills")),
FISH_CAUGHT(NamespaceID.from("minecraft:fish_caught")),
TALKED_TO_VILLAGER(NamespaceID.from("minecraft:talked_to_villager")),
TRADED_WITH_VILLAGER(NamespaceID.from("minecraft:traded_with_villager")),
EAT_CAKE_SLICE(NamespaceID.from("minecraft:eat_cake_slice")),
FILL_CAULDRON(NamespaceID.from("minecraft:fill_cauldron")),
USE_CAULDRON(NamespaceID.from("minecraft:use_cauldron")),
CLEAN_ARMOR(NamespaceID.from("minecraft:clean_armor")),
CLEAN_BANNER(NamespaceID.from("minecraft:clean_banner")),
CLEAN_SHULKER_BOX(NamespaceID.from("minecraft:clean_shulker_box")),
INTERACT_WITH_BREWINGSTAND(NamespaceID.from("minecraft:interact_with_brewingstand")),
INTERACT_WITH_BEACON(NamespaceID.from("minecraft:interact_with_beacon")),
INSPECT_DROPPER(NamespaceID.from("minecraft:inspect_dropper")),
INSPECT_HOPPER(NamespaceID.from("minecraft:inspect_hopper")),
INSPECT_DISPENSER(NamespaceID.from("minecraft:inspect_dispenser")),
PLAY_NOTEBLOCK(NamespaceID.from("minecraft:play_noteblock")),
TUNE_NOTEBLOCK(NamespaceID.from("minecraft:tune_noteblock")),
POT_FLOWER(NamespaceID.from("minecraft:pot_flower")),
TRIGGER_TRAPPED_CHEST(NamespaceID.from("minecraft:trigger_trapped_chest")),
OPEN_ENDERCHEST(NamespaceID.from("minecraft:open_enderchest")),
ENCHANT_ITEM(NamespaceID.from("minecraft:enchant_item")),
PLAY_RECORD(NamespaceID.from("minecraft:play_record")),
INTERACT_WITH_FURNACE(NamespaceID.from("minecraft:interact_with_furnace")),
INTERACT_WITH_CRAFTING_TABLE(NamespaceID.from("minecraft:interact_with_crafting_table")),
OPEN_CHEST(NamespaceID.from("minecraft:open_chest")),
SLEEP_IN_BED(NamespaceID.from("minecraft:sleep_in_bed")),
OPEN_SHULKER_BOX(NamespaceID.from("minecraft:open_shulker_box")),
OPEN_BARREL(NamespaceID.from("minecraft:open_barrel")),
INTERACT_WITH_BLAST_FURNACE(NamespaceID.from("minecraft:interact_with_blast_furnace")),
INTERACT_WITH_SMOKER(NamespaceID.from("minecraft:interact_with_smoker")),
INTERACT_WITH_LECTERN(NamespaceID.from("minecraft:interact_with_lectern")),
INTERACT_WITH_CAMPFIRE(NamespaceID.from("minecraft:interact_with_campfire")),
INTERACT_WITH_CARTOGRAPHY_TABLE(NamespaceID.from("minecraft:interact_with_cartography_table")),
INTERACT_WITH_LOOM(NamespaceID.from("minecraft:interact_with_loom")),
INTERACT_WITH_STONECUTTER(NamespaceID.from("minecraft:interact_with_stonecutter")),
BELL_RING(NamespaceID.from("minecraft:bell_ring")),
RAID_TRIGGER(NamespaceID.from("minecraft:raid_trigger")),
RAID_WIN(NamespaceID.from("minecraft:raid_win")),
INTERACT_WITH_ANVIL(NamespaceID.from("minecraft:interact_with_anvil")),
INTERACT_WITH_GRINDSTONE(NamespaceID.from("minecraft:interact_with_grindstone")),
TARGET_HIT(NamespaceID.from("minecraft:target_hit")),
INTERACT_WITH_SMITHING_TABLE(NamespaceID.from("minecraft:interact_with_smithing_table"));
private static final StatisticType[] VALUES = values();
@NotNull
private final NamespaceID id;
StatisticType(@NotNull NamespaceID id) {
this.id = id;
Registries.statisticTypes.put(id, this);
}
@Override
@NotNull
public Key key() {
return this.id;
}
public short getId() {
return (short) ordinal();
}
@NotNull
public NamespaceID getNamespaceID() {
return this.id;
}
@Nullable
public static StatisticType fromId(short id) {
if(id >= 0 && id < VALUES.length) {
return VALUES[id];
}
return null;
}
@NotNull
@Override
public String toString() {
return "[" + this.id + "]";
}
}

View File

@ -0,0 +1,157 @@
package net.minestom.server.statistic;
/**
* Code autogenerated, do not edit!
*/
@SuppressWarnings("unused")
interface StatisticTypeConstants {
StatisticType LEAVE_GAME = StatisticTypeLoader.get("minecraft:leave_game");
StatisticType PLAY_TIME = StatisticTypeLoader.get("minecraft:play_time");
StatisticType TOTAL_WORLD_TIME = StatisticTypeLoader.get("minecraft:total_world_time");
StatisticType TIME_SINCE_DEATH = StatisticTypeLoader.get("minecraft:time_since_death");
StatisticType TIME_SINCE_REST = StatisticTypeLoader.get("minecraft:time_since_rest");
StatisticType SNEAK_TIME = StatisticTypeLoader.get("minecraft:sneak_time");
StatisticType WALK_ONE_CM = StatisticTypeLoader.get("minecraft:walk_one_cm");
StatisticType CROUCH_ONE_CM = StatisticTypeLoader.get("minecraft:crouch_one_cm");
StatisticType SPRINT_ONE_CM = StatisticTypeLoader.get("minecraft:sprint_one_cm");
StatisticType WALK_ON_WATER_ONE_CM = StatisticTypeLoader.get("minecraft:walk_on_water_one_cm");
StatisticType FALL_ONE_CM = StatisticTypeLoader.get("minecraft:fall_one_cm");
StatisticType CLIMB_ONE_CM = StatisticTypeLoader.get("minecraft:climb_one_cm");
StatisticType FLY_ONE_CM = StatisticTypeLoader.get("minecraft:fly_one_cm");
StatisticType WALK_UNDER_WATER_ONE_CM = StatisticTypeLoader.get("minecraft:walk_under_water_one_cm");
StatisticType MINECART_ONE_CM = StatisticTypeLoader.get("minecraft:minecart_one_cm");
StatisticType BOAT_ONE_CM = StatisticTypeLoader.get("minecraft:boat_one_cm");
StatisticType PIG_ONE_CM = StatisticTypeLoader.get("minecraft:pig_one_cm");
StatisticType HORSE_ONE_CM = StatisticTypeLoader.get("minecraft:horse_one_cm");
StatisticType AVIATE_ONE_CM = StatisticTypeLoader.get("minecraft:aviate_one_cm");
StatisticType SWIM_ONE_CM = StatisticTypeLoader.get("minecraft:swim_one_cm");
StatisticType STRIDER_ONE_CM = StatisticTypeLoader.get("minecraft:strider_one_cm");
StatisticType JUMP = StatisticTypeLoader.get("minecraft:jump");
StatisticType DROP = StatisticTypeLoader.get("minecraft:drop");
StatisticType DAMAGE_DEALT = StatisticTypeLoader.get("minecraft:damage_dealt");
StatisticType DAMAGE_DEALT_ABSORBED = StatisticTypeLoader.get("minecraft:damage_dealt_absorbed");
StatisticType DAMAGE_DEALT_RESISTED = StatisticTypeLoader.get("minecraft:damage_dealt_resisted");
StatisticType DAMAGE_TAKEN = StatisticTypeLoader.get("minecraft:damage_taken");
StatisticType DAMAGE_BLOCKED_BY_SHIELD = StatisticTypeLoader.get("minecraft:damage_blocked_by_shield");
StatisticType DAMAGE_ABSORBED = StatisticTypeLoader.get("minecraft:damage_absorbed");
StatisticType DAMAGE_RESISTED = StatisticTypeLoader.get("minecraft:damage_resisted");
StatisticType DEATHS = StatisticTypeLoader.get("minecraft:deaths");
StatisticType MOB_KILLS = StatisticTypeLoader.get("minecraft:mob_kills");
StatisticType ANIMALS_BRED = StatisticTypeLoader.get("minecraft:animals_bred");
StatisticType PLAYER_KILLS = StatisticTypeLoader.get("minecraft:player_kills");
StatisticType FISH_CAUGHT = StatisticTypeLoader.get("minecraft:fish_caught");
StatisticType TALKED_TO_VILLAGER = StatisticTypeLoader.get("minecraft:talked_to_villager");
StatisticType TRADED_WITH_VILLAGER = StatisticTypeLoader.get("minecraft:traded_with_villager");
StatisticType EAT_CAKE_SLICE = StatisticTypeLoader.get("minecraft:eat_cake_slice");
StatisticType FILL_CAULDRON = StatisticTypeLoader.get("minecraft:fill_cauldron");
StatisticType USE_CAULDRON = StatisticTypeLoader.get("minecraft:use_cauldron");
StatisticType CLEAN_ARMOR = StatisticTypeLoader.get("minecraft:clean_armor");
StatisticType CLEAN_BANNER = StatisticTypeLoader.get("minecraft:clean_banner");
StatisticType CLEAN_SHULKER_BOX = StatisticTypeLoader.get("minecraft:clean_shulker_box");
StatisticType INTERACT_WITH_BREWINGSTAND = StatisticTypeLoader.get("minecraft:interact_with_brewingstand");
StatisticType INTERACT_WITH_BEACON = StatisticTypeLoader.get("minecraft:interact_with_beacon");
StatisticType INSPECT_DROPPER = StatisticTypeLoader.get("minecraft:inspect_dropper");
StatisticType INSPECT_HOPPER = StatisticTypeLoader.get("minecraft:inspect_hopper");
StatisticType INSPECT_DISPENSER = StatisticTypeLoader.get("minecraft:inspect_dispenser");
StatisticType PLAY_NOTEBLOCK = StatisticTypeLoader.get("minecraft:play_noteblock");
StatisticType TUNE_NOTEBLOCK = StatisticTypeLoader.get("minecraft:tune_noteblock");
StatisticType POT_FLOWER = StatisticTypeLoader.get("minecraft:pot_flower");
StatisticType TRIGGER_TRAPPED_CHEST = StatisticTypeLoader.get("minecraft:trigger_trapped_chest");
StatisticType OPEN_ENDERCHEST = StatisticTypeLoader.get("minecraft:open_enderchest");
StatisticType ENCHANT_ITEM = StatisticTypeLoader.get("minecraft:enchant_item");
StatisticType PLAY_RECORD = StatisticTypeLoader.get("minecraft:play_record");
StatisticType INTERACT_WITH_FURNACE = StatisticTypeLoader.get("minecraft:interact_with_furnace");
StatisticType INTERACT_WITH_CRAFTING_TABLE = StatisticTypeLoader.get("minecraft:interact_with_crafting_table");
StatisticType OPEN_CHEST = StatisticTypeLoader.get("minecraft:open_chest");
StatisticType SLEEP_IN_BED = StatisticTypeLoader.get("minecraft:sleep_in_bed");
StatisticType OPEN_SHULKER_BOX = StatisticTypeLoader.get("minecraft:open_shulker_box");
StatisticType OPEN_BARREL = StatisticTypeLoader.get("minecraft:open_barrel");
StatisticType INTERACT_WITH_BLAST_FURNACE = StatisticTypeLoader.get("minecraft:interact_with_blast_furnace");
StatisticType INTERACT_WITH_SMOKER = StatisticTypeLoader.get("minecraft:interact_with_smoker");
StatisticType INTERACT_WITH_LECTERN = StatisticTypeLoader.get("minecraft:interact_with_lectern");
StatisticType INTERACT_WITH_CAMPFIRE = StatisticTypeLoader.get("minecraft:interact_with_campfire");
StatisticType INTERACT_WITH_CARTOGRAPHY_TABLE = StatisticTypeLoader.get("minecraft:interact_with_cartography_table");
StatisticType INTERACT_WITH_LOOM = StatisticTypeLoader.get("minecraft:interact_with_loom");
StatisticType INTERACT_WITH_STONECUTTER = StatisticTypeLoader.get("minecraft:interact_with_stonecutter");
StatisticType BELL_RING = StatisticTypeLoader.get("minecraft:bell_ring");
StatisticType RAID_TRIGGER = StatisticTypeLoader.get("minecraft:raid_trigger");
StatisticType RAID_WIN = StatisticTypeLoader.get("minecraft:raid_win");
StatisticType INTERACT_WITH_ANVIL = StatisticTypeLoader.get("minecraft:interact_with_anvil");
StatisticType INTERACT_WITH_GRINDSTONE = StatisticTypeLoader.get("minecraft:interact_with_grindstone");
StatisticType TARGET_HIT = StatisticTypeLoader.get("minecraft:target_hit");
StatisticType INTERACT_WITH_SMITHING_TABLE = StatisticTypeLoader.get("minecraft:interact_with_smithing_table");
}

View File

@ -6,7 +6,6 @@ import net.minestom.server.command.CommandManager;
import net.minestom.server.data.DataManager;
import net.minestom.server.data.DataType;
import net.minestom.server.data.SerializableData;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.Player;
import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.exception.ExceptionManager;
@ -19,8 +18,6 @@ import net.minestom.server.instance.Chunk;
import net.minestom.server.instance.InstanceManager;
import net.minestom.server.instance.block.BlockManager;
import net.minestom.server.instance.block.rule.BlockPlacementRule;
import net.minestom.server.item.Enchantment;
import net.minestom.server.item.Material;
import net.minestom.server.listener.manager.PacketListenerManager;
import net.minestom.server.monitoring.BenchmarkManager;
import net.minestom.server.network.ConnectionManager;
@ -29,15 +26,10 @@ import net.minestom.server.network.netty.NettyServer;
import net.minestom.server.network.packet.server.play.PluginMessagePacket;
import net.minestom.server.network.packet.server.play.ServerDifficultyPacket;
import net.minestom.server.network.packet.server.play.UpdateViewDistancePacket;
import net.minestom.server.particle.Particle;
import net.minestom.server.ping.ResponseDataConsumer;
import net.minestom.server.potion.PotionEffect;
import net.minestom.server.potion.PotionType;
import net.minestom.server.recipe.RecipeManager;
import net.minestom.server.registry.ResourceGatherer;
import net.minestom.server.scoreboard.TeamManager;
import net.minestom.server.sound.SoundEvent;
import net.minestom.server.statistic.StatisticType;
import net.minestom.server.storage.StorageLocation;
import net.minestom.server.storage.StorageManager;
import net.minestom.server.terminal.MinestomTerminal;
@ -156,14 +148,6 @@ public final class MinecraftServer {
// without this line, registry types that are not loaded explicitly will have an internal empty registry in Registries
// That can happen with PotionType for instance, if no code tries to access a PotionType field
// TODO: automate (probably with code generation)
Material.values();
PotionType.values();
PotionEffect.values();
Enchantment.values();
EntityType.values();
SoundEvent.values();
Particle.values();
StatisticType.values();
Fluid.values();
connectionManager = new ConnectionManager();

View File

@ -13,7 +13,6 @@ import net.minestom.server.network.packet.server.play.EntitySoundEffectPacket;
import net.minestom.server.network.packet.server.play.NamedSoundEffectPacket;
import net.minestom.server.network.packet.server.play.SoundEffectPacket;
import net.minestom.server.network.packet.server.play.StopSoundPacket;
import net.minestom.server.registry.Registries;
import net.minestom.server.sound.SoundEvent;
import org.jetbrains.annotations.NotNull;
@ -108,8 +107,7 @@ public class AdventurePacketConvertor {
* @return the sound packet
*/
public static @NotNull ServerPacket createSoundPacket(@NotNull Sound sound, double x, double y, double z) {
final SoundEvent minestomSound = Registries.getSoundEvent(sound.name());
final SoundEvent minestomSound = SoundEvent.fromNamespaceId(sound.name().asString());
if (minestomSound == null) {
final NamedSoundEffectPacket packet = new NamedSoundEffectPacket();
packet.soundName = sound.name().asString();
@ -122,7 +120,7 @@ public class AdventurePacketConvertor {
return packet;
} else {
final SoundEffectPacket packet = new SoundEffectPacket();
packet.soundId = minestomSound.getId();
packet.soundId = minestomSound.id();
packet.soundSource = sound.source();
packet.x = (int) x;
packet.y = (int) y;
@ -147,11 +145,11 @@ public class AdventurePacketConvertor {
throw new IllegalArgumentException("you can only call this method with entities");
final Entity entity = (Entity) emitter;
final SoundEvent minestomSound = Registries.getSoundEvent(sound.name());
final SoundEvent minestomSound = SoundEvent.fromNamespaceId(sound.name().asString());
if (minestomSound != null) {
final EntitySoundEffectPacket packet = new EntitySoundEffectPacket();
packet.soundId = minestomSound.getId();
packet.soundId = minestomSound.id();
packet.soundSource = sound.source();
packet.entityId = entity.getEntityId();
packet.volume = sound.volume();

View File

@ -3,7 +3,6 @@ package net.minestom.server.command.builder.arguments.minecraft.registry;
import net.minestom.server.command.builder.NodeMaker;
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
import net.minestom.server.particle.Particle;
import net.minestom.server.registry.Registries;
import org.jetbrains.annotations.NotNull;
/**
@ -17,7 +16,7 @@ public class ArgumentParticle extends ArgumentRegistry<Particle> {
@Override
public Particle getRegistry(@NotNull String value) {
return Registries.getParticle(value);
return Particle.fromNamespaceId(value);
}
@Override

View File

@ -3,7 +3,6 @@ package net.minestom.server.command.builder.arguments.minecraft.registry;
import net.minestom.server.command.builder.NodeMaker;
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
import net.minestom.server.potion.PotionEffect;
import net.minestom.server.registry.Registries;
import org.jetbrains.annotations.NotNull;
/**
@ -17,7 +16,7 @@ public class ArgumentPotionEffect extends ArgumentRegistry<PotionEffect> {
@Override
public PotionEffect getRegistry(@NotNull String value) {
return Registries.getPotionEffect(value);
return PotionEffect.fromNamespaceId(value);
}
@Override

View File

@ -62,7 +62,7 @@ import net.minestom.server.recipe.RecipeManager;
import net.minestom.server.resourcepack.ResourcePack;
import net.minestom.server.scoreboard.BelowNameTag;
import net.minestom.server.scoreboard.Team;
import net.minestom.server.stat.PlayerStatistic;
import net.minestom.server.statistic.PlayerStatistic;
import net.minestom.server.utils.ArrayUtils;
import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.PacketUtils;

View File

@ -169,11 +169,11 @@ public interface Block extends ProtocolObject, TagReadable, BlockConstants {
return BlockLoader.values();
}
static Block fromNamespaceId(@NotNull String namespaceID) {
static @Nullable Block fromNamespaceId(@NotNull String namespaceID) {
return BlockLoader.get(namespaceID);
}
static Block fromNamespaceId(@NotNull NamespaceID namespaceID) {
static @Nullable Block fromNamespaceId(@NotNull NamespaceID namespaceID) {
return fromNamespaceId(namespaceID.asString());
}

View File

@ -31,7 +31,7 @@ final class BlockLoader {
// Block state -> block object
private static final Int2ObjectMap<Block> BLOCK_STATE_MAP = new Int2ObjectOpenHashMap<>();
static @Nullable Block get(@NotNull String namespace) {
static Block get(@NotNull String namespace) {
if (namespace.indexOf(':') == -1) {
// Default to minecraft namespace
namespace = "minecraft:" + namespace;

View File

@ -56,7 +56,7 @@ public class BeaconInventory extends Inventory {
*/
public void setFirstPotionEffect(PotionEffect firstPotionEffect) {
this.firstPotionEffect = firstPotionEffect;
sendProperty(InventoryProperty.BEACON_FIRST_POTION, (short) firstPotionEffect.getId());
sendProperty(InventoryProperty.BEACON_FIRST_POTION, (short) firstPotionEffect.id());
}
/**
@ -75,7 +75,6 @@ public class BeaconInventory extends Inventory {
*/
public void setSecondPotionEffect(PotionEffect secondPotionEffect) {
this.secondPotionEffect = secondPotionEffect;
sendProperty(InventoryProperty.BEACON_SECOND_POTION, (short) secondPotionEffect.getId());
sendProperty(InventoryProperty.BEACON_SECOND_POTION, (short) secondPotionEffect.id());
}
}

View File

@ -11,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@ApiStatus.NonExtendable
public interface Enchantment extends ProtocolObject {
public interface Enchantment extends ProtocolObject, EnchantmentConstants {
/**
* Returns the enchantment registry.
@ -35,11 +35,11 @@ public interface Enchantment extends ProtocolObject {
return EnchantmentLoader.values();
}
static Enchantment fromNamespaceId(@NotNull String namespaceID) {
static @Nullable Enchantment fromNamespaceId(@NotNull String namespaceID) {
return EnchantmentLoader.get(namespaceID);
}
static Enchantment fromNamespaceId(@NotNull NamespaceID namespaceID) {
static @Nullable Enchantment fromNamespaceId(@NotNull NamespaceID namespaceID) {
return fromNamespaceId(namespaceID.asString());
}

View File

@ -6,7 +6,6 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minestom.server.registry.Registry;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
@ -24,7 +23,7 @@ final class EnchantmentLoader {
// Block id -> registry data
private static final Int2ObjectMap<Enchantment> ID_MAP = new Int2ObjectOpenHashMap<>();
static @Nullable Enchantment get(@NotNull String namespace) {
static Enchantment get(@NotNull String namespace) {
if (namespace.indexOf(':') == -1) {
// Default to minecraft namespace
namespace = "minecraft:" + namespace;

View File

@ -13,6 +13,7 @@ import java.util.Collection;
@ApiStatus.NonExtendable
public interface Material extends ProtocolObject, MaterialConstants {
/**
* Returns the material registry.
*
@ -63,11 +64,11 @@ public interface Material extends ProtocolObject, MaterialConstants {
return MaterialLoader.values();
}
static Material fromNamespaceId(@NotNull String namespaceID) {
static @Nullable Material fromNamespaceId(@NotNull String namespaceID) {
return MaterialLoader.get(namespaceID);
}
static Material fromNamespaceId(@NotNull NamespaceID namespaceID) {
static @Nullable Material fromNamespaceId(@NotNull NamespaceID namespaceID) {
return fromNamespaceId(namespaceID.asString());
}

View File

@ -6,7 +6,6 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minestom.server.registry.Registry;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
@ -27,7 +26,7 @@ final class MaterialLoader {
// Block id -> registry data
private static final Int2ObjectMap<Material> MATERIAL_ID_MAP = new Int2ObjectOpenHashMap<>();
static @Nullable Material get(@NotNull String namespace) {
static Material get(@NotNull String namespace) {
if (namespace.indexOf(':') == -1) {
// Default to minecraft namespace
namespace = "minecraft:" + namespace;

View File

@ -5,7 +5,6 @@ import net.minestom.server.item.ItemMeta;
import net.minestom.server.item.ItemMetaBuilder;
import net.minestom.server.potion.CustomPotionEffect;
import net.minestom.server.potion.PotionType;
import net.minestom.server.registry.Registries;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
@ -52,7 +51,7 @@ public class PotionMeta extends ItemMeta implements ItemMetaBuilder.Provider<Pot
public Builder potionType(@NotNull PotionType potionType) {
this.potionType = potionType;
mutateNbt(compound -> compound.setString("Potion", potionType.getNamespaceID().asString()));
mutateNbt(compound -> compound.setString("Potion", potionType.name()));
return this;
}
@ -90,7 +89,7 @@ public class PotionMeta extends ItemMeta implements ItemMetaBuilder.Provider<Pot
@Override
public void read(@NotNull NBTCompound nbtCompound) {
if (nbtCompound.containsKey("Potion")) {
potionType(Registries.getPotionType(nbtCompound.getString("Potion")));
potionType(PotionType.fromNamespaceId(nbtCompound.getString("Potion")));
}
if (nbtCompound.containsKey("CustomPotionEffects")) {

View File

@ -3,7 +3,7 @@ package net.minestom.server.listener;
import net.minestom.server.entity.Player;
import net.minestom.server.network.packet.client.play.ClientStatusPacket;
import net.minestom.server.network.packet.server.play.StatisticsPacket;
import net.minestom.server.stat.PlayerStatistic;
import net.minestom.server.statistic.PlayerStatistic;
import java.util.ArrayList;
import java.util.List;

View File

@ -20,7 +20,7 @@ public class EntityEffectPacket implements ServerPacket {
@Override
public void write(@NotNull BinaryWriter writer) {
writer.writeVarInt(entityId);
writer.writeByte((byte) potion.getEffect().getId());
writer.writeByte((byte) potion.getEffect().id());
writer.writeByte(potion.getAmplifier());
writer.writeVarInt(potion.getDuration());
writer.writeByte(potion.getFlags());

View File

@ -17,7 +17,7 @@ public class RemoveEntityEffectPacket implements ServerPacket {
@Override
public void write(@NotNull BinaryWriter writer) {
writer.writeVarInt(entityId);
writer.writeByte((byte) effect.getId());
writer.writeByte((byte) effect.id());
}
@Override

View File

@ -25,7 +25,7 @@ public class SoundEffectPacket implements ServerPacket {
@NotNull
public static SoundEffectPacket create(Source category, SoundEvent sound, Pos position, float volume, float pitch) {
SoundEffectPacket packet = new SoundEffectPacket();
packet.soundId = sound.getId();
packet.soundId = sound.id();
packet.soundSource = category;
// *8 converts to fixed-point representation with 3 bits for fractional part
packet.x = (int) position.x();

View File

@ -2,7 +2,7 @@ package net.minestom.server.network.packet.server.play;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
import net.minestom.server.stat.StatisticCategory;
import net.minestom.server.statistic.StatisticCategory;
import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.utils.binary.Readable;

View File

@ -0,0 +1,29 @@
package net.minestom.server.particle;
import net.minestom.server.registry.ProtocolObject;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@ApiStatus.NonExtendable
public interface Particle extends ProtocolObject, ParticleConstants {
static @NotNull Collection<@NotNull Particle> values() {
return ParticleLoader.values();
}
static @Nullable Particle fromNamespaceId(@NotNull String namespaceID) {
return ParticleLoader.get(namespaceID);
}
static @Nullable Particle fromNamespaceId(@NotNull NamespaceID namespaceID) {
return fromNamespaceId(namespaceID.asString());
}
static @Nullable Particle fromId(int id) {
return ParticleLoader.getId(id);
}
}

View File

@ -16,7 +16,7 @@ public class ParticleCreator {
float offsetX, float offsetY, float offsetZ,
float particleData, int count, @Nullable Consumer<BinaryWriter> dataWriter) {
ParticlePacket particlePacket = new ParticlePacket();
particlePacket.particleId = particleType.getId();
particlePacket.particleId = particleType.id();
particlePacket.longDistance = distance;
particlePacket.x = x;

View File

@ -0,0 +1,24 @@
package net.minestom.server.particle;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
final class ParticleImpl implements Particle {
private final NamespaceID namespaceID;
private final int id;
ParticleImpl(NamespaceID namespaceID, int id) {
this.namespaceID = namespaceID;
this.id = id;
}
@Override
public @NotNull NamespaceID namespace() {
return namespaceID;
}
@Override
public int id() {
return id;
}
}

View File

@ -0,0 +1,56 @@
package net.minestom.server.particle;
import com.google.gson.JsonObject;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minestom.server.registry.Registry;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ApiStatus.Internal
final class ParticleLoader {
// Maps do not need to be thread-safe as they are fully populated
// in the static initializer, should not be modified during runtime
// Block namespace -> registry data
private static final Map<String, Particle> NAMESPACE_MAP = new HashMap<>();
// Block id -> registry data
private static final Int2ObjectMap<Particle> ID_MAP = new Int2ObjectOpenHashMap<>();
static Particle get(@NotNull String namespace) {
if (namespace.indexOf(':') == -1) {
// Default to minecraft namespace
namespace = "minecraft:" + namespace;
}
return NAMESPACE_MAP.get(namespace);
}
static Particle getId(int id) {
return ID_MAP.get(id);
}
static Collection<Particle> values() {
return Collections.unmodifiableCollection(NAMESPACE_MAP.values());
}
static {
// Load data from file
JsonObject particles = Registry.load(Registry.Resource.PARTICLES);
particles.entrySet().forEach(entry -> {
final String namespace = entry.getKey();
final JsonObject object = entry.getValue().getAsJsonObject();
final int id = object.get("id").getAsInt();
final var particle = new ParticleImpl(NamespaceID.from(namespace), id);
ID_MAP.put(id, particle);
NAMESPACE_MAP.put(namespace, particle);
});
}
}

View File

@ -0,0 +1,44 @@
package net.minestom.server.potion;
import net.minestom.server.registry.ProtocolObject;
import net.minestom.server.registry.Registry;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@ApiStatus.NonExtendable
public interface PotionEffect extends ProtocolObject, PotionEffectConstants {
@Contract(pure = true)
@NotNull Registry.PotionEffectEntry registry();
@Override
default @NotNull NamespaceID namespace() {
return registry().namespace();
}
@Override
default int id() {
return registry().id();
}
static @NotNull Collection<@NotNull PotionEffect> values() {
return PotionEffectLoader.values();
}
static @Nullable PotionEffect fromNamespaceId(@NotNull String namespaceID) {
return PotionEffectLoader.get(namespaceID);
}
static @Nullable PotionEffect fromNamespaceId(@NotNull NamespaceID namespaceID) {
return fromNamespaceId(namespaceID.asString());
}
static @Nullable PotionEffect fromId(int id) {
return PotionEffectLoader.getId(id);
}
}

View File

@ -0,0 +1,17 @@
package net.minestom.server.potion;
import net.minestom.server.registry.Registry;
import org.jetbrains.annotations.NotNull;
final class PotionEffectImpl implements PotionEffect {
private final Registry.PotionEffectEntry registry;
PotionEffectImpl(Registry.PotionEffectEntry registry) {
this.registry = registry;
}
@Override
public @NotNull Registry.PotionEffectEntry registry() {
return registry;
}
}

View File

@ -0,0 +1,55 @@
package net.minestom.server.potion;
import com.google.gson.JsonObject;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minestom.server.registry.Registry;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ApiStatus.Internal
final class PotionEffectLoader {
// Maps do not need to be thread-safe as they are fully populated
// in the static initializer, should not be modified during runtime
// Block namespace -> registry data
private static final Map<String, PotionEffect> NAMESPACE_MAP = new HashMap<>();
// Block id -> registry data
private static final Int2ObjectMap<PotionEffect> ID_MAP = new Int2ObjectOpenHashMap<>();
static PotionEffect get(@NotNull String namespace) {
if (namespace.indexOf(':') == -1) {
// Default to minecraft namespace
namespace = "minecraft:" + namespace;
}
return NAMESPACE_MAP.get(namespace);
}
static PotionEffect getId(int id) {
return ID_MAP.get(id);
}
static Collection<PotionEffect> values() {
return Collections.unmodifiableCollection(NAMESPACE_MAP.values());
}
static {
// Load data from file
JsonObject potionEffects = Registry.load(Registry.Resource.POTION_EFFECTS);
potionEffects.entrySet().forEach(entry -> {
final String namespace = entry.getKey();
final JsonObject object = entry.getValue().getAsJsonObject();
final var potionEffect = new PotionEffectImpl(Registry.potionEffect(namespace, object, null));
ID_MAP.put(potionEffect.id(), potionEffect);
NAMESPACE_MAP.put(namespace, potionEffect);
});
}
}

View File

@ -0,0 +1,29 @@
package net.minestom.server.potion;
import net.minestom.server.registry.ProtocolObject;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@ApiStatus.NonExtendable
public interface PotionType extends ProtocolObject, PotionTypeConstants {
static @NotNull Collection<@NotNull PotionType> values() {
return PotionTypeLoader.values();
}
static @Nullable PotionType fromNamespaceId(@NotNull String namespaceID) {
return PotionTypeLoader.get(namespaceID);
}
static @Nullable PotionType fromNamespaceId(@NotNull NamespaceID namespaceID) {
return fromNamespaceId(namespaceID.asString());
}
static @Nullable PotionType fromId(int id) {
return PotionTypeLoader.getId(id);
}
}

View File

@ -0,0 +1,24 @@
package net.minestom.server.potion;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
final class PotionTypeImpl implements PotionType {
private final NamespaceID namespaceID;
private final int id;
PotionTypeImpl(NamespaceID namespaceID, int id) {
this.namespaceID = namespaceID;
this.id = id;
}
@Override
public @NotNull NamespaceID namespace() {
return namespaceID;
}
@Override
public int id() {
return id;
}
}

View File

@ -0,0 +1,56 @@
package net.minestom.server.potion;
import com.google.gson.JsonObject;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minestom.server.registry.Registry;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ApiStatus.Internal
final class PotionTypeLoader {
// Maps do not need to be thread-safe as they are fully populated
// in the static initializer, should not be modified during runtime
// Block namespace -> registry data
private static final Map<String, PotionType> NAMESPACE_MAP = new HashMap<>();
// Block id -> registry data
private static final Int2ObjectMap<PotionType> ID_MAP = new Int2ObjectOpenHashMap<>();
static PotionType get(@NotNull String namespace) {
if (namespace.indexOf(':') == -1) {
// Default to minecraft namespace
namespace = "minecraft:" + namespace;
}
return NAMESPACE_MAP.get(namespace);
}
static PotionType getId(int id) {
return ID_MAP.get(id);
}
static Collection<PotionType> values() {
return Collections.unmodifiableCollection(NAMESPACE_MAP.values());
}
static {
// Load data from file
JsonObject potionTypes = Registry.load(Registry.Resource.POTION_TYPES);
potionTypes.entrySet().forEach(entry -> {
final String namespace = entry.getKey();
final JsonObject object = entry.getValue().getAsJsonObject();
final int id = object.get("id").getAsInt();
final var potionType = new PotionTypeImpl(NamespaceID.from(namespace), id);
ID_MAP.put(id, potionType);
NAMESPACE_MAP.put(namespace, potionType);
});
}
}

View File

@ -37,6 +37,10 @@ public class Registry {
return new EnchantmentEntry(namespace, jsonObject, override);
}
public static PotionEffectEntry potionEffect(String namespace, @NotNull JsonObject jsonObject, JsonObject override) {
return new PotionEffectEntry(namespace, jsonObject, override);
}
public static JsonObject load(Resource resource) {
final String path = String.format("/%s.json", resource.name);
final var resourceStream = Registry.class.getResourceAsStream(path);
@ -47,7 +51,12 @@ public class Registry {
BLOCKS("blocks"),
ITEMS("items"),
ENTITIES("entities"),
ENCHANTMENTS("enchantments");
ENCHANTMENTS("enchantments"),
SOUNDS("sounds"),
STATISTICS("custom_statistics"),
POTION_EFFECTS("potion_effects"),
POTION_TYPES("potions"),
PARTICLES("particles");
private final String name;
@ -333,6 +342,43 @@ public class Registry {
}
}
public static class PotionEffectEntry extends Entry {
private final NamespaceID namespace;
private final int id;
private final String translationKey;
private final int color;
private final boolean isInstantaneous;
private PotionEffectEntry(String namespace, JsonObject main, JsonObject override) {
super(main, override);
this.namespace = NamespaceID.from(namespace);
this.id = getInt("id");
this.translationKey = getString("translationKey");
this.color = getInt("color");
this.isInstantaneous = getBoolean("instantaneous");
}
public @NotNull NamespaceID namespace() {
return namespace;
}
public int id() {
return id;
}
public String translationKey() {
return translationKey;
}
public int color() {
return color;
}
public boolean isInstantaneous() {
return isInstantaneous;
}
}
public static class Entry {
private final JsonObject main, override;

View File

@ -0,0 +1,29 @@
package net.minestom.server.sound;
import net.minestom.server.registry.ProtocolObject;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@ApiStatus.NonExtendable
public interface SoundEvent extends ProtocolObject, SoundEventConstants {
static @NotNull Collection<@NotNull SoundEvent> values() {
return SoundEventLoader.values();
}
static @Nullable SoundEvent fromNamespaceId(@NotNull String namespaceID) {
return SoundEventLoader.get(namespaceID);
}
static @Nullable SoundEvent fromNamespaceId(@NotNull NamespaceID namespaceID) {
return fromNamespaceId(namespaceID.asString());
}
static @Nullable SoundEvent fromId(int id) {
return SoundEventLoader.getId(id);
}
}

View File

@ -0,0 +1,25 @@
package net.minestom.server.sound;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
final class SoundEventImpl implements SoundEvent {
private final NamespaceID namespaceID;
private final int id;
SoundEventImpl(NamespaceID namespaceID, int id) {
this.namespaceID = namespaceID;
this.id = id;
}
@Override
public @NotNull NamespaceID namespace() {
return namespaceID;
}
@Override
public int id() {
return id;
}
}

View File

@ -0,0 +1,56 @@
package net.minestom.server.sound;
import com.google.gson.JsonObject;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minestom.server.registry.Registry;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ApiStatus.Internal
final class SoundEventLoader {
// Maps do not need to be thread-safe as they are fully populated
// in the static initializer, should not be modified during runtime
// Block namespace -> registry data
private static final Map<String, SoundEvent> NAMESPACE_MAP = new HashMap<>();
// Block id -> registry data
private static final Int2ObjectMap<SoundEvent> ID_MAP = new Int2ObjectOpenHashMap<>();
static SoundEvent get(@NotNull String namespace) {
if (namespace.indexOf(':') == -1) {
// Default to minecraft namespace
namespace = "minecraft:" + namespace;
}
return NAMESPACE_MAP.get(namespace);
}
static SoundEvent getId(int id) {
return ID_MAP.get(id);
}
static Collection<SoundEvent> values() {
return Collections.unmodifiableCollection(NAMESPACE_MAP.values());
}
static {
// Load data from file
JsonObject sounds = Registry.load(Registry.Resource.SOUNDS);
sounds.entrySet().forEach(entry -> {
final String namespace = entry.getKey();
final JsonObject object = entry.getValue().getAsJsonObject();
final int id = object.get("id").getAsInt();
final var soundEvent = new SoundEventImpl(NamespaceID.from(namespace), id);
ID_MAP.put(id, soundEvent);
NAMESPACE_MAP.put(namespace, soundEvent);
});
}
}

View File

@ -1,7 +1,6 @@
package net.minestom.server.stat;
package net.minestom.server.statistic;
import net.minestom.server.entity.Player;
import net.minestom.server.statistic.StatisticType;
import org.jetbrains.annotations.NotNull;
/**
@ -10,7 +9,6 @@ import org.jetbrains.annotations.NotNull;
* You can retrieve the statistics map with {@link Player#getStatisticValueMap()} and modify it with your own values.
*/
public class PlayerStatistic {
private final StatisticCategory category;
private final int statisticId;
@ -20,7 +18,7 @@ public class PlayerStatistic {
}
public PlayerStatistic(@NotNull StatisticType type) {
this(StatisticCategory.CUSTOM, type.getId());
this(StatisticCategory.CUSTOM, type.id());
}
@NotNull

View File

@ -1,4 +1,4 @@
package net.minestom.server.stat;
package net.minestom.server.statistic;
public enum StatisticCategory {
MINED,

View File

@ -0,0 +1,29 @@
package net.minestom.server.statistic;
import net.minestom.server.registry.ProtocolObject;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@ApiStatus.NonExtendable
public interface StatisticType extends ProtocolObject, StatisticTypeConstants {
static @NotNull Collection<@NotNull StatisticType> values() {
return StatisticTypeLoader.values();
}
static @Nullable StatisticType fromNamespaceId(@NotNull String namespaceID) {
return StatisticTypeLoader.get(namespaceID);
}
static @Nullable StatisticType fromNamespaceId(@NotNull NamespaceID namespaceID) {
return fromNamespaceId(namespaceID.asString());
}
static @Nullable StatisticType fromId(int id) {
return StatisticTypeLoader.getId(id);
}
}

View File

@ -0,0 +1,24 @@
package net.minestom.server.statistic;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
final class StatisticTypeImpl implements StatisticType {
private final NamespaceID namespaceID;
private final int id;
StatisticTypeImpl(NamespaceID namespaceID, int id) {
this.namespaceID = namespaceID;
this.id = id;
}
@Override
public @NotNull NamespaceID namespace() {
return namespaceID;
}
@Override
public int id() {
return id;
}
}

View File

@ -0,0 +1,57 @@
package net.minestom.server.statistic;
import com.google.gson.JsonObject;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minestom.server.registry.Registry;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ApiStatus.Internal
final class StatisticTypeLoader {
// Maps do not need to be thread-safe as they are fully populated
// in the static initializer, should not be modified during runtime
// Block namespace -> registry data
private static final Map<String, StatisticType> NAMESPACE_MAP = new HashMap<>();
// Block id -> registry data
private static final Int2ObjectMap<StatisticType> ID_MAP = new Int2ObjectOpenHashMap<>();
static StatisticType get(@NotNull String namespace) {
if (namespace.indexOf(':') == -1) {
// Default to minecraft namespace
namespace = "minecraft:" + namespace;
}
return NAMESPACE_MAP.get(namespace);
}
static StatisticType getId(int id) {
return ID_MAP.get(id);
}
static Collection<StatisticType> values() {
return Collections.unmodifiableCollection(NAMESPACE_MAP.values());
}
static {
// Load data from file
JsonObject statistics = Registry.load(Registry.Resource.STATISTICS);
statistics.entrySet().forEach(entry -> {
final String namespace = entry.getKey();
final JsonObject object = entry.getValue().getAsJsonObject();
final int id = object.get("id").getAsInt();
final var statisticType = new StatisticTypeImpl(NamespaceID.from(namespace), id);
ID_MAP.put(id, statisticType);
NAMESPACE_MAP.put(namespace, statisticType);
});
}
}