Search in sources :

Example 1 with BlockFamily

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

the class ReadWriteStorageManager method addGameManifestToSaveTransaction.

private void addGameManifestToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder) {
    BlockManager blockManager = CoreRegistry.get(BlockManager.class);
    BiomeManager biomeManager = CoreRegistry.get(BiomeManager.class);
    WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
    Time time = CoreRegistry.get(Time.class);
    Game game = CoreRegistry.get(Game.class);
    GameManifest gameManifest = new GameManifest(game.getName(), game.getSeed(), time.getGameTimeInMs());
    for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
        gameManifest.addModule(module.getId(), module.getVersion());
    }
    List<String> registeredBlockFamilies = Lists.newArrayList();
    for (BlockFamily family : blockManager.listRegisteredBlockFamilies()) {
        registeredBlockFamilies.add(family.getURI().toString());
    }
    gameManifest.setRegisteredBlockFamilies(registeredBlockFamilies);
    gameManifest.setBlockIdMap(blockManager.getBlockIdMap());
    List<Biome> biomes = biomeManager.getBiomes();
    Map<String, Short> biomeIdMap = new HashMap<>(biomes.size());
    for (Biome biome : biomes) {
        short shortId = biomeManager.getBiomeShortId(biome);
        String id = biomeManager.getBiomeId(biome);
        biomeIdMap.put(id, shortId);
    }
    gameManifest.setBiomeIdMap(biomeIdMap);
    gameManifest.addWorld(worldProvider.getWorldInfo());
    saveTransactionBuilder.setGameManifest(gameManifest);
}
Also used : BiomeManager(org.terasology.world.biomes.BiomeManager) HashMap(java.util.HashMap) Time(org.terasology.engine.Time) ModuleManager(org.terasology.engine.module.ModuleManager) Game(org.terasology.game.Game) Biome(org.terasology.world.biomes.Biome) GameManifest(org.terasology.game.GameManifest) BlockManager(org.terasology.world.block.BlockManager) WorldProvider(org.terasology.world.WorldProvider) BlockFamily(org.terasology.world.block.family.BlockFamily) Module(org.terasology.module.Module)

Example 2 with BlockFamily

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

the class ItemCommonSystem method addOrUpdateBlockMeshComponent.

public static void addOrUpdateBlockMeshComponent(BlockItemComponent blockItemComponent, MutableComponentContainer entity) {
    if (blockItemComponent != null) {
        MeshComponent meshComponent = null;
        if (entity.hasComponent(MeshComponent.class)) {
            meshComponent = entity.getComponent(MeshComponent.class);
        } else {
            meshComponent = new MeshComponent();
        }
        BlockFamily blockFamily = blockItemComponent.blockFamily;
        if (blockFamily == null) {
            return;
        }
        meshComponent.mesh = blockFamily.getArchetypeBlock().getMeshGenerator().getStandaloneMesh();
        meshComponent.material = Assets.getMaterial("engine:terrain").get();
        meshComponent.translucent = blockFamily.getArchetypeBlock().isTranslucent();
        float luminance = blockFamily.getArchetypeBlock().getLuminance() / 15f;
        meshComponent.selfLuminance = luminance;
        if (luminance > 0 && !entity.hasComponent(LightComponent.class)) {
            LightComponent lightComponent = entity.addComponent(new LightComponent());
            // scale the light back if it is a less bright block
            lightComponent.lightAttenuationRange *= luminance;
        }
        entity.addOrSaveComponent(meshComponent);
    }
}
Also used : MeshComponent(org.terasology.rendering.logic.MeshComponent) LightComponent(org.terasology.rendering.logic.LightComponent) BlockFamily(org.terasology.world.block.family.BlockFamily)

Example 3 with BlockFamily

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

the class CoreCommands method spawnBlock.

/**
 * Spawns a block in front of the player
 * @param sender Sender of command
 * @param blockName String containing name of block to spawn
 * @return String containg final message
 */
@Command(shortDescription = "Spawns a block in front of the player", helpText = "Spawns the specified block as a " + "item in front of the player. You can simply pick it up.", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String spawnBlock(@Sender EntityRef sender, @CommandParam("blockName") String blockName) {
    ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
    LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
    Vector3f spawnPos = characterLocation.getWorldPosition();
    Vector3f offset = characterLocation.getWorldDirection();
    offset.scale(3);
    spawnPos.add(offset);
    BlockFamily block = blockManager.getBlockFamily(blockName);
    if (block == null) {
        return "";
    }
    BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
    EntityRef blockItem = blockItemFactory.newInstance(block);
    blockItem.send(new DropItemEvent(spawnPos));
    return "Spawned block.";
}
Also used : DropItemEvent(org.terasology.logic.inventory.events.DropItemEvent) Vector3f(org.terasology.math.geom.Vector3f) BlockItemFactory(org.terasology.world.block.items.BlockItemFactory) BlockFamily(org.terasology.world.block.family.BlockFamily) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Example 4 with BlockFamily

use of org.terasology.world.block.family.BlockFamily 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 5 with BlockFamily

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

the class BlockItemSystem method onPlaceBlock.

@ReceiveEvent(components = { BlockItemComponent.class, ItemComponent.class })
public void onPlaceBlock(ActivateEvent event, EntityRef item) {
    if (!event.getTarget().exists()) {
        event.consume();
        return;
    }
    BlockItemComponent blockItem = item.getComponent(BlockItemComponent.class);
    BlockFamily type = blockItem.blockFamily;
    Side surfaceSide = Side.inDirection(event.getHitNormal());
    Side secondaryDirection = ChunkMath.getSecondaryPlacementDirection(event.getDirection(), event.getHitNormal());
    BlockComponent blockComponent = event.getTarget().getComponent(BlockComponent.class);
    if (blockComponent == null) {
        // If there is no block there (i.e. it's a BlockGroup, we don't allow placing block, try somewhere else)
        event.consume();
        return;
    }
    Vector3i targetBlock = blockComponent.getPosition();
    Vector3i placementPos = new Vector3i(targetBlock);
    placementPos.add(surfaceSide.getVector3i());
    Block block = type.getBlockForPlacement(worldProvider, blockEntityRegistry, placementPos, surfaceSide, secondaryDirection);
    if (canPlaceBlock(block, targetBlock, placementPos)) {
        // TODO: Fix this for changes.
        if (networkSystem.getMode().isAuthority()) {
            PlaceBlocks placeBlocks = new PlaceBlocks(placementPos, block, event.getInstigator());
            worldProvider.getWorldEntity().send(placeBlocks);
            if (!placeBlocks.isConsumed()) {
                item.send(new OnBlockItemPlaced(placementPos, blockEntityRegistry.getBlockEntityAt(placementPos)));
            } else {
                event.consume();
            }
        }
        recordBlockPlaced(event, type);
        event.getInstigator().send(new PlaySoundEvent(Assets.getSound("engine:PlaceBlock").get(), 0.5f));
    } else {
        event.consume();
    }
}
Also used : Side(org.terasology.math.Side) BlockComponent(org.terasology.world.block.BlockComponent) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) BlockFamily(org.terasology.world.block.family.BlockFamily) PlaceBlocks(org.terasology.world.block.entity.placement.PlaceBlocks) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

BlockFamily (org.terasology.world.block.family.BlockFamily)16 Block (org.terasology.world.block.Block)7 EntityRef (org.terasology.entitySystem.entity.EntityRef)4 Command (org.terasology.logic.console.commandSystem.annotations.Command)4 LocationComponent (org.terasology.logic.location.LocationComponent)4 Vector3f (org.terasology.math.geom.Vector3f)4 ClientComponent (org.terasology.network.ClientComponent)4 ResourceUrn (org.terasology.assets.ResourceUrn)3 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)3 DropItemEvent (org.terasology.logic.inventory.events.DropItemEvent)3 BlockItemFactory (org.terasology.world.block.items.BlockItemFactory)3 Iterator (java.util.Iterator)2 ModuleManager (org.terasology.engine.module.ModuleManager)2 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)2 Side (org.terasology.math.Side)2 Vector3i (org.terasology.math.geom.Vector3i)2 Module (org.terasology.module.Module)2 WorldProvider (org.terasology.world.WorldProvider)2 Biome (org.terasology.world.biomes.Biome)2 BlockComponent (org.terasology.world.block.BlockComponent)2