Package org.terasology.world.block

Examples of org.terasology.world.block.Block


    @Override
    public BlockFamily createBlockFamily(BlockBuilderHelper blockBuilder, AssetUri blockDefUri, BlockDefinition blockDefinition, JsonObject blockDefJson) {
        Map<Side, Block> blockMap = Maps.newEnumMap(Side.class);
        BlockDefinition topDef = blockBuilder.getBlockDefinitionForSection(blockDefJson, TOP);
        if (topDef != null) {
            Block block = blockBuilder.constructSimpleBlock(blockDefUri, topDef);
            block.setDirection(Side.TOP);
            blockMap.put(Side.TOP, block);
        }
        BlockDefinition sideDef = blockBuilder.getBlockDefinitionForSection(blockDefJson, SIDES);
        if (sideDef != null) {
            blockMap.putAll(blockBuilder.constructHorizontalRotatedBlocks(blockDefUri, sideDef));
        }
        BlockDefinition bottomDef = blockBuilder.getBlockDefinitionForSection(blockDefJson, BOTTOM);
        if (bottomDef != null) {
            Block block = blockBuilder.constructSimpleBlock(blockDefUri, bottomDef);
            block.setDirection(Side.BOTTOM);
            blockMap.put(Side.BOTTOM, block);
        }
        return new AttachedToSurfaceFamily(new BlockUri(blockDefUri.getModuleName(), blockDefUri.getAssetName()), blockMap, blockDefinition.categories);
    }
View Full Code Here


            }
        }
    }

    private void push(Vector3i pos, byte value) {
        Block block = world.getBlockAt(pos);
        for (Side side : Side.values()) {
            byte spreadValue = rules.propagateValue(value, side, block);
            Vector3i adjPos = side.getAdjacentPos(pos);
            if (rules.canSpreadOutOf(block, side)) {
                byte adjValue = world.getValueAt(adjPos);
                if (adjValue < spreadValue && adjValue != PropagatorWorldView.UNAVAILABLE) {
                    Block adjBlock = world.getBlockAt(adjPos);
                    if (rules.canSpreadInto(adjBlock, side.reverse())) {
                        increase(adjPos, spreadValue);
                    }
                }
            }
View Full Code Here

                    if (expectedValue < 1) {
                        continue;
                    }

                    int depth = 0;
                    Block lastBlock = chunk.getBlock(x, y, z);
                    byte adjValue = rules.getValue(adjChunk, adjPos);
                    while (expectedValue > adjValue && adjValue != PropagatorWorldView.UNAVAILABLE && rules.canSpreadOutOf(lastBlock, side)) {
                        lastBlock = adjChunk.getBlock(adjPos);
                        if (rules.canSpreadInto(lastBlock, side.reverse())) {
                            rules.setValue(adjChunk, adjPos, expectedValue);
View Full Code Here

        return getBlock(new BlockUri(uri));
    }

    @Override
    public Block getBlock(BlockUri uri) {
        Block block = registeredBlockInfo.get().blocksByUri.get(uri);
        if (block == null) {
            // Check if partially registered by getting the block family
            BlockFamily family = getBlockFamily(uri.getFamilyUri());
            if (family != null) {
                block = family.getBlockFor(uri);
View Full Code Here

        return block;
    }

    @Override
    public Block getBlock(short id) {
        Block result = registeredBlockInfo.get().blocksById.get(id);
        if (result == null) {
            return getAir();
        }
        return result;
    }
View Full Code Here

        }
    }

    @ReceiveEvent(components = BlockTypeComponent.class)
    public void onReceivedTypeEntity(OnAddedComponent event, EntityRef entity) {
        Block block = entity.getComponent(BlockTypeComponent.class).block;
        if (block != null) {
            block.setEntity(entity);
        } else {
            logger.error("Received block type entity with missing block type");
        }
    }
View Full Code Here

     * @param blocks The set of blocks that make up the group. Front, Back, Left and Right must be provided - the rest is ignored.
     */
    public AttachedToSurfaceFamily(BlockUri uri, Map<Side, Block> blocks, Iterable<String> categories) {
        super(uri, categories);
        for (Side side : Side.values()) {
            Block block = blocks.get(side);
            if (block != null) {
                this.blocks.put(side, block);
                block.setBlockFamily(this);
                block.setUri(new BlockUri(uri, side.name()));
            }
        }
        if (this.blocks.containsKey(Side.TOP)) {
            archetype = this.blocks.get(Side.TOP);
        } else {
View Full Code Here

        }
    }

    private void push(Vector3i pos, byte value) {
        byte regenValue = value;
        Block block = regenWorld.getBlockAt(pos);
        Vector3i position = new Vector3i(pos);
        while (regenRules.canSpreadOutOf(block, Side.BOTTOM)) {
            regenValue = regenRules.propagateValue(regenValue, Side.BOTTOM, block);
            position.y -= 1;
            byte adjValue = regenWorld.getValueAt(position);
View Full Code Here

        for (int z = 0; z < ChunkConstants.SIZE_Z; ++z) {
            for (int x = 0; x < ChunkConstants.SIZE_X; ++x) {
                int depthIndex = x + ChunkConstants.SIZE_X * z;
                startingRegen[depthIndex] = regenRules.getValue(fromChunk, new Vector3i(x, 0, z));
                byte expectedValue = (byte) Math.min(startingRegen[depthIndex] + 1, ChunkConstants.MAX_SUNLIGHT_REGEN);
                Block fromBlock = fromChunk.getBlock(x, 0, z);
                Block toBlock = toChunk.getBlock(x, ChunkConstants.SIZE_Y - 1, z);
                if (!(regenRules.canSpreadOutOf(fromBlock, Side.BOTTOM) && regenRules.canSpreadInto(toBlock, Side.TOP))) {
                    continue;
                }
                byte predictedValue = 0;
                pos.set(x, ChunkConstants.SIZE_Y - 1, z);
View Full Code Here

@RegisterBlockFamilyFactory("allSides")
public class AllSidesFamilyFactory implements BlockFamilyFactory {
    @Override
    public BlockFamily createBlockFamily(BlockBuilderHelper blockBuilder, AssetUri blockDefUri, BlockDefinition blockDefinition, JsonObject blockDefJson) {
        Map<Side, Block> blocksBySide = new EnumMap<Side, Block>(Side.class);
        final Block frontBlock = blockBuilder.constructSimpleBlock(blockDefUri, blockDefinition);
        blocksBySide.put(Side.FRONT, frontBlock);
        blocksBySide.put(Side.LEFT, blockBuilder.constructTransformedBlock(blockDefUri, blockDefinition, Rotation.rotate(Yaw.CLOCKWISE_90)));
        blocksBySide.put(Side.BACK, blockBuilder.constructTransformedBlock(blockDefUri, blockDefinition, Rotation.rotate(Yaw.CLOCKWISE_180)));
        blocksBySide.put(Side.RIGHT, blockBuilder.constructTransformedBlock(blockDefUri, blockDefinition, Rotation.rotate(Yaw.CLOCKWISE_270)));
        blocksBySide.put(Side.TOP, blockBuilder.constructTransformedBlock(blockDefUri, blockDefinition, Rotation.rotate(Pitch.CLOCKWISE_90)));
View Full Code Here

TOP

Related Classes of org.terasology.world.block.Block

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.