Tile Prediction: make refunds silent
This commit is contained in:
parent
caf7abebfe
commit
3534067801
@ -1153,12 +1153,13 @@ uint64_t Player::itemsCanHold(ItemPtr const& items) const {
|
||||
return m_inventory->itemsCanFit(items);
|
||||
}
|
||||
|
||||
ItemPtr Player::pickupItems(ItemPtr const& items) {
|
||||
ItemPtr Player::pickupItems(ItemPtr const& items, bool silent) {
|
||||
if (isDead() || !items || m_inventory->itemsCanFit(items) == 0)
|
||||
return items;
|
||||
|
||||
triggerPickupEvents(items);
|
||||
|
||||
if (!silent) {
|
||||
if (items->pickupSound().size()) {
|
||||
m_effectsAnimator->setSoundPool("pickup", {items->pickupSound()});
|
||||
float pitch = 1.f - ((float)items->count() / (float)items->maxStack()) * 0.5f;
|
||||
@ -1167,6 +1168,8 @@ ItemPtr Player::pickupItems(ItemPtr const& items) {
|
||||
}
|
||||
auto itemDb = Root::singleton().itemDatabase();
|
||||
queueItemPickupMessage(itemDb->itemShared(items->descriptor()));
|
||||
}
|
||||
|
||||
return m_inventory->addItems(items);
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ public:
|
||||
uint64_t itemsCanHold(ItemPtr const& items) const;
|
||||
// Adds items to the inventory, returning the overflow.
|
||||
// The items parameter is invalid after use.
|
||||
ItemPtr pickupItems(ItemPtr const& items);
|
||||
ItemPtr pickupItems(ItemPtr const& items, bool silent = false);
|
||||
// Pick up all of the given items as possible, dropping the overflow.
|
||||
// The item parameter is invalid after use.
|
||||
void giveItem(ItemPtr const& item);
|
||||
|
@ -214,6 +214,14 @@ ItemPtr PlayerInventory::addItems(ItemPtr items) {
|
||||
if (is<BackArmor>(items) && !backArmor())
|
||||
m_equipment[EquipmentSlot::Back] = items->take(1);
|
||||
|
||||
if (is<MaterialItem>(items)) {
|
||||
if (auto primary = primaryHeldItem()) {
|
||||
primary->stackWith(items);
|
||||
if (items->empty())
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
// Then, finally the bags
|
||||
return addToBags(std::move(items));
|
||||
}
|
||||
|
@ -573,23 +573,28 @@ void WorldClient::render(WorldRenderData& renderData, unsigned bufferTiles) {
|
||||
|
||||
renderTile.liquidId = clientTile.liquid.liquid;
|
||||
renderTile.liquidLevel = floatToByte(clientTile.liquid.level);
|
||||
});
|
||||
|
||||
if (!m_predictedTiles.empty()) {
|
||||
if (auto p = m_predictedTiles.ptr(position)) {
|
||||
if (p->liquid) {
|
||||
auto& liquid = *p->liquid;
|
||||
if (liquid.liquid == renderTile.liquidId)
|
||||
renderTile.liquidLevel = floatToByte(clientTile.liquid.level + liquid.level, true);
|
||||
for (auto& pair : m_predictedTiles) {
|
||||
Vec2I tileArrayPos = m_geometry.diff(pair.first, renderData.tileMinPosition);
|
||||
if (tileArrayPos[0] >= 0 && tileArrayPos[0] < (int)renderData.tiles.size(0) && tileArrayPos[1] >= 0 && tileArrayPos[1] < (int)renderData.tiles.size(1)) {
|
||||
RenderTile& renderTile = renderData.tiles(tileArrayPos[0], tileArrayPos[1]);
|
||||
PredictedTile& p = pair.second;
|
||||
if (p.liquid) {
|
||||
auto& liquid = *p.liquid;
|
||||
if (liquid.liquid == renderTile.liquidId) {
|
||||
uint8_t added = floatToByte(liquid.level, true);
|
||||
renderTile.liquidLevel = (renderTile.liquidLevel > 255 - added) ? 255 : renderTile.liquidLevel + added;
|
||||
}
|
||||
else {
|
||||
renderTile.liquidId = liquid.liquid;
|
||||
renderTile.liquidLevel = floatToByte(liquid.level, true);
|
||||
}
|
||||
}
|
||||
|
||||
p->apply(renderTile);
|
||||
pair.second.apply(renderTile);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (auto const& previewTile : previewTiles) {
|
||||
Vec2I tileArrayPos = m_geometry.diff(previewTile.position, renderData.tileMinPosition);
|
||||
@ -896,10 +901,10 @@ void WorldClient::handleIncomingPackets(List<PacketPtr> const& packets) {
|
||||
|
||||
if (auto placeMaterial = modification.second.ptr<PlaceMaterial>()) {
|
||||
auto stack = materialDatabase->materialItemDrop(placeMaterial->material);
|
||||
tryGiveMainPlayerItem(itemDatabase->item(stack));
|
||||
tryGiveMainPlayerItem(itemDatabase->item(stack), true);
|
||||
} else if (auto placeMod = modification.second.ptr<PlaceMod>()) {
|
||||
auto stack = materialDatabase->modItemDrop(placeMod->mod);
|
||||
tryGiveMainPlayerItem(itemDatabase->item(stack));
|
||||
tryGiveMainPlayerItem(itemDatabase->item(stack), true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1799,8 +1804,8 @@ void WorldClient::clearWorld() {
|
||||
m_forceRegions.clear();
|
||||
}
|
||||
|
||||
void WorldClient::tryGiveMainPlayerItem(ItemPtr item) {
|
||||
if (auto spill = m_mainPlayer->pickupItems(item))
|
||||
void WorldClient::tryGiveMainPlayerItem(ItemPtr item, bool silent) {
|
||||
if (auto spill = m_mainPlayer->pickupItems(item, silent))
|
||||
addEntity(ItemDrop::createRandomizedDrop(spill->descriptor(), m_mainPlayer->position()));
|
||||
}
|
||||
|
||||
|
@ -213,7 +213,7 @@ private:
|
||||
|
||||
void initWorld(WorldStartPacket const& packet);
|
||||
void clearWorld();
|
||||
void tryGiveMainPlayerItem(ItemPtr item);
|
||||
void tryGiveMainPlayerItem(ItemPtr item, bool silent = false);
|
||||
|
||||
void notifyEntityCreate(EntityPtr const& entity);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user