Search in sources :

Example 56 with Name

use of org.terasology.gestalt.naming.Name 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 57 with Name

use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.

the class WorldAtlasImpl method createTextureAtlas.

private void createTextureAtlas(final Texture texture) {
    final Map<Name, Map<Name, SubtextureData>> textureAtlases = Maps.newHashMap();
    final Vector2f texSize = new Vector2f(getRelativeTileSize(), getRelativeTileSize());
    tileIndexes.forEachEntry((tileUri, index) -> {
        Vector2f coords = getTexCoords(index);
        SubtextureData subtextureData = new SubtextureData(texture, new Rectanglef(coords, coords).setSize(texSize));
        Map<Name, SubtextureData> textureAtlas = textureAtlases.get(tileUri.getModuleName());
        if (textureAtlas == null) {
            textureAtlas = Maps.newHashMap();
            textureAtlases.put(tileUri.getModuleName(), textureAtlas);
        }
        textureAtlas.put(tileUri.getResourceName(), subtextureData);
        return true;
    });
    for (Map.Entry<Name, Map<Name, SubtextureData>> atlas : textureAtlases.entrySet()) {
        AtlasData data = new AtlasData(atlas.getValue());
        Assets.generateAsset(new ResourceUrn(atlas.getKey(), new Name("terrain")), data, Atlas.class);
    }
}
Also used : AtlasData(org.terasology.engine.rendering.assets.atlas.AtlasData) Vector2f(org.joml.Vector2f) SubtextureData(org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData) Rectanglef(org.terasology.joml.geom.Rectanglef) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) TObjectIntMap(gnu.trove.map.TObjectIntMap) Map(java.util.Map) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) Name(org.terasology.gestalt.naming.Name)

Example 58 with Name

use of org.terasology.gestalt.naming.Name in project Terasology by MovingBlocks.

the class WorldGeneratorManager method createWorldGenerator.

/**
 * @param uri uri of the world generator to create.
 * @param context that will be used to inject teh world generator.
 * @param environment to be searched for the world generator class.
 * @return a new world generator with the specified uri.
 */
public static WorldGenerator createWorldGenerator(SimpleUri uri, Context context, ModuleEnvironment environment) throws UnresolvedWorldGeneratorException {
    for (Class<?> generatorClass : environment.getTypesAnnotatedWith(RegisterWorldGenerator.class)) {
        RegisterWorldGenerator annotation = generatorClass.getAnnotation(RegisterWorldGenerator.class);
        Name moduleName = environment.getModuleProviding(generatorClass);
        if (moduleName == null) {
            throw new UnresolvedWorldGeneratorException("Cannot find module for world generator " + generatorClass);
        }
        SimpleUri generatorUri = new SimpleUri(moduleName, annotation.id());
        if (generatorUri.equals(uri)) {
            WorldGenerator worldGenerator = loadGenerator(generatorClass, generatorUri);
            InjectionHelper.inject(worldGenerator, context);
            return worldGenerator;
        }
    }
    throw new UnresolvedWorldGeneratorException("Unable to resolve world generator '" + uri + "' - not found");
}
Also used : RegisterWorldGenerator(org.terasology.engine.world.generator.RegisterWorldGenerator) RegisterWorldGenerator(org.terasology.engine.world.generator.RegisterWorldGenerator) WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) SimpleUri(org.terasology.engine.core.SimpleUri) Name(org.terasology.gestalt.naming.Name)

Aggregations

Name (org.terasology.gestalt.naming.Name)58 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)15 Module (org.terasology.gestalt.module.Module)14 SimpleUri (org.terasology.engine.core.SimpleUri)13 ModuleManager (org.terasology.engine.core.module.ModuleManager)10 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)7 IOException (java.io.IOException)6 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)6 List (java.util.List)5 GameEngine (org.terasology.engine.core.GameEngine)5 SubtextureData (org.terasology.engine.rendering.assets.texture.subtexture.SubtextureData)5 BlockUri (org.terasology.engine.world.block.BlockUri)5 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)5 UIText (org.terasology.nui.widgets.UIText)5 Map (java.util.Map)4 Set (java.util.Set)4 Config (org.terasology.engine.config.Config)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3