From 26765d586e187ebd088cdb2f7451768a637968c8 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Fri, 29 Jul 2022 12:17:56 -0700 Subject: feat(mod/libacron): provide entity type to clients API:ADD --- client/helloworld/main.c | 3 ++- client/libacron/ids.c | 4 ++++ client/libacron/include/common.h | 1 + client/libacron/private/serializer.c | 7 +++++++ mod/README.md | 8 ++++++++ mod/src/main/java/moe/ymc/acron/s2c/Entity.java | 5 ++++- 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/client/helloworld/main.c b/client/helloworld/main.c index 6c46ed0..8b3486b 100644 --- a/client/helloworld/main.c +++ b/client/helloworld/main.c @@ -98,8 +98,9 @@ static void handle_event(const ac_event_t *event) { } case AC_EVENT_ENTITY_DEATH: { ac_event_entity_death_t *o = (ac_event_entity_death_t *) event; - printf("Entity '%s' died at %s(%.2f, %.2f, %.2f): %s.\n", + printf("Entity '%s' (%s) died at %s(%.2f, %.2f, %.2f): %s.\n", o->entity.name, + o->entity.type, world_name(o->entity.world), o->entity.pos.x, o->entity.pos.y, diff --git a/client/libacron/ids.c b/client/libacron/ids.c index 7af471d..65be0ab 100644 --- a/client/libacron/ids.c +++ b/client/libacron/ids.c @@ -16,6 +16,7 @@ int ac_object_free(ac_obj_t *obj) { ac_event_player_join_t *v = (ac_event_player_join_t *) obj; if (v->player.name) free(v->player.name); if (v->player.uuid) free(v->player.uuid); + if (v->player.type) free(v->player.type); goto ok; } case AC_EVENT_PLAYER_DISCONNECT: { @@ -23,6 +24,7 @@ int ac_object_free(ac_obj_t *obj) { if (v->player) { if (v->player->name) free(v->player->name); if (v->player->uuid) free(v->player->uuid); + if (v->player->type) free(v->player->type); free(v->player); } if (v->reason) free(v->reason); @@ -32,6 +34,7 @@ int ac_object_free(ac_obj_t *obj) { ac_event_entity_death_t *v = (ac_event_entity_death_t *) obj; if (v->entity.name) free(v->entity.name); if (v->entity.uuid) free(v->entity.uuid); + if (v->entity.type) free(v->entity.type); if (v->message) free(v->message); goto ok; } @@ -39,6 +42,7 @@ int ac_object_free(ac_obj_t *obj) { ac_event_player_message_t *v = (ac_event_player_message_t *) obj; if (v->player.name) free(v->player.name); if (v->player.uuid) free(v->player.uuid); + if (v->player.type) free(v->player.type); if (v->text) free(v->text); goto ok; } diff --git a/client/libacron/include/common.h b/client/libacron/include/common.h index 89738c4..79dd29b 100644 --- a/client/libacron/include/common.h +++ b/client/libacron/include/common.h @@ -50,6 +50,7 @@ typedef struct ac_vec2f { typedef struct ac_entity { char *name; char *uuid; + char *type; ac_vec3d_t pos; enum ac_world world; } ac_entity_t; diff --git a/client/libacron/private/serializer.c b/client/libacron/private/serializer.c index d5171ba..c997585 100644 --- a/client/libacron/private/serializer.c +++ b/client/libacron/private/serializer.c @@ -104,6 +104,13 @@ static int deserialize_entity(const json_object *json, ac_entity_t *entity) { return r; } + if ((r = get_child(json, "type", json_type_string, true, &arg))) { + return r; + } + if ((r = strdup2(json_object_get_string(arg), &entity->type))) { + return r; + } + if ((r = get_child(json, "world", json_type_string, false, &arg))) { return r; } diff --git a/mod/README.md b/mod/README.md index 1e23817..49a7e8e 100644 --- a/mod/README.md +++ b/mod/README.md @@ -254,6 +254,7 @@ Response: "player": { "name": "", "uuid": "", + "type": "", "pos": { "x": 0.0, "y": 0.0, @@ -269,6 +270,7 @@ Parameters: * `.player` (entity, see below, always present): The player. * `.name` (string, any valid Minecraft username, always present): Username. * `.uuid` (uuid, UUID, always present): UUID. + * `.type` (string, namespace:path, always present): Entity type. * `.pos` (vec3d, see below, always present): The position he or she joins. * `.x` (double, any within border limit, 0.0): X * `.y` (double, any within border limit, 0.0): Y @@ -286,6 +288,7 @@ Response: "player": { "name": "", "uuid": "", + "type": "", "pos": { "x": 0.0, "y": 0.0, @@ -302,6 +305,7 @@ Parameters: * `.player` (entity, see below, null only when the server cannot verify the user): The player. * `.name` (string, any valid Minecraft username, always present): Username. * `.uuid` (uuid, UUID, always present): UUID. + * `.type` (string, namespace:path, always present): Entity type. * `.pos` (vec3d, see below, always present): The position he or she leaves. * `.x` (double, any within border limit, 0.0): X * `.y` (double, any within border limit, 0.0): Y @@ -320,6 +324,7 @@ Response: "player": { "name": "", "uuid": "", + "type": "", "pos": { "x": 0.0, "y": 0.0, @@ -336,6 +341,7 @@ Parameters: * `.player` (entity, see below, always present): The player. * `.name` (string, any valid Minecraft username, always present): Username. * `.uuid` (uuid, UUID, always present): UUID. + * `.type` (string, namespace:path, always present): Entity type. * `.pos` (vec3d, see below, always present): The position he or she sends the message. * `.x` (double, any within border limit, 0.0): X * `.y` (double, any within border limit, 0.0): Y @@ -354,6 +360,7 @@ Response: "entity": { "name": "", "uuid": "", + "type": "", "pos": { "x": 0.0, "y": 0.0, @@ -370,6 +377,7 @@ Parameters: * `.entity` (entity, see below, always present): The entity. * `.name` (string, any, always present): Default name or custom name of the entity. * `.uuid` (uuid, UUID, always present): UUID. + * `.type` (string, namespace:path, always present): Entity type. * `.pos` (vec3d, see below, always present): The position of the entity when died. * `.x` (double, any within border limit, 0.0): X * `.y` (double, any within border limit, 0.0): Y diff --git a/mod/src/main/java/moe/ymc/acron/s2c/Entity.java b/mod/src/main/java/moe/ymc/acron/s2c/Entity.java index 3e0add1..b10c041 100644 --- a/mod/src/main/java/moe/ymc/acron/s2c/Entity.java +++ b/mod/src/main/java/moe/ymc/acron/s2c/Entity.java @@ -4,6 +4,7 @@ import com.google.gson.annotations.SerializedName; import com.mojang.authlib.GameProfile; import moe.ymc.acron.common.Vec3d; import moe.ymc.acron.common.WorldKey; +import net.minecraft.entity.EntityType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,16 +12,18 @@ import java.util.UUID; public record Entity(@SerializedName("name") @NotNull String name, @SerializedName("uuid") @NotNull UUID uuid, + @SerializedName("type") @NotNull String type, @SerializedName("pos") @Nullable Vec3d pos, @SerializedName("world") @Nullable WorldKey world) { public Entity(@NotNull net.minecraft.entity.Entity entity) { this(entity.getName().getString(), entity.getUuid(), + EntityType.getId(entity.getType()).toString(), new Vec3d(entity.getPos()), WorldKey.create(entity.world.getRegistryKey().getValue())); } public Entity(@NotNull GameProfile profile) { - this(profile.getName(), profile.getId(), null, null); + this(profile.getName(), profile.getId(), "minecraft:player", null, null); } } -- cgit v1.2.3