3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-09-16 17:21:21 +02:00

Untrack entities in 1.14.1 protocol (#1474)

Dieser Commit ist enthalten in:
Nassim 2019-10-01 22:07:42 +02:00 committet von Myles
Ursprung 7e008226ec
Commit 7e323bc497
2 geänderte Dateien mit 96 neuen und 80 gelöschten Zeilen

Datei anzeigen

@ -7,13 +7,13 @@ import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker;
public class Protocol1_14_1To1_14 extends Protocol { public class Protocol1_14_1To1_14 extends Protocol {
@Override @Override
protected void registerPackets() { protected void registerPackets() {
EntityPackets.register(this); EntityPackets.register(this);
} }
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker(userConnection)); userConnection.put(new EntityTracker(userConnection));
} }
} }

Datei anzeigen

@ -14,88 +14,104 @@ import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker;
public class EntityPackets { public class EntityPackets {
public static void register(Protocol protocol) { public static void register(Protocol protocol) {
// Spawn Mob // Spawn Mob
protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID map(Type.UUID); // 1 - Entity UUID
map(Type.VAR_INT); // 2 - Entity Type map(Type.VAR_INT); // 2 - Entity Type
map(Type.DOUBLE); // 3 - X map(Type.DOUBLE); // 3 - X
map(Type.DOUBLE); // 4 - Y map(Type.DOUBLE); // 4 - Y
map(Type.DOUBLE); // 5 - Z map(Type.DOUBLE); // 5 - Z
map(Type.BYTE); // 6 - Yaw map(Type.BYTE); // 6 - Yaw
map(Type.BYTE); // 7 - Pitch map(Type.BYTE); // 7 - Pitch
map(Type.BYTE); // 8 - Head Pitch map(Type.BYTE); // 8 - Head Pitch
map(Type.SHORT); // 9 - Velocity X map(Type.SHORT); // 9 - Velocity X
map(Type.SHORT); // 10 - Velocity Y map(Type.SHORT); // 10 - Velocity Y
map(Type.SHORT); // 11 - Velocity Z map(Type.SHORT); // 11 - Velocity Z
map(Types1_14.METADATA_LIST); // 12 - Metadata map(Types1_14.METADATA_LIST); // 12 - Metadata
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
int type = wrapper.get(Type.VAR_INT, 1); int type = wrapper.get(Type.VAR_INT, 1);
Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type); Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type);
// Register Type ID // Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
} }
}); });
} }
}); });
// Spawn Player // Spawn Player
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Player UUID map(Type.UUID); // 1 - Player UUID
map(Type.DOUBLE); // 2 - X map(Type.DOUBLE); // 2 - X
map(Type.DOUBLE); // 3 - Y map(Type.DOUBLE); // 3 - Y
map(Type.DOUBLE); // 4 - Z map(Type.DOUBLE); // 4 - Z
map(Type.BYTE); // 5 - Yaw map(Type.BYTE); // 5 - Yaw
map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 6 - Pitch
map(Types1_14.METADATA_LIST); // 7 - Metadata map(Types1_14.METADATA_LIST); // 7 - Metadata
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0); int entityId = wrapper.get(Type.VAR_INT, 0);
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER; Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
// Register Type ID // Register Type ID
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
} }
}); });
} }
}); });
// Entity Metadata // Destroy entities
protocol.registerOutgoing(State.PLAY, 0x43, 0x43, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x37, 0x37, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT_ARRAY); // 0 - Entity ids
map(Types1_14.METADATA_LIST); // 1 - Metadata list handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0)) {
wrapper.user().get(EntityTracker.class).removeEntity(entity);
}
}
});
}
});
handler(new PacketHandler() { // Entity Metadata
@Override protocol.registerOutgoing(State.PLAY, 0x43, 0x43, new PacketRemapper() {
public void handle(PacketWrapper wrapper) throws Exception { @Override
int entityId = wrapper.get(Type.VAR_INT, 0); public void registerMap() {
map(Type.VAR_INT); // 0 - Entity ID
map(Types1_14.METADATA_LIST); // 1 - Metadata list
Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId); handler(new PacketHandler() {
MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user()); @Override
} public void handle(PacketWrapper wrapper) throws Exception {
}); int entityId = wrapper.get(Type.VAR_INT, 0);
}
}); Optional<Entity1_14Types.EntityType> type = wrapper.user().get(EntityTracker.class).get(entityId);
} MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
}
});
}
});
}
} }