use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class BlockRegionTypeHandlerTest method testSerializeBlockRegion.
@Test
public void testSerializeBlockRegion() {
AABBBlockRegion1Test aabb1 = new AABBBlockRegion1Test();
aabb1.a1 = new BlockRegion(5, 5, 5, 13, 12, 14);
aabb1.a2 = new AABBi(3, 5, 5, 22, 12, 14);
JsonElement tree = gson.toJsonTree(aabb1);
JsonObject obj = tree.getAsJsonObject();
assertTrue(obj.has("a1"));
assertBlockRegion(obj.get("a1"), 5, 5, 5, 13, 12, 14);
assertTrue(obj.has("a2"));
assertAABBi(obj.get("a2"), 3, 5, 5, 22, 12, 14);
}
use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class BlockRegionTypeHandler method deserialize.
@Override
public Optional<BlockRegion> 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 BlockRegion(minArr.get(0), minArr.get(1), minArr.get(2), minArr.get(0) + sizeArr.get(0) - 1, minArr.get(1) + sizeArr.get(1) - 1, minArr.get(2) + sizeArr.get(2) - 1));
}
PersistedDataArray maxDataArr = map.get(MAX_FIELD).getAsArray();
TIntList maxArr = maxDataArr.getAsIntegerArray();
return Optional.of(new BlockRegion(minArr.get(0), minArr.get(1), minArr.get(2), maxArr.get(0), maxArr.get(1), maxArr.get(2)));
}
return Optional.empty();
}
use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class EntityAwareWorldProvider method onBlockRegionDeactivated.
@ReceiveEvent(components = BlockRegionComponent.class)
public void onBlockRegionDeactivated(BeforeDeactivateComponent event, EntityRef entity) {
BlockRegion oldRegion = blockRegions.get(entity);
for (Vector3ic pos : oldRegion) {
blockRegionLookup.remove(pos);
}
blockRegions.remove(entity);
}
use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class BlockSelectionSystem method onStartSelectionAtEntity.
@ReceiveEvent
public void onStartSelectionAtEntity(SetBlockSelectionStartingPointEvent event, EntityRef entity, LocationComponent locationComponent) {
if (null == locationComponent) {
// entity isn't LocationComponent, which shouldn't ever be the case
return;
}
BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
if (null == blockSelectionComponent) {
// event did not provide a BlockSelection component to modify
return;
}
Vector3i startPosition = new Vector3i(locationComponent.getWorldPosition(new Vector3f()), RoundingMode.FLOOR);
blockSelectionComponent.startPosition = startPosition;
blockSelectionComponent.currentSelection = new BlockRegion(startPosition);
}
use of org.terasology.engine.world.block.BlockRegion in project Terasology by MovingBlocks.
the class AbstractFullWorldView method setValueAt.
@Override
public void setValueAt(Vector3ic pos, byte value) {
setValueAt(getChunk(pos), Chunks.toRelative(pos, new Vector3i()), value);
BlockRegion chunkRegion = new BlockRegion(pos).expand(1, 1, 1);
for (Vector3ic affectedChunkPos : Chunks.toChunkRegion(chunkRegion, chunkRegion)) {
Chunk dirtiedChunk = chunkProvider.getChunk(affectedChunkPos);
if (dirtiedChunk != null) {
dirtiedChunk.setDirty(true);
}
}
}
Aggregations