Search in sources :

Example 1 with BlockUri

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

the class BlockCommands method listFreeShapeBlocks.

@Command(shortDescription = "Lists available free shape blocks", helpText = "Lists all the available free shape blocks. These blocks can be created with any shape.\n" + "You can filter by adding the beginning of words after the commands, e.g.: \"listFreeShapeBlocks" + "engine: core:\" will list all free shape blocks from the engine and core module", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String listFreeShapeBlocks(@CommandParam(value = "startsWith", required = false) String[] startsWith) {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("Free Shape Blocks");
    stringBuilder.append(Console.NEW_LINE);
    stringBuilder.append("-----------------");
    stringBuilder.append(Console.NEW_LINE);
    List<BlockUri> sortedUris = sortItems(blockExplorer.getFreeformBlockFamilies());
    for (BlockUri uri : sortedUris) {
        if (!uriStartsWithAnyString(uri.toString(), startsWith)) {
            continue;
        }
        stringBuilder.append(uri.toString());
        stringBuilder.append(Console.NEW_LINE);
    }
    return stringBuilder.toString();
}
Also used : BlockUri(org.terasology.world.block.BlockUri) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 2 with BlockUri

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

Example 3 with BlockUri

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

the class HorizontalBlockFamilyFactory method createBlockFamily.

@Override
public BlockFamily createBlockFamily(BlockFamilyDefinition definition, BlockBuilderHelper blockBuilder) {
    if (definition.isFreeform()) {
        throw new IllegalStateException("A shape must be provided when creating a family for a 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, side.toString().toLowerCase(Locale.ENGLISH), rot));
    }
    return new HorizontalBlockFamily(new BlockUri(definition.getUrn()), 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 4 with BlockUri

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

the class BulkLightPropagationTest method setup.

@Before
public void setup() throws Exception {
    super.setup();
    lightRules = new LightPropagationRules();
    AssetManager assetManager = CoreRegistry.get(AssetManager.class);
    blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager, true);
    CoreRegistry.put(BlockManager.class, blockManager);
    BlockFamilyDefinitionData fullLightData = new BlockFamilyDefinitionData();
    fullLightData.getBaseSection().setDisplayName("Torch");
    fullLightData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
    fullLightData.getBaseSection().setLuminance(ChunkConstants.MAX_LIGHT);
    fullLightData.getBaseSection().setTranslucent(true);
    fullLightData.setFamilyFactory(new SymmetricBlockFamilyFactory());
    assetManager.loadAsset(new ResourceUrn("engine:torch"), fullLightData, BlockFamilyDefinition.class);
    fullLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:torch")));
    BlockFamilyDefinitionData weakLightData = new BlockFamilyDefinitionData();
    weakLightData.getBaseSection().setDisplayName("PartLight");
    weakLightData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
    weakLightData.getBaseSection().setLuminance((byte) 2);
    weakLightData.getBaseSection().setTranslucent(true);
    weakLightData.setFamilyFactory(new SymmetricBlockFamilyFactory());
    assetManager.loadAsset(new ResourceUrn("engine:weakLight"), weakLightData, BlockFamilyDefinition.class);
    weakLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:weakLight")));
    BlockFamilyDefinitionData mediumLightData = new BlockFamilyDefinitionData();
    mediumLightData.getBaseSection().setDisplayName("MediumLight");
    mediumLightData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
    mediumLightData.getBaseSection().setLuminance((byte) 5);
    mediumLightData.getBaseSection().setTranslucent(true);
    mediumLightData.setFamilyFactory(new SymmetricBlockFamilyFactory());
    assetManager.loadAsset(new ResourceUrn("engine:mediumLight"), mediumLightData, BlockFamilyDefinition.class);
    mediumLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:mediumLight")));
    BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
    solidData.getBaseSection().setDisplayName("Stone");
    solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
    solidData.getBaseSection().setTranslucent(false);
    solidData.setFamilyFactory(new SymmetricBlockFamilyFactory());
    assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
    solid = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
    BlockFamilyDefinitionData solidMediumLightData = new BlockFamilyDefinitionData();
    solidMediumLightData.getBaseSection().setDisplayName("SolidMediumLight");
    solidMediumLightData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
    solidMediumLightData.getBaseSection().setTranslucent(false);
    solidMediumLightData.getBaseSection().setLuminance((byte) 5);
    solidMediumLightData.setFamilyFactory(new SymmetricBlockFamilyFactory());
    assetManager.loadAsset(new ResourceUrn("engine:solidMediumLight"), solidMediumLightData, BlockFamilyDefinition.class);
    solidMediumLight = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:solidMediumLight")));
    air = blockManager.getBlock(BlockManager.AIR_ID);
}
Also used : LightPropagationRules(org.terasology.world.propagation.light.LightPropagationRules) BlockUri(org.terasology.world.block.BlockUri) AssetManager(org.terasology.assets.management.AssetManager) BlockFamilyDefinitionData(org.terasology.world.block.loader.BlockFamilyDefinitionData) NullWorldAtlas(org.terasology.world.block.tiles.NullWorldAtlas) ResourceUrn(org.terasology.assets.ResourceUrn) SymmetricBlockFamilyFactory(org.terasology.world.block.family.SymmetricBlockFamilyFactory) BlockManagerImpl(org.terasology.world.block.internal.BlockManagerImpl) Before(org.junit.Before)

Example 5 with BlockUri

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

the class BulkSunlightPropagationTest method setup.

@Before
public void setup() throws Exception {
    super.setup();
    regenRules = new SunlightRegenPropagationRules();
    AssetManager assetManager = CoreRegistry.get(AssetManager.class);
    blockManager = new BlockManagerImpl(new NullWorldAtlas(), assetManager, true);
    CoreRegistry.put(BlockManager.class, blockManager);
    BlockFamilyDefinitionData solidData = new BlockFamilyDefinitionData();
    solidData.getBaseSection().setDisplayName("Stone");
    solidData.getBaseSection().setShape(assetManager.getAsset("engine:cube", BlockShape.class).get());
    solidData.getBaseSection().setTranslucent(false);
    solidData.setFamilyFactory(new SymmetricBlockFamilyFactory());
    assetManager.loadAsset(new ResourceUrn("engine:stone"), solidData, BlockFamilyDefinition.class);
    solid = blockManager.getBlock(new BlockUri(new ResourceUrn("engine:stone")));
    air = blockManager.getBlock(BlockManager.AIR_ID);
    Map<Vector3i, Block> blockData = Maps.newHashMap();
    regenWorldView = new StubPropagatorWorldView(ChunkConstants.CHUNK_REGION, air, blockData);
    lightWorldView = new StubPropagatorWorldView(ChunkConstants.CHUNK_REGION, air, blockData);
    lightRules = new SunlightPropagationRules(regenWorldView);
    sunlightPropagator = new StandardBatchPropagator(lightRules, lightWorldView);
    propagator = new SunlightRegenBatchPropagator(regenRules, regenWorldView, sunlightPropagator, lightWorldView);
}
Also used : BlockUri(org.terasology.world.block.BlockUri) AssetManager(org.terasology.assets.management.AssetManager) SunlightPropagationRules(org.terasology.world.propagation.light.SunlightPropagationRules) BlockFamilyDefinitionData(org.terasology.world.block.loader.BlockFamilyDefinitionData) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) NullWorldAtlas(org.terasology.world.block.tiles.NullWorldAtlas) ResourceUrn(org.terasology.assets.ResourceUrn) SunlightRegenPropagationRules(org.terasology.world.propagation.light.SunlightRegenPropagationRules) SymmetricBlockFamilyFactory(org.terasology.world.block.family.SymmetricBlockFamilyFactory) BlockManagerImpl(org.terasology.world.block.internal.BlockManagerImpl) Before(org.junit.Before)

Aggregations

BlockUri (org.terasology.world.block.BlockUri)15 ResourceUrn (org.terasology.assets.ResourceUrn)7 Block (org.terasology.world.block.Block)7 Before (org.junit.Before)6 AssetManager (org.terasology.assets.management.AssetManager)6 SymmetricBlockFamilyFactory (org.terasology.world.block.family.SymmetricBlockFamilyFactory)6 BlockManagerImpl (org.terasology.world.block.internal.BlockManagerImpl)6 BlockFamilyDefinitionData (org.terasology.world.block.loader.BlockFamilyDefinitionData)6 NullWorldAtlas (org.terasology.world.block.tiles.NullWorldAtlas)6 BiomeManager (org.terasology.world.biomes.BiomeManager)4 Rotation (org.terasology.math.Rotation)3 Side (org.terasology.math.Side)3 Command (org.terasology.logic.console.commandSystem.annotations.Command)2 Vector3i (org.terasology.math.geom.Vector3i)2 BlockFamily (org.terasology.world.block.family.BlockFamily)2 SunlightPropagationRules (org.terasology.world.propagation.light.SunlightPropagationRules)2 SunlightRegenPropagationRules (org.terasology.world.propagation.light.SunlightRegenPropagationRules)2 TByteObjectMap (gnu.trove.map.TByteObjectMap)1 TByteObjectHashMap (gnu.trove.map.hash.TByteObjectHashMap)1 Iterator (java.util.Iterator)1