Search in sources :

Example 16 with Block

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

the class StandardBatchPropagator method push.

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);
                }
            }
        }
    }
}
Also used : Side(org.terasology.math.Side) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Example 17 with Block

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

the class StandardBatchPropagator method purge.

private void purge(Vector3i pos, byte oldValue) {
    Block block = world.getBlockAt(pos);
    increaseQueues[rules.getMaxValue() - oldValue].remove(pos);
    byte fixedValue = rules.getFixedValue(block, pos);
    if (fixedValue > 0) {
        increase(pos, fixedValue);
    } else {
        world.setValueAt(pos, NO_VALUE);
    }
    for (Side side : Side.values()) {
        byte expectedValue = rules.propagateValue(oldValue, side, block);
        Vector3i adjPos = side.getAdjacentPos(pos);
        if (rules.canSpreadOutOf(block, side)) {
            byte adjValue = world.getValueAt(adjPos);
            if (adjValue == expectedValue) {
                Block adjBlock = world.getBlockAt(adjPos);
                if (rules.canSpreadInto(adjBlock, side.reverse())) {
                    reduce(adjPos, expectedValue);
                }
            } else if (adjValue > 0) {
                queueSpreadValue(adjPos, adjValue);
            }
        }
    }
}
Also used : Side(org.terasology.math.Side) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Example 18 with Block

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

the class InternalLightProcessor method populateSunlightRegen.

private static void populateSunlightRegen(LitChunk chunk) {
    int top = ChunkConstants.SIZE_Y - 1;
    for (int x = 0; x < ChunkConstants.SIZE_X; x++) {
        for (int z = 0; z < ChunkConstants.SIZE_Z; z++) {
            int y = top;
            byte regen = 0;
            Block lastBlock = chunk.getBlock(x, y, z);
            for (y -= 1; y >= 0; y--) {
                Block block = chunk.getBlock(x, y, z);
                if (SUNLIGHT_REGEN_RULES.canSpreadOutOf(lastBlock, Side.BOTTOM) && SUNLIGHT_REGEN_RULES.canSpreadInto(block, Side.TOP)) {
                    regen = SUNLIGHT_REGEN_RULES.propagateValue(regen, Side.BOTTOM, lastBlock);
                    chunk.setSunlightRegen(x, y, z, regen);
                } else {
                    regen = 0;
                }
                lastBlock = block;
            }
        }
    }
}
Also used : Block(org.terasology.world.block.Block)

Example 19 with Block

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

the class BlockCommands method replaceBlock.

@Command(shortDescription = "Replaces a block in front of user", helpText = "Replaces a block in front of the user at the specified max distance", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public void replaceBlock(@Sender EntityRef sender, @CommandParam("blockName") String uri, @CommandParam(value = "maxDistance", required = false) Integer maxDistanceParam) {
    int maxDistance = maxDistanceParam != null ? maxDistanceParam : 12;
    EntityRef playerEntity = sender.getComponent(ClientComponent.class).character;
    EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(playerEntity);
    LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class);
    Set<ResourceUrn> matchingUris = Assets.resolveAssetUri(uri, BlockFamilyDefinition.class);
    targetSystem.updateTarget(gazeLocation.getWorldPosition(), gazeLocation.getWorldDirection(), maxDistance);
    EntityRef target = targetSystem.getTarget();
    BlockComponent targetLocation = target.getComponent(BlockComponent.class);
    if (matchingUris.size() == 1) {
        Optional<BlockFamilyDefinition> def = Assets.get(matchingUris.iterator().next(), BlockFamilyDefinition.class);
        if (def.isPresent()) {
            BlockFamily blockFamily = blockManager.getBlockFamily(uri);
            Block block = blockManager.getBlock(blockFamily.getURI());
            world.setBlock(targetLocation.getPosition(), block);
        } else if (matchingUris.size() > 1) {
            StringBuilder builder = new StringBuilder();
            builder.append("Non-unique shape name, possible matches: ");
            Iterator<ResourceUrn> shapeUris = sortItems(matchingUris).iterator();
            while (shapeUris.hasNext()) {
                builder.append(shapeUris.next().toString());
                if (shapeUris.hasNext()) {
                    builder.append(", ");
                }
            }
        }
    }
}
Also used : ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) BlockComponent(org.terasology.world.block.BlockComponent) Iterator(java.util.Iterator) Block(org.terasology.world.block.Block) BlockFamily(org.terasology.world.block.family.BlockFamily) ResourceUrn(org.terasology.assets.ResourceUrn) BlockFamilyDefinition(org.terasology.world.block.loader.BlockFamilyDefinition) EntityRef(org.terasology.entitySystem.entity.EntityRef) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 20 with Block

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

the class AttachedToSurfaceFamilyFactory method createBlockFamily.

@Override
public BlockFamily createBlockFamily(BlockFamilyDefinition definition, BlockBuilderHelper blockBuilder) {
    Map<Side, Block> blockMap = Maps.newEnumMap(Side.class);
    if (definition.getData().hasSection("top")) {
        Block block = blockBuilder.constructSimpleBlock(definition, "top");
        block.setDirection(Side.TOP);
        blockMap.put(Side.TOP, block);
    }
    if (definition.getData().hasSection("front")) {
        for (Rotation rot : Rotation.horizontalRotations()) {
            Side side = rot.rotate(Side.FRONT);
            blockMap.put(side, blockBuilder.constructTransformedBlock(definition, side.toString().toLowerCase(Locale.ENGLISH), rot));
        }
    }
    if (definition.getData().hasSection("bottom")) {
        Block block = blockBuilder.constructSimpleBlock(definition, "bottom");
        block.setDirection(Side.BOTTOM);
        blockMap.put(Side.BOTTOM, block);
    }
    return new AttachedToSurfaceFamily(new BlockUri(definition.getUrn()), 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)

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