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 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)));
}
}
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class BlockManagerImpl method initialise.
public void initialise(List<String> registeredBlockFamilies, Map<String, Short> knownBlockMappings) {
if (knownBlockMappings.size() >= MAX_ID) {
nextId.set(UNKNOWN_ID);
} else if (knownBlockMappings.size() > 0) {
nextId.set(knownBlockMappings.values().stream().max(Short::compareTo).orElse((short) 0) + 1);
}
registeredBlockInfo.set(new RegisteredState());
for (String rawFamilyUri : registeredBlockFamilies) {
try {
BlockUri familyUri = new BlockUri(rawFamilyUri);
Optional<BlockFamily> family = loadFamily(familyUri);
if (family.isPresent()) {
for (Block block : family.get().getBlocks()) {
Short id = knownBlockMappings.get(block.getURI().toString());
if (id != null) {
block.setId(id);
} else {
logger.error("Missing id for block {} in provided family {}", block.getURI(), family.get().getURI());
if (generateNewIds) {
block.setId(getNextId());
} else {
block.setId(UNKNOWN_ID);
}
}
}
registerFamily(family.get());
}
} catch (BlockUriParseException e) {
logger.error("Failed to parse block family, skipping", e);
}
}
}
Aggregations