Skip to content

Commit e0a85fa

Browse files
committedSep 17, 2019
Inventory: Undo prediction on drop
1 parent 1db3d25 commit e0a85fa

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
 

Diff for: ‎src/inventorymanager.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,6 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
646646
if (src_can_take_count != -1 && src_can_take_count < take_count)
647647
take_count = src_can_take_count;
648648

649-
int actually_dropped_count = 0;
650-
651649
// Update item due executed callbacks
652650
src_item = list_from->getItem(from_i);
653651

@@ -656,10 +654,12 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
656654
item1.count = take_count;
657655
if(PLAYER_TO_SA(player)->item_OnDrop(item1, player,
658656
player->getBasePosition())) {
659-
actually_dropped_count = take_count - item1.count;
657+
int actually_dropped_count = take_count - item1.count;
660658

661659
if (actually_dropped_count == 0) {
662660
infostream<<"Actually dropped no items"<<std::endl;
661+
// Revert client prediction
662+
mgr->setInventoryModified(from_inv);
663663
return;
664664
}
665665

@@ -670,9 +670,10 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
670670

671671
if (item2.count != actually_dropped_count)
672672
errorstream<<"Could not take dropped count of items"<<std::endl;
673-
674-
mgr->setInventoryModified(from_inv);
675673
}
674+
675+
src_item.count = actually_dropped_count;
676+
mgr->setInventoryModified(from_inv);
676677
}
677678

678679
infostream<<"IDropAction::apply(): dropped "
@@ -681,7 +682,6 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
681682
<<" i="<<from_i
682683
<<std::endl;
683684

684-
src_item.count = actually_dropped_count;
685685

686686
/*
687687
Report drop to endpoints

Diff for: ‎src/server.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,7 @@ void Server::setInventoryModified(const InventoryLocation &loc)
11511151
return;
11521152

11531153
player->setModified(true);
1154+
player->inventory.setModified(true);
11541155
// Updates are sent in ServerEnvironment::step()
11551156
}
11561157
break;

0 commit comments

Comments
 (0)