Search in sources :

Example 41 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testGetTemporaryBlockSendsNoEvent.

@Test
public void testGetTemporaryBlockSendsNoEvent() {
    BlockEventChecker checker = new BlockEventChecker();
    entityManager.getEventSystem().registerEventHandler(checker);
    EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i());
    assertTrue(blockEntity.exists());
    assertFalse(checker.addedReceived);
    assertFalse(checker.activateReceived);
    assertFalse(checker.deactivateReceived);
    assertFalse(checker.removedReceived);
}
Also used : Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 42 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testNetworkComponentRemovedWhenTemporaryCleanedUp.

@Test
public void testNetworkComponentRemovedWhenTemporaryCleanedUp() {
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new RetainedOnBlockChangeComponent(2));
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), NetworkComponent.class);
    entity.removeComponent(RetainedOnBlockChangeComponent.class);
    worldProvider.update(1.0f);
    assertEquals(Lists.newArrayList(new EventInfo(BeforeDeactivateComponent.newInstance(), entity), new EventInfo(BeforeRemoveComponent.newInstance(), entity)), checker.receivedEvents);
}
Also used : RetainedOnBlockChangeComponent(org.terasology.unittest.stubs.RetainedOnBlockChangeComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 43 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testComponentsAddedAndActivatedWhenBlockChanged.

@Disabled("Failing due to #2625. TODO: fix to match new behaviour")
@Test
public void testComponentsAddedAndActivatedWhenBlockChanged() {
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);
    worldProvider.setBlock(new Vector3i(), blockWithString);
    EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i());
    assertTrue(blockEntity.exists());
    assertEquals(Lists.newArrayList(new EventInfo(OnAddedComponent.newInstance(), blockEntity), new EventInfo(OnActivatedComponent.newInstance(), blockEntity)), checker.receivedEvents);
}
Also used : Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 44 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class CharacterSystem method onAttackRequest.

@ReceiveEvent(components = LocationComponent.class, netFilter = RegisterMode.AUTHORITY)
public void onAttackRequest(AttackRequest event, EntityRef character, CharacterComponent characterComponent) {
    // if an item is used,  make sure this entity is allowed to attack with it
    if (event.getItem().exists()) {
        if (!character.equals(event.getItem().getOwner())) {
            return;
        }
    }
    OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
    character.send(onItemUseEvent);
    if (!onItemUseEvent.isConsumed()) {
        EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(character);
        LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class);
        Vector3f direction = gazeLocation.getWorldDirection(new Vector3f());
        Vector3f originPos = gazeLocation.getWorldPosition(new Vector3f());
        if (recordAndReplayCurrentStatus.getStatus() == RecordAndReplayStatus.RECORDING) {
            directionAndOriginPosRecorderList.getAttackEventDirectionAndOriginPosRecorder().add(direction, originPos);
        } else if (recordAndReplayCurrentStatus.getStatus() == RecordAndReplayStatus.REPLAYING) {
            Vector3f[] data = directionAndOriginPosRecorderList.getAttackEventDirectionAndOriginPosRecorder().poll();
            direction = data[0];
            originPos = data[1];
        }
        HitResult result = physics.rayTrace(originPos, direction, characterComponent.interactionRange, Sets.newHashSet(character), DEFAULTPHYSICSFILTER);
        if (result.isHit()) {
            result.getEntity().send(new AttackEvent(character, event.getItem()));
        }
    }
}
Also used : HitResult(org.terasology.engine.physics.HitResult) OnItemUseEvent(org.terasology.engine.logic.characters.events.OnItemUseEvent) Vector3f(org.joml.Vector3f) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) AttackEvent(org.terasology.engine.logic.characters.events.AttackEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 45 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class CharacterSystem method getPlayerNameFromCharacter.

private String getPlayerNameFromCharacter(EntityRef character) {
    CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
    if (characterComponent == null) {
        return "?";
    }
    EntityRef controller = characterComponent.controller;
    ClientComponent clientComponent = controller.getComponent(ClientComponent.class);
    EntityRef clientInfo = clientComponent.clientInfo;
    DisplayNameComponent displayNameComponent = clientInfo.getComponent(DisplayNameComponent.class);
    if (displayNameComponent == null) {
        return "?";
    }
    return displayNameComponent.name;
}
Also used : DisplayNameComponent(org.terasology.engine.logic.common.DisplayNameComponent) PlayerCharacterComponent(org.terasology.engine.logic.players.PlayerCharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent)

Aggregations

EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)298 Test (org.junit.jupiter.api.Test)88 ClientComponent (org.terasology.engine.network.ClientComponent)55 Vector3f (org.joml.Vector3f)51 LocationComponent (org.terasology.engine.logic.location.LocationComponent)44 Vector3i (org.joml.Vector3i)36 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)34 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)29 StringComponent (org.terasology.unittest.stubs.StringComponent)26 NetworkComponent (org.terasology.engine.network.NetworkComponent)23 EntityData (org.terasology.protobuf.EntityData)23 Quaternionf (org.joml.Quaternionf)19 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)19 Component (org.terasology.gestalt.entitysystem.component.Component)19 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)15 Map (java.util.Map)14 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)13 BlockComponent (org.terasology.engine.world.block.BlockComponent)13 Block (org.terasology.engine.world.block.Block)11 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)10