mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-12 08:41:00 -05:00
Update entity metadata for 15w33c changes.
This commit is contained in:
parent
0c2b7fdce8
commit
b89b482bd1
4 changed files with 95 additions and 32 deletions
|
@ -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.WorldBorderAction;
|
||||
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.value.ChestValueType;
|
||||
import org.spacehq.mc.protocol.data.game.values.world.block.value.GenericBlockValueType;
|
||||
|
@ -96,13 +97,17 @@ public class MagicValues {
|
|||
register(ModifierOperation.MULTIPLY, 2);
|
||||
|
||||
register(MetadataType.BYTE, 0);
|
||||
register(MetadataType.SHORT, 1);
|
||||
register(MetadataType.INT, 2);
|
||||
register(MetadataType.FLOAT, 3);
|
||||
register(MetadataType.STRING, 4);
|
||||
register(MetadataType.INT, 1);
|
||||
register(MetadataType.FLOAT, 2);
|
||||
register(MetadataType.STRING, 3);
|
||||
register(MetadataType.CHAT, 4);
|
||||
register(MetadataType.ITEM, 5);
|
||||
register(MetadataType.POSITION, 6);
|
||||
register(MetadataType.BOOLEAN, 6);
|
||||
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.LOGIN, 2);
|
||||
|
@ -899,6 +904,13 @@ public class MagicValues {
|
|||
register(BossBarColor.YELLOW, 4);
|
||||
register(BossBarColor.PURPLE, 5);
|
||||
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) {
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
package org.spacehq.mc.protocol.data.game.values.entity;
|
||||
|
||||
public enum MetadataType {
|
||||
|
||||
BYTE,
|
||||
SHORT,
|
||||
INT,
|
||||
FLOAT,
|
||||
STRING,
|
||||
CHAT,
|
||||
ITEM,
|
||||
BOOLEAN,
|
||||
ROTATION,
|
||||
POSITION,
|
||||
ROTATION;
|
||||
|
||||
OPTIONAL_POSITION,
|
||||
BLOCK_FACE,
|
||||
OPTIONAL_UUID;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package org.spacehq.mc.protocol.data.game.values.world.block;
|
||||
|
||||
public enum BlockFace {
|
||||
DOWN,
|
||||
UP,
|
||||
NORTH,
|
||||
SOUTH,
|
||||
WEST,
|
||||
EAST;
|
||||
}
|
|
@ -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.values.MagicValues;
|
||||
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.tag.builtin.CompoundTag;
|
||||
import org.spacehq.packetlib.io.NetInput;
|
||||
|
@ -24,6 +26,7 @@ import java.nio.ByteOrder;
|
|||
import java.nio.ShortBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NetUtil {
|
||||
|
||||
|
@ -112,21 +115,17 @@ public class NetUtil {
|
|||
|
||||
public static EntityMetadata[] readEntityMetadata(NetInput in) throws IOException {
|
||||
List<EntityMetadata> ret = new ArrayList<EntityMetadata>();
|
||||
byte b;
|
||||
while((b = in.readByte()) != 127) {
|
||||
int typeId = (b & 0xE0) >> 5;
|
||||
int id = b & 0x1F;
|
||||
int id;
|
||||
while((id = in.readUnsignedByte()) != 255) {
|
||||
int typeId = in.readVarInt();
|
||||
MetadataType type = MagicValues.key(MetadataType.class, typeId);
|
||||
Object value = null;
|
||||
switch(type) {
|
||||
case BYTE:
|
||||
value = in.readByte();
|
||||
break;
|
||||
case SHORT:
|
||||
value = in.readShort();
|
||||
break;
|
||||
case INT:
|
||||
value = in.readInt();
|
||||
value = in.readVarInt();
|
||||
break;
|
||||
case FLOAT:
|
||||
value = in.readFloat();
|
||||
|
@ -134,14 +133,37 @@ public class NetUtil {
|
|||
case STRING:
|
||||
value = in.readString();
|
||||
break;
|
||||
case CHAT:
|
||||
value = Message.fromString(in.readString());
|
||||
break;
|
||||
case ITEM:
|
||||
value = readItem(in);
|
||||
break;
|
||||
case POSITION:
|
||||
value = new Position(in.readInt(), in.readInt(), in.readInt());
|
||||
case BOOLEAN:
|
||||
value = in.readBoolean();
|
||||
break;
|
||||
case ROTATION:
|
||||
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;
|
||||
default:
|
||||
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 {
|
||||
for(EntityMetadata meta : metadata) {
|
||||
int id = MagicValues.value(Integer.class, meta.getType()) << 5 | meta.getId() & 0x1F;
|
||||
out.writeByte(id);
|
||||
out.writeByte(meta.getId());
|
||||
out.writeVarInt(MagicValues.value(Integer.class, meta.getType()));
|
||||
switch(meta.getType()) {
|
||||
case BYTE:
|
||||
out.writeByte((Byte) meta.getValue());
|
||||
break;
|
||||
case SHORT:
|
||||
out.writeShort((Short) meta.getValue());
|
||||
break;
|
||||
case INT:
|
||||
out.writeInt((Integer) meta.getValue());
|
||||
out.writeVarInt((Integer) meta.getValue());
|
||||
break;
|
||||
case FLOAT:
|
||||
out.writeFloat((Float) meta.getValue());
|
||||
|
@ -173,27 +192,47 @@ public class NetUtil {
|
|||
case STRING:
|
||||
out.writeString((String) meta.getValue());
|
||||
break;
|
||||
case CHAT:
|
||||
out.writeString(((Message) meta.getValue()).toJsonString());
|
||||
break;
|
||||
case ITEM:
|
||||
writeItem(out, (ItemStack) meta.getValue());
|
||||
break;
|
||||
case POSITION:
|
||||
Position pos = (Position) meta.getValue();
|
||||
out.writeInt(pos.getX());
|
||||
out.writeInt(pos.getY());
|
||||
out.writeInt(pos.getZ());
|
||||
case BOOLEAN:
|
||||
out.writeBoolean((Boolean) meta.getValue());
|
||||
break;
|
||||
case ROTATION:
|
||||
Rotation rot = (Rotation) meta.getValue();
|
||||
out.writeFloat(rot.getPitch());
|
||||
out.writeFloat(rot.getYaw());
|
||||
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;
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue