Search in sources :

Example 6 with EntityRef

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

the class AnatomyScreenWindow method onOpened.

@Override
public void onOpened() {
    EntityRef characterEntity = CoreRegistry.get(LocalPlayer.class).getCharacterEntity();
    CharacterComponent characterComponent = characterEntity.getComponent(CharacterComponent.class);
    // In case the player has been created yet, exit out early to prevent an error.
    if (characterComponent == null) {
        return;
    }
    // erroneously marked as existent.
    if (!player.exists() || (player.exists() && (player == EntityRef.NULL || player.getId() == 0 || player == null))) {
        reInit();
    }
    // As long as there's an interaction target, open this window.
    if (getInteractionTarget() != EntityRef.NULL) {
        initializeWithInteractionTarget(getInteractionTarget());
        super.onOpened();
    }
    // Every time the character screen window is opened, update the Anatomy part statuses.
    updateStatuses();
}
Also used : LocalPlayer(org.terasology.engine.logic.players.LocalPlayer) CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 7 with EntityRef

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

the class EntitySerializerTest method testScopePersisted.

@Test
public void testScopePersisted() {
    EntityRef entity = entityManager.create(prefab);
    for (EntityScope scope : EntityScope.values()) {
        entity.setScope(scope);
        entity = serializeDeserializeEntity(entity);
        assertEquals(scope, entity.getScope());
    }
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) EntityScope(org.terasology.engine.entitySystem.entity.internal.EntityScope) Test(org.junit.jupiter.api.Test)

Example 8 with EntityRef

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

the class EntitySerializerTest method testDeltaLoadNoChange.

@Test
public void testDeltaLoadNoChange() throws Exception {
    EntityRef entity = entityManager.create("test:Test");
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    long nextId = entityManager.getNextId();
    entityManager.clear();
    entityManager.setNextId(nextId);
    EntityRef loadedEntity = entitySerializer.deserialize(entityData);
    assertTrue(loadedEntity.exists());
    assertTrue(loadedEntity.hasComponent(StringComponent.class));
    assertEquals("Value", loadedEntity.getComponent(StringComponent.class).value);
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 9 with EntityRef

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

the class EntitySerializerTest method testDeltaLoadChangedComponent.

@Test
public void testDeltaLoadChangedComponent() throws Exception {
    EntityRef entity = entityManager.create("test:Test");
    StringComponent comp = entity.getComponent(StringComponent.class);
    comp.value = "Delta";
    entity.saveComponent(comp);
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    long nextId = entityManager.getNextId();
    entityManager.clear();
    entityManager.setNextId(nextId);
    EntityRef loadedEntity = entitySerializer.deserialize(entityData);
    assertTrue(loadedEntity.exists());
    assertTrue(loadedEntity.hasComponent(StringComponent.class));
    assertEquals("Delta", loadedEntity.getComponent(StringComponent.class).value);
}
Also used : StringComponent(org.terasology.unittest.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 10 with EntityRef

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

the class EntitySerializerTest method testDeltaNoUnchangedComponents.

@Test
public void testDeltaNoUnchangedComponents() throws Exception {
    EntityRef entity = entityManager.create(prefab);
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    assertEquals(entity.getId(), entityData.getId());
    assertEquals(prefab.getName(), entityData.getParentPrefab());
    assertEquals(0, entityData.getComponentCount());
    assertEquals(0, entityData.getRemovedComponentCount());
}
Also used : EntityData(org.terasology.protobuf.EntityData) 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