Skip to content

Commit

Permalink
Support modded entity types in ServerSpawnMobPacket
Browse files Browse the repository at this point in the history
  • Loading branch information
Johni0702 committed Jul 6, 2019
1 parent f3be505 commit f8a0c71
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class ServerSpawnMobPacket extends MinecraftPacket {
private int entityId;
private UUID uuid;
private MobType type;
private int typeId;
private double x;
private double y;
private double z;
Expand All @@ -31,9 +31,13 @@ private ServerSpawnMobPacket() {
}

public ServerSpawnMobPacket(int entityId, UUID uuid, MobType type, double x, double y, double z, float yaw, float pitch, float headYaw, double motX, double motY, double motZ, EntityMetadata metadata[]) {
this(entityId, uuid, MagicValues.value(Integer.class, type), x, y, z, yaw, pitch, headYaw, motX, motY, motZ, metadata);
}

public ServerSpawnMobPacket(int entityId, UUID uuid, int typeId, double x, double y, double z, float yaw, float pitch, float headYaw, double motX, double motY, double motZ, EntityMetadata metadata[]) {
this.entityId = entityId;
this.uuid = uuid;
this.type = type;
this.typeId = typeId;
this.x = x;
this.y = y;
this.z = z;
Expand All @@ -54,8 +58,21 @@ public UUID getUUID() {
return this.uuid;
}

@Deprecated
public MobType getType() {
return this.type;
return MagicValues.key(MobType.class, this.typeId);
}

public MobType getVanillaType() {
try {
return MagicValues.key(MobType.class, this.typeId);
} catch (IllegalArgumentException e) {
return null;
}
}

public int getTypeId() {
return this.typeId;
}

public double getX() {
Expand Down Expand Up @@ -102,7 +119,7 @@ public EntityMetadata[] getMetadata() {
public void read(NetInput in) throws IOException {
this.entityId = in.readVarInt();
this.uuid = in.readUUID();
this.type = MagicValues.key(MobType.class, in.readVarInt());
this.typeId = in.readVarInt();
this.x = in.readDouble();
this.y = in.readDouble();
this.z = in.readDouble();
Expand All @@ -119,7 +136,7 @@ public void read(NetInput in) throws IOException {
public void write(NetOutput out) throws IOException {
out.writeVarInt(this.entityId);
out.writeUUID(this.uuid);
out.writeVarInt(MagicValues.value(Integer.class, this.type));
out.writeVarInt(this.typeId);
out.writeDouble(this.x);
out.writeDouble(this.y);
out.writeDouble(this.z);
Expand Down

0 comments on commit f8a0c71

Please sign in to comment.