use of org.terasology.engine.world.block.BlockUri 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.engine.world.block.BlockUri in project Terasology by MovingBlocks.
the class BlockCommands method listFreeShapeBlocks.
@Command(shortDescription = "Lists available free shape blocks", helpText = "Lists all the available free shape blocks. These blocks can be created with any shape.\n" + "You can filter by adding the beginning of words after the commands, e.g.: \"listFreeShapeBlocks" + "engine: core\" will list all free shape blocks from the engine and modules starting with 'core'", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String listFreeShapeBlocks(@CommandParam(value = "startsWith", required = false) String[] startsWith) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Free Shape Blocks");
stringBuilder.append(Console.NEW_LINE);
stringBuilder.append("-----------------");
stringBuilder.append(Console.NEW_LINE);
List<BlockUri> sortedUris = sortItems(blockExplorer.getFreeformBlockFamilies());
for (BlockUri uri : sortedUris) {
if (!uriStartsWithAnyString(uri.toString(), startsWith)) {
continue;
}
stringBuilder.append(uri.toString());
stringBuilder.append(Console.NEW_LINE);
}
return stringBuilder.toString();
}
use of org.terasology.engine.world.block.BlockUri in project Terasology by MovingBlocks.
the class BlockCommands method listBlocks.
@Command(shortDescription = "List all available blocks\nYou can filter by adding the beginning of words after the" + " commands, e.g.: \"listBlocks engine: core\" will list all blocks from the engine and modules starting with 'core'", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String listBlocks(@CommandParam(value = "startsWith", required = false) String[] startsWith) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Used Blocks");
stringBuilder.append(Console.NEW_LINE);
stringBuilder.append("-----------");
stringBuilder.append(Console.NEW_LINE);
List<BlockUri> registeredBlocks = sortItems(blockManager.listRegisteredBlockUris());
for (BlockUri blockUri : registeredBlocks) {
if (!uriStartsWithAnyString(blockUri.toString(), startsWith)) {
continue;
}
stringBuilder.append(blockUri.toString());
stringBuilder.append(Console.NEW_LINE);
}
stringBuilder.append(Console.NEW_LINE);
stringBuilder.append("Available Blocks");
stringBuilder.append(Console.NEW_LINE);
stringBuilder.append("----------------");
stringBuilder.append(Console.NEW_LINE);
List<BlockUri> availableBlocks = sortItems(blockExplorer.getAvailableBlockFamilies());
for (BlockUri blockUri : availableBlocks) {
if (!uriStartsWithAnyString(blockUri.toString(), startsWith)) {
continue;
}
stringBuilder.append(blockUri.toString());
stringBuilder.append(Console.NEW_LINE);
}
return stringBuilder.toString();
}
use of org.terasology.engine.world.block.BlockUri in project Terasology by MovingBlocks.
the class MultiConnectFamily method registerBlock.
/**
* @param root The root block URI of the family
* @param definition The definition of the block family as passed down from the engine
* @param blockBuilder The block builder to make the blocks in the family
* @param sides A byte representing the sides which should be connected for this block
* @param rotations All of the ways the block should be rotated
* @return All of the rotations possible for the block with the given sides
*/
public Set<Block> registerBlock(BlockUri root, BlockFamilyDefinition definition, final BlockBuilderHelper blockBuilder, byte sides, Iterable<Rotation> rotations) {
Set<Block> result = Sets.newLinkedHashSet();
for (Rotation rotation : rotations) {
byte sideBits = 0;
for (Side side : SideBitFlag.getSides(sides)) {
sideBits |= SideBitFlag.getSide(rotation.rotate(side));
}
BlockUri uri = new BlockUri(root, new Name(String.valueOf(sideBits)));
Block block = blockBuilder.constructTransformedBlock(definition, rotation, uri, this);
block.setUri(uri);
blocks.put(sideBits, block);
result.add(block);
}
return result;
}
use of org.terasology.engine.world.block.BlockUri in project Terasology by MovingBlocks.
the class InternalLightGeneratorTest method setup.
@BeforeEach
public void setup() throws Exception {
super.setup();
AssetManager assetManager = CoreRegistry.get(AssetManager.class);
blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager);
CoreRegistry.put(BlockManager.class, blockManager);
airBlock = blockManager.getBlock(BlockManager.AIR_ID);
extraDataManager = new ExtraBlockDataManager();
BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
solidData.getBaseSection().setDisplayName("Stone");
solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
solidData.getBaseSection().setTranslucent(false);
solidData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
solidBlock = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
BlockFamilyDefinitionData fullLightData = new BlockFamilyDefinitionData();
fullLightData.getBaseSection().setDisplayName("Torch");
fullLightData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
fullLightData.getBaseSection().setLuminance(Chunks.MAX_LIGHT);
fullLightData.setBlockFamily(SymmetricFamily.class);
assetManager.loadAsset(new ResourceUrn("engine:torch"), fullLightData, BlockFamilyDefinition.class);
fullLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:torch")));
}
Aggregations