use of org.terasology.logic.inventory.events.MoveItemRequest in project Terasology by MovingBlocks.
the class InventoryClientSystem method switchItem.
@Override
public boolean switchItem(EntityRef fromInventory, EntityRef instigator, int slotFrom, EntityRef toInventory, int slotTo) {
Collection<EntityRef> clientTempEntities = new HashSet<>();
if (moveItemFillClientTempEntities(fromInventory, instigator, slotFrom, toInventory, slotTo, clientTempEntities)) {
return false;
}
MoveItemRequest request = new MoveItemRequest(instigator, fromInventory, slotFrom, toInventory, slotTo, changeId++, clientTempEntities);
pendingMoves.put(request.getChangeId(), request);
localPlayer.getClientEntity().send(request);
return true;
}
use of org.terasology.logic.inventory.events.MoveItemRequest in project Terasology by MovingBlocks.
the class InventoryClientSystem method recalculatePredictedState.
private void recalculatePredictedState() {
for (AbstractMoveItemRequest request : pendingMoves.values()) {
// pending request is acknowledged by the server
if (request instanceof MoveItemRequest) {
MoveItemRequest r = (MoveItemRequest) request;
destroyClientTempEntities(r);
Collection<EntityRef> newClientTempEntities = new HashSet<>();
moveItemFillClientTempEntities(request.getFromInventory(), r.getInstigator(), r.getFromSlot(), r.getToInventory(), r.getToSlot(), newClientTempEntities);
r.setClientSideTempEntities(newClientTempEntities);
} else if (request instanceof MoveItemAmountRequest) {
MoveItemAmountRequest r = (MoveItemAmountRequest) request;
destroyClientTempEntities(r);
Collection<EntityRef> newClientTempEntities = new HashSet<>();
moveItemAmountFillClientTempEntities(r.getFromInventory(), r.getInstigator(), r.getFromSlot(), r.getToInventory(), r.getToSlot(), r.getAmount(), newClientTempEntities);
r.setClientSideTempEntities(newClientTempEntities);
} else if (request instanceof MoveItemToSlotsRequest) {
MoveItemToSlotsRequest r = (MoveItemToSlotsRequest) request;
destroyClientTempEntities(r);
Collection<EntityRef> newClientTempEntities = new HashSet<>();
moveItemToSlotsFillClientTempEntities(r.getInstigator(), r.getFromInventory(), r.getFromSlot(), r.getToInventory(), r.getToSlots(), newClientTempEntities);
r.setClientSideTempEntities(newClientTempEntities);
}
}
}
Aggregations