use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class LocalChunkProviderTest method setUp.
@BeforeEach
public void setUp() {
entityManager = mock(EntityManager.class);
blockAtBlockManager = new Block();
blockAtBlockManager.setId((short) 1);
blockAtBlockManager.setUri(BlockManager.AIR_ID);
blockAtBlockManager.setEntity(mock(EntityRef.class));
blockManager = new TestBlockManager(blockAtBlockManager);
extraDataManager = new ExtraBlockDataManager();
blockEntityRegistry = mock(BlockEntityRegistry.class);
worldEntity = mock(EntityRef.class);
chunkCache = Maps.newConcurrentMap();
storageManager = new TestStorageManager();
generator = new TestWorldGenerator(blockManager);
chunkProvider = new LocalChunkProvider(storageManager, entityManager, generator, blockManager, extraDataManager, chunkCache);
chunkProvider.setBlockEntityRegistry(blockEntityRegistry);
chunkProvider.setWorldEntity(worldEntity);
// workaround. initialize loading pipeline
chunkProvider.setRelevanceSystem(new RelevanceSystem(chunkProvider));
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class MapWorldProvider method getBlock.
@Override
public Block getBlock(int x, int y, int z) {
Vector3i pos = new Vector3i(x, y, z);
Block block = blocks.get(pos);
if (block != null) {
return block;
}
// TODO block manager
Vector3i chunkPos = Chunks.toChunkPos(pos, new Vector3i());
Chunk chunk = chunks.get(chunkPos);
if (chunk == null && worldGenerator != null) {
chunk = new ChunkImpl(chunkPos, blockManager, extraDataManager);
worldGenerator.createChunk(chunk, entityBuffer);
chunks.put(chunkPos, chunk);
}
if (chunk != null) {
return chunk.getBlock(Chunks.toRelative(pos, pos));
}
return null;
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method setup.
@BeforeEach
public void setup() throws Exception {
super.setup();
GameThread.setToCurrentThread();
this.entityManager = context.get(EngineEntityManager.class);
AssetManager assetManager = context.get(AssetManager.class);
BlockManager blockManager = context.get(BlockManager.class);
airBlock = blockManager.getBlock(BlockManager.AIR_ID);
worldStub = new WorldProviderCoreStub(airBlock);
worldProvider = new EntityAwareWorldProvider(worldStub, context);
plainBlock = createBlock("test:plainblock", assetManager, blockManager);
prefabWithString = createPrefabWithString("test:prefabWithString", "Test", assetManager);
blockWithString = createBlockWithPrefab("test:blockWithString", prefabWithString, false, assetManager, blockManager);
keepActiveBlock = createBlockWithPrefab("test:keepActiveBlock", prefabWithString, true, assetManager, blockManager);
Prefab prefabWithDifferentString = createPrefabWithString("test:prefabWithDifferentString", "Test2", assetManager);
blockWithDifferentString = createBlockWithPrefab("test:prefabWithDifferentString", prefabWithDifferentString, false, assetManager, blockManager);
BlockFamily blockFamily = createBlockFamily("test:blockFamily", prefabWithString, assetManager, blockManager);
Iterator<Block> iterator = blockFamily.getBlocks().iterator();
blockInFamilyOne = iterator.next();
blockInFamilyTwo = iterator.next();
PrefabData retainedPrefabData = new PrefabData();
retainedPrefabData.addComponent(new RetainedOnBlockChangeComponent(3));
Prefab retainedPrefab = assetManager.loadAsset(new ResourceUrn("test:retainedPrefab"), retainedPrefabData, Prefab.class);
blockWithRetainedComponent = createBlockWithPrefab("test:blockWithRetainedComponent", retainedPrefab, false, assetManager, blockManager);
worldProvider.initialise();
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class KinematicCharacterMover method findClimbable.
private Vector3i findClimbable(CharacterMovementComponent movementComp, Vector3f worldPos, boolean swimming, boolean diving) {
Vector3i finalDir = null;
Vector3f[] sides = { new Vector3f(worldPos), new Vector3f(worldPos), new Vector3f(worldPos), new Vector3f(worldPos), new Vector3f(worldPos) };
float factor = 1.0f;
sides[0].x += factor * movementComp.radius;
sides[1].x -= factor * movementComp.radius;
sides[2].z += factor * movementComp.radius;
sides[3].z -= factor * movementComp.radius;
sides[4].y -= movementComp.height;
float distance = 100f;
for (Vector3f side : sides) {
Block block = worldProvider.getBlock(side);
if (block.isClimbable()) {
// If any of our sides are near a climbable block, check if we are near to the side
Vector3i myPos = new Vector3i(worldPos, org.joml.RoundingMode.HALF_UP);
Vector3i climbBlockPos = new Vector3i(side, org.joml.RoundingMode.HALF_UP);
Vector3i dir = new Vector3i(block.getDirection().direction());
float currentDistance = 10f;
if (dir.x != 0 && Math.abs(worldPos.x - climbBlockPos.x + dir.x * .5f) < movementComp.radius + 0.1f) {
if (myPos.x < climbBlockPos.x) {
dir.x = -dir.x;
}
currentDistance = Math.abs(climbBlockPos.z - worldPos.z);
} else if (dir.z != 0 && Math.abs(worldPos.z - climbBlockPos.z + dir.z * .5f) < movementComp.radius + 0.1f) {
if (myPos.z < climbBlockPos.z) {
dir.z = -dir.z;
}
currentDistance = Math.abs(climbBlockPos.z - worldPos.z);
}
// adjacent ledges around a corner.
if (currentDistance < distance) {
distance = currentDistance;
finalDir = dir;
}
}
}
return finalDir;
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class KinematicCharacterMover method checkBlockEntry.
/*
* Figure out if our position has put us into a new set of blocks and fire the appropriate events.
*/
private void checkBlockEntry(EntityRef entity, Vector3i oldPosition, Vector3i newPosition, float characterHeight) {
if (!oldPosition.equals(newPosition)) {
int characterHeightInBlocks = (int) Math.ceil(characterHeight);
// get the old position's blocks
Block[] oldBlocks = new Block[characterHeightInBlocks];
for (int y = 0; y < characterHeightInBlocks; y++) {
oldBlocks[y] = worldProvider.getBlock(oldPosition.x, oldPosition.y + y, oldPosition.z);
}
// get the new position's blocks
Block[] newBlocks = new Block[characterHeightInBlocks];
for (int y = 0; y < characterHeightInBlocks; y++) {
newBlocks[y] = worldProvider.getBlock(newPosition.x, newPosition.y + y, newPosition.z);
}
for (int y = 0; y < characterHeightInBlocks; y++) {
// send a block enter/leave event for this character
entity.send(new OnEnterBlockEvent(oldBlocks[y], newBlocks[y], new Vector3i(0, y, 0)));
}
}
}
Aggregations