From ced562fdd1da941c91ce39328f7a7a00e023f704 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Thu, 14 Jul 2022 11:57:49 -0700 Subject: Add pos and world in Entity API:ADD Signed-off-by: Trumeet --- README.md | 32 +++++++++++++++++++++++- src/main/java/moe/ymc/acron/common/WorldKey.java | 25 +++++++++++++++++- src/main/java/moe/ymc/acron/s2c/Entity.java | 13 +++++++--- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3a6f81e..fb63f37 100644 --- a/README.md +++ b/README.md @@ -412,7 +412,13 @@ Response: "type": "join", "player": { "name": "", - "uuid": "" + "uuid": "", + "pos": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "world": "end" } } ``` @@ -422,6 +428,12 @@ Parameters: * `.player` (entity, see below, always present): The player. * `.name` (string, any valid Minecraft username, always present): Username. * `.uuid` (uuid, UUID, always present): UUID. + * `.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 + * `.z` (double, any within border limit, 0.0): Z + * `.world` (enum, overworld / nether / end, not present if Acron cannot determine the world): The dimension +he or she joins. #### Player Disconnected @@ -443,6 +455,12 @@ 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. + * `.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 + * `.z` (double, any within border limit, 0.0): Z + * `.world` (enum, overworld / nether / end, not present if Acron cannot determine the world): The dimension + he or she leaves. * `.reason` (string, any valid disconnect reason, always present): Disconnect reason. #### Player Message @@ -465,6 +483,12 @@ Parameters: * `.player` (entity, see below, always present): The player. * `.name` (string, any valid Minecraft username, always present): Username. * `.uuid` (uuid, UUID, always present): UUID. + * `.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 + * `.z` (double, any within border limit, 0.0): Z + * `.world` (enum, overworld / nether / end, not present if Acron cannot determine the world): The dimension +he or she sends the message. * `.text` (string, any valid Minecraft message, always present): The message. #### Entity Death @@ -487,6 +511,12 @@ 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. + * `.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 + * `.z` (double, any within border limit, 0.0): Z + * `.world` (enum, overworld / nether / end, not present if Acron cannot determine the world): The dimension +of the entity when died. * `.text` (string, any valid death message, always present): The user-readable death message. > **Roadmap** diff --git a/src/main/java/moe/ymc/acron/common/WorldKey.java b/src/main/java/moe/ymc/acron/common/WorldKey.java index 9e4212d..fa10d54 100644 --- a/src/main/java/moe/ymc/acron/common/WorldKey.java +++ b/src/main/java/moe/ymc/acron/common/WorldKey.java @@ -1,6 +1,12 @@ package moe.ymc.acron.common; import com.google.gson.annotations.SerializedName; +import net.minecraft.util.Identifier; +import net.minecraft.world.dimension.DimensionType; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public enum WorldKey { @SerializedName("overworld") @@ -8,5 +14,22 @@ public enum WorldKey { @SerializedName("nether") NETHER, @SerializedName("end") - END + END; + + private static final Logger LOGGER = LogManager.getLogger(); + + public static @Nullable WorldKey create(@NotNull Identifier identifier) { + if (identifier.equals(DimensionType.OVERWORLD_ID)) { + return OVERWORLD; + } else if (identifier.equals(DimensionType.THE_NETHER_ID)) { + return NETHER; + } else if (identifier.equals(DimensionType.THE_END_ID)) { + return END; + } else { + LOGGER.warn("Unknown world {}:{}. Returning NULL to the client.", + identifier.getNamespace(), + identifier.getPath()); + return null; + } + } } \ No newline at end of file diff --git a/src/main/java/moe/ymc/acron/s2c/Entity.java b/src/main/java/moe/ymc/acron/s2c/Entity.java index 97bd567..3e0add1 100644 --- a/src/main/java/moe/ymc/acron/s2c/Entity.java +++ b/src/main/java/moe/ymc/acron/s2c/Entity.java @@ -2,18 +2,25 @@ package moe.ymc.acron.s2c; import com.google.gson.annotations.SerializedName; import com.mojang.authlib.GameProfile; +import moe.ymc.acron.common.Vec3d; +import moe.ymc.acron.common.WorldKey; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.UUID; public record Entity(@SerializedName("name") @NotNull String name, - @SerializedName("uuid") @NotNull UUID uuid) { + @SerializedName("uuid") @NotNull UUID uuid, + @SerializedName("pos") @Nullable Vec3d pos, + @SerializedName("world") @Nullable WorldKey world) { public Entity(@NotNull net.minecraft.entity.Entity entity) { this(entity.getName().getString(), - entity.getUuid()); + entity.getUuid(), + new Vec3d(entity.getPos()), + WorldKey.create(entity.world.getRegistryKey().getValue())); } public Entity(@NotNull GameProfile profile) { - this(profile.getName(), profile.getId()); + this(profile.getName(), profile.getId(), null, null); } } -- cgit v1.2.3