Search in sources :

Example 1 with BlockUri

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);
        }
    }
}
Also used : BlockUri(org.terasology.engine.world.block.BlockUri) BlockUriParseException(org.terasology.engine.world.block.BlockUriParseException) Block(org.terasology.engine.world.block.Block) BlockFamily(org.terasology.engine.world.block.family.BlockFamily)

Example 2 with BlockUri

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();
}
Also used : BlockUri(org.terasology.engine.world.block.BlockUri) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 3 with BlockUri

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();
}
Also used : BlockUri(org.terasology.engine.world.block.BlockUri) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 4 with BlockUri

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;
}
Also used : Side(org.terasology.engine.math.Side) BlockUri(org.terasology.engine.world.block.BlockUri) Block(org.terasology.engine.world.block.Block) Rotation(org.terasology.engine.math.Rotation) Name(org.terasology.gestalt.naming.Name)

Example 5 with BlockUri

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")));
}
Also used : BlockUri(org.terasology.engine.world.block.BlockUri) AssetManager(org.terasology.gestalt.assets.management.AssetManager) BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) NullWorldAtlas(org.terasology.engine.world.block.tiles.NullWorldAtlas) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BlockManagerImpl(org.terasology.engine.world.block.internal.BlockManagerImpl) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

BlockUri (org.terasology.engine.world.block.BlockUri)14 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)8 BeforeEach (org.junit.jupiter.api.BeforeEach)6 BlockManagerImpl (org.terasology.engine.world.block.internal.BlockManagerImpl)6 BlockFamilyDefinitionData (org.terasology.engine.world.block.loader.BlockFamilyDefinitionData)6 NullWorldAtlas (org.terasology.engine.world.block.tiles.NullWorldAtlas)6 AssetManager (org.terasology.gestalt.assets.management.AssetManager)6 Block (org.terasology.engine.world.block.Block)4 ExtraBlockDataManager (org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager)4 Rotation (org.terasology.engine.math.Rotation)3 Side (org.terasology.engine.math.Side)3 Name (org.terasology.gestalt.naming.Name)3 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)2 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)2 BlockFamilyDefinition (org.terasology.engine.world.block.loader.BlockFamilyDefinition)2 SunlightPropagationRules (org.terasology.engine.world.propagation.light.SunlightPropagationRules)2 SunlightRegenPropagationRules (org.terasology.engine.world.propagation.light.SunlightRegenPropagationRules)2 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1