Add entity information
This commit is contained in:
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/Tnze/go-mc/bot/world/entity/player"
|
"github.com/Tnze/go-mc/bot/world/entity/player"
|
||||||
"github.com/Tnze/go-mc/chat"
|
"github.com/Tnze/go-mc/chat"
|
||||||
"github.com/Tnze/go-mc/data"
|
"github.com/Tnze/go-mc/data"
|
||||||
|
"github.com/Tnze/go-mc/data/entity"
|
||||||
pk "github.com/Tnze/go-mc/net/packet"
|
pk "github.com/Tnze/go-mc/net/packet"
|
||||||
"github.com/Tnze/go-mc/net/ptypes"
|
"github.com/Tnze/go-mc/net/ptypes"
|
||||||
)
|
)
|
||||||
@ -208,7 +209,11 @@ func handleSpawnEntityPacket(c *Client, p pk.Packet) error {
|
|||||||
if err := se.Decode(p); err != nil {
|
if err := se.Decode(p); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("SpawnEntity: %+v\n", se)
|
if e := entity.ByID[entity.ID(se.Type)]; e != nil {
|
||||||
|
fmt.Printf("Spawning %s at (%f,%f,%f)\n", e.DisplayName, se.X, se.Y, se.Z)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("SpawnEntity: %+v\n", se)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +222,11 @@ func handleSpawnLivingEntityPacket(c *Client, p pk.Packet) error {
|
|||||||
if err := se.Decode(p); err != nil {
|
if err := se.Decode(p); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("SpawnLivingEntity: %+v\n", se)
|
if e := entity.ByID[entity.ID(se.Type)]; e != nil {
|
||||||
|
fmt.Printf("Spawning %s at (%f,%f,%f)\n", e.DisplayName, se.X, se.Y, se.Z)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("SpawnLivingEntity: %+v\n", se)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +244,7 @@ func handleEntityPositionPacket(c *Client, p pk.Packet) error {
|
|||||||
if err := se.Decode(p); err != nil {
|
if err := se.Decode(p); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("EntityPosition: %+v\n", se)
|
// fmt.Printf("EntityPosition: %+v\n", se)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +253,7 @@ func handleEntityPositionLookPacket(c *Client, p pk.Packet) error {
|
|||||||
if err := se.Decode(p); err != nil {
|
if err := se.Decode(p); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("EntityPositionLook: %+v\n", se)
|
// fmt.Printf("EntityPositionLook: %+v\n", se)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +262,7 @@ func handleEntityLookPacket(c *Client, p pk.Packet) error {
|
|||||||
if err := se.Decode(p); err != nil {
|
if err := se.Decode(p); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("EntityRotation: %+v\n", se)
|
// fmt.Printf("EntityRotation: %+v\n", se)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
242
data/entity/entity.go
Normal file
242
data/entity/entity.go
Normal file
@ -0,0 +1,242 @@
|
|||||||
|
// Package entity stores information about entities in Minecraft.
|
||||||
|
package entity
|
||||||
|
|
||||||
|
// ID describes the numeric ID of an entity.
|
||||||
|
type ID uint32
|
||||||
|
|
||||||
|
// Entity describes information about a type of entity.
|
||||||
|
type Entity struct {
|
||||||
|
ID ID
|
||||||
|
InternalID uint32
|
||||||
|
DisplayName string
|
||||||
|
Name string
|
||||||
|
|
||||||
|
Width float64
|
||||||
|
Height float64
|
||||||
|
|
||||||
|
Type string
|
||||||
|
Category string
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
AreaEffectCloud = Entity{ID: 0, InternalID: 0, DisplayName: "Area Effect Cloud", Name: "area_effect_cloud", Width: 6, Height: 0.5, Type: "mob", Category: "Immobile"}
|
||||||
|
ArmorStand = Entity{ID: 1, InternalID: 1, DisplayName: "Armor Stand", Name: "armor_stand", Width: 0.5, Height: 1.975, Type: "mob", Category: "Immobile"}
|
||||||
|
Arrow = Entity{ID: 2, InternalID: 2, DisplayName: "Arrow", Name: "arrow", Width: 0.5, Height: 0.5, Type: "mob", Category: "Projectiles"}
|
||||||
|
Bat = Entity{ID: 3, InternalID: 3, DisplayName: "Bat", Name: "bat", Width: 0.5, Height: 0.9, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Bee = Entity{ID: 4, InternalID: 4, DisplayName: "Bee", Name: "bee", Width: 0.7, Height: 0.6, Type: "UNKNOWN", Category: "UNKNOWN"}
|
||||||
|
Blaze = Entity{ID: 5, InternalID: 5, DisplayName: "Blaze", Name: "blaze", Width: 0.6, Height: 1.8, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Boat = Entity{ID: 6, InternalID: 6, DisplayName: "Boat", Name: "boat", Width: 1.375, Height: 0.5625, Type: "mob", Category: "Vehicles"}
|
||||||
|
Cat = Entity{ID: 7, InternalID: 7, DisplayName: "Cat", Name: "cat", Width: 0.6, Height: 0.7, Type: "mob", Category: "Passive mobs"}
|
||||||
|
CaveSpider = Entity{ID: 8, InternalID: 8, DisplayName: "Cave Spider", Name: "cave_spider", Width: 0.7, Height: 0.5, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Chicken = Entity{ID: 9, InternalID: 9, DisplayName: "Chicken", Name: "chicken", Width: 0.4, Height: 0.7, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Cod = Entity{ID: 10, InternalID: 10, DisplayName: "Cod", Name: "cod", Width: 0.5, Height: 0.3, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Cow = Entity{ID: 11, InternalID: 11, DisplayName: "Cow", Name: "cow", Width: 0.9, Height: 1.4, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Creeper = Entity{ID: 12, InternalID: 12, DisplayName: "Creeper", Name: "creeper", Width: 0.6, Height: 1.7, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Dolphin = Entity{ID: 13, InternalID: 13, DisplayName: "Dolphin", Name: "dolphin", Width: 0.9, Height: 0.6, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Donkey = Entity{ID: 14, InternalID: 14, DisplayName: "Donkey", Name: "donkey", Width: 1.39648, Height: 1.5, Type: "mob", Category: "Passive mobs"}
|
||||||
|
DragonFireball = Entity{ID: 15, InternalID: 15, DisplayName: "Dragon Fireball", Name: "dragon_fireball", Width: 1, Height: 1, Type: "mob", Category: "Projectiles"}
|
||||||
|
Drowned = Entity{ID: 16, InternalID: 16, DisplayName: "Drowned", Name: "drowned", Width: 0.6, Height: 1.95, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
ElderGuardian = Entity{ID: 17, InternalID: 17, DisplayName: "Elder Guardian", Name: "elder_guardian", Width: 1.9975, Height: 1.9975, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
EndCrystal = Entity{ID: 18, InternalID: 18, DisplayName: "End Crystal", Name: "end_crystal", Width: 2, Height: 2, Type: "mob", Category: "UNKNOWN"}
|
||||||
|
EnderDragon = Entity{ID: 19, InternalID: 19, DisplayName: "Ender Dragon", Name: "ender_dragon", Width: 16, Height: 8, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Enderman = Entity{ID: 20, InternalID: 20, DisplayName: "Enderman", Name: "enderman", Width: 0.6, Height: 2.9, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Endermite = Entity{ID: 21, InternalID: 21, DisplayName: "Endermite", Name: "endermite", Width: 0.4, Height: 0.3, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Evoker = Entity{ID: 22, InternalID: 22, DisplayName: "Evoker", Name: "evoker", Width: 0.6, Height: 1.95, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
EvokerFangs = Entity{ID: 23, InternalID: 23, DisplayName: "Evoker Fangs", Name: "evoker_fangs", Width: 0.5, Height: 0.8, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
ExperienceOrb = Entity{ID: 24, InternalID: 24, DisplayName: "Experience Orb", Name: "experience_orb", Width: 0.5, Height: 0.5, Type: "mob", Category: "UNKNOWN"}
|
||||||
|
EyeOfEnder = Entity{ID: 25, InternalID: 25, DisplayName: "Eye of Ender", Name: "eye_of_ender", Width: 0.25, Height: 0.25, Type: "mob", Category: "UNKNOWN"}
|
||||||
|
FallingBlock = Entity{ID: 26, InternalID: 26, DisplayName: "Falling Block", Name: "falling_block", Width: 0.98, Height: 0.98, Type: "mob", Category: "Blocks"}
|
||||||
|
FireworkRocket = Entity{ID: 27, InternalID: 27, DisplayName: "Firework Rocket", Name: "firework_rocket", Width: 0.25, Height: 0.25, Type: "mob", Category: "UNKNOWN"}
|
||||||
|
Fox = Entity{ID: 28, InternalID: 28, DisplayName: "Fox", Name: "fox", Width: 0.6, Height: 0.7, Type: "mob", Category: "UNKNOWN"}
|
||||||
|
Ghast = Entity{ID: 29, InternalID: 29, DisplayName: "Ghast", Name: "ghast", Width: 4, Height: 4, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Giant = Entity{ID: 30, InternalID: 30, DisplayName: "Giant", Name: "giant", Width: 3.6, Height: 12, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Guardian = Entity{ID: 31, InternalID: 31, DisplayName: "Guardian", Name: "guardian", Width: 0.85, Height: 0.85, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Hoglin = Entity{ID: 32, InternalID: 32, DisplayName: "Hoglin", Name: "hoglin", Width: 1.39648, Height: 1.4, Type: "UNKNOWN", Category: "UNKNOWN"}
|
||||||
|
Horse = Entity{ID: 33, InternalID: 33, DisplayName: "Horse", Name: "horse", Width: 1.39648, Height: 1.6, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Husk = Entity{ID: 34, InternalID: 34, DisplayName: "Husk", Name: "husk", Width: 0.6, Height: 1.95, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Illusioner = Entity{ID: 35, InternalID: 35, DisplayName: "Illusioner", Name: "illusioner", Width: 0.6, Height: 1.95, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
IronGolem = Entity{ID: 36, InternalID: 36, DisplayName: "Iron Golem", Name: "iron_golem", Width: 1.4, Height: 2.7, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Item = Entity{ID: 37, InternalID: 37, DisplayName: "Item", Name: "item", Width: 0.25, Height: 0.25, Type: "mob", Category: "Drops"}
|
||||||
|
ItemFrame = Entity{ID: 38, InternalID: 38, DisplayName: "Item Frame", Name: "item_frame", Width: 0.5, Height: 0.5, Type: "mob", Category: "Immobile"}
|
||||||
|
Fireball = Entity{ID: 39, InternalID: 39, DisplayName: "Fireball", Name: "fireball", Width: 1, Height: 1, Type: "mob", Category: "Projectiles"}
|
||||||
|
LeashKnot = Entity{ID: 40, InternalID: 40, DisplayName: "Leash Knot", Name: "leash_knot", Width: 0.5, Height: 0.5, Type: "mob", Category: "Immobile"}
|
||||||
|
LightningBolt = Entity{ID: 41, InternalID: 41, DisplayName: "Lightning Bolt", Name: "lightning_bolt", Width: 0, Height: 0, Type: "mob", Category: "UNKNOWN"}
|
||||||
|
Llama = Entity{ID: 42, InternalID: 42, DisplayName: "Llama", Name: "llama", Width: 0.9, Height: 1.87, Type: "mob", Category: "Passive mobs"}
|
||||||
|
LlamaSpit = Entity{ID: 43, InternalID: 43, DisplayName: "Llama Spit", Name: "llama_spit", Width: 0.25, Height: 0.25, Type: "mob", Category: "Projectiles"}
|
||||||
|
MagmaCube = Entity{ID: 44, InternalID: 44, DisplayName: "Magma Cube", Name: "magma_cube", Width: 2.04, Height: 2.04, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Minecart = Entity{ID: 45, InternalID: 45, DisplayName: "Minecart", Name: "minecart", Width: 0.98, Height: 0.7, Type: "mob", Category: "Vehicles"}
|
||||||
|
ChestMinecart = Entity{ID: 46, InternalID: 46, DisplayName: "Minecart with Chest", Name: "chest_minecart", Width: 0.98, Height: 0.7, Type: "mob", Category: "Vehicles"}
|
||||||
|
CommandBlockMinecart = Entity{ID: 47, InternalID: 47, DisplayName: "Minecart with Command Block", Name: "command_block_minecart", Width: 0.98, Height: 0.7, Type: "mob", Category: "Vehicles"}
|
||||||
|
FurnaceMinecart = Entity{ID: 48, InternalID: 48, DisplayName: "Minecart with Furnace", Name: "furnace_minecart", Width: 0.98, Height: 0.7, Type: "mob", Category: "Vehicles"}
|
||||||
|
HopperMinecart = Entity{ID: 49, InternalID: 49, DisplayName: "Minecart with Hopper", Name: "hopper_minecart", Width: 0.98, Height: 0.7, Type: "mob", Category: "Vehicles"}
|
||||||
|
SpawnerMinecart = Entity{ID: 50, InternalID: 50, DisplayName: "Minecart with Spawner", Name: "spawner_minecart", Width: 0.98, Height: 0.7, Type: "mob", Category: "Vehicles"}
|
||||||
|
TntMinecart = Entity{ID: 51, InternalID: 51, DisplayName: "Minecart with TNT", Name: "tnt_minecart", Width: 0.98, Height: 0.7, Type: "mob", Category: "Vehicles"}
|
||||||
|
Mule = Entity{ID: 52, InternalID: 52, DisplayName: "Mule", Name: "mule", Width: 1.39648, Height: 1.6, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Mooshroom = Entity{ID: 53, InternalID: 53, DisplayName: "Mooshroom", Name: "mooshroom", Width: 0.9, Height: 1.4, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Ocelot = Entity{ID: 54, InternalID: 54, DisplayName: "Ocelot", Name: "ocelot", Width: 0.6, Height: 0.7, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Painting = Entity{ID: 55, InternalID: 55, DisplayName: "Painting", Name: "painting", Width: 0.5, Height: 0.5, Type: "mob", Category: "Immobile"}
|
||||||
|
Panda = Entity{ID: 56, InternalID: 56, DisplayName: "Panda", Name: "panda", Width: 1.3, Height: 1.25, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Parrot = Entity{ID: 57, InternalID: 57, DisplayName: "Parrot", Name: "parrot", Width: 0.5, Height: 0.9, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Phantom = Entity{ID: 58, InternalID: 58, DisplayName: "Phantom", Name: "phantom", Width: 0.9, Height: 0.5, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Pig = Entity{ID: 59, InternalID: 59, DisplayName: "Pig", Name: "pig", Width: 0.9, Height: 0.9, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Piglin = Entity{ID: 60, InternalID: 60, DisplayName: "Piglin", Name: "piglin", Width: 0.6, Height: 1.95, Type: "UNKNOWN", Category: "UNKNOWN"}
|
||||||
|
PiglinBrute = Entity{ID: 61, InternalID: 61, DisplayName: "Piglin Brute", Name: "piglin_brute", Width: 0.6, Height: 1.95, Type: "UNKNOWN", Category: "UNKNOWN"}
|
||||||
|
Pillager = Entity{ID: 62, InternalID: 62, DisplayName: "Pillager", Name: "pillager", Width: 0.6, Height: 1.95, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
PolarBear = Entity{ID: 63, InternalID: 63, DisplayName: "Polar Bear", Name: "polar_bear", Width: 1.4, Height: 1.4, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Tnt = Entity{ID: 64, InternalID: 64, DisplayName: "Primed TNT", Name: "tnt", Width: 0.98, Height: 0.98, Type: "mob", Category: "Blocks"}
|
||||||
|
Pufferfish = Entity{ID: 65, InternalID: 65, DisplayName: "Pufferfish", Name: "pufferfish", Width: 0.7, Height: 0.7, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Rabbit = Entity{ID: 66, InternalID: 66, DisplayName: "Rabbit", Name: "rabbit", Width: 0.4, Height: 0.5, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Ravager = Entity{ID: 67, InternalID: 67, DisplayName: "Ravager", Name: "ravager", Width: 1.95, Height: 2.2, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Salmon = Entity{ID: 68, InternalID: 68, DisplayName: "Salmon", Name: "salmon", Width: 0.7, Height: 0.4, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Sheep = Entity{ID: 69, InternalID: 69, DisplayName: "Sheep", Name: "sheep", Width: 0.9, Height: 1.3, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Shulker = Entity{ID: 70, InternalID: 70, DisplayName: "Shulker", Name: "shulker", Width: 1, Height: 1, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
ShulkerBullet = Entity{ID: 71, InternalID: 71, DisplayName: "Shulker Bullet", Name: "shulker_bullet", Width: 0.3125, Height: 0.3125, Type: "mob", Category: "Projectiles"}
|
||||||
|
Silverfish = Entity{ID: 72, InternalID: 72, DisplayName: "Silverfish", Name: "silverfish", Width: 0.4, Height: 0.3, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Skeleton = Entity{ID: 73, InternalID: 73, DisplayName: "Skeleton", Name: "skeleton", Width: 0.6, Height: 1.99, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
SkeletonHorse = Entity{ID: 74, InternalID: 74, DisplayName: "Skeleton Horse", Name: "skeleton_horse", Width: 1.39648, Height: 1.6, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Slime = Entity{ID: 75, InternalID: 75, DisplayName: "Slime", Name: "slime", Width: 2.04, Height: 2.04, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
SmallFireball = Entity{ID: 76, InternalID: 76, DisplayName: "Small Fireball", Name: "small_fireball", Width: 0.3125, Height: 0.3125, Type: "mob", Category: "Projectiles"}
|
||||||
|
SnowGolem = Entity{ID: 77, InternalID: 77, DisplayName: "Snow Golem", Name: "snow_golem", Width: 0.7, Height: 1.9, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Snowball = Entity{ID: 78, InternalID: 78, DisplayName: "Snowball", Name: "snowball", Width: 0.25, Height: 0.25, Type: "mob", Category: "Projectiles"}
|
||||||
|
SpectralArrow = Entity{ID: 79, InternalID: 79, DisplayName: "Spectral Arrow", Name: "spectral_arrow", Width: 0.5, Height: 0.5, Type: "mob", Category: "Projectiles"}
|
||||||
|
Spider = Entity{ID: 80, InternalID: 80, DisplayName: "Spider", Name: "spider", Width: 1.4, Height: 0.9, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Squid = Entity{ID: 81, InternalID: 81, DisplayName: "Squid", Name: "squid", Width: 0.8, Height: 0.8, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Stray = Entity{ID: 82, InternalID: 82, DisplayName: "Stray", Name: "stray", Width: 0.6, Height: 1.99, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Strider = Entity{ID: 83, InternalID: 83, DisplayName: "Strider", Name: "strider", Width: 0.9, Height: 1.7, Type: "UNKNOWN", Category: "UNKNOWN"}
|
||||||
|
Egg = Entity{ID: 84, InternalID: 84, DisplayName: "Thrown Egg", Name: "egg", Width: 0.25, Height: 0.25, Type: "mob", Category: "Projectiles"}
|
||||||
|
EnderPearl = Entity{ID: 85, InternalID: 85, DisplayName: "Thrown Ender Pearl", Name: "ender_pearl", Width: 0.25, Height: 0.25, Type: "mob", Category: "Projectiles"}
|
||||||
|
ExperienceBottle = Entity{ID: 86, InternalID: 86, DisplayName: "Thrown Bottle o' Enchanting", Name: "experience_bottle", Width: 0.25, Height: 0.25, Type: "mob", Category: "UNKNOWN"}
|
||||||
|
Potion = Entity{ID: 87, InternalID: 87, DisplayName: "Potion", Name: "potion", Width: 0.25, Height: 0.25, Type: "mob", Category: "Projectiles"}
|
||||||
|
Trident = Entity{ID: 88, InternalID: 88, DisplayName: "Trident", Name: "trident", Width: 0.5, Height: 0.5, Type: "mob", Category: "UNKNOWN"}
|
||||||
|
TraderLlama = Entity{ID: 89, InternalID: 89, DisplayName: "Trader Llama", Name: "trader_llama", Width: 0.9, Height: 1.87, Type: "mob", Category: "Passive mobs"}
|
||||||
|
TropicalFish = Entity{ID: 90, InternalID: 90, DisplayName: "Tropical Fish", Name: "tropical_fish", Width: 0.5, Height: 0.4, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Turtle = Entity{ID: 91, InternalID: 91, DisplayName: "Turtle", Name: "turtle", Width: 1.2, Height: 0.4, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Vex = Entity{ID: 92, InternalID: 92, DisplayName: "Vex", Name: "vex", Width: 0.4, Height: 0.8, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Villager = Entity{ID: 93, InternalID: 93, DisplayName: "Villager", Name: "villager", Width: 0.6, Height: 1.95, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Vindicator = Entity{ID: 94, InternalID: 94, DisplayName: "Vindicator", Name: "vindicator", Width: 0.6, Height: 1.95, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
WanderingTrader = Entity{ID: 95, InternalID: 95, DisplayName: "Wandering Trader", Name: "wandering_trader", Width: 0.6, Height: 1.95, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Witch = Entity{ID: 96, InternalID: 96, DisplayName: "Witch", Name: "witch", Width: 0.6, Height: 1.95, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
Wither = Entity{ID: 97, InternalID: 97, DisplayName: "Wither", Name: "wither", Width: 0.9, Height: 3.5, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
WitherSkeleton = Entity{ID: 98, InternalID: 98, DisplayName: "Wither Skeleton", Name: "wither_skeleton", Width: 0.7, Height: 2.4, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
WitherSkull = Entity{ID: 99, InternalID: 99, DisplayName: "Wither Skull", Name: "wither_skull", Width: 0.3125, Height: 0.3125, Type: "mob", Category: "Projectiles"}
|
||||||
|
Wolf = Entity{ID: 100, InternalID: 100, DisplayName: "Wolf", Name: "wolf", Width: 0.6, Height: 0.85, Type: "mob", Category: "Passive mobs"}
|
||||||
|
Zoglin = Entity{ID: 101, InternalID: 101, DisplayName: "Zoglin", Name: "zoglin", Width: 1.39648, Height: 1.4, Type: "UNKNOWN", Category: "UNKNOWN"}
|
||||||
|
Zombie = Entity{ID: 102, InternalID: 102, DisplayName: "Zombie", Name: "zombie", Width: 0.6, Height: 1.95, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
ZombieHorse = Entity{ID: 103, InternalID: 103, DisplayName: "Zombie Horse", Name: "zombie_horse", Width: 1.39648, Height: 1.6, Type: "mob", Category: "Passive mobs"}
|
||||||
|
ZombieVillager = Entity{ID: 104, InternalID: 104, DisplayName: "Zombie Villager", Name: "zombie_villager", Width: 0.6, Height: 1.95, Type: "mob", Category: "Hostile mobs"}
|
||||||
|
ZombifiedPiglin = Entity{ID: 105, InternalID: 105, DisplayName: "Zombified Piglin", Name: "zombified_piglin", Width: 0.6, Height: 1.95, Type: "UNKNOWN", Category: "UNKNOWN"}
|
||||||
|
Player = Entity{ID: 106, InternalID: 106, DisplayName: "Player", Name: "player", Width: 0.6, Height: 1.8, Type: "mob", Category: "UNKNOWN"}
|
||||||
|
FishingBobber = Entity{ID: 107, InternalID: 107, DisplayName: "Fishing Bobber", Name: "fishing_bobber", Width: 0.25, Height: 0.25, Type: "mob", Category: "UNKNOWN"}
|
||||||
|
)
|
||||||
|
|
||||||
|
// ByID is an index of minecraft entities by their ID.
|
||||||
|
var ByID = map[ID]*Entity{
|
||||||
|
0: &AreaEffectCloud,
|
||||||
|
1: &ArmorStand,
|
||||||
|
2: &Arrow,
|
||||||
|
3: &Bat,
|
||||||
|
4: &Bee,
|
||||||
|
5: &Blaze,
|
||||||
|
6: &Boat,
|
||||||
|
7: &Cat,
|
||||||
|
8: &CaveSpider,
|
||||||
|
9: &Chicken,
|
||||||
|
10: &Cod,
|
||||||
|
11: &Cow,
|
||||||
|
12: &Creeper,
|
||||||
|
13: &Dolphin,
|
||||||
|
14: &Donkey,
|
||||||
|
15: &DragonFireball,
|
||||||
|
16: &Drowned,
|
||||||
|
17: &ElderGuardian,
|
||||||
|
18: &EndCrystal,
|
||||||
|
19: &EnderDragon,
|
||||||
|
20: &Enderman,
|
||||||
|
21: &Endermite,
|
||||||
|
22: &Evoker,
|
||||||
|
23: &EvokerFangs,
|
||||||
|
24: &ExperienceOrb,
|
||||||
|
25: &EyeOfEnder,
|
||||||
|
26: &FallingBlock,
|
||||||
|
27: &FireworkRocket,
|
||||||
|
28: &Fox,
|
||||||
|
29: &Ghast,
|
||||||
|
30: &Giant,
|
||||||
|
31: &Guardian,
|
||||||
|
32: &Hoglin,
|
||||||
|
33: &Horse,
|
||||||
|
34: &Husk,
|
||||||
|
35: &Illusioner,
|
||||||
|
36: &IronGolem,
|
||||||
|
37: &Item,
|
||||||
|
38: &ItemFrame,
|
||||||
|
39: &Fireball,
|
||||||
|
40: &LeashKnot,
|
||||||
|
41: &LightningBolt,
|
||||||
|
42: &Llama,
|
||||||
|
43: &LlamaSpit,
|
||||||
|
44: &MagmaCube,
|
||||||
|
45: &Minecart,
|
||||||
|
46: &ChestMinecart,
|
||||||
|
47: &CommandBlockMinecart,
|
||||||
|
48: &FurnaceMinecart,
|
||||||
|
49: &HopperMinecart,
|
||||||
|
50: &SpawnerMinecart,
|
||||||
|
51: &TntMinecart,
|
||||||
|
52: &Mule,
|
||||||
|
53: &Mooshroom,
|
||||||
|
54: &Ocelot,
|
||||||
|
55: &Painting,
|
||||||
|
56: &Panda,
|
||||||
|
57: &Parrot,
|
||||||
|
58: &Phantom,
|
||||||
|
59: &Pig,
|
||||||
|
60: &Piglin,
|
||||||
|
61: &PiglinBrute,
|
||||||
|
62: &Pillager,
|
||||||
|
63: &PolarBear,
|
||||||
|
64: &Tnt,
|
||||||
|
65: &Pufferfish,
|
||||||
|
66: &Rabbit,
|
||||||
|
67: &Ravager,
|
||||||
|
68: &Salmon,
|
||||||
|
69: &Sheep,
|
||||||
|
70: &Shulker,
|
||||||
|
71: &ShulkerBullet,
|
||||||
|
72: &Silverfish,
|
||||||
|
73: &Skeleton,
|
||||||
|
74: &SkeletonHorse,
|
||||||
|
75: &Slime,
|
||||||
|
76: &SmallFireball,
|
||||||
|
77: &SnowGolem,
|
||||||
|
78: &Snowball,
|
||||||
|
79: &SpectralArrow,
|
||||||
|
80: &Spider,
|
||||||
|
81: &Squid,
|
||||||
|
82: &Stray,
|
||||||
|
83: &Strider,
|
||||||
|
84: &Egg,
|
||||||
|
85: &EnderPearl,
|
||||||
|
86: &ExperienceBottle,
|
||||||
|
87: &Potion,
|
||||||
|
88: &Trident,
|
||||||
|
89: &TraderLlama,
|
||||||
|
90: &TropicalFish,
|
||||||
|
91: &Turtle,
|
||||||
|
92: &Vex,
|
||||||
|
93: &Villager,
|
||||||
|
94: &Vindicator,
|
||||||
|
95: &WanderingTrader,
|
||||||
|
96: &Witch,
|
||||||
|
97: &Wither,
|
||||||
|
98: &WitherSkeleton,
|
||||||
|
99: &WitherSkull,
|
||||||
|
100: &Wolf,
|
||||||
|
101: &Zoglin,
|
||||||
|
102: &Zombie,
|
||||||
|
103: &ZombieHorse,
|
||||||
|
104: &ZombieVillager,
|
||||||
|
105: &ZombifiedPiglin,
|
||||||
|
106: &Player,
|
||||||
|
107: &FishingBobber,
|
||||||
|
}
|
151
data/entity/gen_entity.go
Normal file
151
data/entity/gen_entity.go
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
// gen_entity.go generates entity information.
|
||||||
|
|
||||||
|
//+build ignore
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"go/ast"
|
||||||
|
"go/format"
|
||||||
|
"go/token"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/iancoleman/strcase"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
infoURL = "https://raw.githubusercontent.com/PrismarineJS/minecraft-data/master/data/pc/1.16.2/entities.json"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Entity struct {
|
||||||
|
ID uint32 `json:"id"`
|
||||||
|
InternalID uint32 `json:"internalId"`
|
||||||
|
DisplayName string `json:"displayName"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
Width float64 `json:"width"`
|
||||||
|
Height float64 `json:"height"`
|
||||||
|
|
||||||
|
Type string `json:"type"`
|
||||||
|
Category string `json:"category"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func downloadInfo() ([]Entity, error) {
|
||||||
|
resp, err := http.Get(infoURL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var data []Entity
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeEntityDeclaration(entities []Entity) *ast.DeclStmt {
|
||||||
|
out := &ast.DeclStmt{Decl: &ast.GenDecl{Tok: token.VAR}}
|
||||||
|
|
||||||
|
for _, e := range entities {
|
||||||
|
t := reflect.TypeOf(e)
|
||||||
|
fields := make([]ast.Expr, t.NumField())
|
||||||
|
|
||||||
|
for i := 0; i < t.NumField(); i++ {
|
||||||
|
ft := t.Field(i)
|
||||||
|
|
||||||
|
var val ast.Expr
|
||||||
|
switch ft.Type.Kind() {
|
||||||
|
case reflect.Uint32, reflect.Int:
|
||||||
|
val = &ast.BasicLit{Kind: token.INT, Value: fmt.Sprint(reflect.ValueOf(e).Field(i))}
|
||||||
|
case reflect.Float64:
|
||||||
|
val = &ast.BasicLit{Kind: token.FLOAT, Value: fmt.Sprint(reflect.ValueOf(e).Field(i))}
|
||||||
|
case reflect.String:
|
||||||
|
val = &ast.BasicLit{Kind: token.STRING, Value: strconv.Quote(reflect.ValueOf(e).Field(i).String())}
|
||||||
|
case reflect.Bool:
|
||||||
|
val = &ast.BasicLit{Kind: token.IDENT, Value: fmt.Sprint(reflect.ValueOf(e).Field(i).Bool())}
|
||||||
|
|
||||||
|
case reflect.Slice:
|
||||||
|
val = &ast.CompositeLit{
|
||||||
|
Type: &ast.ArrayType{
|
||||||
|
Elt: &ast.BasicLit{Kind: token.IDENT, Value: ft.Type.Elem().Name()},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
v := reflect.ValueOf(e).Field(i)
|
||||||
|
switch ft.Type.Elem().Kind() {
|
||||||
|
case reflect.Uint32, reflect.Int:
|
||||||
|
for x := 0; x < v.Len(); x++ {
|
||||||
|
val.(*ast.CompositeLit).Elts = append(val.(*ast.CompositeLit).Elts, &ast.BasicLit{
|
||||||
|
Kind: token.INT,
|
||||||
|
Value: fmt.Sprint(v.Index(x)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fields[i] = &ast.KeyValueExpr{
|
||||||
|
Key: &ast.Ident{Name: ft.Name},
|
||||||
|
Value: val,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out.Decl.(*ast.GenDecl).Specs = append(out.Decl.(*ast.GenDecl).Specs, &ast.ValueSpec{
|
||||||
|
Names: []*ast.Ident{{Name: strcase.ToCamel(e.Name)}},
|
||||||
|
Values: []ast.Expr{
|
||||||
|
&ast.CompositeLit{
|
||||||
|
Type: &ast.Ident{Name: reflect.TypeOf(e).Name()},
|
||||||
|
Elts: fields,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
entities, err := downloadInfo()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(`// Package entity stores information about entities in Minecraft.
|
||||||
|
package entity
|
||||||
|
|
||||||
|
// ID describes the numeric ID of an entity.
|
||||||
|
type ID uint32
|
||||||
|
|
||||||
|
// Entity describes information about a type of entity.
|
||||||
|
type Entity struct {
|
||||||
|
ID ID
|
||||||
|
InternalID uint32
|
||||||
|
DisplayName string
|
||||||
|
Name string
|
||||||
|
|
||||||
|
Width float64
|
||||||
|
Height float64
|
||||||
|
|
||||||
|
Type string
|
||||||
|
Category string
|
||||||
|
}
|
||||||
|
|
||||||
|
`)
|
||||||
|
format.Node(os.Stdout, token.NewFileSet(), makeEntityDeclaration(entities))
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println()
|
||||||
|
fmt.Println("// ByID is an index of minecraft entities by their ID.")
|
||||||
|
fmt.Println("var ByID = map[ID]*Entity{")
|
||||||
|
for _, e := range entities {
|
||||||
|
fmt.Printf(" %d: &%s,\n", e.ID, strcase.ToCamel(e.Name))
|
||||||
|
}
|
||||||
|
fmt.Println("}")
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
|
}
|
@ -7,7 +7,7 @@ type SpawnEntity struct {
|
|||||||
ID pk.VarInt
|
ID pk.VarInt
|
||||||
UUID pk.UUID
|
UUID pk.UUID
|
||||||
Type pk.VarInt
|
Type pk.VarInt
|
||||||
X, Y, Z pk.Int
|
X, Y, Z pk.Double
|
||||||
Pitch, Yaw pk.Angle
|
Pitch, Yaw pk.Angle
|
||||||
Data pk.Int
|
Data pk.Int
|
||||||
VelX, VelY, VelZ pk.Short
|
VelX, VelY, VelZ pk.Short
|
||||||
|
Reference in New Issue
Block a user