Skip to content

Commit

Permalink
fix to map sync (#9853)
Browse files Browse the repository at this point in the history
More crash tolerant map synching
  • Loading branch information
Raycoms committed Mar 20, 2024
1 parent 349f404 commit d1c4b76
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,27 @@ public void serializeToView(@NotNull final FriendlyByteBuf buf)

final Level level = colony.getWorld();

int validMapCount = 0;
final List<MapItemSavedData> mapDataList = new ArrayList<>();
for (final ItemStack stack : maps)
{
if(MapItem.getSavedData(stack, level) != null)
try
{
validMapCount++;
final MapItemSavedData mapData = MapItem.getSavedData(stack, level);
if (mapData != null)
{
mapDataList.add(mapData);
}
}
catch (final Exception ex)
{
// Do nothing
}
}

buf.writeInt(validMapCount);
for (final ItemStack stack : maps)
buf.writeInt(mapDataList.size());
for (final MapItemSavedData mapData : mapDataList)
{
final MapItemSavedData mapData = MapItem.getSavedData(stack, level);
if(mapData != null)
{
buf.writeNbt(mapData.save(new CompoundTag()));
}
buf.writeNbt(mapData.save(new CompoundTag()));
}
}

Expand Down

0 comments on commit d1c4b76

Please # to comment.