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 --- src/main/java/moe/ymc/acron/common/WorldKey.java | 25 +++++++++++++++++++++++- src/main/java/moe/ymc/acron/s2c/Entity.java | 13 +++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) (limited to 'src/main/java/moe/ymc') 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