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;
}
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);
}
}
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");
}
Aggregations