Skip to content

Commit

Permalink
Make sure empty model data is not inserted into manager (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt authored Jan 11, 2024
1 parent 3711edf commit b84211f
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,22 @@ private void refreshAt(long section) {
Long2ObjectMap<ModelData> data = modelDataCache.computeIfAbsent(section, $ -> new Long2ObjectOpenHashMap<>());
for (BlockPos pos : needUpdate) {
BlockEntity toUpdate = level.getBlockEntity(pos);
ModelData newData = ModelData.EMPTY;
// Query the BE for new model data if it exists
if (toUpdate != null && !toUpdate.isRemoved()) {
data.put(pos.asLong(), toUpdate.getModelData());
newData = toUpdate.getModelData();
}
// Make sure we don't bother storing empty data in the map
if (newData != ModelData.EMPTY) {
data.put(pos.asLong(), newData);
} else {
data.remove(pos.asLong());
}
}
// Remove the map completely if it's now empty
if (data.isEmpty()) {
modelDataCache.remove(section);
}
}
}

Expand Down

0 comments on commit b84211f

Please sign in to comment.