use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class ServerImpl method onChunkReady.
@Override
public void onChunkReady(Vector3i chunkPos) {
WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
List<NetData.BlockChangeMessage> updateBlockMessages = awaitingChunkReadyBlockUpdates.removeAll(chunkPos);
for (NetData.BlockChangeMessage message : updateBlockMessages) {
Vector3i pos = NetMessageUtil.convert(message.getPos());
Block newBlock = blockManager.getBlock((short) message.getNewBlock());
worldProvider.setBlock(pos, newBlock);
}
List<NetData.BiomeChangeMessage> updateBiomeMessages = awaitingChunkReadyBiomeUpdates.removeAll(chunkPos);
for (NetData.BiomeChangeMessage message : updateBiomeMessages) {
Vector3i pos = NetMessageUtil.convert(message.getPos());
Biome newBiome = biomeManager.getBiomeByShortId((short) message.getNewBiome());
worldProvider.setBiome(pos, newBiome);
}
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class LocalChunkProviderTest method registerBlockWithIdAndEntity.
private static void registerBlockWithIdAndEntity(final short blockId, final EntityRef blockEntity, final BlockManager blockManager) {
final Block block = new Block();
block.setEntity(blockEntity);
when(blockManager.getBlock(eq(blockId))).thenReturn(block);
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method setup.
@Before
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, null);
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.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) {
// is this a different position than previously
if (!oldPosition.equals(newPosition)) {
Biome oldBiome = worldProvider.getBiome(oldPosition);
Biome newBiome = worldProvider.getBiome(newPosition);
if (oldBiome != newBiome) {
entity.send(new OnEnterBiomeEvent(oldPosition, newPosition, oldBiome, newBiome));
}
// get the old position's blocks
Block[] oldBlocks = new Block[(int) Math.ceil(characterHeight)];
Vector3i currentPosition = new Vector3i(oldPosition);
for (int currentHeight = 0; currentHeight < oldBlocks.length; currentHeight++) {
oldBlocks[currentHeight] = worldProvider.getBlock(currentPosition);
currentPosition.add(0, 1, 0);
}
// get the new position's blocks
Block[] newBlocks = new Block[(int) Math.ceil(characterHeight)];
currentPosition = new Vector3i(newPosition);
for (int currentHeight = 0; currentHeight < characterHeight; currentHeight++) {
newBlocks[currentHeight] = worldProvider.getBlock(currentPosition);
currentPosition.add(0, 1, 0);
}
for (int i = 0; i < characterHeight; i++) {
// send a block enter/leave event for this character
entity.send(new OnEnterBlockEvent(oldBlocks[i], newBlocks[i], new Vector3i(0, i, 0)));
}
}
}
use of org.terasology.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, RoundingMode.HALF_UP);
Vector3i climbBlockPos = new Vector3i(side, RoundingMode.HALF_UP);
Vector3i dir = new Vector3i(block.getDirection().getVector3i());
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;
}
Aggregations