Search in sources :

Example 1 with MoveItemAmountRequest

use of org.terasology.logic.inventory.events.MoveItemAmountRequest in project Terasology by MovingBlocks.

the class InventoryClientSystem method moveItem.

@Override
public boolean moveItem(EntityRef fromInventory, EntityRef instigator, int slotFrom, EntityRef toInventory, int slotTo, int count) {
    Collection<EntityRef> clientTempEntities = new HashSet<>();
    if (moveItemAmountFillClientTempEntities(fromInventory, instigator, slotFrom, toInventory, slotTo, count, clientTempEntities)) {
        return false;
    }
    MoveItemAmountRequest request = new MoveItemAmountRequest(instigator, fromInventory, slotFrom, toInventory, slotTo, count, changeId++, clientTempEntities);
    pendingMoves.put(request.getChangeId(), request);
    localPlayer.getClientEntity().send(request);
    return true;
}
Also used : MoveItemAmountRequest(org.terasology.logic.inventory.events.MoveItemAmountRequest) EntityRef(org.terasology.entitySystem.entity.EntityRef) HashSet(java.util.HashSet)

Example 2 with MoveItemAmountRequest

use of org.terasology.logic.inventory.events.MoveItemAmountRequest 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);
        }
    }
}
Also used : AbstractMoveItemRequest(org.terasology.logic.inventory.events.AbstractMoveItemRequest) MoveItemRequest(org.terasology.logic.inventory.events.MoveItemRequest) MoveItemToSlotsRequest(org.terasology.logic.inventory.events.MoveItemToSlotsRequest) MoveItemAmountRequest(org.terasology.logic.inventory.events.MoveItemAmountRequest) AbstractMoveItemRequest(org.terasology.logic.inventory.events.AbstractMoveItemRequest) Collection(java.util.Collection) EntityRef(org.terasology.entitySystem.entity.EntityRef) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 MoveItemAmountRequest (org.terasology.logic.inventory.events.MoveItemAmountRequest)2 Collection (java.util.Collection)1 AbstractMoveItemRequest (org.terasology.logic.inventory.events.AbstractMoveItemRequest)1 MoveItemRequest (org.terasology.logic.inventory.events.MoveItemRequest)1 MoveItemToSlotsRequest (org.terasology.logic.inventory.events.MoveItemToSlotsRequest)1