3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Cleanup more entity tracking and rewriting

Dieser Commit ist enthalten in:
KennyTV 2019-10-02 15:09:50 +02:00
Ursprung b11456d86b
Commit 655ef137c1
18 geänderte Dateien mit 185 neuen und 191 gelöschten Zeilen

Datei anzeigen

@ -116,8 +116,8 @@ public abstract class Protocol {
incoming.put(pair, protocolPacket); incoming.put(pair, protocolPacket);
} }
public void cancelIncoming(State state, int newPacketID) { public void cancelIncoming(State state, int oldPacketID, int newPacketID) {
registerIncoming(state, -1, newPacketID, new PacketRemapper() { registerIncoming(state, oldPacketID, newPacketID, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(PacketWrapper::cancel); 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. * Register an outgoing packet, with simple id transformation.
* *
@ -158,8 +162,8 @@ public abstract class Protocol {
outgoing.put(pair, protocolPacket); outgoing.put(pair, protocolPacket);
} }
public void cancelOutgoing(State state, int oldPacketID) { public void cancelOutgoing(State state, int oldPacketID, int newPacketID) {
registerIncoming(state, oldPacketID, -1, new PacketRemapper() { registerIncoming(state, oldPacketID, newPacketID, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(PacketWrapper::cancel); handler(PacketWrapper::cancel);

Datei anzeigen

@ -78,23 +78,76 @@ public abstract class MetadataRewriter<T extends Protocol> extends Rewriter<T> {
registerMetadataRewriter(oldPacketId, newPacketId, null, metaType); 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.
@Override *
public void registerMap() { * @param metaType type of the metadata list
map(intType); // 0 - Entity id * @return handler for tracking and rewriting entities
handler(new PacketHandler() { */
public PacketHandler getTrackerAndRewriter(Type<List<Metadata>> metaType) {
return new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
wrapper.user().get(entityTrackerClass).addEntity((int) wrapper.get(intType, 0), entityType); 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);
} }
public void registerExtraTracker(int packetId, EntityType entityType) { EntityType entType = getTypeFromId(newType);
registerExtraTracker(packetId, entityType, Type.VAR_INT); // Register Type ID
wrapper.user().get(entityTrackerClass).addEntity(entityId, entType);
if (metaType != null) {
handleMetadata(entityId, wrapper.get(metaType, 0), wrapper.user());
}
}
};
}
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) { public void registerEntityDestroy(int oldPacketId, int newPacketId) {
@ -119,6 +172,16 @@ public abstract class MetadataRewriter<T extends Protocol> extends Rewriter<T> {
registerEntityDestroy(packetId, packetId); 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 { protected void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
} }

Datei anzeigen

@ -44,19 +44,7 @@ public class Protocol1_11To1_10 extends Protocol {
map(Type.BYTE); // 2 - Type map(Type.BYTE); // 2 - Type
// Track Entity // Track Entity
handler(new PacketHandler() { handler(metadataRewriter.getObjectTracker());
@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);
}
});
} }
}); });

Datei anzeigen

@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_11to1_10.metadata;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; 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.entities.Entity1_11Types.EntityType;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; 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) { public static EntityType rewriteEntityType(int numType, List<Metadata> metadata) {
Optional<EntityType> optType = EntityType.findById(numType); Optional<EntityType> optType = EntityType.findById(numType);
if (!optType.isPresent()) { if (!optType.isPresent()) {

Datei anzeigen

@ -8,7 +8,6 @@ import com.google.gson.JsonParser;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; 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.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection; import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.platform.providers.ViaProviders; 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 map(Type.BYTE); // 2 - Type
// Track Entity // Track Entity
handler(new PacketHandler() { handler(metadataRewriter.getObjectTracker());
@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);
}
});
} }
}); });
@ -77,19 +64,8 @@ public class Protocol1_12To1_11_1 extends Protocol {
map(Type.SHORT); // 11 - Velocity Z map(Type.SHORT); // 11 - Velocity Z
map(Types1_12.METADATA_LIST); // 12 - Metadata map(Types1_12.METADATA_LIST); // 12 - Metadata
handler(new PacketHandler() { // Track mob and rewrite metadata
@Override handler(metadataRewriter.getTrackerAndRewriter(Types1_12.METADATA_LIST));
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());
}
});
} }
}); });
@ -272,7 +248,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
// Incoming // Incoming
// New packet at 0x01 // New packet at 0x01
cancelIncoming(State.PLAY, 0x01); cancelIncoming(State.PLAY, 0x01, 0x01);
registerIncoming(State.PLAY, 0x01, 0x02); registerIncoming(State.PLAY, 0x01, 0x02);
registerIncoming(State.PLAY, 0x02, 0x03); registerIncoming(State.PLAY, 0x02, 0x03);
@ -328,12 +304,12 @@ public class Protocol1_12To1_11_1 extends Protocol {
registerIncoming(State.PLAY, 0x15, 0x16); registerIncoming(State.PLAY, 0x15, 0x16);
// New packet at 0x17 // New packet at 0x17
cancelIncoming(State.PLAY, 0x17); cancelIncoming(State.PLAY, 0x17, 0x17);
registerIncoming(State.PLAY, 0x16, 0x18); registerIncoming(State.PLAY, 0x16, 0x18);
// New packet 0x19 // New packet 0x19
cancelIncoming(State.PLAY, 0x19); cancelIncoming(State.PLAY, 0x19, 0x19);
registerIncoming(State.PLAY, 0x17, 0x1a); registerIncoming(State.PLAY, 0x17, 0x1a);
// registerIncoming(State.PLAY, 0x18, 0x1b); - Handled in InventoryPackets // registerIncoming(State.PLAY, 0x18, 0x1b); - Handled in InventoryPackets

Datei anzeigen

@ -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);
}
} }

Datei anzeigen

@ -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);
}
} }

Datei anzeigen

@ -51,6 +51,7 @@ public class EntityPackets {
}); });
} }
}); });
// Spawn mob packet // Spawn mob packet
protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() {
@Override @Override
@ -69,20 +70,7 @@ public class EntityPackets {
map(Type.SHORT); // 11 - Velocity Z map(Type.SHORT); // 11 - Velocity Z
map(Types1_13.METADATA_LIST); // 12 - Metadata map(Types1_13.METADATA_LIST); // 12 - Metadata
handler(new PacketHandler() { handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST));
@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());
}
});
} }
}); });
@ -99,17 +87,7 @@ public class EntityPackets {
map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 6 - Pitch
map(Types1_13.METADATA_LIST); // 7 - Metadata map(Types1_13.METADATA_LIST); // 7 - Metadata
handler(new PacketHandler() { handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER));
@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());
}
});
} }
}); });

Datei anzeigen

@ -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.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; 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.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.Particle;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ParticleRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPackets; 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 // 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);
}
} }

Datei anzeigen

@ -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_12;
import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.api.type.types.version.Types1_13;
import us.myles.ViaVersion.packets.State; 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.metadata.MetadataRewriter1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
import java.util.Optional;
public class EntityPackets { public class EntityPackets {
public static void register(final Protocol protocol) { public static void register(final Protocol protocol) {
MetadataRewriter1_13To1_12_2 metadataRewriter = protocol.get(MetadataRewriter1_13To1_12_2.class); 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(Type.SHORT); // 11 - Velocity Z
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 12 - Metadata map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 12 - Metadata
handler(new PacketHandler() { handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST));
@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());
}
});
} }
}); });
@ -132,17 +111,7 @@ public class EntityPackets {
map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 6 - Pitch
map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 7 - Metadata map(Types1_12.METADATA_LIST, Types1_13.METADATA_LIST); // 7 - Metadata
handler(new PacketHandler() { handler(metadataRewriter.getTrackerAndRewriter(Types1_13.METADATA_LIST, Entity1_13Types.EntityType.PLAYER));
@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());
}
});
} }
}); });

Datei anzeigen

@ -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);
}
} }

Datei anzeigen

@ -1,16 +1,12 @@
package us.myles.ViaVersion.protocols.protocol1_14_1to1_14.packets; 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.entities.Entity1_14Types;
import us.myles.ViaVersion.api.protocol.Protocol; 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.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.packets.State; 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.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 { public class EntityPackets {
@ -35,38 +31,12 @@ public class EntityPackets {
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(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST));
@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());
}
});
} }
}); });
// Destroy entities // Destroy entities
protocol.registerOutgoing(State.PLAY, 0x37, 0x37, new PacketRemapper() { metadataRewriter.registerEntityDestroy(0x37);
@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);
}
}
});
}
});
// Spawn Player // Spawn Player
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@ -81,18 +51,7 @@ public class EntityPackets {
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(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST, Entity1_14Types.EntityType.PLAYER));
@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());
}
});
} }
}); });

Datei anzeigen

@ -13,6 +13,7 @@ import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle; 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.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.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14; 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) { private static boolean isSneaking(byte flags) {
return (flags & 0x2) != 0; return (flags & 0x2) != 0;
} }

Datei anzeigen

@ -122,22 +122,7 @@ public class EntityPackets {
map(Type.SHORT); // 11 - Velocity Z map(Type.SHORT); // 11 - Velocity Z
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 12 - Metadata map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 12 - Metadata
handler(new PacketHandler() { handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST));
@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());
}
});
} }
}); });
@ -166,17 +151,7 @@ public class EntityPackets {
map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 6 - Pitch
map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 7 - Metadata map(Types1_13_2.METADATA_LIST, Types1_14.METADATA_LIST); // 7 - Metadata
handler(new PacketHandler() { handler(metadataRewriter.getTrackerAndRewriter(Types1_14.METADATA_LIST, Entity1_14Types.EntityType.PLAYER));
@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());
}
});
} }
}); });

Datei anzeigen

@ -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.minecraft.metadata.types.MetaType1_14;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter; 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.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.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.storage.EntityTracker1_15; 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 //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);
}
} }

Datei anzeigen

@ -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);
}
} }

Datei anzeigen

@ -249,7 +249,7 @@ public class EntityPackets {
// Update Entity NBT // Update Entity NBT
protocol.cancelOutgoing(State.PLAY, 0x49); protocol.cancelOutgoing(State.PLAY, 0x49, 0x49);
// Combat Event Packet // Combat Event Packet
protocol.registerOutgoing(State.PLAY, 0x42, 0x2C, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x42, 0x2C, new PacketRemapper() {

Datei anzeigen

@ -402,7 +402,7 @@ public class PlayerPackets {
/* Removed packets */ /* Removed packets */
// Set Compression // Set Compression
protocol.cancelOutgoing(State.PLAY, 0x46); protocol.cancelOutgoing(State.PLAY, 0x46, 0x46);
/* Packets which do not have any field remapping or handlers */ /* Packets which do not have any field remapping or handlers */