use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class InventoryCell method giveAmount.
private void giveAmount(int amount) {
EntityRef characterEntity = CoreRegistry.get(LocalPlayer.class).getCharacterEntity();
InventoryManager inventoryManager = CoreRegistry.get(InventoryManager.class);
inventoryManager.moveItem(getTargetInventory(), characterEntity, getTargetSlot(), getTransferEntity(), 0, amount);
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class InventoryCell method swapItem.
private void swapItem() {
EntityRef characterEntity = CoreRegistry.get(LocalPlayer.class).getCharacterEntity();
InventoryManager inventoryManager = CoreRegistry.get(InventoryManager.class);
inventoryManager.switchItem(getTransferEntity(), characterEntity, 0, getTargetInventory(), getTargetSlot());
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method removePartOfStackWithDestroy.
@Test
public void removePartOfStackWithDestroy() {
ItemComponent itemComp = new ItemComponent();
EntityRef item = Mockito.mock(EntityRef.class);
setupItemRef(item, itemComp, 2, 10);
inventoryComp.itemSlots.set(0, item);
RemoveItemAction action = new RemoveItemAction(instigator, item, true, 1);
inventoryAuthoritySystem.removeItem(action, inventory);
assertEquals(1, itemComp.stackCount);
Mockito.verify(item, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(item).saveComponent(itemComp);
Mockito.verify(inventory, atLeast(0)).getComponent(InventoryComponent.class);
Mockito.verify(inventory).send(any(InventorySlotStackSizeChangedEvent.class));
Mockito.verifyNoMoreInteractions(instigator, inventory, entityManager, item);
assertTrue(action.isConsumed());
assertNull(action.getRemovedItem());
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method removeWholeStackWithVeto.
@Test
public void removeWholeStackWithVeto() {
ItemComponent itemComp = new ItemComponent();
EntityRef item = Mockito.mock(EntityRef.class);
setupItemRef(item, itemComp, 2, 10);
inventoryComp.itemSlots.set(0, item);
Mockito.when(inventory.send(any(BeforeItemRemovedFromInventory.class))).then(invocation -> {
BeforeItemRemovedFromInventory event = (BeforeItemRemovedFromInventory) invocation.getArguments()[0];
event.consume();
return null;
});
RemoveItemAction action = new RemoveItemAction(instigator, item, true, 2);
inventoryAuthoritySystem.removeItem(action, inventory);
assertFalse(action.isConsumed());
assertNull(action.getRemovedItem());
Mockito.verify(item, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(item, atLeast(0)).exists();
Mockito.verify(inventory, atLeast(0)).getComponent(InventoryComponent.class);
Mockito.verify(inventory).send(any(BeforeItemRemovedFromInventory.class));
Mockito.verifyNoMoreInteractions(instigator, inventory, entityManager, item);
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method addItemToPartialAndOverflow.
@Test
public void addItemToPartialAndOverflow() {
ItemComponent itemComp = new ItemComponent();
EntityRef item = Mockito.mock(EntityRef.class);
setupItemRef(item, itemComp, 2, 10);
ItemComponent partialItemComp = new ItemComponent();
EntityRef partialItem = Mockito.mock(EntityRef.class);
setupItemRef(partialItem, partialItemComp, 9, 10);
inventoryComp.itemSlots.set(0, partialItem);
GiveItemAction action = new GiveItemAction(instigator, item);
inventoryAuthoritySystem.giveItem(action, inventory);
Mockito.verify(item, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(item, atLeast(0)).exists();
Mockito.verify(item, atLeast(0)).iterateComponents();
Mockito.verify(item).saveComponent(itemComp);
Mockito.verify(partialItem, atLeast(0)).getComponent(ItemComponent.class);
Mockito.verify(partialItem, atLeast(0)).exists();
Mockito.verify(partialItem, atLeast(0)).iterateComponents();
Mockito.verify(partialItem).saveComponent(partialItemComp);
Mockito.verify(inventory, atLeast(0)).getComponent(InventoryComponent.class);
Mockito.verify(inventory).saveComponent(inventoryComp);
Mockito.verify(inventory, times(1)).send(any(InventorySlotStackSizeChangedEvent.class));
Mockito.verify(inventory, times(1)).send(any(InventorySlotChangedEvent.class));
Mockito.verify(inventory, times(1)).send(any(BeforeItemPutInInventory.class));
Mockito.verifyNoMoreInteractions(instigator, inventory, entityManager, item, partialItem);
assertEquals(partialItem, inventoryComp.itemSlots.get(0));
assertEquals(item, inventoryComp.itemSlots.get(1));
assertEquals(10, partialItemComp.stackCount);
assertEquals(1, itemComp.stackCount);
assertTrue(action.isConsumed());
}
Aggregations