More accurate liquid collection prediction

This commit is contained in:
Kae 2023-08-19 21:08:44 +10:00
parent d2ec7f37c1
commit 2fb2616384

View File

@ -1344,9 +1344,36 @@ void WorldClient::collectLiquid(List<Vec2I> const& tilePositions, LiquidId liqui
if (!inWorld()) if (!inWorld())
return; return;
TileModification modification = PlaceLiquid{ EmptyLiquidId, 0.0f }; float bucketSize = Root::singleton().assets()->json("/items/defaultParameters.config:liquidItems.bucketSize").toFloat();
for (auto& pos : tilePositions) unsigned drainedUnits = 0;
informTilePrediction(pos, modification); float nextUnit = bucketSize;
List<Vec2I> maybeDrainTiles;
for (auto& pos : tilePositions) {
if (isTileProtected(pos))
continue;
auto& p = m_predictedTiles[pos];
auto const& tile = m_tileArray->tile(pos);
if ((p.liquid ? p.liquid->liquid : tile.liquid.liquid) == liquidId) {
if (!p.liquid)
p.liquid.emplace(tile.liquid.liquid, tile.liquid.level);
auto& liquid = *p.liquid;
if (liquid.level >= nextUnit) {
liquid.take(nextUnit);
nextUnit = bucketSize;
for (auto& previousTile : maybeDrainTiles)
m_predictedTiles[pos].liquid.emplace(EmptyLiquidId, 0.0f);
maybeDrainTiles.clear();
}
if (liquid.level > 0) {
nextUnit -= liquid.level;
maybeDrainTiles.append(pos);
}
}
}
m_outgoingPackets.append(make_shared<CollectLiquidPacket>(tilePositions, liquidId)); m_outgoingPackets.append(make_shared<CollectLiquidPacket>(tilePositions, liquidId));
} }