Correctly handle unknown entity types

This commit is contained in:
FlorianMichael 2024-12-15 17:48:55 +01:00
parent f2a7c74ee5
commit 71484d45bb
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
3 changed files with 22 additions and 2 deletions

View File

@ -270,7 +270,9 @@ public class Protocolr1_2_4_5Tor1_3_1_2 extends StatelessProtocol<ClientboundPac
wrapper.write(Types.SHORT, speedZ);
}
if (type != null) {
entityTracker.getTrackedEntities().put(entityId, new TrackedEntity(entityId, location, type));
}
final EntityTypes1_8.ObjectType objectType = EntityTypes1_8.ObjectType.findById(typeId);
if (objectType == null) return;
@ -312,6 +314,10 @@ public class Protocolr1_2_4_5Tor1_3_1_2 extends StatelessProtocol<ClientboundPac
final double z = wrapper.get(Types.INT, 3) / 32.0D;
final List<EntityData> entityDataList = wrapper.get(Types1_3_1.ENTITY_DATA_LIST, 0);
final EntityTypes1_8.EntityType entityType = EntityTypes1_8.getTypeFromId(type, false);
if (entityType == null) {
wrapper.cancel();
return;
}
final EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.getTrackedEntities().put(entityId, new TrackedLivingEntity(entityId, new Location(x, y, z), entityType));
tracker.updateEntityDataList(entityId, entityDataList);

View File

@ -133,7 +133,10 @@ public class Protocolr1_5_2Tor1_6_1 extends StatelessProtocol<ClientboundPackets
handler(wrapper -> {
final int entityID = wrapper.get(Types.INT, 0);
final int typeID = wrapper.get(Types.BYTE, 0);
wrapper.user().get(EntityTracker.class).getTrackedEntities().put(entityID, EntityTypes1_8.getTypeFromId(typeID, true));
final EntityTypes1_8.EntityType entityType = EntityTypes1_8.getTypeFromId(typeID, true);
if (entityType != null) {
wrapper.user().get(EntityTracker.class).getTrackedEntities().put(entityID, entityType);
}
});
}
});
@ -156,6 +159,10 @@ public class Protocolr1_5_2Tor1_6_1 extends StatelessProtocol<ClientboundPackets
final int entityID = wrapper.get(Types.INT, 0);
final int typeID = wrapper.get(Types.UNSIGNED_BYTE, 0);
final EntityTypes1_8.EntityType entityType = EntityTypes1_8.getTypeFromId(typeID, false);
if (entityType == null) {
wrapper.cancel();
return;
}
final List<EntityData> entityDataList = wrapper.get(Types1_6_4.ENTITY_DATA_LIST, 0);
wrapper.user().get(EntityTracker.class).getTrackedEntities().put(entityID, entityType);
EntityDataRewriter.transform(entityType, entityDataList);

View File

@ -305,6 +305,9 @@ public class Protocolr1_7_6_10Tor1_8 extends AbstractProtocol<ClientboundPackets
byte yaw = wrapper.get(Types.BYTE, 2);
int data = wrapper.get(Types.INT, 3);
final EntityTypes1_8.EntityType type = EntityTypes1_8.getTypeFromId(typeID, true);
if (type == null) {
return;
}
tracker.trackEntity(entityID, type);
tracker.updateEntityLocation(entityID, x, y, z, false);
@ -370,6 +373,10 @@ public class Protocolr1_7_6_10Tor1_8 extends AbstractProtocol<ClientboundPackets
final int z = wrapper.get(Types.INT, 2);
final List<EntityData> entityDataList = wrapper.get(Types1_8.ENTITY_DATA_LIST, 0);
final EntityTypes1_8.EntityType entityType = EntityTypes1_8.getTypeFromId(typeID, false);
if (entityType == null) {
wrapper.cancel();
return;
}
tracker.trackEntity(entityID, entityType);
tracker.updateEntityLocation(entityID, x, y, z, false);
tracker.updateEntityData(entityID, entityDataList);