Make EntityType an interface

This commit is contained in:
TheMode 2021-07-27 11:56:20 +02:00
parent 00b991e970
commit 274a40ea27
15 changed files with 677 additions and 962 deletions

View File

@ -1,11 +1,8 @@
package net.minestom.codegen.entity;
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 net.minestom.codegen.util.NameUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
@ -15,168 +12,11 @@ import javax.lang.model.element.Modifier;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.List;
import java.util.Locale;
public final class EntityTypeGenerator extends MinestomCodeGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(EntityTypeGenerator.class);
private static final Map<String, String> metadata = new HashMap<>() {{
// Class's name (without the Meta suffix) <--> Package
// UPDATE: Handle new entity metadata
// Ambient
// put("AmbientCreature", "net.minestom.server.entity.metadata.ambient");
put("Bat", "net.minestom.server.entity.metadata.ambient");
// Animal
// put("Animal", "net.minestom.server.entity.metadata.animal");
put("AbstractHorse", "net.minestom.server.entity.metadata.animal");
put("Bee", "net.minestom.server.entity.metadata.animal");
put("ChestedHorse", "net.minestom.server.entity.metadata.animal");
put("Chicken", "net.minestom.server.entity.metadata.animal");
put("Cow", "net.minestom.server.entity.metadata.animal");
put("Donkey", "net.minestom.server.entity.metadata.animal");
put("Fox", "net.minestom.server.entity.metadata.animal");
put("Goat", "net.minestom.server.entity.metadata.animal");
put("Hoglin", "net.minestom.server.entity.metadata.animal");
put("Horse", "net.minestom.server.entity.metadata.animal");
put("Llama", "net.minestom.server.entity.metadata.animal");
put("Mooshroom", "net.minestom.server.entity.metadata.animal");
put("Mule", "net.minestom.server.entity.metadata.animal");
put("Ocelot", "net.minestom.server.entity.metadata.animal");
put("Panda", "net.minestom.server.entity.metadata.animal");
put("Pig", "net.minestom.server.entity.metadata.animal");
put("PolarBear", "net.minestom.server.entity.metadata.animal");
put("Rabbit", "net.minestom.server.entity.metadata.animal");
put("Sheep", "net.minestom.server.entity.metadata.animal");
put("SkeletonHorse", "net.minestom.server.entity.metadata.animal");
put("Strider", "net.minestom.server.entity.metadata.animal");
put("Turtle", "net.minestom.server.entity.metadata.animal");
put("ZombieHorse", "net.minestom.server.entity.metadata.animal");
// Animal - Tameable
// put("TameableAnimal", "net.minestom.server.entity.metadata.animal.tameable");
put("Cat", "net.minestom.server.entity.metadata.animal.tameable");
put("Parrot", "net.minestom.server.entity.metadata.animal.tameable");
put("Wolf", "net.minestom.server.entity.metadata.animal.tameable");
// Arrow
// put("AbstractArrow", "net.minestom.server.entity.metadata.arrow");
put("Arrow", "net.minestom.server.entity.metadata.arrow");
put("SpectralArrow", "net.minestom.server.entity.metadata.arrow");
put("ThrownTrident", "net.minestom.server.entity.metadata.arrow");
// Flying
// put("Flying", "net.minestom.server.entity.metadata.flying");
put("Ghast", "net.minestom.server.entity.metadata.flying");
put("Phantom", "net.minestom.server.entity.metadata.flying");
// Golem
// put("AbstractGolem", "net.minestom.server.entity.metadata.golem");
put("IronGolem", "net.minestom.server.entity.metadata.golem");
put("Shulker", "net.minestom.server.entity.metadata.golem");
put("SnowGolem", "net.minestom.server.entity.metadata.golem");
// Item
put("EyeOfEnder", "net.minestom.server.entity.metadata.item");
put("Fireball", "net.minestom.server.entity.metadata.item");
put("ItemContaining", "net.minestom.server.entity.metadata.item");
put("ItemEntity", "net.minestom.server.entity.metadata.item");
put("SmallFireball", "net.minestom.server.entity.metadata.item");
put("Snowball", "net.minestom.server.entity.metadata.item");
put("ThrownEgg", "net.minestom.server.entity.metadata.item");
put("ThrownEnderPearl", "net.minestom.server.entity.metadata.item");
put("ThrownExperienceBottle", "net.minestom.server.entity.metadata.item");
put("ThrownPotion", "net.minestom.server.entity.metadata.item");
// Minecart
// put("AbstractMinecart", "net.minestom.server.entity.metadata.minecart");
// put("AbstractMinecartContainer", "net.minestom.server.entity.metadata.minecart");
put("ChestMinecart", "net.minestom.server.entity.metadata.minecart");
put("CommandBlockMinecart", "net.minestom.server.entity.metadata.minecart");
put("FurnaceMinecart", "net.minestom.server.entity.metadata.minecart");
put("HopperMinecart", "net.minestom.server.entity.metadata.minecart");
put("Minecart", "net.minestom.server.entity.metadata.minecart");
put("SpawnerMinecart", "net.minestom.server.entity.metadata.minecart");
put("TntMinecart", "net.minestom.server.entity.metadata.minecart");
// Monster
// put("Monster", "net.minestom.server.entity.metadata.monster");
// put("BasePiglin", "net.minestom.server.entity.metadata.monster");
put("Blaze", "net.minestom.server.entity.metadata.monster");
put("CaveSpider", "net.minestom.server.entity.metadata.monster");
put("Creeper", "net.minestom.server.entity.metadata.monster");
put("ElderGuardian", "net.minestom.server.entity.metadata.monster");
put("Enderman", "net.minestom.server.entity.metadata.monster");
put("Endermite", "net.minestom.server.entity.metadata.monster");
put("Giant", "net.minestom.server.entity.metadata.monster");
put("Guardian", "net.minestom.server.entity.metadata.monster");
put("PiglinBrute", "net.minestom.server.entity.metadata.monster");
put("Piglin", "net.minestom.server.entity.metadata.monster");
put("Silverfish", "net.minestom.server.entity.metadata.monster");
put("Spider", "net.minestom.server.entity.metadata.monster");
put("Vex", "net.minestom.server.entity.metadata.monster");
put("Wither", "net.minestom.server.entity.metadata.monster");
put("Zoglin", "net.minestom.server.entity.metadata.monster");
// Monster - Raider
// put("AbstractIllager", "net.minestom.server.entity.metadata.monster.raider")
put("Evoker", "net.minestom.server.entity.metadata.monster.raider");
put("Illusioner", "net.minestom.server.entity.metadata.monster.raider");
put("Pillager", "net.minestom.server.entity.metadata.monster.raider");
put("Raider", "net.minestom.server.entity.metadata.monster.raider");
put("Ravager", "net.minestom.server.entity.metadata.monster.raider");
put("SpellcasterIllager", "net.minestom.server.entity.metadata.monster.raider");
put("Vindicator", "net.minestom.server.entity.metadata.monster.raider");
put("Witch", "net.minestom.server.entity.metadata.monster.raider");
// Monster - Skeleton
// put("AbstractSkeleton", "net.minestom.server.entity.metadata.monster.skeleton");
put("Skeleton", "net.minestom.server.entity.metadata.monster.skeleton");
put("Stray", "net.minestom.server.entity.metadata.monster.skeleton");
put("WitherSkeleton", "net.minestom.server.entity.metadata.monster.skeleton");
// Monster - Zombie
put("Drowned", "net.minestom.server.entity.metadata.monster.zombie");
put("Husk", "net.minestom.server.entity.metadata.monster.zombie");
put("Zombie", "net.minestom.server.entity.metadata.monster.zombie");
put("ZombieVillager", "net.minestom.server.entity.metadata.monster.zombie");
put("ZombifiedPiglin", "net.minestom.server.entity.metadata.monster.zombie");
// Other
put("AreaEffectCloud", "net.minestom.server.entity.metadata.other");
put("ArmorStand", "net.minestom.server.entity.metadata.other");
put("Boat", "net.minestom.server.entity.metadata.other");
put("DragonFireball", "net.minestom.server.entity.metadata.other");
put("EndCrystal", "net.minestom.server.entity.metadata.other");
put("EnderDragon", "net.minestom.server.entity.metadata.other");
put("EvokerFangs", "net.minestom.server.entity.metadata.other");
put("ExperienceOrb", "net.minestom.server.entity.metadata.other");
put("FallingBlock", "net.minestom.server.entity.metadata.other");
put("FireworkRocket", "net.minestom.server.entity.metadata.other");
put("FishingHook", "net.minestom.server.entity.metadata.other");
put("GlowItemFrame", "net.minestom.server.entity.metadata.other");
put("ItemFrame", "net.minestom.server.entity.metadata.other");
put("LeashKnot", "net.minestom.server.entity.metadata.other");
put("LightningBolt", "net.minestom.server.entity.metadata.other");
put("LlamaSpit", "net.minestom.server.entity.metadata.other");
put("MagmaCube", "net.minestom.server.entity.metadata.other");
put("Marker", "net.minestom.server.entity.metadata.other");
put("Painting", "net.minestom.server.entity.metadata.other");
put("PrimedTnt", "net.minestom.server.entity.metadata.other");
put("ShulkerBullet", "net.minestom.server.entity.metadata.other");
put("Slime", "net.minestom.server.entity.metadata.other");
put("TraderLlama", "net.minestom.server.entity.metadata.other");
put("WitherSkull", "net.minestom.server.entity.metadata.other");
// Villager
// put("AbstractVillager", "net.minestom.server.entity.metadata.villager");
put("Villager", "net.minestom.server.entity.metadata.villager");
put("WanderingTrader", "net.minestom.server.entity.metadata.villager");
// Water
// put("WaterAnimalMeta", "net.minestom.server.entity.metadata.water")
put("Axolotl", "net.minestom.server.entity.metadata.water");
put("Squid", "net.minestom.server.entity.metadata.water");
put("GlowSquid", "net.minestom.server.entity.metadata.water");
put("Dolphin", "net.minestom.server.entity.metadata.water");
// Water - Fish
// put("AbstractFish", "net.minestom.server.entity.metadata.water.fish");
put("Cod", "net.minestom.server.entity.metadata.water.fish");
put("Pufferfish", "net.minestom.server.entity.metadata.water.fish");
put("Salmon", "net.minestom.server.entity.metadata.water.fish");
put("TropicalFish", "net.minestom.server.entity.metadata.water.fish");
// Player
put("Player", "net.minestom.server.entity.metadata");
}};
private final InputStream entitiesFile;
private final File outputFolder;
@ -192,248 +32,35 @@ public final class EntityTypeGenerator extends MinestomCodeGenerator {
LOGGER.error("Stopped code generation for entities.");
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");
ClassName entityCN = ClassName.get("net.minestom.server.entity", "EntityType");
JsonObject entities = GSON.fromJson(new InputStreamReader(entitiesFile), JsonObject.class);
ClassName entityClassName = ClassName.get("net.minestom.server.entity", "EntityType");
JsonObject entities;
entities = GSON.fromJson(new InputStreamReader(entitiesFile), JsonObject.class);
ClassName entitiesCN = ClassName.get("net.minestom.server.entity", "EntityTypeConstants");
// BlockConstants class
TypeSpec.Builder blockConstantsClass = TypeSpec.interfaceBuilder(entitiesCN)
// Add @SuppressWarnings("unused")
.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "unused").build())
.addJavadoc("AUTOGENERATED by " + getClass().getSimpleName());
// Particle
TypeSpec.Builder entityClass = TypeSpec.enumBuilder(entityClassName)
.addSuperinterface(ClassName.get("net.kyori.adventure.key", "Keyed"))
.addModifiers(Modifier.PUBLIC).addJavadoc("AUTOGENERATED by " + getClass().getSimpleName());
entityClass.addField(
FieldSpec.builder(namespaceIDClassName, "id")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).addAnnotation(NotNull.class).build()
);
entityClass.addField(
FieldSpec.builder(TypeName.DOUBLE, "width")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build()
);
entityClass.addField(
FieldSpec.builder(TypeName.DOUBLE, "height")
.addModifiers(Modifier.PRIVATE, Modifier.FINAL).build()
);
entityClass.addField(
FieldSpec.builder(
ParameterizedTypeName.get(
ClassName.get(BiFunction.class),
ClassName.get("net.minestom.server.entity", "Entity"),
ClassName.get("net.minestom.server.entity", "Metadata"),
ClassName.get("net.minestom.server.entity.metadata", "EntityMeta")
),
"metaConstructor"
)
.addModifiers(Modifier.PRIVATE, Modifier.FINAL)
.addAnnotation(NotNull.class)
.build()
);
entityClass.addField(
FieldSpec.builder(
ClassName.get("net.minestom.server.entity", "EntitySpawnType"),
"spawnType"
)
.addModifiers(Modifier.PRIVATE, Modifier.FINAL)
.addAnnotation(NotNull.class)
.build()
);
// static field
entityClass.addField(
FieldSpec.builder(ArrayTypeName.of(entityClassName), "VALUES")
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
.initializer("values()")
.build()
);
entityClass.addMethod(
MethodSpec.constructorBuilder()
.addParameter(ParameterSpec.builder(namespaceIDClassName, "id").addAnnotation(NotNull.class).build())
.addParameter(ParameterSpec.builder(TypeName.DOUBLE, "width").build())
.addParameter(ParameterSpec.builder(TypeName.DOUBLE, "height").build())
.addParameter(
ParameterSpec.builder(
ParameterizedTypeName.get(
ClassName.get(BiFunction.class),
ClassName.get("net.minestom.server.entity", "Entity"),
ClassName.get("net.minestom.server.entity", "Metadata"),
ClassName.get("net.minestom.server.entity.metadata", "EntityMeta")
),
"metaConstructor"
)
.addAnnotation(NotNull.class)
.build()
)
.addParameter(
ParameterSpec.builder(
ClassName.get("net.minestom.server.entity", "EntitySpawnType"),
"spawnType"
)
.addAnnotation(NotNull.class)
.build()
)
.addStatement("this.id = id")
.addStatement("this.width = width")
.addStatement("this.height = height")
.addStatement("this.metaConstructor = metaConstructor")
.addStatement("this.spawnType = spawnType")
.addStatement("$T.entityTypes.put(id, this)", registriesClassName)
.build()
);
// Override key method (adventure)
entityClass.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
entityClass.addMethod(
MethodSpec.methodBuilder("getId")
.returns(TypeName.SHORT)
.addStatement("return (short) ordinal()")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getNamespaceID method
entityClass.addMethod(
MethodSpec.methodBuilder("getNamespaceID")
.returns(namespaceIDClassName)
.addAnnotation(NotNull.class)
.addStatement("return this.id")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getWidth method
entityClass.addMethod(
MethodSpec.methodBuilder("getWidth")
.returns(TypeName.DOUBLE)
.addStatement("return this.width")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getHeight method
entityClass.addMethod(
MethodSpec.methodBuilder("getHeight")
.returns(TypeName.DOUBLE)
.addStatement("return this.height")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getMetaConstructor method
entityClass.addMethod(
MethodSpec.methodBuilder("getMetaConstructor")
.returns(
ParameterizedTypeName.get(
ClassName.get(BiFunction.class),
ClassName.get("net.minestom.server.entity", "Entity"),
ClassName.get("net.minestom.server.entity", "Metadata"),
ClassName.get("net.minestom.server.entity.metadata", "EntityMeta")
)
)
.addStatement("return this.metaConstructor")
.addModifiers(Modifier.PUBLIC)
.build()
);
// getSpawnType method
entityClass.addMethod(
MethodSpec.methodBuilder("getSpawnType")
.returns(ClassName.get("net.minestom.server.entity", "EntitySpawnType"))
.addStatement("return this.spawnType")
.addModifiers(Modifier.PUBLIC)
.build()
);
// fromId Method
entityClass.addMethod(
MethodSpec.methodBuilder("fromId")
.returns(entityClassName)
.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
entityClass.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
entities.entrySet().forEach(entry -> {
final String entityNamespace = entry.getKey();
final String entityConstant = toConstant(entityNamespace);
JsonObject entity = entry.getValue().getAsJsonObject();
// Get metaClass (this is a little complicated)
String metaClassName = NameUtil.convertSnakeCaseToCamelCase(entityConstant.toLowerCase());
switch (metaClassName) {
// These are cases where the entity name doesn't fully match up to the meta name.
// UPDATE: Handle new entity names that don't match up to their meta name.
case "Item":
metaClassName = "ItemEntity";
break;
case "Tnt":
metaClassName = "PrimedTnt";
break;
case "FishingBobber":
metaClassName = "FishingHook";
break;
case "Egg":
case "EnderPearl":
case "ExperienceBottle":
case "Potion":
case "Trident":
metaClassName = "Thrown" + metaClassName;
break;
default:
break;
}
String packageName = metadata.get(metaClassName);
String className = metaClassName + "Meta";
if (packageName == null) {
LOGGER.error("The Entity metadata for " + entityNamespace + " is not implemented!");
LOGGER.error("The metadata has been defaulted to EntityMeta.");
packageName = "net.minestom.server.entity.metadata";
className = "EntityMeta";
}
entityClass.addEnumConstant(
entityConstant,
TypeSpec.anonymousClassBuilder(
"$T.from($S), $L, $L, $T::new, $T.$N",
namespaceIDClassName,
entityNamespace,
entity.get("width").getAsDouble(),
entity.get("height").getAsDouble(),
ClassName.get(packageName, className),
ClassName.get("net.minestom.server.entity", "EntitySpawnType"),
entity.get("packetType").getAsString().toUpperCase()
).build()
entities.keySet().forEach(namespace -> {
final String constantName = namespace.replace("minecraft:", "").toUpperCase(Locale.ROOT);
blockConstantsClass.addField(
FieldSpec.builder(entityCN, constantName)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer(
// Material.STONE = Material.fromNamespaceId("minecraft:stone")
"$T.fromNamespaceId($S)",
entityCN,
namespace
)
.build()
);
});
// Write files to outputFolder
writeFiles(
Collections.singletonList(
JavaFile.builder("net.minestom.server.entity", entityClass.build())
List.of(
JavaFile.builder("net.minestom.server.entity", blockConstantsClass.build())
.indent(" ")
.skipJavaLangImports(true)
.build()

View File

@ -1,425 +0,0 @@
package net.minestom.server.entity;
import java.util.function.BiFunction;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.Keyed;
import net.minestom.server.entity.metadata.EntityMeta;
import net.minestom.server.entity.metadata.PlayerMeta;
import net.minestom.server.entity.metadata.ambient.BatMeta;
import net.minestom.server.entity.metadata.animal.BeeMeta;
import net.minestom.server.entity.metadata.animal.ChickenMeta;
import net.minestom.server.entity.metadata.animal.CowMeta;
import net.minestom.server.entity.metadata.animal.DonkeyMeta;
import net.minestom.server.entity.metadata.animal.FoxMeta;
import net.minestom.server.entity.metadata.animal.GoatMeta;
import net.minestom.server.entity.metadata.animal.HoglinMeta;
import net.minestom.server.entity.metadata.animal.HorseMeta;
import net.minestom.server.entity.metadata.animal.LlamaMeta;
import net.minestom.server.entity.metadata.animal.MooshroomMeta;
import net.minestom.server.entity.metadata.animal.MuleMeta;
import net.minestom.server.entity.metadata.animal.OcelotMeta;
import net.minestom.server.entity.metadata.animal.PandaMeta;
import net.minestom.server.entity.metadata.animal.PigMeta;
import net.minestom.server.entity.metadata.animal.PolarBearMeta;
import net.minestom.server.entity.metadata.animal.RabbitMeta;
import net.minestom.server.entity.metadata.animal.SheepMeta;
import net.minestom.server.entity.metadata.animal.SkeletonHorseMeta;
import net.minestom.server.entity.metadata.animal.StriderMeta;
import net.minestom.server.entity.metadata.animal.TurtleMeta;
import net.minestom.server.entity.metadata.animal.ZombieHorseMeta;
import net.minestom.server.entity.metadata.animal.tameable.CatMeta;
import net.minestom.server.entity.metadata.animal.tameable.ParrotMeta;
import net.minestom.server.entity.metadata.animal.tameable.WolfMeta;
import net.minestom.server.entity.metadata.arrow.ArrowMeta;
import net.minestom.server.entity.metadata.arrow.SpectralArrowMeta;
import net.minestom.server.entity.metadata.arrow.ThrownTridentMeta;
import net.minestom.server.entity.metadata.flying.GhastMeta;
import net.minestom.server.entity.metadata.flying.PhantomMeta;
import net.minestom.server.entity.metadata.golem.IronGolemMeta;
import net.minestom.server.entity.metadata.golem.ShulkerMeta;
import net.minestom.server.entity.metadata.golem.SnowGolemMeta;
import net.minestom.server.entity.metadata.item.EyeOfEnderMeta;
import net.minestom.server.entity.metadata.item.FireballMeta;
import net.minestom.server.entity.metadata.item.ItemEntityMeta;
import net.minestom.server.entity.metadata.item.SmallFireballMeta;
import net.minestom.server.entity.metadata.item.SnowballMeta;
import net.minestom.server.entity.metadata.item.ThrownEggMeta;
import net.minestom.server.entity.metadata.item.ThrownEnderPearlMeta;
import net.minestom.server.entity.metadata.item.ThrownExperienceBottleMeta;
import net.minestom.server.entity.metadata.item.ThrownPotionMeta;
import net.minestom.server.entity.metadata.minecart.ChestMinecartMeta;
import net.minestom.server.entity.metadata.minecart.CommandBlockMinecartMeta;
import net.minestom.server.entity.metadata.minecart.FurnaceMinecartMeta;
import net.minestom.server.entity.metadata.minecart.HopperMinecartMeta;
import net.minestom.server.entity.metadata.minecart.MinecartMeta;
import net.minestom.server.entity.metadata.minecart.SpawnerMinecartMeta;
import net.minestom.server.entity.metadata.minecart.TntMinecartMeta;
import net.minestom.server.entity.metadata.monster.BlazeMeta;
import net.minestom.server.entity.metadata.monster.CaveSpiderMeta;
import net.minestom.server.entity.metadata.monster.CreeperMeta;
import net.minestom.server.entity.metadata.monster.ElderGuardianMeta;
import net.minestom.server.entity.metadata.monster.EndermanMeta;
import net.minestom.server.entity.metadata.monster.EndermiteMeta;
import net.minestom.server.entity.metadata.monster.GiantMeta;
import net.minestom.server.entity.metadata.monster.GuardianMeta;
import net.minestom.server.entity.metadata.monster.PiglinBruteMeta;
import net.minestom.server.entity.metadata.monster.PiglinMeta;
import net.minestom.server.entity.metadata.monster.SilverfishMeta;
import net.minestom.server.entity.metadata.monster.SpiderMeta;
import net.minestom.server.entity.metadata.monster.VexMeta;
import net.minestom.server.entity.metadata.monster.WitherMeta;
import net.minestom.server.entity.metadata.monster.ZoglinMeta;
import net.minestom.server.entity.metadata.monster.raider.EvokerMeta;
import net.minestom.server.entity.metadata.monster.raider.IllusionerMeta;
import net.minestom.server.entity.metadata.monster.raider.PillagerMeta;
import net.minestom.server.entity.metadata.monster.raider.RavagerMeta;
import net.minestom.server.entity.metadata.monster.raider.VindicatorMeta;
import net.minestom.server.entity.metadata.monster.raider.WitchMeta;
import net.minestom.server.entity.metadata.monster.skeleton.SkeletonMeta;
import net.minestom.server.entity.metadata.monster.skeleton.StrayMeta;
import net.minestom.server.entity.metadata.monster.skeleton.WitherSkeletonMeta;
import net.minestom.server.entity.metadata.monster.zombie.DrownedMeta;
import net.minestom.server.entity.metadata.monster.zombie.HuskMeta;
import net.minestom.server.entity.metadata.monster.zombie.ZombieMeta;
import net.minestom.server.entity.metadata.monster.zombie.ZombieVillagerMeta;
import net.minestom.server.entity.metadata.monster.zombie.ZombifiedPiglinMeta;
import net.minestom.server.entity.metadata.other.AreaEffectCloudMeta;
import net.minestom.server.entity.metadata.other.ArmorStandMeta;
import net.minestom.server.entity.metadata.other.BoatMeta;
import net.minestom.server.entity.metadata.other.DragonFireballMeta;
import net.minestom.server.entity.metadata.other.EndCrystalMeta;
import net.minestom.server.entity.metadata.other.EnderDragonMeta;
import net.minestom.server.entity.metadata.other.EvokerFangsMeta;
import net.minestom.server.entity.metadata.other.ExperienceOrbMeta;
import net.minestom.server.entity.metadata.other.FallingBlockMeta;
import net.minestom.server.entity.metadata.other.FireworkRocketMeta;
import net.minestom.server.entity.metadata.other.FishingHookMeta;
import net.minestom.server.entity.metadata.other.GlowItemFrameMeta;
import net.minestom.server.entity.metadata.other.ItemFrameMeta;
import net.minestom.server.entity.metadata.other.LeashKnotMeta;
import net.minestom.server.entity.metadata.other.LightningBoltMeta;
import net.minestom.server.entity.metadata.other.LlamaSpitMeta;
import net.minestom.server.entity.metadata.other.MagmaCubeMeta;
import net.minestom.server.entity.metadata.other.MarkerMeta;
import net.minestom.server.entity.metadata.other.PaintingMeta;
import net.minestom.server.entity.metadata.other.PrimedTntMeta;
import net.minestom.server.entity.metadata.other.ShulkerBulletMeta;
import net.minestom.server.entity.metadata.other.SlimeMeta;
import net.minestom.server.entity.metadata.other.TraderLlamaMeta;
import net.minestom.server.entity.metadata.other.WitherSkullMeta;
import net.minestom.server.entity.metadata.villager.VillagerMeta;
import net.minestom.server.entity.metadata.villager.WanderingTraderMeta;
import net.minestom.server.entity.metadata.water.AxolotlMeta;
import net.minestom.server.entity.metadata.water.DolphinMeta;
import net.minestom.server.entity.metadata.water.GlowSquidMeta;
import net.minestom.server.entity.metadata.water.SquidMeta;
import net.minestom.server.entity.metadata.water.fish.CodMeta;
import net.minestom.server.entity.metadata.water.fish.PufferfishMeta;
import net.minestom.server.entity.metadata.water.fish.SalmonMeta;
import net.minestom.server.entity.metadata.water.fish.TropicalFishMeta;
import net.minestom.server.registry.Registries;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* AUTOGENERATED by EntityTypeGenerator
*/
public enum EntityType implements Keyed {
AREA_EFFECT_CLOUD(NamespaceID.from("minecraft:area_effect_cloud"), 6.0, 0.5, AreaEffectCloudMeta::new, EntitySpawnType.BASE),
ARMOR_STAND(NamespaceID.from("minecraft:armor_stand"), 0.5, 1.975, ArmorStandMeta::new, EntitySpawnType.LIVING),
ARROW(NamespaceID.from("minecraft:arrow"), 0.5, 0.5, ArrowMeta::new, EntitySpawnType.BASE),
AXOLOTL(NamespaceID.from("minecraft:axolotl"), 0.75, 0.42, AxolotlMeta::new, EntitySpawnType.LIVING),
BAT(NamespaceID.from("minecraft:bat"), 0.5, 0.9, BatMeta::new, EntitySpawnType.LIVING),
BEE(NamespaceID.from("minecraft:bee"), 0.7, 0.6, BeeMeta::new, EntitySpawnType.LIVING),
BLAZE(NamespaceID.from("minecraft:blaze"), 0.6, 1.8, BlazeMeta::new, EntitySpawnType.LIVING),
BOAT(NamespaceID.from("minecraft:boat"), 1.375, 0.5625, BoatMeta::new, EntitySpawnType.BASE),
CAT(NamespaceID.from("minecraft:cat"), 0.6, 0.7, CatMeta::new, EntitySpawnType.LIVING),
CAVE_SPIDER(NamespaceID.from("minecraft:cave_spider"), 0.7, 0.5, CaveSpiderMeta::new, EntitySpawnType.LIVING),
CHICKEN(NamespaceID.from("minecraft:chicken"), 0.4, 0.7, ChickenMeta::new, EntitySpawnType.LIVING),
COD(NamespaceID.from("minecraft:cod"), 0.5, 0.3, CodMeta::new, EntitySpawnType.LIVING),
COW(NamespaceID.from("minecraft:cow"), 0.9, 1.4, CowMeta::new, EntitySpawnType.LIVING),
CREEPER(NamespaceID.from("minecraft:creeper"), 0.6, 1.7, CreeperMeta::new, EntitySpawnType.LIVING),
DOLPHIN(NamespaceID.from("minecraft:dolphin"), 0.9, 0.6, DolphinMeta::new, EntitySpawnType.LIVING),
DONKEY(NamespaceID.from("minecraft:donkey"), 1.3964844, 1.5, DonkeyMeta::new, EntitySpawnType.LIVING),
DRAGON_FIREBALL(NamespaceID.from("minecraft:dragon_fireball"), 1.0, 1.0, DragonFireballMeta::new, EntitySpawnType.BASE),
DROWNED(NamespaceID.from("minecraft:drowned"), 0.6, 1.95, DrownedMeta::new, EntitySpawnType.LIVING),
ELDER_GUARDIAN(NamespaceID.from("minecraft:elder_guardian"), 1.9975, 1.9975, ElderGuardianMeta::new, EntitySpawnType.LIVING),
END_CRYSTAL(NamespaceID.from("minecraft:end_crystal"), 2.0, 2.0, EndCrystalMeta::new, EntitySpawnType.BASE),
ENDER_DRAGON(NamespaceID.from("minecraft:ender_dragon"), 16.0, 8.0, EnderDragonMeta::new, EntitySpawnType.LIVING),
ENDERMAN(NamespaceID.from("minecraft:enderman"), 0.6, 2.9, EndermanMeta::new, EntitySpawnType.LIVING),
ENDERMITE(NamespaceID.from("minecraft:endermite"), 0.4, 0.3, EndermiteMeta::new, EntitySpawnType.LIVING),
EVOKER(NamespaceID.from("minecraft:evoker"), 0.6, 1.95, EvokerMeta::new, EntitySpawnType.LIVING),
EVOKER_FANGS(NamespaceID.from("minecraft:evoker_fangs"), 0.5, 0.8, EvokerFangsMeta::new, EntitySpawnType.BASE),
EXPERIENCE_ORB(NamespaceID.from("minecraft:experience_orb"), 0.5, 0.5, ExperienceOrbMeta::new, EntitySpawnType.EXPERIENCE_ORB),
EYE_OF_ENDER(NamespaceID.from("minecraft:eye_of_ender"), 0.25, 0.25, EyeOfEnderMeta::new, EntitySpawnType.BASE),
FALLING_BLOCK(NamespaceID.from("minecraft:falling_block"), 0.98, 0.98, FallingBlockMeta::new, EntitySpawnType.BASE),
FIREWORK_ROCKET(NamespaceID.from("minecraft:firework_rocket"), 0.25, 0.25, FireworkRocketMeta::new, EntitySpawnType.BASE),
FOX(NamespaceID.from("minecraft:fox"), 0.6, 0.7, FoxMeta::new, EntitySpawnType.LIVING),
GHAST(NamespaceID.from("minecraft:ghast"), 4.0, 4.0, GhastMeta::new, EntitySpawnType.LIVING),
GIANT(NamespaceID.from("minecraft:giant"), 3.6, 12.0, GiantMeta::new, EntitySpawnType.LIVING),
GLOW_ITEM_FRAME(NamespaceID.from("minecraft:glow_item_frame"), 0.5, 0.5, GlowItemFrameMeta::new, EntitySpawnType.BASE),
GLOW_SQUID(NamespaceID.from("minecraft:glow_squid"), 0.8, 0.8, GlowSquidMeta::new, EntitySpawnType.LIVING),
GOAT(NamespaceID.from("minecraft:goat"), 0.9, 1.3, GoatMeta::new, EntitySpawnType.LIVING),
GUARDIAN(NamespaceID.from("minecraft:guardian"), 0.85, 0.85, GuardianMeta::new, EntitySpawnType.LIVING),
HOGLIN(NamespaceID.from("minecraft:hoglin"), 1.3964844, 1.4, HoglinMeta::new, EntitySpawnType.LIVING),
HORSE(NamespaceID.from("minecraft:horse"), 1.3964844, 1.6, HorseMeta::new, EntitySpawnType.LIVING),
HUSK(NamespaceID.from("minecraft:husk"), 0.6, 1.95, HuskMeta::new, EntitySpawnType.LIVING),
ILLUSIONER(NamespaceID.from("minecraft:illusioner"), 0.6, 1.95, IllusionerMeta::new, EntitySpawnType.LIVING),
IRON_GOLEM(NamespaceID.from("minecraft:iron_golem"), 1.4, 2.7, IronGolemMeta::new, EntitySpawnType.LIVING),
ITEM(NamespaceID.from("minecraft:item"), 0.25, 0.25, ItemEntityMeta::new, EntitySpawnType.BASE),
ITEM_FRAME(NamespaceID.from("minecraft:item_frame"), 0.5, 0.5, ItemFrameMeta::new, EntitySpawnType.BASE),
FIREBALL(NamespaceID.from("minecraft:fireball"), 1.0, 1.0, FireballMeta::new, EntitySpawnType.BASE),
LEASH_KNOT(NamespaceID.from("minecraft:leash_knot"), 0.375, 0.5, LeashKnotMeta::new, EntitySpawnType.BASE),
LIGHTNING_BOLT(NamespaceID.from("minecraft:lightning_bolt"), 0.0, 0.0, LightningBoltMeta::new, EntitySpawnType.BASE),
LLAMA(NamespaceID.from("minecraft:llama"), 0.9, 1.87, LlamaMeta::new, EntitySpawnType.LIVING),
LLAMA_SPIT(NamespaceID.from("minecraft:llama_spit"), 0.25, 0.25, LlamaSpitMeta::new, EntitySpawnType.BASE),
MAGMA_CUBE(NamespaceID.from("minecraft:magma_cube"), 2.04, 2.04, MagmaCubeMeta::new, EntitySpawnType.LIVING),
MARKER(NamespaceID.from("minecraft:marker"), 0.0, 0.0, MarkerMeta::new, EntitySpawnType.BASE),
MINECART(NamespaceID.from("minecraft:minecart"), 0.98, 0.7, MinecartMeta::new, EntitySpawnType.BASE),
CHEST_MINECART(NamespaceID.from("minecraft:chest_minecart"), 0.98, 0.7, ChestMinecartMeta::new, EntitySpawnType.BASE),
COMMAND_BLOCK_MINECART(NamespaceID.from("minecraft:command_block_minecart"), 0.98, 0.7, CommandBlockMinecartMeta::new, EntitySpawnType.BASE),
FURNACE_MINECART(NamespaceID.from("minecraft:furnace_minecart"), 0.98, 0.7, FurnaceMinecartMeta::new, EntitySpawnType.BASE),
HOPPER_MINECART(NamespaceID.from("minecraft:hopper_minecart"), 0.98, 0.7, HopperMinecartMeta::new, EntitySpawnType.BASE),
SPAWNER_MINECART(NamespaceID.from("minecraft:spawner_minecart"), 0.98, 0.7, SpawnerMinecartMeta::new, EntitySpawnType.BASE),
TNT_MINECART(NamespaceID.from("minecraft:tnt_minecart"), 0.98, 0.7, TntMinecartMeta::new, EntitySpawnType.BASE),
MULE(NamespaceID.from("minecraft:mule"), 1.3964844, 1.6, MuleMeta::new, EntitySpawnType.LIVING),
MOOSHROOM(NamespaceID.from("minecraft:mooshroom"), 0.9, 1.4, MooshroomMeta::new, EntitySpawnType.LIVING),
OCELOT(NamespaceID.from("minecraft:ocelot"), 0.6, 0.7, OcelotMeta::new, EntitySpawnType.LIVING),
PAINTING(NamespaceID.from("minecraft:painting"), 0.5, 0.5, PaintingMeta::new, EntitySpawnType.PAINTING),
PANDA(NamespaceID.from("minecraft:panda"), 1.3, 1.25, PandaMeta::new, EntitySpawnType.LIVING),
PARROT(NamespaceID.from("minecraft:parrot"), 0.5, 0.9, ParrotMeta::new, EntitySpawnType.LIVING),
PHANTOM(NamespaceID.from("minecraft:phantom"), 0.9, 0.5, PhantomMeta::new, EntitySpawnType.LIVING),
PIG(NamespaceID.from("minecraft:pig"), 0.9, 0.9, PigMeta::new, EntitySpawnType.LIVING),
PIGLIN(NamespaceID.from("minecraft:piglin"), 0.6, 1.95, PiglinMeta::new, EntitySpawnType.LIVING),
PIGLIN_BRUTE(NamespaceID.from("minecraft:piglin_brute"), 0.6, 1.95, PiglinBruteMeta::new, EntitySpawnType.LIVING),
PILLAGER(NamespaceID.from("minecraft:pillager"), 0.6, 1.95, PillagerMeta::new, EntitySpawnType.LIVING),
POLAR_BEAR(NamespaceID.from("minecraft:polar_bear"), 1.4, 1.4, PolarBearMeta::new, EntitySpawnType.LIVING),
TNT(NamespaceID.from("minecraft:tnt"), 0.98, 0.98, PrimedTntMeta::new, EntitySpawnType.BASE),
PUFFERFISH(NamespaceID.from("minecraft:pufferfish"), 0.7, 0.7, PufferfishMeta::new, EntitySpawnType.LIVING),
RABBIT(NamespaceID.from("minecraft:rabbit"), 0.4, 0.5, RabbitMeta::new, EntitySpawnType.LIVING),
RAVAGER(NamespaceID.from("minecraft:ravager"), 1.95, 2.2, RavagerMeta::new, EntitySpawnType.LIVING),
SALMON(NamespaceID.from("minecraft:salmon"), 0.7, 0.4, SalmonMeta::new, EntitySpawnType.LIVING),
SHEEP(NamespaceID.from("minecraft:sheep"), 0.9, 1.3, SheepMeta::new, EntitySpawnType.LIVING),
SHULKER(NamespaceID.from("minecraft:shulker"), 1.0, 1.0, ShulkerMeta::new, EntitySpawnType.LIVING),
SHULKER_BULLET(NamespaceID.from("minecraft:shulker_bullet"), 0.3125, 0.3125, ShulkerBulletMeta::new, EntitySpawnType.BASE),
SILVERFISH(NamespaceID.from("minecraft:silverfish"), 0.4, 0.3, SilverfishMeta::new, EntitySpawnType.LIVING),
SKELETON(NamespaceID.from("minecraft:skeleton"), 0.6, 1.99, SkeletonMeta::new, EntitySpawnType.LIVING),
SKELETON_HORSE(NamespaceID.from("minecraft:skeleton_horse"), 1.3964844, 1.6, SkeletonHorseMeta::new, EntitySpawnType.LIVING),
SLIME(NamespaceID.from("minecraft:slime"), 2.04, 2.04, SlimeMeta::new, EntitySpawnType.LIVING),
SMALL_FIREBALL(NamespaceID.from("minecraft:small_fireball"), 0.3125, 0.3125, SmallFireballMeta::new, EntitySpawnType.BASE),
SNOW_GOLEM(NamespaceID.from("minecraft:snow_golem"), 0.7, 1.9, SnowGolemMeta::new, EntitySpawnType.LIVING),
SNOWBALL(NamespaceID.from("minecraft:snowball"), 0.25, 0.25, SnowballMeta::new, EntitySpawnType.BASE),
SPECTRAL_ARROW(NamespaceID.from("minecraft:spectral_arrow"), 0.5, 0.5, SpectralArrowMeta::new, EntitySpawnType.BASE),
SPIDER(NamespaceID.from("minecraft:spider"), 1.4, 0.9, SpiderMeta::new, EntitySpawnType.LIVING),
SQUID(NamespaceID.from("minecraft:squid"), 0.8, 0.8, SquidMeta::new, EntitySpawnType.LIVING),
STRAY(NamespaceID.from("minecraft:stray"), 0.6, 1.99, StrayMeta::new, EntitySpawnType.LIVING),
STRIDER(NamespaceID.from("minecraft:strider"), 0.9, 1.7, StriderMeta::new, EntitySpawnType.LIVING),
EGG(NamespaceID.from("minecraft:egg"), 0.25, 0.25, ThrownEggMeta::new, EntitySpawnType.BASE),
ENDER_PEARL(NamespaceID.from("minecraft:ender_pearl"), 0.25, 0.25, ThrownEnderPearlMeta::new, EntitySpawnType.BASE),
EXPERIENCE_BOTTLE(NamespaceID.from("minecraft:experience_bottle"), 0.25, 0.25, ThrownExperienceBottleMeta::new, EntitySpawnType.BASE),
POTION(NamespaceID.from("minecraft:potion"), 0.25, 0.25, ThrownPotionMeta::new, EntitySpawnType.BASE),
TRIDENT(NamespaceID.from("minecraft:trident"), 0.5, 0.5, ThrownTridentMeta::new, EntitySpawnType.BASE),
TRADER_LLAMA(NamespaceID.from("minecraft:trader_llama"), 0.9, 1.87, TraderLlamaMeta::new, EntitySpawnType.LIVING),
TROPICAL_FISH(NamespaceID.from("minecraft:tropical_fish"), 0.5, 0.4, TropicalFishMeta::new, EntitySpawnType.LIVING),
TURTLE(NamespaceID.from("minecraft:turtle"), 1.2, 0.4, TurtleMeta::new, EntitySpawnType.LIVING),
VEX(NamespaceID.from("minecraft:vex"), 0.4, 0.8, VexMeta::new, EntitySpawnType.LIVING),
VILLAGER(NamespaceID.from("minecraft:villager"), 0.6, 1.95, VillagerMeta::new, EntitySpawnType.LIVING),
VINDICATOR(NamespaceID.from("minecraft:vindicator"), 0.6, 1.95, VindicatorMeta::new, EntitySpawnType.LIVING),
WANDERING_TRADER(NamespaceID.from("minecraft:wandering_trader"), 0.6, 1.95, WanderingTraderMeta::new, EntitySpawnType.LIVING),
WITCH(NamespaceID.from("minecraft:witch"), 0.6, 1.95, WitchMeta::new, EntitySpawnType.LIVING),
WITHER(NamespaceID.from("minecraft:wither"), 0.9, 3.5, WitherMeta::new, EntitySpawnType.LIVING),
WITHER_SKELETON(NamespaceID.from("minecraft:wither_skeleton"), 0.7, 2.4, WitherSkeletonMeta::new, EntitySpawnType.LIVING),
WITHER_SKULL(NamespaceID.from("minecraft:wither_skull"), 0.3125, 0.3125, WitherSkullMeta::new, EntitySpawnType.BASE),
WOLF(NamespaceID.from("minecraft:wolf"), 0.6, 0.85, WolfMeta::new, EntitySpawnType.LIVING),
ZOGLIN(NamespaceID.from("minecraft:zoglin"), 1.3964844, 1.4, ZoglinMeta::new, EntitySpawnType.LIVING),
ZOMBIE(NamespaceID.from("minecraft:zombie"), 0.6, 1.95, ZombieMeta::new, EntitySpawnType.LIVING),
ZOMBIE_HORSE(NamespaceID.from("minecraft:zombie_horse"), 1.3964844, 1.6, ZombieHorseMeta::new, EntitySpawnType.LIVING),
ZOMBIE_VILLAGER(NamespaceID.from("minecraft:zombie_villager"), 0.6, 1.95, ZombieVillagerMeta::new, EntitySpawnType.LIVING),
ZOMBIFIED_PIGLIN(NamespaceID.from("minecraft:zombified_piglin"), 0.6, 1.95, ZombifiedPiglinMeta::new, EntitySpawnType.LIVING),
PLAYER(NamespaceID.from("minecraft:player"), 0.6, 1.8, PlayerMeta::new, EntitySpawnType.PLAYER),
FISHING_BOBBER(NamespaceID.from("minecraft:fishing_bobber"), 0.25, 0.25, FishingHookMeta::new, EntitySpawnType.BASE);
private static final EntityType[] VALUES = values();
@NotNull
private final NamespaceID id;
private final double width;
private final double height;
@NotNull
private final BiFunction<Entity, Metadata, EntityMeta> metaConstructor;
@NotNull
private final EntitySpawnType spawnType;
EntityType(@NotNull NamespaceID id, double width, double height,
@NotNull BiFunction<Entity, Metadata, EntityMeta> metaConstructor,
@NotNull EntitySpawnType spawnType) {
this.id = id;
this.width = width;
this.height = height;
this.metaConstructor = metaConstructor;
this.spawnType = spawnType;
Registries.entityTypes.put(id, this);
}
@Override
@NotNull
public Key key() {
return this.id;
}
public short getId() {
return (short) ordinal();
}
@NotNull
public NamespaceID getNamespaceID() {
return this.id;
}
public double getWidth() {
return this.width;
}
public double getHeight() {
return this.height;
}
public BiFunction<Entity, Metadata, EntityMeta> getMetaConstructor() {
return this.metaConstructor;
}
public EntitySpawnType getSpawnType() {
return this.spawnType;
}
@Nullable
public static EntityType 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,233 @@
package net.minestom.server.entity;
/**
* AUTOGENERATED by EntityTypeGenerator
*/
@SuppressWarnings("unused")
interface EntityTypeConstants {
EntityType AREA_EFFECT_CLOUD = EntityType.fromNamespaceId("minecraft:area_effect_cloud");
EntityType ARMOR_STAND = EntityType.fromNamespaceId("minecraft:armor_stand");
EntityType ARROW = EntityType.fromNamespaceId("minecraft:arrow");
EntityType AXOLOTL = EntityType.fromNamespaceId("minecraft:axolotl");
EntityType BAT = EntityType.fromNamespaceId("minecraft:bat");
EntityType BEE = EntityType.fromNamespaceId("minecraft:bee");
EntityType BLAZE = EntityType.fromNamespaceId("minecraft:blaze");
EntityType BOAT = EntityType.fromNamespaceId("minecraft:boat");
EntityType CAT = EntityType.fromNamespaceId("minecraft:cat");
EntityType CAVE_SPIDER = EntityType.fromNamespaceId("minecraft:cave_spider");
EntityType CHICKEN = EntityType.fromNamespaceId("minecraft:chicken");
EntityType COD = EntityType.fromNamespaceId("minecraft:cod");
EntityType COW = EntityType.fromNamespaceId("minecraft:cow");
EntityType CREEPER = EntityType.fromNamespaceId("minecraft:creeper");
EntityType DOLPHIN = EntityType.fromNamespaceId("minecraft:dolphin");
EntityType DONKEY = EntityType.fromNamespaceId("minecraft:donkey");
EntityType DRAGON_FIREBALL = EntityType.fromNamespaceId("minecraft:dragon_fireball");
EntityType DROWNED = EntityType.fromNamespaceId("minecraft:drowned");
EntityType ELDER_GUARDIAN = EntityType.fromNamespaceId("minecraft:elder_guardian");
EntityType END_CRYSTAL = EntityType.fromNamespaceId("minecraft:end_crystal");
EntityType ENDER_DRAGON = EntityType.fromNamespaceId("minecraft:ender_dragon");
EntityType ENDERMAN = EntityType.fromNamespaceId("minecraft:enderman");
EntityType ENDERMITE = EntityType.fromNamespaceId("minecraft:endermite");
EntityType EVOKER = EntityType.fromNamespaceId("minecraft:evoker");
EntityType EVOKER_FANGS = EntityType.fromNamespaceId("minecraft:evoker_fangs");
EntityType EXPERIENCE_ORB = EntityType.fromNamespaceId("minecraft:experience_orb");
EntityType EYE_OF_ENDER = EntityType.fromNamespaceId("minecraft:eye_of_ender");
EntityType FALLING_BLOCK = EntityType.fromNamespaceId("minecraft:falling_block");
EntityType FIREWORK_ROCKET = EntityType.fromNamespaceId("minecraft:firework_rocket");
EntityType FOX = EntityType.fromNamespaceId("minecraft:fox");
EntityType GHAST = EntityType.fromNamespaceId("minecraft:ghast");
EntityType GIANT = EntityType.fromNamespaceId("minecraft:giant");
EntityType GLOW_ITEM_FRAME = EntityType.fromNamespaceId("minecraft:glow_item_frame");
EntityType GLOW_SQUID = EntityType.fromNamespaceId("minecraft:glow_squid");
EntityType GOAT = EntityType.fromNamespaceId("minecraft:goat");
EntityType GUARDIAN = EntityType.fromNamespaceId("minecraft:guardian");
EntityType HOGLIN = EntityType.fromNamespaceId("minecraft:hoglin");
EntityType HORSE = EntityType.fromNamespaceId("minecraft:horse");
EntityType HUSK = EntityType.fromNamespaceId("minecraft:husk");
EntityType ILLUSIONER = EntityType.fromNamespaceId("minecraft:illusioner");
EntityType IRON_GOLEM = EntityType.fromNamespaceId("minecraft:iron_golem");
EntityType ITEM = EntityType.fromNamespaceId("minecraft:item");
EntityType ITEM_FRAME = EntityType.fromNamespaceId("minecraft:item_frame");
EntityType FIREBALL = EntityType.fromNamespaceId("minecraft:fireball");
EntityType LEASH_KNOT = EntityType.fromNamespaceId("minecraft:leash_knot");
EntityType LIGHTNING_BOLT = EntityType.fromNamespaceId("minecraft:lightning_bolt");
EntityType LLAMA = EntityType.fromNamespaceId("minecraft:llama");
EntityType LLAMA_SPIT = EntityType.fromNamespaceId("minecraft:llama_spit");
EntityType MAGMA_CUBE = EntityType.fromNamespaceId("minecraft:magma_cube");
EntityType MARKER = EntityType.fromNamespaceId("minecraft:marker");
EntityType MINECART = EntityType.fromNamespaceId("minecraft:minecart");
EntityType CHEST_MINECART = EntityType.fromNamespaceId("minecraft:chest_minecart");
EntityType COMMAND_BLOCK_MINECART = EntityType.fromNamespaceId("minecraft:command_block_minecart");
EntityType FURNACE_MINECART = EntityType.fromNamespaceId("minecraft:furnace_minecart");
EntityType HOPPER_MINECART = EntityType.fromNamespaceId("minecraft:hopper_minecart");
EntityType SPAWNER_MINECART = EntityType.fromNamespaceId("minecraft:spawner_minecart");
EntityType TNT_MINECART = EntityType.fromNamespaceId("minecraft:tnt_minecart");
EntityType MULE = EntityType.fromNamespaceId("minecraft:mule");
EntityType MOOSHROOM = EntityType.fromNamespaceId("minecraft:mooshroom");
EntityType OCELOT = EntityType.fromNamespaceId("minecraft:ocelot");
EntityType PAINTING = EntityType.fromNamespaceId("minecraft:painting");
EntityType PANDA = EntityType.fromNamespaceId("minecraft:panda");
EntityType PARROT = EntityType.fromNamespaceId("minecraft:parrot");
EntityType PHANTOM = EntityType.fromNamespaceId("minecraft:phantom");
EntityType PIG = EntityType.fromNamespaceId("minecraft:pig");
EntityType PIGLIN = EntityType.fromNamespaceId("minecraft:piglin");
EntityType PIGLIN_BRUTE = EntityType.fromNamespaceId("minecraft:piglin_brute");
EntityType PILLAGER = EntityType.fromNamespaceId("minecraft:pillager");
EntityType POLAR_BEAR = EntityType.fromNamespaceId("minecraft:polar_bear");
EntityType TNT = EntityType.fromNamespaceId("minecraft:tnt");
EntityType PUFFERFISH = EntityType.fromNamespaceId("minecraft:pufferfish");
EntityType RABBIT = EntityType.fromNamespaceId("minecraft:rabbit");
EntityType RAVAGER = EntityType.fromNamespaceId("minecraft:ravager");
EntityType SALMON = EntityType.fromNamespaceId("minecraft:salmon");
EntityType SHEEP = EntityType.fromNamespaceId("minecraft:sheep");
EntityType SHULKER = EntityType.fromNamespaceId("minecraft:shulker");
EntityType SHULKER_BULLET = EntityType.fromNamespaceId("minecraft:shulker_bullet");
EntityType SILVERFISH = EntityType.fromNamespaceId("minecraft:silverfish");
EntityType SKELETON = EntityType.fromNamespaceId("minecraft:skeleton");
EntityType SKELETON_HORSE = EntityType.fromNamespaceId("minecraft:skeleton_horse");
EntityType SLIME = EntityType.fromNamespaceId("minecraft:slime");
EntityType SMALL_FIREBALL = EntityType.fromNamespaceId("minecraft:small_fireball");
EntityType SNOW_GOLEM = EntityType.fromNamespaceId("minecraft:snow_golem");
EntityType SNOWBALL = EntityType.fromNamespaceId("minecraft:snowball");
EntityType SPECTRAL_ARROW = EntityType.fromNamespaceId("minecraft:spectral_arrow");
EntityType SPIDER = EntityType.fromNamespaceId("minecraft:spider");
EntityType SQUID = EntityType.fromNamespaceId("minecraft:squid");
EntityType STRAY = EntityType.fromNamespaceId("minecraft:stray");
EntityType STRIDER = EntityType.fromNamespaceId("minecraft:strider");
EntityType EGG = EntityType.fromNamespaceId("minecraft:egg");
EntityType ENDER_PEARL = EntityType.fromNamespaceId("minecraft:ender_pearl");
EntityType EXPERIENCE_BOTTLE = EntityType.fromNamespaceId("minecraft:experience_bottle");
EntityType POTION = EntityType.fromNamespaceId("minecraft:potion");
EntityType TRIDENT = EntityType.fromNamespaceId("minecraft:trident");
EntityType TRADER_LLAMA = EntityType.fromNamespaceId("minecraft:trader_llama");
EntityType TROPICAL_FISH = EntityType.fromNamespaceId("minecraft:tropical_fish");
EntityType TURTLE = EntityType.fromNamespaceId("minecraft:turtle");
EntityType VEX = EntityType.fromNamespaceId("minecraft:vex");
EntityType VILLAGER = EntityType.fromNamespaceId("minecraft:villager");
EntityType VINDICATOR = EntityType.fromNamespaceId("minecraft:vindicator");
EntityType WANDERING_TRADER = EntityType.fromNamespaceId("minecraft:wandering_trader");
EntityType WITCH = EntityType.fromNamespaceId("minecraft:witch");
EntityType WITHER = EntityType.fromNamespaceId("minecraft:wither");
EntityType WITHER_SKELETON = EntityType.fromNamespaceId("minecraft:wither_skeleton");
EntityType WITHER_SKULL = EntityType.fromNamespaceId("minecraft:wither_skull");
EntityType WOLF = EntityType.fromNamespaceId("minecraft:wolf");
EntityType ZOGLIN = EntityType.fromNamespaceId("minecraft:zoglin");
EntityType ZOMBIE = EntityType.fromNamespaceId("minecraft:zombie");
EntityType ZOMBIE_HORSE = EntityType.fromNamespaceId("minecraft:zombie_horse");
EntityType ZOMBIE_VILLAGER = EntityType.fromNamespaceId("minecraft:zombie_villager");
EntityType ZOMBIFIED_PIGLIN = EntityType.fromNamespaceId("minecraft:zombified_piglin");
EntityType PLAYER = EntityType.fromNamespaceId("minecraft:player");
EntityType FISHING_BOBBER = EntityType.fromNamespaceId("minecraft:fishing_bobber");
}

View File

@ -2,7 +2,6 @@
package net.minestom.server.registry;
import net.kyori.adventure.key.Key;
import net.minestom.server.entity.EntityType;
import net.minestom.server.fluid.Fluid;
import net.minestom.server.item.Enchantment;
import net.minestom.server.particle.Particle;
@ -27,12 +26,6 @@ public final class Registries {
@Deprecated
public static final HashMap<NamespaceID, Enchantment> enchantments = new HashMap<>();
/**
* Should only be used for internal code, please use the get* methods.
*/
@Deprecated
public static final HashMap<NamespaceID, EntityType> entityTypes = new HashMap<>();
/**
* Should only be used for internal code, please use the get* methods.
*/
@ -93,30 +86,6 @@ public final class Registries {
return getEnchantment(NamespaceID.from(key));
}
/**
* Returns the corresponding EntityType matching the given id. Returns null if none match.
*/
@Nullable
public static EntityType getEntityType(String id) {
return getEntityType(NamespaceID.from(id));
}
/**
* Returns the corresponding EntityType matching the given id. Returns null if none match.
*/
@Nullable
public static EntityType getEntityType(NamespaceID id) {
return entityTypes.get(id);
}
/**
* Returns the corresponding EntityType matching the given key. Returns null if none match.
*/
@Nullable
public static EntityType getEntityType(Key key) {
return getEntityType(NamespaceID.from(key));
}
/**
* Returns the corresponding Particle matching the given id. Returns null if none match.
*/

View File

@ -211,7 +211,7 @@ public class ArgumentEntity extends Argument<EntityFinder> {
case "type": {
final boolean include = !value.startsWith("!");
final String entityName = include ? value : value.substring(1);
final EntityType entityType = Registries.getEntityType(entityName);
final EntityType entityType = EntityType.fromNamespaceId(entityName);
if (entityType == null)
throw new ArgumentSyntaxException("Invalid entity name", input, INVALID_ARGUMENT_VALUE);
entityFinder.setEntity(entityType, include ? EntityFinder.ToggleableType.INCLUDE : EntityFinder.ToggleableType.EXCLUDE);

View File

@ -4,7 +4,6 @@ import net.minestom.server.command.builder.NodeMaker;
import net.minestom.server.command.builder.arguments.minecraft.SuggestionType;
import net.minestom.server.entity.EntityType;
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
import net.minestom.server.registry.Registries;
import org.jetbrains.annotations.NotNull;
/**
@ -18,7 +17,7 @@ public class ArgumentEntityType extends ArgumentRegistry<EntityType> {
@Override
public EntityType getRegistry(@NotNull String value) {
return Registries.getEntityType(value);
return EntityType.fromNamespaceId(value);
}
@Override

View File

@ -138,16 +138,17 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
this.position = Pos.ZERO;
this.lastSyncedPosition = Pos.ZERO;
setBoundingBox(entityType.getWidth(), entityType.getHeight(), entityType.getWidth());
setBoundingBox(entityType.width(), entityType.height(), entityType.width());
this.entityMeta = entityType.getMetaConstructor().apply(this, this.metadata);
this.entityMeta = EntityTypeLoader.createMeta(entityType, this, this.metadata);
setAutoViewable(true);
Entity.ENTITY_BY_ID.put(id, this);
Entity.ENTITY_BY_UUID.put(uuid, this);
initializeDefaultGravity();
this.gravityAcceleration = EntityTypeLoader.getAcceleration(entityType.name());
this.gravityDragPerTick = EntityTypeLoader.getDrag(entityType.name());
}
public Entity(@NotNull EntityType entityType) {
@ -172,8 +173,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
* @param id the entity unique id
* @return the entity having the specified id, null if not found
*/
@Nullable
public static Entity getEntity(int id) {
public static @Nullable Entity getEntity(int id) {
return Entity.ENTITY_BY_ID.getOrDefault(id, null);
}
@ -183,8 +183,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
* @param uuid the entity UUID
* @return the entity having the specified uuid, null if not found
*/
@Nullable
public static Entity getEntity(@NotNull UUID uuid) {
public static @Nullable Entity getEntity(@NotNull UUID uuid) {
return Entity.ENTITY_BY_UUID.getOrDefault(uuid, null);
}
@ -226,8 +225,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
*
* @return metadata of this entity.
*/
@NotNull
public EntityMeta getEntityMeta() {
public @NotNull EntityMeta getEntityMeta() {
return this.entityMeta;
}
@ -313,7 +311,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
player.viewableEntities.add(this);
PlayerConnection playerConnection = player.getPlayerConnection();
playerConnection.sendPacket(getEntityType().getSpawnType().getSpawnPacket(this));
playerConnection.sendPacket(getEntityType().registry().spawnType().getSpawnPacket(this));
if (hasVelocity()) {
playerConnection.sendPacket(getVelocityPacket());
}
@ -364,7 +362,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
synchronized (entityTypeLock) {
this.entityType = entityType;
this.metadata = new Metadata(this);
this.entityMeta = entityType.getMetaConstructor().apply(this, this.metadata);
this.entityMeta = EntityTypeLoader.createMeta(entityType, this, this.metadata);
Set<Player> viewers = new HashSet<>(getViewers());
getViewers().forEach(this::removeViewer0);
@ -1406,90 +1404,6 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
tag.write(nbtCompound, value);
}
/**
* Sets the Entity's {@link gravityAcceleration} and {@link gravityDragPerTick} fields to
* the default values according to <a href="https://minecraft.fandom.com/wiki/Entity#Motion_of_entities">Motion of entities</a>
*/
@SuppressWarnings("JavadocReference")
private void initializeDefaultGravity() {
// TODO Add support for these values in the data generator
// Acceleration
switch (entityType) {
// 0
case ITEM_FRAME:
this.gravityAcceleration = 0;
break;
// 0.03
case EGG:
case FISHING_BOBBER:
case EXPERIENCE_BOTTLE:
case ENDER_PEARL:
case POTION:
case SNOWBALL:
this.gravityAcceleration = 0.03;
break;
// 0.04
case BOAT:
case TNT:
case FALLING_BLOCK:
case ITEM:
case MINECART:
this.gravityAcceleration = 0.04;
break;
// 0.05
case ARROW:
case SPECTRAL_ARROW:
case TRIDENT:
this.gravityAcceleration = 0.05;
break;
// 0.06
case LLAMA_SPIT:
this.gravityAcceleration = 0.06;
break;
// 0.1
case FIREBALL:
case WITHER_SKULL:
case DRAGON_FIREBALL:
this.gravityAcceleration = 0.1;
break;
// 0.08
default:
this.gravityAcceleration = 0.08;
break;
}
// Drag
switch (entityType) {
// 0
case BOAT:
this.gravityDragPerTick = 0;
break;
// 0.01
case LLAMA_SPIT:
case ENDER_PEARL:
case POTION:
case SNOWBALL:
case EGG:
case TRIDENT:
case SPECTRAL_ARROW:
case ARROW:
this.gravityDragPerTick = 0.01;
break;
// 0.05
case MINECART:
this.gravityDragPerTick = 0.05;
break;
// 0.08
case FISHING_BOBBER:
this.gravityDragPerTick = 0.08;
break;
// 0.02
default:
this.gravityDragPerTick = 0.02;
break;
}
}
/**
* Applies knockback to the entity
*

View File

@ -14,7 +14,7 @@ public enum EntitySpawnType {
SpawnEntityPacket packet = new SpawnEntityPacket();
packet.entityId = entity.getEntityId();
packet.uuid = entity.getUuid();
packet.type = entity.getEntityType().ordinal();
packet.type = entity.getEntityType().id();
packet.position = entity.getPosition();
if (entity.getEntityMeta() instanceof ObjectDataProvider) {
ObjectDataProvider objectDataProvider = (ObjectDataProvider) entity.getEntityMeta();
@ -35,7 +35,7 @@ public enum EntitySpawnType {
SpawnLivingEntityPacket packet = new SpawnLivingEntityPacket();
packet.entityId = entity.getEntityId();
packet.entityUuid = entity.getUuid();
packet.entityType = entity.getEntityType().ordinal();
packet.entityType = entity.getEntityType().id();
packet.position = entity.getPosition();
packet.headPitch = entity.getPosition().pitch();
final var velocity = entity.getVelocityForPacket();

View File

@ -0,0 +1,56 @@
package net.minestom.server.entity;
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 EntityType extends ProtocolObject, EntityTypeConstants {
/**
* Returns the entity registry.
*
* @return the entity registry
*/
@Contract(pure = true)
@NotNull Registry.EntityEntry registry();
@Override
default @NotNull NamespaceID namespace() {
return registry().namespace();
}
@Override
default int id() {
return registry().id();
}
default double width() {
return registry().width();
}
default double height() {
return registry().height();
}
static @NotNull Collection<@NotNull EntityType> values() {
return EntityTypeLoader.values();
}
static EntityType fromNamespaceId(@NotNull String namespaceID) {
return EntityTypeLoader.get(namespaceID);
}
static EntityType fromNamespaceId(@NotNull NamespaceID namespaceID) {
return fromNamespaceId(namespaceID.asString());
}
static @Nullable EntityType fromId(int id) {
return EntityTypeLoader.getId(id);
}
}

View File

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

View File

@ -0,0 +1,276 @@
package net.minestom.server.entity;
import com.google.gson.JsonObject;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minestom.server.entity.metadata.EntityMeta;
import net.minestom.server.entity.metadata.PlayerMeta;
import net.minestom.server.entity.metadata.ambient.BatMeta;
import net.minestom.server.entity.metadata.animal.*;
import net.minestom.server.entity.metadata.animal.tameable.CatMeta;
import net.minestom.server.entity.metadata.animal.tameable.ParrotMeta;
import net.minestom.server.entity.metadata.animal.tameable.WolfMeta;
import net.minestom.server.entity.metadata.arrow.ArrowMeta;
import net.minestom.server.entity.metadata.arrow.SpectralArrowMeta;
import net.minestom.server.entity.metadata.arrow.ThrownTridentMeta;
import net.minestom.server.entity.metadata.flying.GhastMeta;
import net.minestom.server.entity.metadata.flying.PhantomMeta;
import net.minestom.server.entity.metadata.golem.IronGolemMeta;
import net.minestom.server.entity.metadata.golem.ShulkerMeta;
import net.minestom.server.entity.metadata.golem.SnowGolemMeta;
import net.minestom.server.entity.metadata.item.*;
import net.minestom.server.entity.metadata.minecart.*;
import net.minestom.server.entity.metadata.monster.*;
import net.minestom.server.entity.metadata.monster.raider.*;
import net.minestom.server.entity.metadata.monster.skeleton.SkeletonMeta;
import net.minestom.server.entity.metadata.monster.skeleton.StrayMeta;
import net.minestom.server.entity.metadata.monster.skeleton.WitherSkeletonMeta;
import net.minestom.server.entity.metadata.monster.zombie.DrownedMeta;
import net.minestom.server.entity.metadata.monster.zombie.ZombieMeta;
import net.minestom.server.entity.metadata.monster.zombie.ZombieVillagerMeta;
import net.minestom.server.entity.metadata.monster.zombie.ZombifiedPiglinMeta;
import net.minestom.server.entity.metadata.other.*;
import net.minestom.server.entity.metadata.villager.VillagerMeta;
import net.minestom.server.entity.metadata.villager.WanderingTraderMeta;
import net.minestom.server.entity.metadata.water.AxolotlMeta;
import net.minestom.server.entity.metadata.water.DolphinMeta;
import net.minestom.server.entity.metadata.water.GlowSquidMeta;
import net.minestom.server.entity.metadata.water.SquidMeta;
import net.minestom.server.entity.metadata.water.fish.CodMeta;
import net.minestom.server.entity.metadata.water.fish.PufferfishMeta;
import net.minestom.server.entity.metadata.water.fish.SalmonMeta;
import net.minestom.server.entity.metadata.water.fish.TropicalFishMeta;
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;
import java.util.function.BiFunction;
@ApiStatus.Internal
final class EntityTypeLoader {
// 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, EntityType> NAMESPACE_MAP = new HashMap<>();
// Block id -> registry data
private static final Int2ObjectMap<EntityType> ENTITY_ID_MAP = new Int2ObjectOpenHashMap<>();
private static final Map<String, BiFunction<Entity, Metadata, EntityMeta>> ENTITY_META_SUPPLIER = createMetaMap();
private static final Map<String, Double> ACCELERATION_MAP = createAccelerationMap();
private static final Map<String, Double> DRAG_MAP = createDragMap();
static @Nullable EntityType get(@NotNull String namespace) {
if (namespace.indexOf(':') == -1) {
// Default to minecraft namespace
namespace = "minecraft:" + namespace;
}
return NAMESPACE_MAP.get(namespace);
}
static EntityType getId(int id) {
return ENTITY_ID_MAP.get(id);
}
static Collection<EntityType> values() {
return Collections.unmodifiableCollection(NAMESPACE_MAP.values());
}
static EntityMeta createMeta(EntityType entityType, Entity entity, Metadata metadata) {
return ENTITY_META_SUPPLIER.get(entityType.name()).apply(entity, metadata);
}
static double getAcceleration(String namespace) {
return ACCELERATION_MAP.getOrDefault(namespace, 0.08);
}
static double getDrag(String namespace) {
return DRAG_MAP.getOrDefault(namespace, 0.02);
}
static {
// Load data from file
JsonObject entities = Registry.load(Registry.Resource.ENTITY);
entities.entrySet().forEach(entry -> {
final String namespace = entry.getKey();
final JsonObject entityObject = entry.getValue().getAsJsonObject();
final var metaSupplier = ENTITY_META_SUPPLIER.get(namespace);
final var entityType = new EntityTypeImpl(Registry.entity(namespace, entityObject, null));
ENTITY_ID_MAP.put(entityType.id(), entityType);
NAMESPACE_MAP.put(namespace, entityType);
});
}
private static Map<String, BiFunction<Entity, Metadata, EntityMeta>> createMetaMap() {
Map<String, BiFunction<Entity, Metadata, EntityMeta>> supplier = new HashMap<>();
supplier.put("minecraft:area_effect_cloud", AreaEffectCloudMeta::new);
supplier.put("minecraft:armor_stand", ArmorStandMeta::new);
supplier.put("minecraft:arrow", ArrowMeta::new);
supplier.put("minecraft:axolotl", AxolotlMeta::new);
supplier.put("minecraft:bat", BatMeta::new);
supplier.put("minecraft:bee", BeeMeta::new);
supplier.put("minecraft:boat", BoatMeta::new);
supplier.put("minecraft:cat", CatMeta::new);
supplier.put("minecraft:cave_spider", CaveSpiderMeta::new);
supplier.put("minecraft:chicken", ChickenMeta::new);
supplier.put("minecraft:cod", CodMeta::new);
supplier.put("minecraft:cow", CowMeta::new);
supplier.put("minecraft:creeper", CreeperMeta::new);
supplier.put("minecraft:dolphin", DolphinMeta::new);
supplier.put("minecraft:donkey", DonkeyMeta::new);
supplier.put("minecraft:dragon_fireball", DragonFireballMeta::new);
supplier.put("minecraft:drowned", DrownedMeta::new);
supplier.put("minecraft:elder_guardian", ElderGuardianMeta::new);
supplier.put("minecraft:end_crystal", EndCrystalMeta::new);
supplier.put("minecraft:ender_dragon", EnderDragonMeta::new);
supplier.put("minecraft:enderman", EndermanMeta::new);
supplier.put("minecraft:endermite", EndermiteMeta::new);
supplier.put("minecraft:evoker", EvokerMeta::new);
supplier.put("minecraft:evoker_fangs", EvokerFangsMeta::new);
supplier.put("minecraft:experience_orb", ExperienceOrbMeta::new);
supplier.put("minecraft:eye_of_ender", EyeOfEnderMeta::new);
supplier.put("minecraft:falling_block", FallingBlockMeta::new);
supplier.put("minecraft:firework_rocket", FireworkRocketMeta::new);
supplier.put("minecraft:fox", FoxMeta::new);
supplier.put("minecraft:ghast", GhastMeta::new);
supplier.put("minecraft:giant", GiantMeta::new);
supplier.put("minecraft:glow_item_frame", GlowItemFrameMeta::new);
supplier.put("minecraft:glow_squid", GlowSquidMeta::new);
supplier.put("minecraft:goat", GoatMeta::new);
supplier.put("minecraft:guardian", GuardianMeta::new);
supplier.put("minecraft:hoglin", HoglinMeta::new);
supplier.put("minecraft:horse", HorseMeta::new);
supplier.put("minecraft:illusioner", IllusionerMeta::new);
supplier.put("minecraft:iron_golem", IronGolemMeta::new);
supplier.put("minecraft:item", ItemEntityMeta::new);
supplier.put("minecraft:item_frame", ItemFrameMeta::new);
supplier.put("minecraft:fireball", FireballMeta::new);
supplier.put("minecraft:leash_knot", LeashKnotMeta::new);
supplier.put("minecraft:lightning_bolt", LightningBoltMeta::new);
supplier.put("minecraft:llama", LlamaMeta::new);
supplier.put("minecraft:llama_spit", LlamaSpitMeta::new);
supplier.put("minecraft:magma_cube", MagmaCubeMeta::new);
supplier.put("minecraft:marker", MarkerMeta::new);
supplier.put("minecraft:minecart", MinecartMeta::new);
supplier.put("minecraft:chest_minecart", ChestMinecartMeta::new);
supplier.put("minecraft:command_block_minecart", CommandBlockMinecartMeta::new);
supplier.put("minecraft:furnace_minecart", FurnaceMinecartMeta::new);
supplier.put("minecraft:hopper_minecart", HopperMinecartMeta::new);
supplier.put("minecraft:spawner_minecart", SpawnerMinecartMeta::new);
supplier.put("minecraft:tnt_minecart", TntMinecartMeta::new);
supplier.put("minecraft:mule", MuleMeta::new);
supplier.put("minecraft:mooshroom", MooshroomMeta::new);
supplier.put("minecraft:ocelot", OcelotMeta::new);
supplier.put("minecraft:painting", PaintingMeta::new);
supplier.put("minecraft:panda", PandaMeta::new);
supplier.put("minecraft:parrot", ParrotMeta::new);
supplier.put("minecraft:phantom", PhantomMeta::new);
supplier.put("minecraft:pig", PigMeta::new);
supplier.put("minecraft:piglin", PiglinMeta::new);
supplier.put("minecraft:piglin_brute", PiglinBruteMeta::new);
supplier.put("minecraft:pillager", PillagerMeta::new);
supplier.put("minecraft:polar_bear", PolarBearMeta::new);
supplier.put("minecraft:tnt", PrimedTntMeta::new);
supplier.put("minecraft:pufferfish", PufferfishMeta::new);
supplier.put("minecraft:rabbit", RabbitMeta::new);
supplier.put("minecraft:ravager", RavagerMeta::new);
supplier.put("minecraft:salmon", SalmonMeta::new);
supplier.put("minecraft:sheep", SheepMeta::new);
supplier.put("minecraft:shulker", ShulkerMeta::new);
supplier.put("minecraft:shulker_bullet", ShulkerBulletMeta::new);
supplier.put("minecraft:silverfish", SilverfishMeta::new);
supplier.put("minecraft:skeleton", SkeletonMeta::new);
supplier.put("minecraft:skeleton_horse", SkeletonHorseMeta::new);
supplier.put("minecraft:slime", SlimeMeta::new);
supplier.put("minecraft:small_fireball", SmallFireballMeta::new);
supplier.put("minecraft:snow_golem", SnowGolemMeta::new);
supplier.put("minecraft:snowball", SnowballMeta::new);
supplier.put("minecraft:spectral_arrow", SpectralArrowMeta::new);
supplier.put("minecraft:spider", SpiderMeta::new);
supplier.put("minecraft:squid", SquidMeta::new);
supplier.put("minecraft:stray", StrayMeta::new);
supplier.put("minecraft:strider", StriderMeta::new);
supplier.put("minecraft:egg", ThrownEggMeta::new);
supplier.put("minecraft:ender_pearl", ThrownEnderPearlMeta::new);
supplier.put("minecraft:experience_bottle", ThrownExperienceBottleMeta::new);
supplier.put("minecraft:potion", ThrownPotionMeta::new);
supplier.put("minecraft:trident", ThrownTridentMeta::new);
supplier.put("minecraft:trader_llama", TraderLlamaMeta::new);
supplier.put("minecraft:tropical_fish", TropicalFishMeta::new);
supplier.put("minecraft:turtle", TurtleMeta::new);
supplier.put("minecraft:vex", VexMeta::new);
supplier.put("minecraft:villager", VillagerMeta::new);
supplier.put("minecraft:vindicator", VindicatorMeta::new);
supplier.put("minecraft:wandering_trader", WanderingTraderMeta::new);
supplier.put("minecraft:witch", WitchMeta::new);
supplier.put("minecraft:wither", WitherMeta::new);
supplier.put("minecraft:wither_skeleton", WitherSkeletonMeta::new);
supplier.put("minecraft:wither_skull", WitherSkullMeta::new);
supplier.put("minecraft:wolf", WolfMeta::new);
supplier.put("minecraft:zoglin", ZoglinMeta::new);
supplier.put("minecraft:zombie", ZombieMeta::new);
supplier.put("minecraft:zombie_horse", ZombieHorseMeta::new);
supplier.put("minecraft:zombie_villager", ZombieVillagerMeta::new);
supplier.put("minecraft:zombified_piglin", ZombifiedPiglinMeta::new);
supplier.put("minecraft:player", PlayerMeta::new);
supplier.put("minecraft:fishing_bobber", FishingHookMeta::new);
return supplier;
}
private static Map<String, Double> createDragMap() {
Map<String, Double> result = new HashMap<>();
result.put("minecraft:boat", 0d);
result.put("minecraft:llama_spit", 0.01);
result.put("minecraft:ender_pearl", 0.01);
result.put("minecraft:potion", 0.01);
result.put("minecraft:snowball", 0.01);
result.put("minecraft:egg", 0.01);
result.put("minecraft:trident", 0.01);
result.put("minecraft:spectral_arrow", 0.01);
result.put("minecraft:arrow", 0.01);
result.put("minecraft:minecart", 0.05);
result.put("minecraft:fishing_bobber", 0.08);
return result;
}
private static Map<String, Double> createAccelerationMap() {
Map<String, Double> result = new HashMap<>();
result.put("minecraft:item_frame", 0d);
result.put("minecraft:egg", 0.03);
result.put("minecraft:fishing_bobber", 0.03);
result.put("minecraft:experience_bottle", 0.03);
result.put("minecraft:ender_pearl", 0.03);
result.put("minecraft:potion", 0.03);
result.put("minecraft:snowball", 0.03);
result.put("minecraft:boat", 0.04);
result.put("minecraft:tnt", 0.04);
result.put("minecraft:falling_block", 0.04);
result.put("minecraft:item", 0.04);
result.put("minecraft:minecart", 0.04);
result.put("minecraft:arrow", 0.05);
result.put("minecraft:spectral_arrow", 0.05);
result.put("minecraft:trident", 0.05);
result.put("minecraft:llama_spit", 0.06);
result.put("minecraft:fireball", 0.1);
result.put("minecraft:wither_skull", 0.1);
result.put("minecraft:dragon_fireball", 0.1);
return result;
}
}

View File

@ -1107,8 +1107,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
* and send data to his new viewers.
*/
protected void refreshAfterTeleport() {
sendPacketsToViewers(getEntityType().getSpawnType().getSpawnPacket(this));
sendPacketsToViewers(getEntityType().registry().spawnType().getSpawnPacket(this));
// Update for viewers
sendPacketToViewersAndSelf(getVelocityPacket());
@ -1995,7 +1994,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
*/
protected void showPlayer(@NotNull PlayerConnection connection) {
connection.sendPacket(getAddPlayerToList());
connection.sendPacket(getEntityType().getSpawnType().getSpawnPacket(this));
connection.sendPacket(getEntityType().registry().spawnType().getSpawnPacket(this));
connection.sendPacket(getVelocityPacket());
connection.sendPacket(getMetadataPacket());
connection.sendPacket(getEquipmentsPacket());

View File

@ -45,8 +45,8 @@ final class MaterialLoader {
static {
// Load data from file
JsonObject blocks = Registry.load(Registry.Resource.ITEM);
blocks.entrySet().forEach(entry -> {
JsonObject materials = Registry.load(Registry.Resource.ITEM);
materials.entrySet().forEach(entry -> {
final String namespace = entry.getKey();
final JsonObject materialObject = entry.getValue().getAsJsonObject();

View File

@ -73,11 +73,11 @@ public class TagsPacket implements ServerPacket {
writer.writeVarInt(values.size());
// entries
for (NamespaceID name : values) {
EntityType et = Registries.getEntityType(name);
EntityType et = EntityType.fromNamespaceId(name);
if (et == null) {
writer.writeVarInt(-1);
} else {
writer.writeVarInt(et.ordinal());
writer.writeVarInt(et.id());
}
}
}

View File

@ -4,6 +4,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minestom.server.entity.EntitySpawnType;
import net.minestom.server.entity.EquipmentSlot;
import net.minestom.server.instance.block.Block;
import net.minestom.server.item.Material;
@ -13,6 +14,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.InputStreamReader;
import java.util.Locale;
import java.util.function.Supplier;
@ApiStatus.Internal
@ -27,6 +29,10 @@ public class Registry {
return new MaterialEntry(namespace, jsonObject, override);
}
public static EntityEntry entity(String namespace, @NotNull JsonObject jsonObject, JsonObject override) {
return new EntityEntry(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);
@ -35,7 +41,8 @@ public class Registry {
public enum Resource {
BLOCK("blocks"),
ITEM("items");
ITEM("items"),
ENTITY("entities");
private final String name;
@ -223,6 +230,49 @@ public class Registry {
}
}
public static class EntityEntry extends Entry {
private final NamespaceID namespace;
private final int id;
private final String translationKey;
private final double width;
private final double height;
private final EntitySpawnType spawnType;
private EntityEntry(String namespace, JsonObject main, JsonObject override) {
super(main, override);
this.namespace = NamespaceID.from(namespace);
this.id = getInt("id");
this.translationKey = getString("translationKey");
this.width = getDouble("width");
this.height = getDouble("height");
this.spawnType = EntitySpawnType.valueOf(getString("packetType").toUpperCase(Locale.ROOT));
}
public @NotNull NamespaceID namespace() {
return namespace;
}
public int id() {
return id;
}
public String translationKey() {
return translationKey;
}
public double width() {
return width;
}
public double height() {
return height;
}
public EntitySpawnType spawnType() {
return spawnType;
}
}
public static class Entry {
private final JsonObject main, override;