aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorTrumeet <yuuta@yuuta.moe>2022-07-14 11:57:49 -0700
committerTrumeet <yuuta@yuuta.moe>2022-07-14 11:57:49 -0700
commitced562fdd1da941c91ce39328f7a7a00e023f704 (patch)
tree3aee992d310f6801ddf6d5517d985f119e616d48 /src/main/java
parentaaff4fc71027968f22100d216ff22edc42a96629 (diff)
downloadacron-ced562fdd1da941c91ce39328f7a7a00e023f704.tar
acron-ced562fdd1da941c91ce39328f7a7a00e023f704.tar.gz
acron-ced562fdd1da941c91ce39328f7a7a00e023f704.tar.bz2
acron-ced562fdd1da941c91ce39328f7a7a00e023f704.zip
Add pos and world in Entity
API:ADD Signed-off-by: Trumeet <yuuta@yuuta.moe>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/moe/ymc/acron/common/WorldKey.java25
-rw-r--r--src/main/java/moe/ymc/acron/s2c/Entity.java13
2 files changed, 34 insertions, 4 deletions
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);
}
}