Examples of BlockFamily


Examples of org.terasology.world.block.family.BlockFamily

        Vector3f spawnPos = camera.getPosition();
        Vector3f offset = camera.getViewingDirection();
        offset.scale(3);
        spawnPos.add(offset);

        BlockFamily block = blockManager.getBlockFamily(blockName);
        if (block == null) {
            return "";
        }

        BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
View Full Code Here

Examples of org.terasology.world.block.family.BlockFamily

    }

    @ReceiveEvent
    public void onBlockItemDropped(ItemDroppedEvent event, EntityRef itemEntity, BlockItemComponent blockItemComponent) {
        EntityBuilder builder = event.getPickup();
        BlockFamily blockFamily = blockItemComponent.blockFamily;
        if (builder.hasComponent(MeshComponent.class)) {
            MeshComponent mesh = builder.getComponent(MeshComponent.class);
            mesh.mesh = blockFamily.getArchetypeBlock().getMesh();
            mesh.material = Assets.getMaterial("engine:terrain");
        }
        if (blockFamily.getArchetypeBlock().getCollisionShape() instanceof BoxShape && builder.hasComponent(BoxShapeComponent.class)) {
            Vector3f extents = ((BoxShape) blockFamily.getArchetypeBlock().getCollisionShape()).getHalfExtentsWithoutMargin(new Vector3f());
            extents.scale(2.0f);
            extents.clampMin(0.5f);
            builder.getComponent(BoxShapeComponent.class).extents.set(extents);
        }
        if (blockFamily.getArchetypeBlock().getLuminance() > 0 && !builder.hasComponent(LightComponent.class)) {
            LightComponent lightComponent = builder.addComponent(new LightComponent());

            Vector3f randColor = new Vector3f(rand.nextFloat(), rand.nextFloat(), rand.nextFloat());
            lightComponent.lightColorDiffuse.set(randColor);
            lightComponent.lightColorAmbient.set(randColor);
View Full Code Here

Examples of org.terasology.world.block.family.BlockFamily

    @Test
    public void testActiveBlockNotCleanedUp() {
        Block testBlock = new Block();
        testBlock.setKeepActive(true);
        BlockFamily blockFamily = new SymmetricFamily(new BlockUri("test:keepActive"), testBlock);
        blockManager.addBlockFamily(blockFamily, true);
        worldStub.setBlock(Vector3i.zero(), testBlock);

        BlockEventChecker checker = new BlockEventChecker();
        entityManager.getEventSystem().registerEventHandler(checker);
View Full Code Here

Examples of org.terasology.world.block.family.BlockFamily

            nextId = (short) knownBlockMappings.size();
        }

        for (String rawFamilyUri : registeredBlockFamilies) {
            BlockUri familyUri = new BlockUri(rawFamilyUri);
            BlockFamily family;
            if (isFreeformFamily(familyUri)) {
                family = blockLoader.loadWithShape(familyUri);
            } else {
                family = getAvailableBlockFamily(familyUri);
            }
            if (family != null) {
                for (Block block : family.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.getURI());
                        if (generateNewIds) {
                            block.setId(getNextId());
                        } else {
                            block.setId(UNKNOWN_ID);
                        }
View Full Code Here

Examples of org.terasology.world.block.family.BlockFamily

    public void unsubscribe(BlockRegistrationListener listener) {
        this.listeners.remove(listener);
    }

    public void receiveFamilyRegistration(BlockUri familyUri, Map<String, Integer> registration) {
        BlockFamily family;
        if (isFreeformFamily(familyUri)) {
            family = blockLoader.loadWithShape(familyUri);
        } else {
            family = getAvailableBlockFamily(familyUri);
        }
        if (family != null) {
            for (Block block : family.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);
View Full Code Here

Examples of org.terasology.world.block.family.BlockFamily

        return null;
    }

    @Override
    public BlockFamily getBlockFamily(BlockUri uri) {
        BlockFamily family = registeredBlockInfo.get().registeredFamilyByUri.get(uri);
        if (family == null && generateNewIds) {
            if (isFreeformFamily(uri.getRootFamilyUri())) {
                family = blockLoader.loadWithShape(uri);
            } else {
                family = getAvailableBlockFamily(uri);
            }
            if (family != null) {
                lock.lock();
                try {
                    for (Block block : family.getBlocks()) {
                        block.setId(getNextId());
                    }
                    registerFamily(family);
                } finally {
                    lock.unlock();
View Full Code Here

Examples of org.terasology.world.block.family.BlockFamily

    @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);
            }
            if (block == null) {
                return getAir();
            }
        }
View Full Code Here

Examples of org.terasology.world.block.family.BlockFamily

        Vector3f spawnPos = camera.getPosition();
        Vector3f offset = camera.getViewingDirection();
        offset.scale(3);
        spawnPos.add(offset);

        BlockFamily blockFamily;

        List<BlockUri> matchingUris = blockManager.resolveAllBlockFamilyUri(blockName);
        if (matchingUris.size() == 1) {
            blockFamily = blockManager.getBlockFamily(matchingUris.get(0));

        } else if (matchingUris.isEmpty()) {
            throw new IllegalArgumentException("No block found for '" + blockName + "'");
        } else {
            StringBuilder builder = new StringBuilder();
            builder.append("Non-unique block name, possible matches: ");
            Joiner.on(", ").appendTo(builder, matchingUris);
            return builder.toString();
        }

        if (world != null) {
            world.setBlock(new Vector3i((int) spawnPos.x, (int) spawnPos.y, (int) spawnPos.z), blockFamily.getArchetypeBlock());

            StringBuilder builder = new StringBuilder();
            builder.append(blockFamily.getArchetypeBlock());
            builder.append(" block placed at position (");
            builder.append((int) spawnPos.x).append((int) spawnPos.y).append((int) spawnPos.z).append(")");
            return builder.toString();
        }
        throw new IllegalArgumentException("Sorry, something went wrong!");
View Full Code Here

Examples of org.terasology.world.block.family.BlockFamily

    @Command(shortDescription = "Adds a block to your inventory", helpText = "Puts a desired number of the given block into your inventory", runOnServer = true)
    public String giveBlock(@CommandParam("blockName") String uri, @CommandParam("quantity") int quantity, EntityRef client) {
        List<BlockUri> matchingUris = blockManager.resolveAllBlockFamilyUri(uri);
        if (matchingUris.size() == 1) {
            BlockFamily blockFamily = blockManager.getBlockFamily(matchingUris.get(0));
            return giveBlock(blockFamily, quantity, client);
        } else if (matchingUris.isEmpty()) {
            throw new IllegalArgumentException("No block found for '" + uri + "'");
        } else {
            StringBuilder builder = new StringBuilder();
View Full Code Here

Examples of org.terasology.world.block.family.BlockFamily

    private void beforeDamageCommon(BeforeDamagedEvent event, Block block) {
        if (event.getDamageType() != null) {
            BlockDamageModifierComponent blockDamage = event.getDamageType().getComponent(BlockDamageModifierComponent.class);
            if (blockDamage != null) {
                BlockFamily blockFamily = block.getBlockFamily();
                for (String category : blockFamily.getCategories()) {
                    if (blockDamage.materialDamageMultiplier.containsKey(category)) {
                        event.multiply(blockDamage.materialDamageMultiplier.get(category));
                    }
                }
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.