Search in sources :

Example 41 with Block

use of org.terasology.engine.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.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.engine.world.block.Block)

Example 42 with Block

use of org.terasology.engine.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, BlockUri uri, BlockFamily blockFamily) {
    Block block = createRawBlock(defaultName, section);
    block.setRotation(rotation);
    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, new Color().set(section.getColorOffsets().get(part)));
    }
    block.setUri(uri);
    block.setBlockFamily(blockFamily);
    // Lowered mesh for liquids
    if (block.isLiquid()) {
        applyLiquidShapes(block, section.getBlockTiles());
    }
    return block;
}
Also used : BlockPart(org.terasology.engine.world.block.BlockPart) Color(org.terasology.nui.Color) Block(org.terasology.engine.world.block.Block)

Example 43 with Block

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

the class BlockItemSystem method canPlaceBlock.

private boolean canPlaceBlock(Block block, Vector3i targetBlock, Vector3i blockPos) {
    if (block == null) {
        return false;
    }
    Block centerBlock = worldProvider.getBlock(targetBlock.x, targetBlock.y, targetBlock.z);
    if (!centerBlock.isAttachmentAllowed()) {
        return false;
    }
    Block adjBlock = worldProvider.getBlock(blockPos.x, blockPos.y, blockPos.z);
    if (!adjBlock.isReplacementAllowed() || adjBlock.isTargetable()) {
        return false;
    }
    if (block.getBlockFamily().equals(adjBlock.getBlockFamily())) {
        return false;
    }
    // Prevent players from placing blocks inside their bounding boxes
    if (!block.isPenetrable()) {
        Physics physics = CoreRegistry.get(Physics.class);
        AABBf blockBounds = block.getBounds(blockPos);
        /**
         * Characters can enter other solid objects/blocks for certain amount. This is does to detect collsion
         * start and end without noise. So if the user walked as close to a block as possible it is only natural
         * to let it place a block exactly above it even if that technically would mean a collision start.
         */
        blockBounds.minX += KinematicCharacterMover.HORIZONTAL_PENETRATION;
        blockBounds.maxX -= KinematicCharacterMover.HORIZONTAL_PENETRATION;
        blockBounds.minY += KinematicCharacterMover.VERTICAL_PENETRATION;
        blockBounds.maxY -= KinematicCharacterMover.VERTICAL_PENETRATION;
        blockBounds.minZ += KinematicCharacterMover.HORIZONTAL_PENETRATION;
        blockBounds.maxZ -= KinematicCharacterMover.HORIZONTAL_PENETRATION;
        /*
             * Calculations aren't exact and in the corner cases it is better to let the user place the block.
             */
        blockBounds.minX += ADDITIONAL_ALLOWED_PENETRATION;
        blockBounds.minY += ADDITIONAL_ALLOWED_PENETRATION;
        blockBounds.minZ += ADDITIONAL_ALLOWED_PENETRATION;
        blockBounds.maxX -= ADDITIONAL_ALLOWED_PENETRATION;
        blockBounds.maxY -= ADDITIONAL_ALLOWED_PENETRATION;
        blockBounds.maxZ -= ADDITIONAL_ALLOWED_PENETRATION;
        return physics.scanArea(blockBounds, StandardCollisionGroup.DEFAULT, StandardCollisionGroup.CHARACTER).isEmpty();
    }
    return true;
}
Also used : AABBf(org.terasology.joml.geom.AABBf) Block(org.terasology.engine.world.block.Block) Physics(org.terasology.engine.physics.Physics)

Example 44 with Block

use of org.terasology.engine.world.block.Block 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 name The name of the section of the block to be registered, ex: "no_connections"
 * @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, BlockBuilderHelper blockBuilder, String name, 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));
        }
        Block block = blockBuilder.constructTransformedBlock(definition, name, rotation, new BlockUri(root, new Name(String.valueOf(sideBits))), this);
        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 45 with Block

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

the class BlockManagerImpl method receiveFamilyRegistration.

public void receiveFamilyRegistration(BlockUri familyUri, Map<String, Integer> registration) {
    Optional<BlockFamily> family = loadFamily(familyUri);
    if (family.isPresent()) {
        lock.lock();
        try {
            for (Block block : family.get().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);
                    block.setId(UNKNOWN_ID);
                }
            }
            registerFamily(family.get());
        } finally {
            lock.unlock();
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Block(org.terasology.engine.world.block.Block) BlockFamily(org.terasology.engine.world.block.family.BlockFamily)

Aggregations

Block (org.terasology.engine.world.block.Block)54 Vector3i (org.joml.Vector3i)23 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)13 Vector3ic (org.joml.Vector3ic)12 Vector3f (org.joml.Vector3f)9 OnChangedBlock (org.terasology.engine.world.OnChangedBlock)9 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)7 Side (org.terasology.engine.math.Side)7 Map (java.util.Map)6 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)6 EntityManager (org.terasology.engine.entitySystem.entity.EntityManager)5 BlockComponent (org.terasology.engine.world.block.BlockComponent)5 Chunk (org.terasology.engine.world.chunks.Chunk)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)4 Maps (com.google.common.collect.Maps)3 Optional (java.util.Optional)3 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)3 LocationComponent (org.terasology.engine.logic.location.LocationComponent)3 BlockEntityRegistry (org.terasology.engine.world.BlockEntityRegistry)3