mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-23 02:25:19 +01:00
Cleanup more entity tracking and rewriting
This commit is contained in:
parent
b11456d86b
commit
655ef137c1
@ -116,8 +116,8 @@ public abstract class Protocol {
|
||||
incoming.put(pair, protocolPacket);
|
||||
}
|
||||
|
||||
public void cancelIncoming(State state, int newPacketID) {
|
||||
registerIncoming(state, -1, newPacketID, new PacketRemapper() {
|
||||
public void cancelIncoming(State state, int oldPacketID, int newPacketID) {
|
||||
registerIncoming(state, oldPacketID, newPacketID, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(PacketWrapper::cancel);
|
||||
@ -125,6 +125,10 @@ public abstract class Protocol {
|
||||
});
|
||||
}
|
||||
|
||||
public void cancelIncoming(State state, int newPacketID) {
|
||||
cancelOutgoing(state, -1, newPacketID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an outgoing packet, with simple id transformation.
|
||||
*
|
||||
@ -158,8 +162,8 @@ public abstract class Protocol {
|
||||
outgoing.put(pair, protocolPacket);
|
||||
}
|
||||
|
||||
public void cancelOutgoing(State state, int oldPacketID) {
|
||||
registerIncoming(state, oldPacketID, -1, new PacketRemapper() {
|
||||
public void cancelOutgoing(State state, int oldPacketID, int newPacketID) {
|
||||
registerIncoming(state, oldPacketID, newPacketID, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(PacketWrapper::cancel);
|
||||
|
@ -78,23 +78,76 @@ public abstract class MetadataRewriter<T extends Protocol> extends Rewriter<T> {
|
||||
registerMetadataRewriter(oldPacketId, newPacketId, null, metaType);
|
||||
}
|
||||
|
||||
public void registerExtraTracker(int packetId, EntityType entityType, Type intType) {
|
||||
getProtocol().registerOutgoing(State.PLAY, packetId, packetId, new PacketRemapper() {
|
||||
/**
|
||||
* Returns a packethandler to track and rewrite an entity.
|
||||
*
|
||||
* @param metaType type of the metadata list
|
||||
* @return handler for tracking and rewriting entities
|
||||
*/
|
||||
public PacketHandler getTrackerAndRewriter(Type<List<Metadata>> metaType) {
|
||||
return new PacketHandler() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(intType); // 0 - Entity id
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.user().get(entityTrackerClass).addEntity((int) wrapper.get(intType, 0), entityType);
|
||||
}
|
||||
});
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
int newType = getNewEntityId(type);
|
||||
if (newType != type) {
|
||||
wrapper.set(Type.VAR_INT, 1, newType);
|
||||
}
|
||||
|
||||
EntityType entType = getTypeFromId(newType);
|
||||
// Register Type ID
|
||||
wrapper.user().get(entityTrackerClass).addEntity(entityId, entType);
|
||||
|
||||
if (metaType != null) {
|
||||
handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user());
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public void registerExtraTracker(int packetId, EntityType entityType) {
|
||||
registerExtraTracker(packetId, entityType, Type.VAR_INT);
|
||||
public PacketHandler getTracker() {
|
||||
return getTrackerAndRewriter(null);
|
||||
}
|
||||
|
||||
public PacketHandler getTrackerAndRewriter(Type<List<Metadata>> metaType, EntityType entityType) {
|
||||
return new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
// Register Type ID
|
||||
wrapper.user().get(entityTrackerClass).addEntity(entityId, entityType);
|
||||
|
||||
if (metaType != null) {
|
||||
handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a packethandler to track an object entity.
|
||||
*
|
||||
* @return handler for tracking and rewriting entities
|
||||
*/
|
||||
public PacketHandler getObjectTracker() {
|
||||
return 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);
|
||||
|
||||
int newType = getNewEntityId(type);
|
||||
if (newType != type) {
|
||||
wrapper.set(Type.BYTE, 0, (byte) newType);
|
||||
}
|
||||
|
||||
EntityType entType = getObjectTypeFromId(newType);
|
||||
// Register Type ID
|
||||
wrapper.user().get(entityTrackerClass).addEntity(entityId, entType);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void registerEntityDestroy(int oldPacketId, int newPacketId) {
|
||||
@ -119,6 +172,16 @@ public abstract class MetadataRewriter<T extends Protocol> extends Rewriter<T> {
|
||||
registerEntityDestroy(packetId, packetId);
|
||||
}
|
||||
|
||||
protected abstract EntityType getTypeFromId(int type);
|
||||
|
||||
protected EntityType getObjectTypeFromId(int type) {
|
||||
return getTypeFromId(type);
|
||||
}
|
||||
|
||||
protected int getNewEntityId(int oldId) {
|
||||
return oldId;
|
||||
}
|
||||
|
||||
protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
|
||||
}
|
||||
|
||||
|
@ -44,19 +44,7 @@ public class Protocol1_11To1_10 extends Protocol {
|
||||
map(Type.BYTE); // 2 - Type
|
||||
|
||||
// Track Entity
|
||||
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);
|
||||
|
||||
Entity1_11Types.EntityType entType = Entity1_11Types.getTypeFromId(type, true);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_11.class).addEntity(entityId, entType);
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getObjectTracker());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_11to1_10.metadata;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_11Types;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_11Types.EntityType;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
@ -130,6 +131,16 @@ public class MetadataRewriter1_11To1_10 extends MetadataRewriter<Protocol1_11To1
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected us.myles.ViaVersion.api.entities.EntityType getTypeFromId(int type) {
|
||||
return Entity1_11Types.getTypeFromId(type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected us.myles.ViaVersion.api.entities.EntityType getObjectTypeFromId(int type) {
|
||||
return Entity1_11Types.getTypeFromId(type, true);
|
||||
}
|
||||
|
||||
public static EntityType rewriteEntityType(int numType, List<Metadata> metadata) {
|
||||
Optional<EntityType> optType = EntityType.findById(numType);
|
||||
if (!optType.isPresent()) {
|
||||
|
@ -8,7 +8,6 @@ import com.google.gson.JsonParser;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_12Types;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
|
||||
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
|
||||
@ -43,19 +42,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
map(Type.BYTE); // 2 - Type
|
||||
|
||||
// Track Entity
|
||||
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);
|
||||
|
||||
Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, true);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_12.class).addEntity(entityId, entType);
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getObjectTracker());
|
||||
}
|
||||
});
|
||||
|
||||
@ -77,19 +64,8 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
map(Type.SHORT); // 11 - Velocity Z
|
||||
map(Types1_12.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
// Change Type :)
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
Entity1_12Types.EntityType entType = Entity1_12Types.getTypeFromId(type, false);
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_12.class).addEntity(entityId, entType);
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_12.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
// Track mob and rewrite metadata
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_12.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@ -272,7 +248,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
|
||||
// Incoming
|
||||
// New packet at 0x01
|
||||
cancelIncoming(State.PLAY, 0x01);
|
||||
cancelIncoming(State.PLAY, 0x01, 0x01);
|
||||
|
||||
registerIncoming(State.PLAY, 0x01, 0x02);
|
||||
registerIncoming(State.PLAY, 0x02, 0x03);
|
||||
@ -328,12 +304,12 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
||||
registerIncoming(State.PLAY, 0x15, 0x16);
|
||||
|
||||
// New packet at 0x17
|
||||
cancelIncoming(State.PLAY, 0x17);
|
||||
cancelIncoming(State.PLAY, 0x17, 0x17);
|
||||
|
||||
registerIncoming(State.PLAY, 0x16, 0x18);
|
||||
|
||||
// New packet 0x19
|
||||
cancelIncoming(State.PLAY, 0x19);
|
||||
cancelIncoming(State.PLAY, 0x19, 0x19);
|
||||
|
||||
registerIncoming(State.PLAY, 0x17, 0x1a);
|
||||
// registerIncoming(State.PLAY, 0x18, 0x1b); - Handled in InventoryPackets
|
||||
|
@ -33,4 +33,14 @@ public class MetadataRewriter1_12To1_11_1 extends MetadataRewriter<Protocol1_12T
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_12Types.getTypeFromId(type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(int type) {
|
||||
return Entity1_12Types.getTypeFromId(type, true);
|
||||
}
|
||||
}
|
||||
|
@ -43,4 +43,13 @@ public class MetadataRewriter1_13_1To1_13 extends MetadataRewriter<Protocol1_13_
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_13Types.getTypeFromId(type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(int type) {
|
||||
return Entity1_13Types.getTypeFromId(type, true);
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ public class EntityPackets {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Spawn mob packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() {
|
||||
@Override
|
||||
@ -69,20 +70,7 @@ public class EntityPackets {
|
||||
map(Type.SHORT); // 11 - Velocity Z
|
||||
map(Types1_13.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@ -99,17 +87,7 @@ public class EntityPackets {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(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_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13;
|
||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityTypeRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets;
|
||||
@ -98,4 +99,19 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter<Protocol1_13T
|
||||
|
||||
// TODO: Boat has changed
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNewEntityId(final int oldId) {
|
||||
return EntityTypeRewriter.getNewId(oldId).orElse(oldId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_13Types.getTypeFromId(type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(int type) {
|
||||
return Entity1_13Types.getTypeFromId(type, true);
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,9 @@ 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.protocol1_13to1_12_2.data.EntityTypeRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.metadata.MetadataRewriter1_13To1_12_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class EntityPackets {
|
||||
public static void register(final Protocol protocol) {
|
||||
MetadataRewriter1_13To1_12_2 metadataRewriter = protocol.get(MetadataRewriter1_13To1_12_2.class);
|
||||
@ -97,25 +94,7 @@ public class EntityPackets {
|
||||
map(Type.SHORT); // 11 - Velocity Z
|
||||
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
Optional<Integer> optNewType = EntityTypeRewriter.getNewId(type);
|
||||
type = optNewType.orElse(type);
|
||||
Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false);
|
||||
|
||||
wrapper.set(Type.VAR_INT, 1, type);
|
||||
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@ -132,17 +111,7 @@ public class EntityPackets {
|
||||
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_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_13.class).addEntity(entityId, entType);
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -26,4 +26,9 @@ public class MetadataRewriter1_14_1To1_14 extends MetadataRewriter<Protocol1_14_
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_14Types.getTypeFromId(type);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,12 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.entities.Entity1_14Types;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
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_14;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.metadata.MetadataRewriter1_14_1To1_14;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.storage.EntityTracker1_14_1;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||
|
||||
public class EntityPackets {
|
||||
|
||||
@ -35,38 +31,12 @@ public class EntityPackets {
|
||||
map(Type.SHORT); // 11 - Velocity Z
|
||||
map(Types1_14.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type);
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType);
|
||||
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
// Destroy entities
|
||||
protocol.registerOutgoing(State.PLAY, 0x37, 0x37, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT_ARRAY); // 0 - Entity ids
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0)) {
|
||||
wrapper.user().get(EntityTracker1_14.class).removeEntity(entity);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
metadataRewriter.registerEntityDestroy(0x37);
|
||||
|
||||
// Spawn Player
|
||||
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
|
||||
@ -81,18 +51,7 @@ public class EntityPackets {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_14.METADATA_LIST); // 7 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
||||
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_14_1.class).addEntity(entityId, entType);
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST, Entity1_14Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -13,6 +13,7 @@ import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.EntityTypeRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14;
|
||||
|
||||
@ -167,6 +168,16 @@ public class MetadataRewriter1_14To1_13_2 extends MetadataRewriter<Protocol1_14T
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNewEntityId(final int oldId) {
|
||||
return EntityTypeRewriter.getNewId(oldId).orElse(oldId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_14Types.getTypeFromId(type);
|
||||
}
|
||||
|
||||
private static boolean isSneaking(byte flags) {
|
||||
return (flags & 0x2) != 0;
|
||||
}
|
||||
|
@ -122,22 +122,7 @@ public class EntityPackets {
|
||||
map(Type.SHORT); // 11 - Velocity Z
|
||||
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 12 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
int type = wrapper.get(Type.VAR_INT, 1);
|
||||
|
||||
type = EntityTypeRewriter.getNewId(type).orElse(type);
|
||||
wrapper.set(Type.VAR_INT, 1, type);
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.getTypeFromId(type);
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, entType);
|
||||
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST));
|
||||
}
|
||||
});
|
||||
|
||||
@ -166,17 +151,7 @@ public class EntityPackets {
|
||||
map(Type.BYTE); // 6 - Pitch
|
||||
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 7 - Metadata
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker1_14.class).addEntity(entityId, entType);
|
||||
metadataRewriter.handleMetadata(entityId, wrapper.get(Types1_14.METADATA_LIST, 0), wrapper.user());
|
||||
}
|
||||
});
|
||||
handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST, Entity1_14Types.EntityType.PLAYER));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -8,6 +8,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
|
||||
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
|
||||
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.EntityPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.packets.InventoryPackets;
|
||||
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15;
|
||||
|
||||
@ -38,4 +39,14 @@ public class MetadataRewriter1_15To1_14_4 extends MetadataRewriter<Protocol1_15T
|
||||
|
||||
//TODO new boolean with id 17 for enderman
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNewEntityId(final int oldId) {
|
||||
return EntityPackets.getNewEntityId(oldId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_15Types.getTypeFromId(type);
|
||||
}
|
||||
}
|
||||
|
@ -130,4 +130,13 @@ public class MetadataRewriter1_9To1_8 extends MetadataRewriter<Protocol1_9To1_8>
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getTypeFromId(int type) {
|
||||
return Entity1_10Types.getTypeFromId(type, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityType getObjectTypeFromId(int type) {
|
||||
return Entity1_10Types.getTypeFromId(type, true);
|
||||
}
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ public class EntityPackets {
|
||||
|
||||
|
||||
// Update Entity NBT
|
||||
protocol.cancelOutgoing(State.PLAY, 0x49);
|
||||
protocol.cancelOutgoing(State.PLAY, 0x49, 0x49);
|
||||
|
||||
// Combat Event Packet
|
||||
protocol.registerOutgoing(State.PLAY, 0x42, 0x2C, new PacketRemapper() {
|
||||
|
@ -402,7 +402,7 @@ public class PlayerPackets {
|
||||
/* Removed packets */
|
||||
|
||||
// Set Compression
|
||||
protocol.cancelOutgoing(State.PLAY, 0x46);
|
||||
protocol.cancelOutgoing(State.PLAY, 0x46, 0x46);
|
||||
|
||||
/* Packets which do not have any field remapping or handlers */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user