Search in sources :

Example 1 with IntegerComponent

use of org.terasology.entitySystem.stubs.IntegerComponent in project Terasology by MovingBlocks.

the class EntitySerializerTest method testDeltaAddNewComponent.

@Test
public void testDeltaAddNewComponent() throws Exception {
    EntityRef entity = entityManager.create(prefab);
    entity.addComponent(new IntegerComponent(1));
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    assertEquals(entity.getId(), entityData.getId());
    assertEquals(prefab.getName(), entityData.getParentPrefab());
    assertEquals(1, entityData.getComponentCount());
    assertEquals(0, entityData.getRemovedComponentCount());
    EntityData.Component componentData = entityData.getComponent(0);
    assertEquals("test:integer", componentData.getType());
    assertEquals(1, componentData.getFieldCount());
    EntityData.NameValue field = componentData.getField(0);
    assertEquals("value", field.getName());
    assertEquals(1, field.getValue().getInteger(0));
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 2 with IntegerComponent

use of org.terasology.entitySystem.stubs.IntegerComponent in project Terasology by MovingBlocks.

the class ByteCodeReflectFactoryTest method testAccessIntegerField.

@Test
public void testAccessIntegerField() throws Exception {
    ReflectFactory reflectFactory = new ByteCodeReflectFactory();
    FieldAccessor fieldAccessor = reflectFactory.createFieldAccessor(IntegerComponent.class, IntegerComponent.class.getDeclaredField("value"));
    IntegerComponent comp = new IntegerComponent();
    fieldAccessor.setValue(comp, 1);
    assertEquals(1, fieldAccessor.getValue(comp));
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) Test(org.junit.Test)

Example 3 with IntegerComponent

use of org.terasology.entitySystem.stubs.IntegerComponent in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testComponentUntouchedIfRetainRequested.

@Test
public void testComponentUntouchedIfRetainRequested() {
    worldProvider.setBlock(Vector3i.zero(), blockInFamilyOne);
    EntityRef entity = worldProvider.getBlockEntityAt(Vector3i.zero());
    entity.addComponent(new IntegerComponent());
    worldProvider.setBlockRetainComponent(Vector3i.zero(), blockWithString, IntegerComponent.class);
    assertNotNull(entity.getComponent(IntegerComponent.class));
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 4 with IntegerComponent

use of org.terasology.entitySystem.stubs.IntegerComponent in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testComponentsAlteredIfBlockInSameFamilyWhenForced.

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

Example 5 with IntegerComponent

use of org.terasology.entitySystem.stubs.IntegerComponent in project Terasology by MovingBlocks.

the class EntityAwareWorldProviderTest method testComponentsNotAlteredIfBlockInSameFamily.

@Test
public void testComponentsNotAlteredIfBlockInSameFamily() {
    worldProvider.setBlock(Vector3i.zero(), blockInFamilyOne);
    EntityRef entity = worldProvider.getBlockEntityAt(Vector3i.zero());
    entity.addComponent(new IntegerComponent());
    worldProvider.setBlock(Vector3i.zero(), blockInFamilyTwo);
    assertNotNull(entity.getComponent(IntegerComponent.class));
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 IntegerComponent (org.terasology.entitySystem.stubs.IntegerComponent)14 EntityRef (org.terasology.entitySystem.entity.EntityRef)8 StringComponent (org.terasology.entitySystem.stubs.StringComponent)6 SimpleUri (org.terasology.engine.SimpleUri)2 EntityData (org.terasology.protobuf.EntityData)2 Vector3i (org.terasology.math.geom.Vector3i)1