use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.
the class StorageManagerTest method testEntitySurvivesStorageInChunkStore.
@Test
public void testEntitySurvivesStorageInChunkStore() throws Exception {
Chunk chunk = new ChunkImpl(CHUNK_POS, blockManager, extraDataManager);
chunk.setBlock(0, 0, 0, testBlock);
chunk.markReady();
ChunkProvider chunkProvider = mock(ChunkProvider.class);
when(chunkProvider.getAllChunks()).thenReturn(Arrays.asList(chunk));
CoreRegistry.put(ChunkProvider.class, chunkProvider);
EntityRef entity = entityManager.create();
long id = entity.getId();
LocationComponent locationComponent = new LocationComponent();
AABBfc aabb = chunk.getAABB();
Vector3f positionInChunk = new Vector3f(aabb.minX(), aabb.minY(), aabb.minZ());
positionInChunk.x += 1;
positionInChunk.y += 1;
positionInChunk.z += 1;
locationComponent.setWorldPosition(positionInChunk);
entity.addComponent(locationComponent);
esm.waitForCompletionOfPreviousSaveAndStartSaving();
esm.finishSavingAndShutdown();
EntitySystemSetupUtil.addReflectionBasedLibraries(context);
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
EngineEntityManager newEntityManager = context.get(EngineEntityManager.class);
StorageManager newSM = new ReadWriteStorageManager(savePath, moduleEnvironment, newEntityManager, blockManager, extraDataManager, false, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus);
newSM.loadGlobalStore();
ChunkStore restored = newSM.loadChunkStore(CHUNK_POS);
restored.restoreEntities();
EntityRef ref = newEntityManager.getEntity(id);
assertTrue(ref.exists());
assertTrue(ref.isActive());
}
use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.
the class LocalChunkView method getValueAt.
@Override
public byte getValueAt(Vector3ic pos) {
int index = chunkIndexOf(pos);
if (index < 0) {
return UNAVAILABLE;
}
Chunk chunk = chunks[index];
if (chunk != null) {
return rules.getValue(chunk, Chunks.toRelative(pos, new Vector3i()));
}
return UNAVAILABLE;
}
use of org.terasology.engine.world.chunks.Chunk 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);
}
}
}
use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.
the class ChunkViewCoreImpl method setDirtyAround.
@Override
public void setDirtyAround(BlockRegionc region) {
BlockRegion tmp = new BlockRegion(region).expand(1, 1, 1);
for (Vector3ic pos : Chunks.toChunkRegion(tmp, tmp)) {
int px = pos.x() + offset.x;
int py = pos.y() + offset.y;
int pz = pos.z() + offset.z;
Chunk chunk = chunks[px + chunkRegion.getSizeX() * (pz + chunkRegion.getSizeZ() * py)];
if (chunk != null) {
chunk.setDirty(true);
}
}
}
use of org.terasology.engine.world.chunks.Chunk in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method setBlocks.
@Override
public Map<Vector3ic, Block> setBlocks(Map<? extends Vector3ic, Block> blocks) {
/*
* Hint: This method has a benchmark available in the BenchmarkScreen, The screen can be opened ingame via the
* command "showSCreen BenchmarkScreen".
*/
Set<BlockChange> changedBlocks = new HashSet<>();
Map<Vector3ic, Block> result = new HashMap<>(blocks.size());
Vector3i chunkPos = new Vector3i();
Vector3i relativePos = new Vector3i();
for (Map.Entry<? extends Vector3ic, Block> entry : blocks.entrySet()) {
Vector3ic worldPos = entry.getKey();
Chunks.toChunkPos(worldPos, chunkPos);
Chunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Block type = entry.getValue();
Chunks.toRelative(worldPos, relativePos);
Block oldBlockType = chunk.setBlock(relativePos, type);
if (oldBlockType != type) {
BlockChange oldChange = blockChanges.get(worldPos);
if (oldChange == null) {
blockChanges.put(new Vector3i(worldPos), new BlockChange(worldPos, oldBlockType, type));
} else {
oldChange.setTo(type);
}
setDirtyChunksNear(worldPos);
changedBlocks.add(new BlockChange(worldPos, oldBlockType, type));
}
result.put(worldPos, oldBlockType);
} else {
result.put(worldPos, null);
}
}
for (BlockChange change : changedBlocks) {
notifyBlockChanged(change.getPosition(), change.getTo(), change.getFrom());
}
return result;
}
Aggregations