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;
}
Aggregations