Search in sources :

Example 36 with Block

use of org.terasology.world.block.Block in project Terasology by MovingBlocks.

the class HorizontalBlockFamilyFactory method createBlockFamily.

@Override
public BlockFamily createBlockFamily(BlockFamilyDefinition definition, BlockShape shape, BlockBuilderHelper blockBuilder) {
    if (!definition.isFreeform()) {
        throw new IllegalStateException("A shape cannot be provided when creating a family for a non-freeform block family definition");
    }
    Map<Side, Block> blockMap = Maps.newHashMap();
    for (Rotation rot : Rotation.horizontalRotations()) {
        Side side = rot.rotate(Side.FRONT);
        blockMap.put(side, blockBuilder.constructTransformedBlock(definition, shape, side.toString().toLowerCase(Locale.ENGLISH), rot));
    }
    BlockUri uri;
    if (CUBE_SHAPE_URN.equals(shape.getUrn())) {
        uri = new BlockUri(definition.getUrn());
    } else {
        uri = new BlockUri(definition.getUrn(), shape.getUrn());
    }
    return new HorizontalBlockFamily(uri, getArchetypeSide(), blockMap, definition.getCategories());
}
Also used : Side(org.terasology.math.Side) BlockUri(org.terasology.world.block.BlockUri) Block(org.terasology.world.block.Block) Rotation(org.terasology.math.Rotation)

Example 37 with Block

use of org.terasology.world.block.Block in project Terasology by MovingBlocks.

the class SymmetricBlockFamilyFactory method createBlockFamily.

@Override
public BlockFamily createBlockFamily(BlockFamilyDefinition definition, BlockShape shape, BlockBuilderHelper blockBuilder) {
    if (!definition.isFreeform()) {
        throw new IllegalStateException("A shape cannot be provided when creating a family for a non-freeform block family definition");
    }
    Block block = blockBuilder.constructSimpleBlock(definition, shape);
    BlockUri uri;
    if (CUBE_SHAPE_URN.equals(shape.getUrn())) {
        uri = new BlockUri(definition.getUrn());
    } else {
        uri = new BlockUri(definition.getUrn(), shape.getUrn());
    }
    return new SymmetricFamily(uri, block, definition.getCategories());
}
Also used : BlockUri(org.terasology.world.block.BlockUri) Block(org.terasology.world.block.Block)

Example 38 with Block

use of org.terasology.world.block.Block in project Terasology by MovingBlocks.

the class UpdatesWithNeighboursFamilyFactory method createBlockFamily.

@Override
public BlockFamily createBlockFamily(BlockFamilyDefinition definition, BlockBuilderHelper blockBuilder) {
    TByteObjectMap<String>[] basicBlocks = new TByteObjectMap[7];
    TByteObjectMap<Block> blocksForConnections = new TByteObjectHashMap<>();
    addConnections(basicBlocks, 0, NO_CONNECTIONS);
    addConnections(basicBlocks, 1, ONE_CONNECTION);
    addConnections(basicBlocks, 2, TWO_CONNECTIONS_LINE);
    addConnections(basicBlocks, 2, TWO_CONNECTIONS_CORNER);
    addConnections(basicBlocks, 3, THREE_CONNECTIONS_CORNER);
    addConnections(basicBlocks, 3, THREE_CONNECTIONS_T);
    addConnections(basicBlocks, 4, FOUR_CONNECTIONS_CROSS);
    addConnections(basicBlocks, 4, FOUR_CONNECTIONS_SIDE);
    addConnections(basicBlocks, 5, FIVE_CONNECTIONS);
    addConnections(basicBlocks, 6, SIX_CONNECTIONS);
    BlockUri blockUri = new BlockUri(definition.getUrn());
    // Now make sure we have all combinations based on the basic set (above) and rotations
    for (byte connections = 0; connections < 64; connections++) {
        // Only the allowed connections should be created
        if ((connections & connectionSides) == connections) {
            Block block = constructBlockForConnections(connections, blockBuilder, definition, basicBlocks);
            if (block == null) {
                throw new IllegalStateException("Unable to find correct block definition for connections: " + connections);
            }
            block.setUri(new BlockUri(blockUri, new Name(String.valueOf(connections))));
            blocksForConnections.put(connections, block);
        }
    }
    final Block archetypeBlock = blocksForConnections.get(SideBitFlag.getSides(Side.RIGHT, Side.LEFT));
    return new UpdatesWithNeighboursFamily(connectionCondition, blockUri, definition.getCategories(), archetypeBlock, blocksForConnections, connectionSides);
}
Also used : BlockUri(org.terasology.world.block.BlockUri) TByteObjectMap(gnu.trove.map.TByteObjectMap) Block(org.terasology.world.block.Block) TByteObjectHashMap(gnu.trove.map.hash.TByteObjectHashMap) Name(org.terasology.naming.Name)

Example 39 with Block

use of org.terasology.world.block.Block in project Terasology by MovingBlocks.

the class BlockBuilder method constructCustomBlock.

@Override
public Block constructCustomBlock(String defaultName, BlockShape shape, Rotation rotation, SectionDefinitionData section) {
    Block block = createRawBlock(defaultName, section);
    block.setDirection(rotation.rotate(Side.FRONT));
    block.setPrimaryAppearance(createAppearance(shape, section.getBlockTiles(), rotation));
    setBlockFullSides(block, shape, rotation);
    block.setCollision(shape.getCollisionOffset(rotation), shape.getCollisionShape(rotation));
    for (BlockPart part : BlockPart.values()) {
        block.setColorSource(part, section.getColorSources().get(part));
        block.setColorOffset(part, section.getColorOffsets().get(part));
    }
    return block;
}
Also used : BlockPart(org.terasology.world.block.BlockPart) Block(org.terasology.world.block.Block)

Example 40 with Block

use of org.terasology.world.block.Block in project Terasology by MovingBlocks.

the class BlockBuilder method createRawBlock.

private Block createRawBlock(String defaultName, SectionDefinitionData def) {
    Block block = new Block();
    block.setLiquid(def.isLiquid());
    block.setWater(def.isWater());
    block.setLava(def.isLava());
    block.setGrass(def.isGrass());
    block.setIce(def.isIce());
    block.setHardness(def.getHardness());
    block.setAttachmentAllowed(def.isAttachmentAllowed());
    block.setReplacementAllowed(def.isReplacementAllowed());
    block.setSupportRequired(def.isSupportRequired());
    block.setPenetrable(def.isPenetrable());
    block.setTargetable(def.isTargetable());
    block.setClimbable(def.isClimbable());
    block.setTranslucent(def.isTranslucent());
    block.setDoubleSided(def.isDoubleSided());
    block.setShadowCasting(def.isShadowCasting());
    block.setWaving(def.isWaving());
    block.setLuminance(def.getLuminance());
    block.setTint(def.getTint());
    if (Strings.isNullOrEmpty(def.getDisplayName())) {
        block.setDisplayName(properCase(defaultName));
    } else {
        block.setDisplayName(def.getDisplayName());
    }
    block.setSounds(def.getSounds());
    block.setMass(def.getMass());
    block.setDebrisOnDestroy(def.isDebrisOnDestroy());
    block.setFriction(def.getFriction());
    block.setRestitution(def.getRestitution());
    if (def.getEntity() != null) {
        block.setPrefab(def.getEntity().getPrefab());
        block.setKeepActive(def.getEntity().isKeepActive());
    }
    if (def.getInventory() != null) {
        block.setStackable(def.getInventory().isStackable());
        block.setDirectPickup(def.getInventory().isDirectPickup());
    }
    return block;
}
Also used : Block(org.terasology.world.block.Block)

Aggregations

Block (org.terasology.world.block.Block)67 Vector3i (org.terasology.math.geom.Vector3i)32 EntityRef (org.terasology.entitySystem.entity.EntityRef)16 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)11 Side (org.terasology.math.Side)11 Vector3f (org.terasology.math.geom.Vector3f)9 LocationComponent (org.terasology.logic.location.LocationComponent)7 BlockUri (org.terasology.world.block.BlockUri)7 BlockFamily (org.terasology.world.block.family.BlockFamily)7 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)6 OnChangedBlock (org.terasology.world.OnChangedBlock)6 BlockComponent (org.terasology.world.block.BlockComponent)5 BlockManager (org.terasology.world.block.BlockManager)5 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Before (org.junit.Before)3 ResourceUrn (org.terasology.assets.ResourceUrn)3 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)3 DoDamageEvent (org.terasology.logic.health.DoDamageEvent)3