Skip to content

Commit

Permalink
Handle unknown entity types correctly
Browse files Browse the repository at this point in the history
Adds null checks for VV#4312, removes warnings that a vanilla client wouldn't print.
  • Loading branch information
FlorianMichael committed Dec 14, 2024
1 parent 8896528 commit 02c9cc1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public PacketHandler worldTrackerHandlerByKey() {
protected EntityType trackAndMapEntity(PacketWrapper wrapper) {
int typeId = wrapper.get(Types.VAR_INT, 1);
EntityType entityType = typeFromId(typeId);
if (entityType == null) {
return null;
}
tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), entityType);

int mappedTypeId = newEntityId(entityType.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ public void registerEntityDataTypeHandler1_20_3(
protected PacketHandler getTrackerHandler(Type<? extends Number> intType, int typeIndex) {
return wrapper -> {
Number id = wrapper.get(intType, typeIndex);
tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), typeFromId(id.intValue()));
EntityType entityType = typeFromId(id.intValue());
if (entityType != null) {
tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), entityType);
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ protected PacketHandler getObjectRewriter(Function<Byte, ObjectType> objectGette
return wrapper -> {
ObjectType type = objectGetter.apply(wrapper.get(Types.BYTE, 0));
if (type == null) {
protocol.getLogger().warning("Could not find entity type " + wrapper.get(Types.BYTE, 0));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public void register() {
byte type = wrapper.get(Types.BYTE, 0);
EntityTypes1_13.EntityType entType = EntityTypes1_13.getTypeFromId(type, true);
if (entType == null) {
protocol.getLogger().warning("Could not find entity type " + type);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public void register() {
handler(wrapper -> {
int type = wrapper.get(Types.VAR_INT, 1);
EntityType entityType = EntityTypes1_13.getTypeFromId(type, false);
if (entityType == null) {
return;
}
tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), entityType);

int oldId = EntityIdMappings1_12_2.getOldId(type);
Expand All @@ -145,10 +148,8 @@ public void register() {
} else {
wrapper.set(Types.VAR_INT, 1, oldId);
}
getMobSpawnRewriter1_11(Types1_12.ENTITY_DATA_LIST).handle(wrapper);
});

// Rewrite entity type / ddata
handler(getMobSpawnRewriter1_11(Types1_12.ENTITY_DATA_LIST));
}
});

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
projectVersion=5.2.0
projectVersion=5.2.1-SNAPSHOT

# Smile emoji
mcVersions=1.21.4,1.21.3,1.21.2,1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10
Expand Down

0 comments on commit 02c9cc1

Please sign in to comment.