use of org.terasology.engine.world.block.loader.BlockFamilyDefinition in project Terasology by MovingBlocks.
the class BlockManagerImpl method loadFamily.
private Optional<BlockFamily> loadFamily(BlockUri uri) {
Optional<BlockFamilyDefinition> familyDef = assetManager.getAsset(uri.getBlockFamilyDefinitionUrn(), BlockFamilyDefinition.class);
if (familyDef.isPresent() && familyDef.get().isLoadable()) {
if (familyDef.get().isFreeform()) {
ResourceUrn shapeUrn;
if (uri.getShapeUrn().isPresent()) {
shapeUrn = uri.getShapeUrn().get();
} else {
shapeUrn = CUBE_SHAPE_URN;
}
Optional<BlockShape> shape = assetManager.getAsset(shapeUrn, BlockShape.class);
if (shape.isPresent()) {
return Optional.of(familyDef.get().createFamily(shape.get(), blockBuilder));
}
} else if (!familyDef.get().isFreeform()) {
return Optional.of(familyDef.get().createFamily(blockBuilder));
}
} else {
logger.error("Family not available: {}", uri);
}
return Optional.empty();
}
use of org.terasology.engine.world.block.loader.BlockFamilyDefinition 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(new Vector3f()), gazeLocation.getWorldDirection(new Vector3f()), 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(", ");
}
}
}
}
}
use of org.terasology.engine.world.block.loader.BlockFamilyDefinition in project Terasology by MovingBlocks.
the class TerasologyEngine method initAssets.
private void initAssets() {
// cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
assetTypeManager.createAssetType(BlockShape.class, BlockShapeImpl::new, "shapes");
assetTypeManager.createAssetType(BlockSounds.class, BlockSounds::new, "blockSounds");
assetTypeManager.createAssetType(BlockTile.class, BlockTile::new, "blockTiles");
AssetType<BlockFamilyDefinition, BlockFamilyDefinitionData> blockFamilyDefinitionAssetType = assetTypeManager.createAssetType(BlockFamilyDefinition.class, BlockFamilyDefinition::new, "blocks");
assetTypeManager.getAssetFileDataProducer(blockFamilyDefinitionAssetType).addAssetFormat(new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager()));
assetTypeManager.createAssetType(UISkinAsset.class, UISkinAsset::new, "skins");
assetTypeManager.createAssetType(BehaviorTree.class, BehaviorTree::new, "behaviors");
assetTypeManager.createAssetType(UIElement.class, UIElement::new, "ui");
assetTypeManager.createAssetType(ByteBufferAsset.class, ByteBufferAsset::new, "mesh");
for (EngineSubsystem subsystem : allSubsystems) {
subsystem.registerCoreAssetTypes(assetTypeManager);
}
}
use of org.terasology.engine.world.block.loader.BlockFamilyDefinition in project Terasology by MovingBlocks.
the class UniverseSetupScreen method initAssets.
private void initAssets() {
ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
BlockFamilyLibrary library = new BlockFamilyLibrary(environment, context);
// cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
assetTypeManager.createAssetType(BlockShape.class, BlockShapeImpl::new, "shapes");
assetTypeManager.createAssetType(BlockSounds.class, BlockSounds::new, "blockSounds");
assetTypeManager.createAssetType(BlockTile.class, BlockTile::new, "blockTiles");
AssetType<BlockFamilyDefinition, BlockFamilyDefinitionData> blockFamilyDefinitionDataAssetType = assetTypeManager.createAssetType(BlockFamilyDefinition.class, BlockFamilyDefinition::new, "blocks");
assetTypeManager.getAssetFileDataProducer(blockFamilyDefinitionDataAssetType).addAssetFormat(new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager()));
assetTypeManager.createAssetType(UISkinAsset.class, UISkinAsset::new, "skins");
assetTypeManager.createAssetType(BehaviorTree.class, BehaviorTree::new, "behaviors");
assetTypeManager.createAssetType(UIElement.class, UIElement::new, "ui");
}
use of org.terasology.engine.world.block.loader.BlockFamilyDefinition in project Terasology by MovingBlocks.
the class HeadlessEnvironment method setupAssetManager.
@Override
protected AssetManager setupAssetManager() {
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
// cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
assetTypeManager.createAssetType(BlockShape.class, BlockShapeImpl::new, "shapes");
assetTypeManager.createAssetType(BlockSounds.class, BlockSounds::new, "blockSounds");
assetTypeManager.createAssetType(BlockTile.class, BlockTile::new, "blockTiles");
AssetType<BlockFamilyDefinition, BlockFamilyDefinitionData> blockFamilyDefinitionDataAssetType = assetTypeManager.createAssetType(BlockFamilyDefinition.class, BlockFamilyDefinition::new, "blocks");
assetTypeManager.getAssetFileDataProducer(blockFamilyDefinitionDataAssetType).addAssetFormat(new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager()));
assetTypeManager.createAssetType(StaticSound.class, NullSound::new, "sounds");
assetTypeManager.createAssetType(StreamingSound.class, NullStreamingSound::new, "music");
assetTypeManager.createAssetType(UISkinAsset.class, UISkinAsset::new, "skins");
assetTypeManager.createAssetType(BehaviorTree.class, BehaviorTree::new, "behaviors");
assetTypeManager.createAssetType(UIElement.class, UIElement::new, "ui");
assetTypeManager.createAssetType(Font.class, FontImpl::new, "fonts");
AssetType<Texture, TextureData> textureDataAssetType = assetTypeManager.createAssetType(Texture.class, HeadlessTexture::create, "textures", "fonts");
assetTypeManager.getAssetFileDataProducer(textureDataAssetType).addAssetFormat(new PNGTextureFormat(Texture.FilterMode.NEAREST, path -> path.getPath().get(1).equals("textures")));
assetTypeManager.getAssetFileDataProducer(textureDataAssetType).addAssetFormat(new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> path.getPath().get(1).equals("fonts")));
assetTypeManager.createAssetType(Shader.class, HeadlessShader::new, "shaders");
assetTypeManager.createAssetType(Material.class, HeadlessMaterial::new, "materials");
assetTypeManager.createAssetType(Mesh.class, HeadlessMesh::new, "mesh");
assetTypeManager.createAssetType(SkeletalMesh.class, HeadlessSkeletalMesh::new, "skeletalMesh");
assetTypeManager.createAssetType(MeshAnimation.class, MeshAnimationImpl::new, "animations");
assetTypeManager.createAssetType(Atlas.class, Atlas::new, "atlas");
assetTypeManager.createAssetType(Subtexture.class, Subtexture::new);
assetTypeManager.switchEnvironment(context.get(ModuleManager.class).getEnvironment());
context.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
context.put(AssetManager.class, assetTypeManager.getAssetManager());
return assetTypeManager.getAssetManager();
}
Aggregations