Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unknown entity types correctly #932

Merged
merged 3 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -98,6 +98,9 @@ protected PacketHandler getMobSpawnRewriter(Type<List<EntityData>> dataType, IdS
return wrapper -> {
int entityId = wrapper.get(Types.VAR_INT, 0);
EntityType type = tracker(wrapper.user()).entityType(entityId);
if (type == null) {
return;
}

List<EntityData> entityDataList = wrapper.get(dataType, 0);
handleEntityData(entityId, entityDataList, wrapper.user());
Expand Down Expand Up @@ -136,7 +139,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 @@ -89,6 +89,9 @@ public void register() {
handler(wrapper -> {
int entityId = wrapper.get(Types.VAR_INT, 0);
EntityType type = tracker(wrapper.user()).entityType(entityId);
if (type == null) {
return;
}

List<EntityData> entityDataList = wrapper.get(Types1_9.ENTITY_DATA_LIST, 0);
handleEntityData(wrapper.get(Types.VAR_INT, 0), entityDataList, wrapper.user());
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ public void register() {
int id = wrapper.get(Types.BYTE, 0);
int mappedId = newEntityId(id);
EntityTypes1_13.EntityType entityType = EntityTypes1_13.getTypeFromId(mappedId, false);
if (entityType == null) {
// Would be EntityType.PIG on a 1.14 client, but later discarded anyway since not an object type
return;
}

EntityTypes1_13.ObjectType objectType = null;
if (entityType.isOrHasParent(EntityTypes1_13.EntityType.ABSTRACT_MINECART)) {
objectType = EntityTypes1_13.ObjectType.MINECART;
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