diff --git a/src/autogenerated/java/net/minestom/server/entity/EntityType.java b/src/autogenerated/java/net/minestom/server/entity/EntityType.java index 3eae2a6ce..e580f7bc0 100644 --- a/src/autogenerated/java/net/minestom/server/entity/EntityType.java +++ b/src/autogenerated/java/net/minestom/server/entity/EntityType.java @@ -1,27 +1,8 @@ package net.minestom.server.entity; -import net.minestom.server.entity.type.ambient.EntityBat; -import net.minestom.server.entity.type.ambient.EntityTraderLlama; -import net.minestom.server.entity.type.ambient.EntityVillager; -import net.minestom.server.entity.type.ambient.EntityWanderingTrader; -import net.minestom.server.entity.type.animal.*; -import net.minestom.server.entity.type.decoration.EntityArmorStand; -import net.minestom.server.entity.type.monster.*; -import net.minestom.server.entity.type.other.EntityAreaEffectCloud; -import net.minestom.server.entity.type.other.EntityIronGolem; -import net.minestom.server.entity.type.other.EntityShulker; -import net.minestom.server.entity.type.other.EntitySnowman; -import net.minestom.server.entity.type.projectile.EntityPotion; -import net.minestom.server.entity.type.projectile.EntitySpectralArrow; -import net.minestom.server.entity.type.vehicle.EntityBoat; -import net.minestom.server.entity.type.water.*; import net.minestom.server.registry.Registries; -import net.minestom.server.utils.LambdaMetafactoryUtils; import net.minestom.server.utils.NamespaceID; -import net.minestom.server.utils.Position; -import net.minestom.server.utils.validate.Check; - -import java.util.function.Function; +import org.jetbrains.annotations.NotNull; /** * //============================== @@ -30,276 +11,254 @@ import java.util.function.Function; */ @SuppressWarnings({"deprecation"}) public enum EntityType { - AREA_EFFECT_CLOUD("minecraft:area_effect_cloud", EntityAreaEffectCloud.class), + AREA_EFFECT_CLOUD("minecraft:area_effect_cloud", 6.0, 0.5), - ARMOR_STAND("minecraft:armor_stand", EntityArmorStand.class), + ARMOR_STAND("minecraft:armor_stand", 0.5, 1.975), - ARROW("minecraft:arrow"), + ARROW("minecraft:arrow", 0.5, 0.5), - BAT("minecraft:bat", EntityBat.class), + BAT("minecraft:bat", 0.5, 0.9), - BEE("minecraft:bee", EntityBee.class), + BEE("minecraft:bee", 0.7, 0.6), - BLAZE("minecraft:blaze", EntityBlaze.class), + BLAZE("minecraft:blaze", 0.6, 1.8), - BOAT("minecraft:boat", EntityBoat.class), + BOAT("minecraft:boat", 1.375, 0.5625), - CAT("minecraft:cat", EntityCat.class), + CAT("minecraft:cat", 0.6, 0.7), - CAVE_SPIDER("minecraft:cave_spider", EntityCaveSpider.class), + CAVE_SPIDER("minecraft:cave_spider", 0.7, 0.5), - CHICKEN("minecraft:chicken", EntityChicken.class), + CHICKEN("minecraft:chicken", 0.4, 0.7), - COD("minecraft:cod", EntityCod.class), + COD("minecraft:cod", 0.5, 0.3), - COW("minecraft:cow", EntityCow.class), + COW("minecraft:cow", 0.9, 1.4), - CREEPER("minecraft:creeper", EntityCreeper.class), + CREEPER("minecraft:creeper", 0.6, 1.7), - DOLPHIN("minecraft:dolphin", EntityDolphin.class), + DOLPHIN("minecraft:dolphin", 0.9, 0.6), - DONKEY("minecraft:donkey", EntityDonkey.class), + DONKEY("minecraft:donkey", 1.39648, 1.5), - DRAGON_FIREBALL("minecraft:dragon_fireball"), + DRAGON_FIREBALL("minecraft:dragon_fireball", 1.0, 1.0), - DROWNED("minecraft:drowned", EntityDrowned.class), + DROWNED("minecraft:drowned", 0.6, 1.95), - ELDER_GUARDIAN("minecraft:elder_guardian", EntityElderGuardian.class), + ELDER_GUARDIAN("minecraft:elder_guardian", 1.9975, 1.9975), - END_CRYSTAL("minecraft:end_crystal"), + END_CRYSTAL("minecraft:end_crystal", 2.0, 2.0), - ENDER_DRAGON("minecraft:ender_dragon"), + ENDER_DRAGON("minecraft:ender_dragon", 16.0, 8.0), - ENDERMAN("minecraft:enderman", EntityEnderman.class), + ENDERMAN("minecraft:enderman", 0.6, 2.9), - ENDERMITE("minecraft:endermite", EntityEndermite.class), + ENDERMITE("minecraft:endermite", 0.4, 0.3), - EVOKER("minecraft:evoker", EntityEvoker.class), + EVOKER("minecraft:evoker", 0.6, 1.95), - EVOKER_FANGS("minecraft:evoker_fangs"), + EVOKER_FANGS("minecraft:evoker_fangs", 0.5, 0.8), - EXPERIENCE_ORB("minecraft:experience_orb"), + EXPERIENCE_ORB("minecraft:experience_orb", 0.5, 0.5), - EYE_OF_ENDER("minecraft:eye_of_ender"), + EYE_OF_ENDER("minecraft:eye_of_ender", 0.25, 0.25), - FALLING_BLOCK("minecraft:falling_block"), + FALLING_BLOCK("minecraft:falling_block", 0.98, 0.98), - FIREWORK_ROCKET("minecraft:firework_rocket"), + FIREWORK_ROCKET("minecraft:firework_rocket", 0.25, 0.25), - FOX("minecraft:fox", EntityFox.class), + FOX("minecraft:fox", 0.6, 0.7), - GHAST("minecraft:ghast", EntityGhast.class), + GHAST("minecraft:ghast", 4.0, 4.0), - GIANT("minecraft:giant", EntityGiant.class), + GIANT("minecraft:giant", 3.6, 12.0), - GUARDIAN("minecraft:guardian", EntityGuardian.class), + GUARDIAN("minecraft:guardian", 0.85, 0.85), - HOGLIN("minecraft:hoglin", EntityHoglin.class), + HOGLIN("minecraft:hoglin", 1.39648, 1.4), - HORSE("minecraft:horse", EntityHorse.class), + HORSE("minecraft:horse", 1.39648, 1.6), - HUSK("minecraft:husk", EntityHusk.class), + HUSK("minecraft:husk", 0.6, 1.95), - ILLUSIONER("minecraft:illusioner", EntityIllusioner.class), + ILLUSIONER("minecraft:illusioner", 0.6, 1.95), - IRON_GOLEM("minecraft:iron_golem", EntityIronGolem.class), + IRON_GOLEM("minecraft:iron_golem", 1.4, 2.7), - ITEM("minecraft:item"), + ITEM("minecraft:item", 0.25, 0.25), - ITEM_FRAME("minecraft:item_frame"), + ITEM_FRAME("minecraft:item_frame", 0.5, 0.5), - FIREBALL("minecraft:fireball"), + FIREBALL("minecraft:fireball", 1.0, 1.0), - LEASH_KNOT("minecraft:leash_knot"), + LEASH_KNOT("minecraft:leash_knot", 0.5, 0.5), - LIGHTNING_BOLT("minecraft:lightning_bolt"), + LIGHTNING_BOLT("minecraft:lightning_bolt", 0.0, 0.0), - LLAMA("minecraft:llama", EntityLlama.class), + LLAMA("minecraft:llama", 0.9, 1.87), - LLAMA_SPIT("minecraft:llama_spit"), + LLAMA_SPIT("minecraft:llama_spit", 0.25, 0.25), - MAGMA_CUBE("minecraft:magma_cube", EntityMagmaCube.class), + MAGMA_CUBE("minecraft:magma_cube", 2.04, 2.04), - MINECART("minecraft:minecart"), + MINECART("minecraft:minecart", 0.98, 0.7), - CHEST_MINECART("minecraft:chest_minecart"), + CHEST_MINECART("minecraft:chest_minecart", 0.98, 0.7), - COMMAND_BLOCK_MINECART("minecraft:command_block_minecart"), + COMMAND_BLOCK_MINECART("minecraft:command_block_minecart", 0.98, 0.7), - FURNACE_MINECART("minecraft:furnace_minecart"), + FURNACE_MINECART("minecraft:furnace_minecart", 0.98, 0.7), - HOPPER_MINECART("minecraft:hopper_minecart"), + HOPPER_MINECART("minecraft:hopper_minecart", 0.98, 0.7), - SPAWNER_MINECART("minecraft:spawner_minecart"), + SPAWNER_MINECART("minecraft:spawner_minecart", 0.98, 0.7), - TNT_MINECART("minecraft:tnt_minecart"), + TNT_MINECART("minecraft:tnt_minecart", 0.98, 0.7), - MULE("minecraft:mule", EntityMule.class), + MULE("minecraft:mule", 1.39648, 1.6), - MOOSHROOM("minecraft:mooshroom", EntityMooshroom.class), + MOOSHROOM("minecraft:mooshroom", 0.9, 1.4), - OCELOT("minecraft:ocelot", EntityOcelot.class), + OCELOT("minecraft:ocelot", 0.6, 0.7), - PAINTING("minecraft:painting"), + PAINTING("minecraft:painting", 0.5, 0.5), - PANDA("minecraft:panda", EntityPanda.class), + PANDA("minecraft:panda", 1.3, 1.25), - PARROT("minecraft:parrot", EntityParrot.class), + PARROT("minecraft:parrot", 0.5, 0.9), - PHANTOM("minecraft:phantom", EntityPhantom.class), + PHANTOM("minecraft:phantom", 0.9, 0.5), - PIG("minecraft:pig", EntityPig.class), + PIG("minecraft:pig", 0.9, 0.9), - PIGLIN("minecraft:piglin", EntityPiglin.class), + PIGLIN("minecraft:piglin", 0.6, 1.95), - PIGLIN_BRUTE("minecraft:piglin_brute", EntityPiglinBrute.class), + PIGLIN_BRUTE("minecraft:piglin_brute", 0.6, 1.95), - PILLAGER("minecraft:pillager", EntityPillager.class), + PILLAGER("minecraft:pillager", 0.6, 1.95), - POLAR_BEAR("minecraft:polar_bear", EntityPolarBear.class), + POLAR_BEAR("minecraft:polar_bear", 1.4, 1.4), - TNT("minecraft:tnt"), + TNT("minecraft:tnt", 0.98, 0.98), - PUFFERFISH("minecraft:pufferfish", EntityPufferFish.class), + PUFFERFISH("minecraft:pufferfish", 0.7, 0.7), - RABBIT("minecraft:rabbit", EntityRabbit.class), + RABBIT("minecraft:rabbit", 0.4, 0.5), - RAVAGER("minecraft:ravager", EntityRavager.class), + RAVAGER("minecraft:ravager", 1.95, 2.2), - SALMON("minecraft:salmon", EntitySalmon.class), + SALMON("minecraft:salmon", 0.7, 0.4), - SHEEP("minecraft:sheep", EntitySheep.class), + SHEEP("minecraft:sheep", 0.9, 1.3), - SHULKER("minecraft:shulker", EntityShulker.class), + SHULKER("minecraft:shulker", 1.0, 1.0), - SHULKER_BULLET("minecraft:shulker_bullet"), + SHULKER_BULLET("minecraft:shulker_bullet", 0.3125, 0.3125), - SILVERFISH("minecraft:silverfish", EntitySilverfish.class), + SILVERFISH("minecraft:silverfish", 0.4, 0.3), - SKELETON("minecraft:skeleton", EntitySkeleton.class), + SKELETON("minecraft:skeleton", 0.6, 1.99), - SKELETON_HORSE("minecraft:skeleton_horse", EntitySkeletonHorse.class), + SKELETON_HORSE("minecraft:skeleton_horse", 1.39648, 1.6), - SLIME("minecraft:slime", EntitySlime.class), + SLIME("minecraft:slime", 2.04, 2.04), - SMALL_FIREBALL("minecraft:small_fireball"), + SMALL_FIREBALL("minecraft:small_fireball", 0.3125, 0.3125), - SNOW_GOLEM("minecraft:snow_golem", EntitySnowman.class), + SNOW_GOLEM("minecraft:snow_golem", 0.7, 1.9), - SNOWBALL("minecraft:snowball"), + SNOWBALL("minecraft:snowball", 0.25, 0.25), - SPECTRAL_ARROW("minecraft:spectral_arrow", EntitySpectralArrow.class), + SPECTRAL_ARROW("minecraft:spectral_arrow", 0.5, 0.5), - SPIDER("minecraft:spider", EntitySpider.class), + SPIDER("minecraft:spider", 1.4, 0.9), - SQUID("minecraft:squid", EntitySquid.class), + SQUID("minecraft:squid", 0.8, 0.8), - STRAY("minecraft:stray", EntityStray.class), + STRAY("minecraft:stray", 0.6, 1.99), - STRIDER("minecraft:strider", EntityStrider.class), + STRIDER("minecraft:strider", 0.9, 1.7), - EGG("minecraft:egg"), + EGG("minecraft:egg", 0.25, 0.25), - ENDER_PEARL("minecraft:ender_pearl"), + ENDER_PEARL("minecraft:ender_pearl", 0.25, 0.25), - EXPERIENCE_BOTTLE("minecraft:experience_bottle"), + EXPERIENCE_BOTTLE("minecraft:experience_bottle", 0.25, 0.25), - POTION("minecraft:potion", EntityPotion.class), + POTION("minecraft:potion", 0.25, 0.25), - TRIDENT("minecraft:trident"), + TRIDENT("minecraft:trident", 0.5, 0.5), - TRADER_LLAMA("minecraft:trader_llama", EntityTraderLlama.class), + TRADER_LLAMA("minecraft:trader_llama", 0.9, 1.87), - TROPICAL_FISH("minecraft:tropical_fish", EntityTropicalFish.class), + TROPICAL_FISH("minecraft:tropical_fish", 0.5, 0.4), - TURTLE("minecraft:turtle"), + TURTLE("minecraft:turtle", 1.2, 0.4), - VEX("minecraft:vex", EntityVex.class), + VEX("minecraft:vex", 0.4, 0.8), - VILLAGER("minecraft:villager", EntityVillager.class), + VILLAGER("minecraft:villager", 0.6, 1.95), - VINDICATOR("minecraft:vindicator", EntityVindicator.class), + VINDICATOR("minecraft:vindicator", 0.6, 1.95), - WANDERING_TRADER("minecraft:wandering_trader", EntityWanderingTrader.class), + WANDERING_TRADER("minecraft:wandering_trader", 0.6, 1.95), - WITCH("minecraft:witch", EntityWitch.class), + WITCH("minecraft:witch", 0.6, 1.95), - WITHER("minecraft:wither"), + WITHER("minecraft:wither", 0.9, 3.5), - WITHER_SKELETON("minecraft:wither_skeleton", EntityWitherSkeleton.class), + WITHER_SKELETON("minecraft:wither_skeleton", 0.7, 2.4), - WITHER_SKULL("minecraft:wither_skull"), + WITHER_SKULL("minecraft:wither_skull", 0.3125, 0.3125), - WOLF("minecraft:wolf", EntityWolf.class), + WOLF("minecraft:wolf", 0.6, 0.85), - ZOGLIN("minecraft:zoglin", EntityZoglin.class), + ZOGLIN("minecraft:zoglin", 1.39648, 1.4), - ZOMBIE("minecraft:zombie", EntityZombie.class), + ZOMBIE("minecraft:zombie", 0.6, 1.95), - ZOMBIE_HORSE("minecraft:zombie_horse", EntityZombieHorse.class), + ZOMBIE_HORSE("minecraft:zombie_horse", 1.39648, 1.6), - ZOMBIE_VILLAGER("minecraft:zombie_villager", EntityZombieVillager.class), + ZOMBIE_VILLAGER("minecraft:zombie_villager", 0.6, 1.95), - ZOMBIFIED_PIGLIN("minecraft:zombified_piglin", EntityZombifiedPiglin.class), + ZOMBIFIED_PIGLIN("minecraft:zombified_piglin", 0.6, 1.95), - PLAYER("minecraft:player"), + PLAYER("minecraft:player", 0.6, 1.8), - FISHING_BOBBER("minecraft:fishing_bobber"); + FISHING_BOBBER("minecraft:fishing_bobber", 0.25, 0.25); - private final String namespaceID; - private Class defaultEntityClass; - private Function defaultGenerator; + @NotNull + private String namespaceID; - EntityType(String namespaceID, Class defaultEntityClass) { + private double width; + + private double height; + + EntityType(@NotNull String namespaceID, double width, double height) { this.namespaceID = namespaceID; + this.width = width; + this.height = height; Registries.entityTypes.put(NamespaceID.from(namespaceID), this); - - this.defaultEntityClass = defaultEntityClass; - if (defaultEntityClass != null) { - try { - this.defaultGenerator = LambdaMetafactoryUtils.getSingleArgumentConstructor(defaultEntityClass, Position.class); - } catch (Throwable t) { - // no position constructor - } - } } - EntityType(String namespaceID) { - this(namespaceID, null); - } - - public int getId() { - return ordinal(); + public short getId() { + return (short)ordinal(); } public String getNamespaceID() { return namespaceID; } - public void setDefaultEntityClass(Class defaultEntityClass) { - this.defaultEntityClass = defaultEntityClass; + public double getWidth() { + return this.width; } - public Class getDefaultEntityClass() { - Check.notNull(this.defaultEntityClass, "Default class for " + name() + " is not yet present"); - return this.defaultEntityClass; + public double getHeight() { + return this.height; } - public Entity createFromPosition(Position position) { - Check.notNull(this.defaultGenerator, "Default generator for " + name() + " is not yet supported"); - return this.defaultGenerator.apply(position); - } - - public double getDefaultWidth() { - return 0D; - } - - public double getDefaultHeight() { - return 0D; - } - - public static EntityType fromId(int id) { - if (id >= 0 && id < values().length) { + public static EntityType fromId(short id) { + if(id >= 0 && id < values().length) { return values()[id]; } return PIG; diff --git a/src/generators/java/net/minestom/codegen/entitytypes/BurgerEntity.java b/src/generators/java/net/minestom/codegen/entitytypes/BurgerEntity.java new file mode 100644 index 000000000..2d0279d78 --- /dev/null +++ b/src/generators/java/net/minestom/codegen/entitytypes/BurgerEntity.java @@ -0,0 +1,8 @@ +package net.minestom.codegen.entitytypes; + +public class BurgerEntity { + int id; + String name; + double width; + double height; +} diff --git a/src/generators/java/net/minestom/codegen/entitytypes/EntityTypeContainer.java b/src/generators/java/net/minestom/codegen/entitytypes/EntityTypeContainer.java new file mode 100644 index 000000000..2a94e6f2c --- /dev/null +++ b/src/generators/java/net/minestom/codegen/entitytypes/EntityTypeContainer.java @@ -0,0 +1,40 @@ +package net.minestom.codegen.entitytypes; + +import net.minestom.server.utils.NamespaceID; +import org.jetbrains.annotations.NotNull; + +public class EntityTypeContainer implements Comparable { + + private int id; + private NamespaceID name; + private double width; + private double height; + + public EntityTypeContainer(int id, NamespaceID name, double width, double height) { + this.id = id; + this.name = name; + this.width = width; + this.height = height; + } + + public int getId() { + return id; + } + + public NamespaceID getName() { + return name; + } + + public double getWidth() { + return width; + } + + public double getHeight() { + return height; + } + + @Override + public int compareTo(@NotNull EntityTypeContainer o) { + return Integer.compare(id, o.id); + } +} diff --git a/src/generators/java/net/minestom/codegen/entitytypes/EntityTypeEnumGenerator.java b/src/generators/java/net/minestom/codegen/entitytypes/EntityTypeEnumGenerator.java index f9cdc6e05..563920824 100644 --- a/src/generators/java/net/minestom/codegen/entitytypes/EntityTypeEnumGenerator.java +++ b/src/generators/java/net/minestom/codegen/entitytypes/EntityTypeEnumGenerator.java @@ -1,21 +1,35 @@ package net.minestom.codegen.entitytypes; -import net.minestom.codegen.BasicEnumGenerator; -import net.minestom.codegen.stats.StatsEnumGenerator; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.squareup.javapoet.*; +import net.minestom.codegen.EnumGenerator; +import net.minestom.codegen.MinestomEnumGenerator; +import net.minestom.server.registry.Registries; import net.minestom.server.registry.ResourceGatherer; +import net.minestom.server.utils.NamespaceID; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; +import java.io.*; +import java.net.URL; +import java.util.*; -public class EntityTypeEnumGenerator extends BasicEnumGenerator { +/** + * Generates an EntityType enum containing all data about entity types + */ +public class EntityTypeEnumGenerator extends MinestomEnumGenerator { private static final Logger LOGGER = LoggerFactory.getLogger(EntityTypeEnumGenerator.class); + private final String targetVersion; + private final File targetFolder; + public static void main(String[] args) throws IOException { String targetVersion; - if(args.length < 1) { + if (args.length < 1) { System.err.println("Usage: [target folder]"); return; } @@ -29,25 +43,44 @@ public class EntityTypeEnumGenerator extends BasicEnumGenerator { } String targetPart = DEFAULT_TARGET_PATH; - if(args.length >= 2) { + if (args.length >= 2) { targetPart = args[1]; } File targetFolder = new File(targetPart); - if(!targetFolder.exists()) { + if (!targetFolder.exists()) { targetFolder.mkdirs(); } - new EntityTypeEnumGenerator(targetFolder); + new EntityTypeEnumGenerator(targetVersion, targetFolder); } - private EntityTypeEnumGenerator(File targetFolder) throws IOException { - super(targetFolder); + private EntityTypeEnumGenerator(String targetVersion, File targetFolder) throws IOException { + this.targetVersion = targetVersion; + this.targetFolder = targetFolder; + generateTo(targetFolder); } - @Override - protected String getCategoryID() { - return "minecraft:entity_type"; + /** + * Extract entity information from Burger (submodule of Minestom) + * + * @param gson + * @param url + * @return + * @throws IOException + */ + private List parseEntitiesFromBurger(Gson gson, String url) throws IOException { + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) { + LOGGER.debug("\tConnection established, reading file"); + JsonObject dictionary = gson.fromJson(bufferedReader, JsonArray.class).get(0).getAsJsonObject(); + JsonObject entitiesMap = dictionary.getAsJsonObject("entities").getAsJsonObject("entity"); + List entities = new LinkedList<>(); + for (var entry : entitiesMap.entrySet()) { + BurgerEntity entity = gson.fromJson(entry.getValue(), BurgerEntity.class); + entities.add(entity); + } + return entities; + } } @Override @@ -60,6 +93,74 @@ public class EntityTypeEnumGenerator extends BasicEnumGenerator { return "EntityType"; } + @Override + protected Collection compile() throws IOException { + Gson gson = new Gson(); + LOGGER.debug("Loading PrismarineJS entity types data"); + List burgerEntities = parseEntitiesFromBurger(gson, BURGER_URL_BASE_URL + targetVersion + ".json"); + + TreeSet types = new TreeSet<>(EntityTypeContainer::compareTo); + for (var burgerEntity : burgerEntities) { + types.add(new EntityTypeContainer( + burgerEntity.id, + NamespaceID.from("minecraft:" + burgerEntity.name), + burgerEntity.width, + burgerEntity.height + )); + } + return types; + } + + @Override + protected void prepare(EnumGenerator generator) { + ClassName className = ClassName.get(getPackageName(), getClassName()); + generator.addClassAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "{$S}", "deprecation").build()); + generator.setParams(ParameterSpec.builder(String.class, "namespaceID").addAnnotation(NotNull.class).build(), ParameterSpec.builder(TypeName.DOUBLE, "width").build(), + ParameterSpec.builder(TypeName.DOUBLE, "height").build()); + generator.appendToConstructor(code -> { + code.addStatement("$T.$N.put($T.from(namespaceID), this)", Registries.class, "entityTypes", NamespaceID.class); + }); + + generator.addMethod("getId", new ParameterSpec[0], TypeName.SHORT, code -> { + code.addStatement("return (short)ordinal()"); + }); + generator.addMethod("getNamespaceID", new ParameterSpec[0], ClassName.get(String.class), code -> { + code.addStatement("return namespaceID"); + }); + generator.addMethod("getWidth", new ParameterSpec[0], TypeName.DOUBLE, code -> { + code.addStatement("return this.width"); + }); + generator.addMethod("getHeight", new ParameterSpec[0], TypeName.DOUBLE, code -> { + code.addStatement("return this.height"); + }); + + generator.addStaticMethod("fromId", new ParameterSpec[]{ParameterSpec.builder(TypeName.SHORT, "id").build()}, className, code -> { + code.beginControlFlow("if(id >= 0 && id < values().length)") + .addStatement("return values()[id]") + .endControlFlow() + .addStatement("return PIG"); + }); + } + + @Override + protected void writeSingle(EnumGenerator generator, EntityTypeContainer type) { + String instanceName = type.getName().getPath().toUpperCase(); + generator.addInstance(instanceName, + "\"" + type.getName().toString() + "\"", + type.getWidth(), + type.getHeight() + ); + } + + @Override + protected List postGeneration(Collection types) { + return Collections.emptyList(); + } + + @Override + protected void postWrite(EnumGenerator generator) { + } + @Override public Logger getLogger() { return LOGGER;