Update entity metadata for 15w33c changes.

This commit is contained in:
Steven Smith 2015-08-14 20:02:55 -07:00
parent 0c2b7fdce8
commit b89b482bd1
4 changed files with 95 additions and 32 deletions

View file

@ -48,6 +48,7 @@ import org.spacehq.mc.protocol.data.game.values.world.GenericSound;
import org.spacehq.mc.protocol.data.game.values.world.Particle; import org.spacehq.mc.protocol.data.game.values.world.Particle;
import org.spacehq.mc.protocol.data.game.values.world.WorldBorderAction; import org.spacehq.mc.protocol.data.game.values.world.WorldBorderAction;
import org.spacehq.mc.protocol.data.game.values.world.WorldType; import org.spacehq.mc.protocol.data.game.values.world.WorldType;
import org.spacehq.mc.protocol.data.game.values.world.block.BlockFace;
import org.spacehq.mc.protocol.data.game.values.world.block.UpdatedTileType; import org.spacehq.mc.protocol.data.game.values.world.block.UpdatedTileType;
import org.spacehq.mc.protocol.data.game.values.world.block.value.ChestValueType; import org.spacehq.mc.protocol.data.game.values.world.block.value.ChestValueType;
import org.spacehq.mc.protocol.data.game.values.world.block.value.GenericBlockValueType; import org.spacehq.mc.protocol.data.game.values.world.block.value.GenericBlockValueType;
@ -96,13 +97,17 @@ public class MagicValues {
register(ModifierOperation.MULTIPLY, 2); register(ModifierOperation.MULTIPLY, 2);
register(MetadataType.BYTE, 0); register(MetadataType.BYTE, 0);
register(MetadataType.SHORT, 1); register(MetadataType.INT, 1);
register(MetadataType.INT, 2); register(MetadataType.FLOAT, 2);
register(MetadataType.FLOAT, 3); register(MetadataType.STRING, 3);
register(MetadataType.STRING, 4); register(MetadataType.CHAT, 4);
register(MetadataType.ITEM, 5); register(MetadataType.ITEM, 5);
register(MetadataType.POSITION, 6); register(MetadataType.BOOLEAN, 6);
register(MetadataType.ROTATION, 7); register(MetadataType.ROTATION, 7);
register(MetadataType.POSITION, 8);
register(MetadataType.OPTIONAL_POSITION, 9);
register(MetadataType.BLOCK_FACE, 10);
register(MetadataType.OPTIONAL_UUID, 11);
register(HandshakeIntent.STATUS, 1); register(HandshakeIntent.STATUS, 1);
register(HandshakeIntent.LOGIN, 2); register(HandshakeIntent.LOGIN, 2);
@ -899,6 +904,13 @@ public class MagicValues {
register(BossBarColor.YELLOW, 4); register(BossBarColor.YELLOW, 4);
register(BossBarColor.PURPLE, 5); register(BossBarColor.PURPLE, 5);
register(BossBarColor.WHITE, 6); register(BossBarColor.WHITE, 6);
register(BlockFace.DOWN, 0);
register(BlockFace.UP, 1);
register(BlockFace.NORTH, 2);
register(BlockFace.SOUTH, 3);
register(BlockFace.WEST, 4);
register(BlockFace.EAST, 5);
} }
private static void register(Enum<?> key, Object value) { private static void register(Enum<?> key, Object value) {

View file

@ -1,14 +1,16 @@
package org.spacehq.mc.protocol.data.game.values.entity; package org.spacehq.mc.protocol.data.game.values.entity;
public enum MetadataType { public enum MetadataType {
BYTE, BYTE,
SHORT,
INT, INT,
FLOAT, FLOAT,
STRING, STRING,
CHAT,
ITEM, ITEM,
BOOLEAN,
ROTATION,
POSITION, POSITION,
ROTATION; OPTIONAL_POSITION,
BLOCK_FACE,
OPTIONAL_UUID;
} }

View file

@ -0,0 +1,10 @@
package org.spacehq.mc.protocol.data.game.values.world.block;
public enum BlockFace {
DOWN,
UP,
NORTH,
SOUTH,
WEST,
EAST;
}

View file

@ -9,6 +9,8 @@ import org.spacehq.mc.protocol.data.game.Rotation;
import org.spacehq.mc.protocol.data.game.ShortArray3d; import org.spacehq.mc.protocol.data.game.ShortArray3d;
import org.spacehq.mc.protocol.data.game.values.MagicValues; import org.spacehq.mc.protocol.data.game.values.MagicValues;
import org.spacehq.mc.protocol.data.game.values.entity.MetadataType; import org.spacehq.mc.protocol.data.game.values.entity.MetadataType;
import org.spacehq.mc.protocol.data.game.values.world.block.BlockFace;
import org.spacehq.mc.protocol.data.message.Message;
import org.spacehq.opennbt.NBTIO; import org.spacehq.opennbt.NBTIO;
import org.spacehq.opennbt.tag.builtin.CompoundTag; import org.spacehq.opennbt.tag.builtin.CompoundTag;
import org.spacehq.packetlib.io.NetInput; import org.spacehq.packetlib.io.NetInput;
@ -24,6 +26,7 @@ import java.nio.ByteOrder;
import java.nio.ShortBuffer; import java.nio.ShortBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
public class NetUtil { public class NetUtil {
@ -112,21 +115,17 @@ public class NetUtil {
public static EntityMetadata[] readEntityMetadata(NetInput in) throws IOException { public static EntityMetadata[] readEntityMetadata(NetInput in) throws IOException {
List<EntityMetadata> ret = new ArrayList<EntityMetadata>(); List<EntityMetadata> ret = new ArrayList<EntityMetadata>();
byte b; int id;
while((b = in.readByte()) != 127) { while((id = in.readUnsignedByte()) != 255) {
int typeId = (b & 0xE0) >> 5; int typeId = in.readVarInt();
int id = b & 0x1F;
MetadataType type = MagicValues.key(MetadataType.class, typeId); MetadataType type = MagicValues.key(MetadataType.class, typeId);
Object value = null; Object value = null;
switch(type) { switch(type) {
case BYTE: case BYTE:
value = in.readByte(); value = in.readByte();
break; break;
case SHORT:
value = in.readShort();
break;
case INT: case INT:
value = in.readInt(); value = in.readVarInt();
break; break;
case FLOAT: case FLOAT:
value = in.readFloat(); value = in.readFloat();
@ -134,14 +133,37 @@ public class NetUtil {
case STRING: case STRING:
value = in.readString(); value = in.readString();
break; break;
case CHAT:
value = Message.fromString(in.readString());
break;
case ITEM: case ITEM:
value = readItem(in); value = readItem(in);
break; break;
case POSITION: case BOOLEAN:
value = new Position(in.readInt(), in.readInt(), in.readInt()); value = in.readBoolean();
break; break;
case ROTATION: case ROTATION:
value = new Rotation(in.readFloat(), in.readFloat(), in.readFloat()); value = new Rotation(in.readFloat(), in.readFloat(), in.readFloat());
break;
case POSITION:
value = readPosition(in);
break;
case OPTIONAL_POSITION:
boolean positionPresent = in.readBoolean();
if(positionPresent) {
value = readPosition(in);
}
break;
case BLOCK_FACE:
value = MagicValues.key(BlockFace.class, in.readVarInt());
break;
case OPTIONAL_UUID:
boolean uuidPresent = in.readBoolean();
if(uuidPresent) {
value = in.readUUID();
}
break; break;
default: default:
throw new IOException("Unknown metadata type id: " + typeId); throw new IOException("Unknown metadata type id: " + typeId);
@ -155,17 +177,14 @@ public class NetUtil {
public static void writeEntityMetadata(NetOutput out, EntityMetadata[] metadata) throws IOException { public static void writeEntityMetadata(NetOutput out, EntityMetadata[] metadata) throws IOException {
for(EntityMetadata meta : metadata) { for(EntityMetadata meta : metadata) {
int id = MagicValues.value(Integer.class, meta.getType()) << 5 | meta.getId() & 0x1F; out.writeByte(meta.getId());
out.writeByte(id); out.writeVarInt(MagicValues.value(Integer.class, meta.getType()));
switch(meta.getType()) { switch(meta.getType()) {
case BYTE: case BYTE:
out.writeByte((Byte) meta.getValue()); out.writeByte((Byte) meta.getValue());
break; break;
case SHORT:
out.writeShort((Short) meta.getValue());
break;
case INT: case INT:
out.writeInt((Integer) meta.getValue()); out.writeVarInt((Integer) meta.getValue());
break; break;
case FLOAT: case FLOAT:
out.writeFloat((Float) meta.getValue()); out.writeFloat((Float) meta.getValue());
@ -173,27 +192,47 @@ public class NetUtil {
case STRING: case STRING:
out.writeString((String) meta.getValue()); out.writeString((String) meta.getValue());
break; break;
case CHAT:
out.writeString(((Message) meta.getValue()).toJsonString());
break;
case ITEM: case ITEM:
writeItem(out, (ItemStack) meta.getValue()); writeItem(out, (ItemStack) meta.getValue());
break; break;
case POSITION: case BOOLEAN:
Position pos = (Position) meta.getValue(); out.writeBoolean((Boolean) meta.getValue());
out.writeInt(pos.getX());
out.writeInt(pos.getY());
out.writeInt(pos.getZ());
break; break;
case ROTATION: case ROTATION:
Rotation rot = (Rotation) meta.getValue(); Rotation rot = (Rotation) meta.getValue();
out.writeFloat(rot.getPitch()); out.writeFloat(rot.getPitch());
out.writeFloat(rot.getYaw()); out.writeFloat(rot.getYaw());
out.writeFloat(rot.getRoll()); out.writeFloat(rot.getRoll());
break;
case POSITION:
writePosition(out, (Position) meta.getValue());
break;
case OPTIONAL_POSITION:
out.writeBoolean(meta.getValue() != null);
if(meta.getValue() != null) {
writePosition(out, (Position) meta.getValue());
}
break;
case BLOCK_FACE:
out.writeVarInt(MagicValues.value(Integer.class, (BlockFace) meta.getValue()));
break;
case OPTIONAL_UUID:
out.writeBoolean(meta.getValue() != null);
if(meta.getValue() != null) {
out.writeUUID((UUID) meta.getValue());
}
break; break;
default: default:
throw new IOException("Unmapped metadata type: " + meta.getType()); throw new IOException("Unknown metadata type: " + meta.getType());
} }
} }
out.writeByte(127); out.writeByte(255);
} }
public static ParsedChunkData dataToChunks(NetworkChunkData data, boolean checkForSky) { public static ParsedChunkData dataToChunks(NetworkChunkData data, boolean checkForSky) {