Search in sources :

Example 91 with EntityRef

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);
}
Also used : InventoryManager(org.terasology.logic.inventory.InventoryManager) LocalPlayer(org.terasology.logic.players.LocalPlayer) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 92 with EntityRef

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());
}
Also used : InventoryManager(org.terasology.logic.inventory.InventoryManager) LocalPlayer(org.terasology.logic.players.LocalPlayer) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 93 with EntityRef

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());
}
Also used : InventorySlotStackSizeChangedEvent(org.terasology.logic.inventory.events.InventorySlotStackSizeChangedEvent) RemoveItemAction(org.terasology.logic.inventory.action.RemoveItemAction) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 94 with EntityRef

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);
}
Also used : BeforeItemRemovedFromInventory(org.terasology.logic.inventory.events.BeforeItemRemovedFromInventory) RemoveItemAction(org.terasology.logic.inventory.action.RemoveItemAction) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 95 with EntityRef

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());
}
Also used : InventorySlotStackSizeChangedEvent(org.terasology.logic.inventory.events.InventorySlotStackSizeChangedEvent) BeforeItemPutInInventory(org.terasology.logic.inventory.events.BeforeItemPutInInventory) GiveItemAction(org.terasology.logic.inventory.action.GiveItemAction) EntityRef(org.terasology.entitySystem.entity.EntityRef) InventorySlotChangedEvent(org.terasology.logic.inventory.events.InventorySlotChangedEvent) Test(org.junit.Test)

Aggregations

EntityRef (org.terasology.entitySystem.entity.EntityRef)337 Test (org.junit.Test)106 ClientComponent (org.terasology.network.ClientComponent)49 LocationComponent (org.terasology.logic.location.LocationComponent)45 Vector3f (org.terasology.math.geom.Vector3f)44 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)36 Vector3i (org.terasology.math.geom.Vector3i)34 Command (org.terasology.logic.console.commandSystem.annotations.Command)28 StringComponent (org.terasology.entitySystem.stubs.StringComponent)26 NetworkComponent (org.terasology.network.NetworkComponent)21 EntityData (org.terasology.protobuf.EntityData)21 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)17 Block (org.terasology.world.block.Block)16 Component (org.terasology.entitySystem.Component)15 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)15 CharacterComponent (org.terasology.logic.characters.CharacterComponent)14 Quat4f (org.terasology.math.geom.Quat4f)14 BlockComponent (org.terasology.world.block.BlockComponent)13 Map (java.util.Map)11 LocalPlayer (org.terasology.logic.players.LocalPlayer)11