3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Handle metadata correctly, implement new MetaTypes & bump protocol to 18w01a (non-stable)

Dieser Commit ist enthalten in:
Matsv 2018-01-04 14:59:59 +01:00
Ursprung ede4fa5a5d
Commit 444eabcebf
15 geänderte Dateien mit 153 neuen und 68 gelöschten Zeilen

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-17w50a</version>
<version>1.4.0-18w01a</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-17w50a</version>
<version>1.4.0-18w01a</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -37,7 +37,7 @@
<dependency>
<groupId>us.myles</groupId>
<artifactId>viaversion-common</artifactId>
<version>1.4.0-17w50a</version>
<version>1.4.0-18w01a</version>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-17w50a</version>
<version>1.4.0-18w01a</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -13,15 +13,17 @@ public enum MetaType1_13 implements MetaType {
Float(2, Type.FLOAT),
String(3, Type.STRING),
Chat(4, Type.STRING),
Slot(5, Type.FLAT_ITEM),
Boolean(6, Type.BOOLEAN),
Vector3F(7, Type.ROTATION),
Position(8, Type.POSITION),
OptPosition(9, Type.OPTIONAL_POSITION),
Direction(10, Type.VAR_INT),
OptUUID(11, Type.OPTIONAL_UUID),
BlockID(12, Type.VAR_INT),
NBTTag(13, Type.NBT),
OptChat(5, Type.OPTIONAL_CHAT),
Slot(6, Type.FLAT_ITEM),
Boolean(7, Type.BOOLEAN),
Vector3F(8, Type.ROTATION),
Position(9, Type.POSITION),
OptPosition(10, Type.OPTIONAL_POSITION),
Direction(11, Type.VAR_INT),
OptUUID(12, Type.OPTIONAL_UUID),
BlockID(13, Type.VAR_INT),
NBTTag(14, Type.NBT),
UNKNOWN(15, null), // TODO do research
Discontinued(99, null);
private final int typeID;

Datei anzeigen

@ -62,7 +62,7 @@ public class ProtocolVersion {
register(v1_12 = new ProtocolVersion(335, "1.12"));
register(v1_12_1 = new ProtocolVersion(338, "1.12.1"));
register(v1_12_2 = new ProtocolVersion(340, "1.12.2"));
register(v1_13 = new ProtocolVersion(351, "17w50a"));
register(v1_13 = new ProtocolVersion(352, "18w01a"));
register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
}

Datei anzeigen

@ -63,6 +63,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
public static final Type<CompoundTag[]> NBT_ARRAY = new ArrayType<>(Type.NBT);
public static final Type<UUID> OPTIONAL_UUID = new OptUUIDType();
public static final Type<String> OPTIONAL_CHAT = new OptionalChatType();
public static final Type<Position> OPTIONAL_POSITION = new OptPositionType();
public static final Type<Item> ITEM = new ItemType();

Datei anzeigen

@ -0,0 +1,27 @@
package us.myles.ViaVersion.api.type.types.minecraft;
import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.type.Type;
public class OptionalChatType extends Type<String> {
public OptionalChatType() {
super(String.class);
}
@Override
public String read(ByteBuf buffer) throws Exception {
boolean present = buffer.readBoolean();
if (!present) return null;
return Type.STRING.read(buffer);
}
@Override
public void write(ByteBuf buffer, String object) throws Exception {
if (object == null) {
buffer.writeBoolean(false);
} else {
buffer.writeBoolean(true);
Type.STRING.write(buffer, object);
}
}
}

Datei anzeigen

@ -6,36 +6,46 @@ import us.myles.ViaVersion.api.entities.Entity1_12Types;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets.WorldPackets;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets.WorldPackets;
import java.util.ArrayList;
import java.util.List;
public class MetadataRewriter {
public static void handleMetadata(int entityId, Entity1_12Types.EntityType type, List<Metadata> metadatas, UserConnection connection) {
// metadatas.clear();
for (Metadata metadata : new ArrayList<>(metadatas)) {
// Handle new MetaTypes
if (metadata.getMetaType().getTypeID() > 4)
metadata.setMetaType(MetaType1_13.byId(metadata.getMetaType().getTypeID() + 1));
// TODO Fix displayname
if (metadata.getId() == 2) {
metadata.setMetaType(MetaType1_13.OptChat);
metadata.setValue(metadata.getValue() != null ? Protocol1_9TO1_8.fixJson((String) metadata.getValue()) : null);
}
// 1.13 changed item to flat item (no data)
if (metadata.getMetaType().getType() == Type.ITEM) {
if (metadata.getMetaType() == MetaType1_13.Slot) {
metadata.setMetaType(MetaType1_13.Slot);
InventoryPackets.toClient((Item) metadata.getValue());
}
if (metadata.getMetaType().getTypeID() == MetaType1_13.BlockID.getTypeID()) {
// Convert to new block id
metadata.setValue(WorldPackets.toNewId((int) metadata.getValue()));
}
if (metadata.getMetaType() == MetaType1_13.BlockID) {
// Convert to new block id
metadata.setValue(WorldPackets.toNewId((int) metadata.getValue()));
}
// Handle other changes
try {
if (type != null && type.is(Entity1_12Types.EntityType.AREA_EFFECT_CLOUD)) {
if (metadata.getId() == 9 || metadata.getId() == 10 || metadata.getId() == 11) {
if (type != null && type.is(Entity1_12Types.EntityType.AREA_EFFECT_CLOUD)) {
if (metadata.getId() == 9 || metadata.getId() == 10 || metadata.getId() == 11) {
// TODO: AreaEffectCloud has lost 2 integers and gained "ef"
// Will be implemented when more info is known
metadatas.remove(metadata); // Remove
}
}
// TODO: Boat has changed
// TODO: Boat has changed
} catch (Exception e) {
metadatas.remove(metadata);
if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) {
@ -46,5 +56,8 @@ public class MetadataRewriter {
}
}
for (Metadata metadata : metadatas) {
System.out.println(metadata.getMetaType() instanceof MetaType1_13);
}
}
}

Datei anzeigen

@ -157,14 +157,26 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol {
registerOutgoing(State.PLAY, 0x28, 0x29);
registerOutgoing(State.PLAY, 0x29, 0x2A);
registerOutgoing(State.PLAY, 0x2A, 0x2B);
registerOutgoing(State.PLAY, 0x2B, 0x2C);
// Craft recipe response
registerOutgoing(State.PLAY, 0x2B, 0x2C, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// TODO This packet changed
wrapper.cancel();
}
});
}
});
registerOutgoing(State.PLAY, 0x2C, 0x2D);
registerOutgoing(State.PLAY, 0x2D, 0x2E);
registerOutgoing(State.PLAY, 0x2E, 0x2F);
registerOutgoing(State.PLAY, 0x2F, 0x30);
registerOutgoing(State.PLAY, 0x30, 0x31);
registerOutgoing(State.PLAY, 0x2F, 0x31);
registerOutgoing(State.PLAY, 0x30, 0x32);
// Recipe
registerOutgoing(State.PLAY, 0x31, 0x32, new PacketRemapper() {
registerOutgoing(State.PLAY, 0x31, 0x33, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@ -177,11 +189,11 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol {
}
});
registerOutgoing(State.PLAY, 0x33, 0x34);
registerOutgoing(State.PLAY, 0x34, 0x35);
registerOutgoing(State.PLAY, 0x33, 0x35);
registerOutgoing(State.PLAY, 0x34, 0x36);
// Respawn (save dimension id)
registerOutgoing(State.PLAY, 0x35, 0x36, new PacketRemapper() {
registerOutgoing(State.PLAY, 0x35, 0x37, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Dimension ID
@ -196,20 +208,20 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol {
}
});
registerOutgoing(State.PLAY, 0x36, 0x37);
registerOutgoing(State.PLAY, 0x37, 0x38);
registerOutgoing(State.PLAY, 0x38, 0x39);
registerOutgoing(State.PLAY, 0x39, 0x3A);
registerOutgoing(State.PLAY, 0x3A, 0x3B);
registerOutgoing(State.PLAY, 0x3B, 0x3C);
registerOutgoing(State.PLAY, 0x36, 0x38);
registerOutgoing(State.PLAY, 0x37, 0x39);
registerOutgoing(State.PLAY, 0x38, 0x3A);
registerOutgoing(State.PLAY, 0x39, 0x3B);
registerOutgoing(State.PLAY, 0x3A, 0x3C);
registerOutgoing(State.PLAY, 0x3B, 0x3D);
registerOutgoing(State.PLAY, 0x3D, 0x3E);
registerOutgoing(State.PLAY, 0x3E, 0x3F);
registerOutgoing(State.PLAY, 0x3D, 0x3F);
registerOutgoing(State.PLAY, 0x3E, 0x40);
registerOutgoing(State.PLAY, 0x40, 0x41);
registerOutgoing(State.PLAY, 0x41, 0x42);
registerOutgoing(State.PLAY, 0x40, 0x42);
registerOutgoing(State.PLAY, 0x41, 0x43);
// Scoreboard Objective
registerOutgoing(State.PLAY, 0x42, 0x43, new PacketRemapper() {
registerOutgoing(State.PLAY, 0x42, 0x44, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.STRING);
@ -228,20 +240,22 @@ public class ProtocolSnapshotTo1_12_2 extends Protocol {
}
});
registerOutgoing(State.PLAY, 0x43, 0x44);
registerOutgoing(State.PLAY, 0x44, 0x45);
registerOutgoing(State.PLAY, 0x45, 0x46);
registerOutgoing(State.PLAY, 0x46, 0x47);
registerOutgoing(State.PLAY, 0x47, 0x48);
registerOutgoing(State.PLAY, 0x48, 0x49);
// TODO UPDATE BLOCK ENTITY?
registerOutgoing(State.PLAY, 0x43, 0x45);
registerOutgoing(State.PLAY, 0x44, 0x46);
registerOutgoing(State.PLAY, 0x45, 0x47);
registerOutgoing(State.PLAY, 0x46, 0x48);
registerOutgoing(State.PLAY, 0x47, 0x49);
registerOutgoing(State.PLAY, 0x48, 0x4A);
// New packet 0x4A - Stop sound (TODO: Migrate from Plugin Messages)
registerOutgoing(State.PLAY, 0x49, 0x4B);
registerOutgoing(State.PLAY, 0x4A, 0x4C);
registerOutgoing(State.PLAY, 0x4B, 0x4D);
registerOutgoing(State.PLAY, 0x4C, 0x4E);
registerOutgoing(State.PLAY, 0x4D, 0x4F);
registerOutgoing(State.PLAY, 0x4E, 0x50);
registerOutgoing(State.PLAY, 0x4F, 0x51);
registerOutgoing(State.PLAY, 0x49, 0x4C);
registerOutgoing(State.PLAY, 0x4A, 0x4D);
registerOutgoing(State.PLAY, 0x4B, 0x4E);
registerOutgoing(State.PLAY, 0x4C, 0x4F);
registerOutgoing(State.PLAY, 0x4D, 0x50);
registerOutgoing(State.PLAY, 0x4E, 0x51);
registerOutgoing(State.PLAY, 0x4F, 0x52);
// New packet 0x52 - Declare Recipes
// New packet 0x53 - Tags

Datei anzeigen

@ -8,6 +8,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_12;
import us.myles.ViaVersion.api.type.types.version.Types1_13;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.MetadataRewriter;
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.storage.EntityTracker;
@ -28,7 +29,6 @@ public class EntityPackets {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
byte type = wrapper.get(Type.BYTE, 0);
@ -57,7 +57,7 @@ public class EntityPackets {
map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z
map(Types1_12.METADATA_LIST); // 12 - Metadata
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 12 - Metadata
handler(new PacketHandler() {
@Override
@ -68,14 +68,42 @@ public class EntityPackets {
Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, false);
// Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
}
});
}
});
// Spawn player packet
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 7 - Metadata
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
Entity1_12Types.EntityType entType = Entity1_12Types.EntityType.PLAYER;
System.out.println("REGISTER PLAYER");
// Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
}
});
}
});
// Destroy entities
protocol.registerOutgoing(State.PLAY, 0x32, 0x33, new PacketRemapper() {
protocol.registerOutgoing(State.PLAY, 0x32, 0x34, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT_ARRAY); // 0 - Entity IDS
@ -91,11 +119,11 @@ public class EntityPackets {
});
// Metadata packet
protocol.registerOutgoing(State.PLAY, 0x3C, 0x3D, new PacketRemapper() {
protocol.registerOutgoing(State.PLAY, 0x3C, 0x3E, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Types1_12.METADATA_LIST); // 1 - Metadata list
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 1 - Metadata list
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
@ -103,7 +131,7 @@ public class EntityPackets {
Optional<Entity1_12Types.EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
}
});
}

Datei anzeigen

@ -101,7 +101,7 @@ public class InventoryPackets {
});
// Entity Equipment Packet
protocol.registerOutgoing(State.PLAY, 0x3F, 0x40, new PacketRemapper() {
protocol.registerOutgoing(State.PLAY, 0x3F, 0x41, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-17w50a</version>
<version>1.4.0-18w01a</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>viaversion-jar</name>

Datei anzeigen

@ -6,7 +6,7 @@
<groupId>us.myles</groupId>
<artifactId>viaversion-parent</artifactId>
<version>1.4.0-17w50a</version>
<version>1.4.0-18w01a</version>
<packaging>pom</packaging>
<name>viaversion-parent</name>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-17w50a</version>
<version>1.4.0-18w01a</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>1.4.0-17w50a</version>
<version>1.4.0-18w01a</version>
</parent>
<modelVersion>4.0.0</modelVersion>