Search in sources :

Example 6 with BeforeItemRemovedFromInventory

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

the class InventoryUtils method validateMove.

private static boolean validateMove(EntityRef instigator, EntityRef from, int slotFrom, EntityRef to, int slotTo) {
    // Validate the move
    EntityRef itemFrom = InventoryUtils.getItemAt(from, slotFrom);
    EntityRef itemTo = InventoryUtils.getItemAt(to, slotTo);
    if (itemFrom.exists()) {
        BeforeItemRemovedFromInventory removeFrom = new BeforeItemRemovedFromInventory(instigator, itemFrom, slotFrom);
        from.send(removeFrom);
        if (removeFrom.isConsumed()) {
            return false;
        }
    }
    if (itemTo.exists()) {
        BeforeItemRemovedFromInventory removeTo = new BeforeItemRemovedFromInventory(instigator, itemTo, slotTo);
        to.send(removeTo);
        if (removeTo.isConsumed()) {
            return false;
        }
    }
    if (itemTo.exists()) {
        BeforeItemPutInInventory putFrom = new BeforeItemPutInInventory(instigator, itemTo, slotFrom);
        from.send(putFrom);
        if (putFrom.isConsumed()) {
            return false;
        }
    }
    if (itemFrom.exists()) {
        BeforeItemPutInInventory putTo = new BeforeItemPutInInventory(instigator, itemFrom, slotTo);
        to.send(putTo);
        if (putTo.isConsumed()) {
            return false;
        }
    }
    return true;
}
Also used : BeforeItemRemovedFromInventory(org.terasology.logic.inventory.events.BeforeItemRemovedFromInventory) BeforeItemPutInInventory(org.terasology.logic.inventory.events.BeforeItemPutInInventory) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Aggregations

BeforeItemRemovedFromInventory (org.terasology.logic.inventory.events.BeforeItemRemovedFromInventory)6 EntityRef (org.terasology.entitySystem.entity.EntityRef)4 Test (org.junit.Test)2 BeforeItemPutInInventory (org.terasology.logic.inventory.events.BeforeItemPutInInventory)2 RemoveItemAction (org.terasology.logic.inventory.action.RemoveItemAction)1