3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 00:00:28 +01:00

Merge pull request #1477 from KennyTV/abstraction

Cleanup more entity tracking and rewriting
Dieser Commit ist enthalten in:
Myles 2019-10-04 13:40:48 +01:00 committet von GitHub
Commit 857ae523cf
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
21 geänderte Dateien mit 213 neuen und 343 gelöschten Zeilen

Datei anzeigen

@ -331,13 +331,6 @@ public interface ViaVersionConfig {
boolean is1_14HealthNaNFix(); boolean is1_14HealthNaNFix();
/**
* Fixes non full blocks having 0 light for 1.14+ clients on sub 1.14 servers.
*
* @return True if enabled
*/
boolean isNonFullBlockLightFix();
/** /**
* Should 1.15 clients respawn instantly / without showing the death screen * Should 1.15 clients respawn instantly / without showing the death screen
* *

Datei anzeigen

@ -116,6 +116,19 @@ public abstract class Protocol {
incoming.put(pair, protocolPacket); incoming.put(pair, protocolPacket);
} }
public void cancelIncoming(State state, int oldPacketID, int newPacketID) {
registerIncoming(state, oldPacketID, newPacketID, new PacketRemapper() {
@Override
public void registerMap() {
handler(PacketWrapper::cancel);
}
});
}
public void cancelIncoming(State state, int newPacketID) {
cancelIncoming(state, -1, newPacketID);
}
/** /**
* Register an outgoing packet, with simple id transformation. * Register an outgoing packet, with simple id transformation.
* *
@ -149,6 +162,19 @@ public abstract class Protocol {
outgoing.put(pair, protocolPacket); outgoing.put(pair, protocolPacket);
} }
public void cancelOutgoing(State state, int oldPacketID, int newPacketID) {
registerOutgoing(state, oldPacketID, newPacketID, new PacketRemapper() {
@Override
public void registerMap() {
handler(PacketWrapper::cancel);
}
});
}
public void cancelOutgoing(State state, int oldPacketID) {
cancelOutgoing(state, oldPacketID, -1);
}
/** /**
* Transform a packet using this protocol * Transform a packet using this protocol
* *

Datei anzeigen

@ -78,23 +78,71 @@ 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.
*
* @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 @Override
public void registerMap() { public void handle(PacketWrapper wrapper) throws Exception {
map(intType); // 0 - Entity id int entityId = wrapper.get(Type.VAR_INT, 0);
handler(new PacketHandler() { int type = wrapper.get(Type.VAR_INT, 1);
@Override
public void handle(PacketWrapper wrapper) throws Exception { int newType = getNewEntityId(type);
wrapper.user().get(entityTrackerClass).addEntity((int) wrapper.get(intType, 0), entityType); 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) { public PacketHandler getTracker() {
registerExtraTracker(packetId, entityType, Type.VAR_INT); 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);
EntityType entType = getObjectTypeFromId(type);
// 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 +167,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,18 +248,8 @@ public class Protocol1_12To1_11_1 extends Protocol {
// Incoming // Incoming
// New packet at 0x01 // New packet at 0x01
registerIncoming(State.PLAY, 0x01, 0x01, new PacketRemapper() { cancelIncoming(State.PLAY, 0x01, 0x01);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
registerIncoming(State.PLAY, 0x01, 0x02); registerIncoming(State.PLAY, 0x01, 0x02);
registerIncoming(State.PLAY, 0x02, 0x03); registerIncoming(State.PLAY, 0x02, 0x03);
registerIncoming(State.PLAY, 0x03, 0x04); registerIncoming(State.PLAY, 0x03, 0x04);
@ -336,33 +302,15 @@ public class Protocol1_12To1_11_1 extends Protocol {
registerIncoming(State.PLAY, 0x13, 0x14); registerIncoming(State.PLAY, 0x13, 0x14);
registerIncoming(State.PLAY, 0x14, 0x15); registerIncoming(State.PLAY, 0x14, 0x15);
registerIncoming(State.PLAY, 0x15, 0x16); registerIncoming(State.PLAY, 0x15, 0x16);
// New packet at 0x17 // New packet at 0x17
registerIncoming(State.PLAY, 0x17, 0x17, new PacketRemapper() { cancelIncoming(State.PLAY, 0x17, 0x17);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
registerIncoming(State.PLAY, 0x16, 0x18); registerIncoming(State.PLAY, 0x16, 0x18);
// New packet 0x19
registerIncoming(State.PLAY, 0x19, 0x19, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override // New packet 0x19
public void handle(PacketWrapper wrapper) throws Exception { cancelIncoming(State.PLAY, 0x19, 0x19);
wrapper.cancel();
}
});
}
});
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
registerIncoming(State.PLAY, 0x19, 0x1c); registerIncoming(State.PLAY, 0x19, 0x1c);

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

@ -799,30 +799,10 @@ public class Protocol1_13To1_12_2 extends Protocol {
// Incoming packets // Incoming packets
// New packet 0x02 - Login Plugin Message // New packet 0x02 - Login Plugin Message
registerIncoming(State.LOGIN, -1, 0x02, new PacketRemapper() { cancelIncoming(State.LOGIN, 0x02);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
// New 0x01 - Query Block NBT // New 0x01 - Query Block NBT
registerIncoming(State.PLAY, -1, 0x01, new PacketRemapper() { cancelIncoming(State.PLAY, 0x01);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
// Tab-Complete // Tab-Complete
registerIncoming(State.PLAY, 0x1, 0x5, new PacketRemapper() { registerIncoming(State.PLAY, 0x1, 0x5, new PacketRemapper() {
@ -890,17 +870,8 @@ public class Protocol1_13To1_12_2 extends Protocol {
} }
}); });
// New 0x0C - Query Entity NBT // New 0x0C - Query Entity NBT
registerIncoming(State.PLAY, -1, 0x0C, new PacketRemapper() { cancelIncoming(State.PLAY, 0x0C);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
registerIncoming(State.PLAY, 0x0A, 0x0D); registerIncoming(State.PLAY, 0x0A, 0x0D);
registerIncoming(State.PLAY, 0x0B, 0x0E); registerIncoming(State.PLAY, 0x0B, 0x0E);
registerIncoming(State.PLAY, 0x0C, 0x0F); registerIncoming(State.PLAY, 0x0C, 0x0F);

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,15 +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;
public class EntityPackets { public class EntityPackets {
@ -34,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(EntityTracker.class).removeEntity(entity);
}
}
});
}
});
// Spawn Player // Spawn Player
protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() {
@ -80,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

@ -217,17 +217,8 @@ public class Protocol1_14To1_13_2 extends Protocol {
}); });
//Set Difficulty packet added in 19w11a //Set Difficulty packet added in 19w11a
registerIncoming(State.PLAY, -1, 0x02, new PacketRemapper() { cancelIncoming(State.PLAY, 0x02);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) {
wrapper.cancel();
}
});
}
});
registerIncoming(State.PLAY, 0x02, 0x03); registerIncoming(State.PLAY, 0x02, 0x03);
registerIncoming(State.PLAY, 0x03, 0x04); registerIncoming(State.PLAY, 0x03, 0x04);
registerIncoming(State.PLAY, 0x04, 0x05); registerIncoming(State.PLAY, 0x04, 0x05);
@ -242,17 +233,8 @@ public class Protocol1_14To1_13_2 extends Protocol {
registerIncoming(State.PLAY, 0x0D, 0x0E); registerIncoming(State.PLAY, 0x0D, 0x0E);
//Lock Difficulty packet added in 19w11a //Lock Difficulty packet added in 19w11a
registerIncoming(State.PLAY, -1, 0x10, new PacketRemapper() { cancelIncoming(State.PLAY, 0x10);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) {
wrapper.cancel();
}
});
}
});
registerIncoming(State.PLAY, 0x0E, 0x0F); registerIncoming(State.PLAY, 0x0E, 0x0F);
registerIncoming(State.PLAY, 0x0F, 0x14); registerIncoming(State.PLAY, 0x0F, 0x14);
registerIncoming(State.PLAY, 0x10, 0x11); registerIncoming(State.PLAY, 0x10, 0x11);
@ -276,17 +258,7 @@ public class Protocol1_14To1_13_2 extends Protocol {
registerIncoming(State.PLAY, 0x23, 0x25); registerIncoming(State.PLAY, 0x23, 0x25);
//Unknown packet added in 19w13a //Unknown packet added in 19w13a
registerIncoming(State.PLAY, -1, 0x27, new PacketRemapper() { cancelIncoming(State.PLAY, 0x27);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) {
wrapper.cancel();
}
});
}
});
registerIncoming(State.PLAY, 0x27, 0x2A); registerIncoming(State.PLAY, 0x27, 0x2A);
registerIncoming(State.PLAY, 0x28, 0x2B); registerIncoming(State.PLAY, 0x28, 0x2B);

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,17 +249,7 @@ public class EntityPackets {
// Update Entity NBT // Update Entity NBT
protocol.registerOutgoing(State.PLAY, 0x49, 0x49, new PacketRemapper() { protocol.cancelOutgoing(State.PLAY, 0x49, 0x49);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
// 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,17 +402,7 @@ public class PlayerPackets {
/* Removed packets */ /* Removed packets */
// Set Compression // Set Compression
protocol.registerOutgoing(State.PLAY, 0x46, 0x46, new PacketRemapper() { protocol.cancelOutgoing(State.PLAY, 0x46, 0x46);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
/* Packets which do not have any field remapping or handlers */ /* Packets which do not have any field remapping or handlers */
@ -482,43 +472,13 @@ public class PlayerPackets {
}); });
// TP Confirm // TP Confirm
protocol.registerIncoming(State.PLAY, -1, 0x00, new PacketRemapper() { protocol.cancelIncoming(State.PLAY, 0x00);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
// Vehicle Move // Vehicle Move
protocol.registerIncoming(State.PLAY, -1, 0x10, new PacketRemapper() { protocol.cancelIncoming(State.PLAY, 0x10);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
// Steer Boat // Steer Boat
protocol.registerIncoming(State.PLAY, -1, 0x11, new PacketRemapper() { protocol.cancelIncoming(State.PLAY, 0x11);
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.cancel();
}
});
}
});
// Packet Plugin Message Incoming // Packet Plugin Message Incoming
protocol.registerIncoming(State.PLAY, 0x17, 0x09, new PacketRemapper() { protocol.registerIncoming(State.PLAY, 0x17, 0x09, new PacketRemapper() {