use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method testMoveItemToSlotsWithToLessSpaceInTargetSlots.
@Test
public void testMoveItemToSlotsWithToLessSpaceInTargetSlots() {
int stackSize = 10;
EntityRef toInventory = inventory;
InventoryComponent toInventoryComp = toInventory.getComponent(InventoryComponent.class);
EntityRef itemA1 = createItem("A", 8, stackSize);
EntityRef itemB1 = createItem("B", 8, stackSize);
EntityRef itemA2 = createItem("A", 7, stackSize);
toInventoryComp.itemSlots.set(0, itemA1);
toInventoryComp.itemSlots.set(2, itemB1);
toInventoryComp.itemSlots.set(3, itemA2);
EntityRef fromInventory = Mockito.mock(EntityRef.class);
InventoryComponent fromInventoryComp = new InventoryComponent(5);
Mockito.when(fromInventory.getComponent(InventoryComponent.class)).thenReturn(fromInventoryComp);
EntityRef itemA3 = createItem("A", 4, stackSize);
int fromSlot = 1;
fromInventoryComp.itemSlots.set(fromSlot, itemA3);
List<Integer> toSlots = Arrays.asList(0, 2);
// The method that gets tested:
boolean result = inventoryAuthoritySystem.moveItemToSlots(instigator, fromInventory, fromSlot, toInventory, toSlots);
assertTrue(result);
assertEquals(10, itemA1.getComponent(ItemComponent.class).stackCount);
assertEquals(7, itemA2.getComponent(ItemComponent.class).stackCount);
assertEquals(2, itemA3.getComponent(ItemComponent.class).stackCount);
assertEquals(itemA3, fromInventoryComp.itemSlots.get(fromSlot));
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method testMoveItemToSlotsWithSplittingToMultipleStacks.
@Test
public void testMoveItemToSlotsWithSplittingToMultipleStacks() {
int stackSize = 10;
EntityRef toInventory = inventory;
InventoryComponent toInventoryComp = toInventory.getComponent(InventoryComponent.class);
EntityRef itemA1 = createItem("A", 8, stackSize);
EntityRef itemB1 = createItem("B", 8, stackSize);
EntityRef itemA2 = createItem("A", 7, stackSize);
toInventoryComp.itemSlots.set(0, itemA1);
toInventoryComp.itemSlots.set(2, itemB1);
toInventoryComp.itemSlots.set(3, itemA2);
EntityRef fromInventory = Mockito.mock(EntityRef.class);
InventoryComponent fromInventoryComp = new InventoryComponent(5);
Mockito.when(fromInventory.getComponent(InventoryComponent.class)).thenReturn(fromInventoryComp);
EntityRef itemA3 = createItem("A", 4, stackSize);
int fromSlot = 1;
fromInventoryComp.itemSlots.set(fromSlot, itemA3);
List<Integer> toSlots = Arrays.asList(0, 1, 2, 3, 4);
// The method that gets tested:
inventoryAuthoritySystem.moveItemToSlots(instigator, fromInventory, fromSlot, toInventory, toSlots);
assertEquals(10, itemA1.getComponent(ItemComponent.class).stackCount);
assertEquals(9, itemA2.getComponent(ItemComponent.class).stackCount);
assertFalse(fromInventoryComp.itemSlots.get(fromSlot).exists());
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method testMoveItemToSlotsWithSplittingToMultipleStacksAndEmptySlot.
@Test
public void testMoveItemToSlotsWithSplittingToMultipleStacksAndEmptySlot() {
int stackSize = 10;
EntityRef toInventory = inventory;
InventoryComponent toInventoryComp = toInventory.getComponent(InventoryComponent.class);
EntityRef itemA1 = createItem("A", 8, stackSize);
EntityRef itemB1 = createItem("B", 8, stackSize);
EntityRef itemA2 = createItem("A", 7, stackSize);
toInventoryComp.itemSlots.set(0, itemA1);
toInventoryComp.itemSlots.set(2, itemB1);
toInventoryComp.itemSlots.set(3, itemA2);
EntityRef fromInventory = Mockito.mock(EntityRef.class);
InventoryComponent fromInventoryComp = new InventoryComponent(5);
Mockito.when(fromInventory.getComponent(InventoryComponent.class)).thenReturn(fromInventoryComp);
EntityRef itemA3 = createItem("A", 8, stackSize);
int fromSlot = 1;
fromInventoryComp.itemSlots.set(fromSlot, itemA3);
List<Integer> toSlots = Arrays.asList(0, 1, 2, 3, 4);
// The method that gets tested:
inventoryAuthoritySystem.moveItemToSlots(instigator, fromInventory, fromSlot, toInventory, toSlots);
assertEquals(10, itemA1.getComponent(ItemComponent.class).stackCount);
assertEquals(10, itemA2.getComponent(ItemComponent.class).stackCount);
assertEquals(3, itemA3.getComponent(ItemComponent.class).stackCount);
assertEquals(itemA3, toInventoryComp.itemSlots.get(1));
assertFalse(fromInventoryComp.itemSlots.get(fromSlot).exists());
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method testMoveItemToSlotsWithRemovalVeto.
/**
* A shift click isn't possible because the removal of the item gets blocked
*/
@Test
public void testMoveItemToSlotsWithRemovalVeto() {
int stackSize = 10;
EntityRef toInventory = inventory;
InventoryComponent toInventoryComp = toInventory.getComponent(InventoryComponent.class);
EntityRef itemA1 = createItem("A", 8, stackSize);
toInventoryComp.itemSlots.set(0, itemA1);
EntityRef fromInventory = Mockito.mock(EntityRef.class);
InventoryComponent fromInventoryComp = new InventoryComponent(5);
Mockito.when(fromInventory.getComponent(InventoryComponent.class)).thenReturn(fromInventoryComp);
EntityRef itemA2 = createItem("A", 5, stackSize);
int fromSlot = 1;
fromInventoryComp.itemSlots.set(fromSlot, itemA2);
// Placement to slots 1 gets blocked by veto
Mockito.when(fromInventory.send(any(BeforeItemRemovedFromInventory.class))).then(invocation -> {
Object arg = invocation.getArguments()[0];
if (arg instanceof BeforeItemRemovedFromInventory) {
BeforeItemRemovedFromInventory event = (BeforeItemRemovedFromInventory) arg;
if (event.getSlot() == 1) {
event.consume();
}
}
return null;
});
List<Integer> toSlots = Arrays.asList(0, 1, 2, 3, 4);
// The method that gets tested:
boolean result = inventoryAuthoritySystem.moveItemToSlots(instigator, fromInventory, fromSlot, toInventory, toSlots);
assertFalse(result);
assertEquals(8, itemA1.getComponent(ItemComponent.class).stackCount);
assertEquals(5, itemA2.getComponent(ItemComponent.class).stackCount);
assertEquals(EntityRef.NULL, toInventoryComp.itemSlots.get(1));
assertEquals(itemA2, fromInventoryComp.itemSlots.get(fromSlot));
}
use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.
the class InventoryAuthoritySystemTest method testMoveItemToSlotsWithFullTargetInventorySlots.
@Test
public void testMoveItemToSlotsWithFullTargetInventorySlots() {
int stackSize = 10;
EntityRef toInventory = inventory;
InventoryComponent toInventoryComp = toInventory.getComponent(InventoryComponent.class);
EntityRef itemA1 = createItem("A", 10, stackSize);
EntityRef itemB1 = createItem("B", 8, stackSize);
EntityRef itemA2 = createItem("A", 10, stackSize);
toInventoryComp.itemSlots.set(0, itemA1);
toInventoryComp.itemSlots.set(1, itemB1);
toInventoryComp.itemSlots.set(2, itemA2);
EntityRef fromInventory = Mockito.mock(EntityRef.class);
InventoryComponent fromInventoryComp = new InventoryComponent(5);
Mockito.when(fromInventory.getComponent(InventoryComponent.class)).thenReturn(fromInventoryComp);
EntityRef itemA3 = createItem("A", 4, stackSize);
int fromSlot = 1;
fromInventoryComp.itemSlots.set(fromSlot, itemA3);
List<Integer> toSlots = Arrays.asList(0, 1, 2);
// The method that gets tested:
boolean result = inventoryAuthoritySystem.moveItemToSlots(instigator, fromInventory, fromSlot, toInventory, toSlots);
assertFalse(result);
assertEquals(10, itemA1.getComponent(ItemComponent.class).stackCount);
assertEquals(10, itemA2.getComponent(ItemComponent.class).stackCount);
assertEquals(4, itemA3.getComponent(ItemComponent.class).stackCount);
assertEquals(itemA3, fromInventoryComp.itemSlots.get(fromSlot));
}
Aggregations