Skip to content

Commit

Permalink
Correctly handle unknown entity types
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Dec 15, 2024
1 parent f2a7c74 commit 71484d4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ public void register() {
wrapper.write(Types.SHORT, speedZ);
}

entityTracker.getTrackedEntities().put(entityId, new TrackedEntity(entityId, location, type));
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;

Expand Down Expand Up @@ -312,6 +314,10 @@ public void register() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ public void register() {
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);
}
});
}
});
Expand All @@ -156,6 +159,10 @@ public void register() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ public void register() {
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);

Expand Down Expand Up @@ -370,6 +373,10 @@ public void register() {
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);
Expand Down

0 comments on commit 71484d4

Please sign in to comment.