use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class BlockManagerImpl method receiveFamilyRegistration.
public void receiveFamilyRegistration(BlockUri familyUri, Map<String, Integer> registration) {
Optional<BlockFamily> family = loadFamily(familyUri);
if (family.isPresent()) {
lock.lock();
try {
for (Block block : family.get().getBlocks()) {
Integer id = registration.get(block.getURI().toString());
if (id != null) {
block.setId((short) id.intValue());
} else {
logger.error("Missing id for block {} in registered family {}", block.getURI(), familyUri);
block.setId(UNKNOWN_ID);
}
}
registerFamily(family.get());
} finally {
lock.unlock();
}
}
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class BlockManagerImpl method registerFamily.
@VisibleForTesting
protected void registerFamily(BlockFamily family) {
Preconditions.checkNotNull(family);
logger.info("Registered {}", family);
lock.lock();
try {
RegisteredState newState = new RegisteredState(registeredBlockInfo.get());
newState.registeredFamilyByUri.put(family.getURI(), family);
for (Block block : family.getBlocks()) {
registerBlock(block, newState);
}
registeredBlockInfo.set(newState);
} finally {
lock.unlock();
}
for (BlockRegistrationListener listener : listeners) {
listener.onBlockFamilyRegistered(family);
}
}
use of org.terasology.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);
}
}
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class AttachSupportRequired method getEntity.
private EntityRef getEntity(Vector3i location, Map<Vector3i, Block> blockOverrides) {
final Block overwrittenBlock = blockOverrides.get(location);
if (overwrittenBlock != null) {
return overwrittenBlock.getEntity();
}
EntityRef blockEntity = getBlockEntityRegistry().getExistingBlockEntityAt(location);
if (blockEntity.exists()) {
return blockEntity;
} else {
return getWorldProvider().getBlock(location).getEntity();
}
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class EntityAwareWorldProvider method getBlockEntityAt.
@Override
public EntityRef getBlockEntityAt(Vector3i blockPosition) {
if (GameThread.isCurrentThread()) {
EntityRef blockEntity = getExistingBlockEntityAt(blockPosition);
if ((!blockEntity.exists() || !blockEntity.hasComponent(NetworkComponent.class)) && isBlockRelevant(blockPosition.x, blockPosition.y, blockPosition.z)) {
Block block = getBlock(blockPosition.x, blockPosition.y, blockPosition.z);
blockEntity = createBlockEntity(blockPosition, block);
}
return blockEntity;
}
logger.error("Attempted to get block entity off-thread");
return EntityRef.NULL;
}
Aggregations