Search in sources :

Example 31 with EntityRef

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

the class EntityAwareWorldProvider method setBlockForceUpdateEntity.

@Override
public Block setBlockForceUpdateEntity(Vector3ic position, Block type) {
    if (GameThread.isCurrentThread()) {
        EntityRef blockEntity = getBlockEntityAt(position);
        Block oldType = super.setBlock(position, type);
        if (oldType != null) {
            updateBlockEntity(blockEntity, position, oldType, type, true, Collections.<Class<? extends Component>>emptySet());
        }
        return oldType;
    }
    return null;
}
Also used : OnChangedBlock(org.terasology.engine.world.OnChangedBlock) Block(org.terasology.engine.world.block.Block) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 32 with EntityRef

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

the class EntityAwareWorldProviderTest method testComponentsAlteredIfBlockInSameFamilyWhenForced.

@Test
public void testComponentsAlteredIfBlockInSameFamilyWhenForced() {
    worldProvider.setBlock(new Vector3i(), blockInFamilyOne);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.addComponent(new IntegerComponent());
    worldProvider.setBlockForceUpdateEntity(new Vector3i(), blockInFamilyTwo);
    assertNull(entity.getComponent(IntegerComponent.class));
}
Also used : IntegerComponent(org.terasology.unittest.stubs.IntegerComponent) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 33 with EntityRef

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

the class EntityAwareWorldProviderTest method testBlockEntityPrefabCorrectlyRemovedOnChangeToBlockWithNoPrefab.

@Disabled("Failing due to #2625. TODO: fix to match new behaviour")
@Test
public void testBlockEntityPrefabCorrectlyRemovedOnChangeToBlockWithNoPrefab() {
    worldProvider.setBlock(new Vector3i(), blockWithString);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    worldProvider.setBlock(new Vector3i(), plainBlock);
    assertEquals(null, entity.getParentPrefab());
}
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 34 with EntityRef

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

the class EntityAwareWorldProviderTest method testEntityMissingComponentsAddedBeforeCleanUp.

@Test
public void testEntityMissingComponentsAddedBeforeCleanUp() {
    worldStub.setBlock(new Vector3i(), blockWithString);
    EntityRef entity = worldProvider.getBlockEntityAt(new Vector3i());
    entity.removeComponent(StringComponent.class);
    LifecycleEventChecker checker = new LifecycleEventChecker(entityManager.getEventSystem(), StringComponent.class);
    worldProvider.update(1.0f);
    assertEquals(Lists.newArrayList(new EventInfo(OnAddedComponent.newInstance(), entity), new EventInfo(OnActivatedComponent.newInstance(), entity)), checker.receivedEvents);
}
Also used : Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 35 with EntityRef

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

the class EntityAwareWorldProviderTest method testEntityBecomesTemporaryWhenChangedFromAKeepActiveBlock.

@Test
public void testEntityBecomesTemporaryWhenChangedFromAKeepActiveBlock() {
    worldProvider.setBlock(new Vector3i(), keepActiveBlock);
    EntityRef blockEntity = worldProvider.getBlockEntityAt(new Vector3i());
    worldProvider.setBlock(new Vector3i(), airBlock);
    worldProvider.update(1.0f);
    assertFalse(blockEntity.isActive());
}
Also used : Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

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