Search in sources :

Example 1 with BlockArea

use of org.terasology.engine.world.block.BlockArea in project Terasology by MovingBlocks.

the class BlockAreaTypeHandler method deserialize.

@Override
public Optional<BlockArea> deserialize(PersistedData data) {
    if (!data.isNull() && data.isValueMap()) {
        PersistedDataMap map = data.getAsValueMap();
        PersistedDataArray minDataArr = map.get(MIN_FIELD).getAsArray();
        TIntList minArr = minDataArr.getAsIntegerArray();
        if (map.has(SIZE_FIELD)) {
            PersistedDataArray sizedataArray = map.get(SIZE_FIELD).getAsArray();
            TIntList sizeArr = sizedataArray.getAsIntegerArray();
            return Optional.of(new BlockArea(minArr.get(0), minArr.get(1)).setSize(sizeArr.get(0), sizeArr.get(1)));
        }
        PersistedDataArray maxDataArr = map.get(MAX_FIELD).getAsArray();
        TIntList maxArr = maxDataArr.getAsIntegerArray();
        return Optional.of(new BlockArea(minArr.get(0), minArr.get(1), maxArr.get(0), maxArr.get(1)));
    }
    return Optional.empty();
}
Also used : BlockArea(org.terasology.engine.world.block.BlockArea) PersistedDataArray(org.terasology.persistence.typeHandling.PersistedDataArray) PersistedDataMap(org.terasology.persistence.typeHandling.PersistedDataMap) TIntList(gnu.trove.list.TIntList)

Example 2 with BlockArea

use of org.terasology.engine.world.block.BlockArea in project Terasology by MovingBlocks.

the class BlockAreaTypeHandlerTest method testGsonSerialization.

@Test
public void testGsonSerialization() throws IOException {
    TestObject a = new TestObject();
    a.b1 = new BlockArea(-1, -1, 0, 0);
    a.b2 = new BlockArea(0, 0, 1, 1);
    byte[] data = gsonSerializer.serialize(a, new TypeInfo<TestObject>() {
    }).get();
    TestObject o = gsonSerializer.deserialize(new TypeInfo<TestObject>() {
    }, data).get();
    assertEquals(new BlockArea(-1, -1, 0, 0), o.b1);
    assertEquals(new BlockArea(0, 0, 1, 1), o.b2);
}
Also used : BlockArea(org.terasology.engine.world.block.BlockArea) TypeInfo(org.terasology.reflection.TypeInfo) Test(org.junit.jupiter.api.Test) ModuleEnvironmentTest(org.terasology.engine.ModuleEnvironmentTest)

Example 3 with BlockArea

use of org.terasology.engine.world.block.BlockArea in project Terasology by MovingBlocks.

the class BlockAreacTypeHandler method deserialize.

@Override
public Optional<BlockAreac> deserialize(PersistedData data) {
    if (!data.isNull() && data.isValueMap()) {
        PersistedDataMap map = data.getAsValueMap();
        PersistedDataArray minDataArr = map.get(MIN_FIELD).getAsArray();
        TIntList minArr = minDataArr.getAsIntegerArray();
        if (map.has(SIZE_FIELD)) {
            PersistedDataArray sizedataArray = map.get(SIZE_FIELD).getAsArray();
            TIntList sizeArr = sizedataArray.getAsIntegerArray();
            return Optional.of(new BlockArea(minArr.get(0), minArr.get(1)).setSize(sizeArr.get(0), sizeArr.get(1)));
        }
        PersistedDataArray maxDataArr = map.get(MAX_FIELD).getAsArray();
        TIntList maxArr = maxDataArr.getAsIntegerArray();
        return Optional.of(new BlockArea(minArr.get(0), minArr.get(1), maxArr.get(0), maxArr.get(1)));
    }
    return Optional.empty();
}
Also used : BlockArea(org.terasology.engine.world.block.BlockArea) PersistedDataArray(org.terasology.persistence.typeHandling.PersistedDataArray) PersistedDataMap(org.terasology.persistence.typeHandling.PersistedDataMap) TIntList(gnu.trove.list.TIntList)

Example 4 with BlockArea

use of org.terasology.engine.world.block.BlockArea in project Terasology by MovingBlocks.

the class SubSampledNoise method noise.

public float[] noise(BlockAreac area, float scale) {
    BlockArea fullRegion = determineRequiredRegion(area);
    float[] keyData = getKeyValues(fullRegion, scale);
    float[] fullData = mapExpand(keyData, fullRegion);
    return getSubset(fullData, fullRegion, area);
}
Also used : BlockArea(org.terasology.engine.world.block.BlockArea)

Aggregations

BlockArea (org.terasology.engine.world.block.BlockArea)4 TIntList (gnu.trove.list.TIntList)2 PersistedDataArray (org.terasology.persistence.typeHandling.PersistedDataArray)2 PersistedDataMap (org.terasology.persistence.typeHandling.PersistedDataMap)2 Test (org.junit.jupiter.api.Test)1 ModuleEnvironmentTest (org.terasology.engine.ModuleEnvironmentTest)1 TypeInfo (org.terasology.reflection.TypeInfo)1