Search in sources :

Example 1 with BlockFamily

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

the class EntityAwareWorldProviderTest method setup.

@BeforeEach
public void setup() throws Exception {
    super.setup();
    GameThread.setToCurrentThread();
    this.entityManager = context.get(EngineEntityManager.class);
    AssetManager assetManager = context.get(AssetManager.class);
    BlockManager blockManager = context.get(BlockManager.class);
    airBlock = blockManager.getBlock(BlockManager.AIR_ID);
    worldStub = new WorldProviderCoreStub(airBlock);
    worldProvider = new EntityAwareWorldProvider(worldStub, context);
    plainBlock = createBlock("test:plainblock", assetManager, blockManager);
    prefabWithString = createPrefabWithString("test:prefabWithString", "Test", assetManager);
    blockWithString = createBlockWithPrefab("test:blockWithString", prefabWithString, false, assetManager, blockManager);
    keepActiveBlock = createBlockWithPrefab("test:keepActiveBlock", prefabWithString, true, assetManager, blockManager);
    Prefab prefabWithDifferentString = createPrefabWithString("test:prefabWithDifferentString", "Test2", assetManager);
    blockWithDifferentString = createBlockWithPrefab("test:prefabWithDifferentString", prefabWithDifferentString, false, assetManager, blockManager);
    BlockFamily blockFamily = createBlockFamily("test:blockFamily", prefabWithString, assetManager, blockManager);
    Iterator<Block> iterator = blockFamily.getBlocks().iterator();
    blockInFamilyOne = iterator.next();
    blockInFamilyTwo = iterator.next();
    PrefabData retainedPrefabData = new PrefabData();
    retainedPrefabData.addComponent(new RetainedOnBlockChangeComponent(3));
    Prefab retainedPrefab = assetManager.loadAsset(new ResourceUrn("test:retainedPrefab"), retainedPrefabData, Prefab.class);
    blockWithRetainedComponent = createBlockWithPrefab("test:blockWithRetainedComponent", retainedPrefab, false, assetManager, blockManager);
    worldProvider.initialise();
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) AssetManager(org.terasology.gestalt.assets.management.AssetManager) PrefabData(org.terasology.engine.entitySystem.prefab.PrefabData) RetainedOnBlockChangeComponent(org.terasology.unittest.stubs.RetainedOnBlockChangeComponent) BlockManager(org.terasology.engine.world.block.BlockManager) Block(org.terasology.engine.world.block.Block) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) EntityAwareWorldProvider(org.terasology.engine.world.internal.EntityAwareWorldProvider) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) WorldProviderCoreStub(org.terasology.engine.testUtil.WorldProviderCoreStub) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with BlockFamily

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

the class CoreCommands method bowlingPrep.

@Command(shortDescription = "Sets up a typical bowling pin arrangement in front of the player. ", helpText = "Spawns the specific block in a regular bowling pin pattern, Throw something at it!", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String bowlingPrep(@Sender EntityRef sender, @CommandParam("blockName") String blockName) {
    ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
    LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
    Vector3f spawnPos = characterLocation.getWorldPosition(new Vector3f());
    Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
    offset.mul(5);
    spawnPos.add(offset);
    BlockFamily block = blockManager.getBlockFamily(blockName);
    if (block == null) {
        return "Sorry, your block is not found";
    }
    BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
    Vector3f startPos = new Vector3f(spawnPos);
    // delta x is the distance between the pins in the rows.
    float deltax = 0.5f;
    // delta z is the distance between the rows.
    float deltaz = 1.0f;
    // the height of the drop (to be modified to keep the bowlingPin upright)
    float vectorY = 0.0f;
    // rownumber loop is for selecting row
    for (int rownumber = 0; rownumber < 4; rownumber++) {
        // Spawn starting position for Rownumber
        startPos.add(deltax * (4 - rownumber), vectorY, deltaz);
        // pinPosx loop is for vectorx position of bowling pin  in  a particular row
        for (int pinPosx = 0; pinPosx <= rownumber; pinPosx++) {
            EntityRef blockItem = blockItemFactory.newInstance(block);
            blockItem.send(new DropItemEvent(startPos));
            if (pinPosx < rownumber) {
                // drift of position in vector x coordinate, for the last pin stop drifting
                startPos.add(2 * deltax, 0, 0);
            }
        }
        // returns to start position
        startPos.add(-deltax * (rownumber + 4), 0, 0);
    }
    return "prepared 10 " + blockName + " in a bowling pin pattern :)";
}
Also used : DropItemEvent(org.terasology.engine.logic.inventory.events.DropItemEvent) Vector3f(org.joml.Vector3f) BlockItemFactory(org.terasology.engine.world.block.items.BlockItemFactory) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Example 3 with BlockFamily

use of org.terasology.engine.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.engine.rendering.logic.MeshComponent) LightComponent(org.terasology.engine.rendering.logic.LightComponent) BlockFamily(org.terasology.engine.world.block.family.BlockFamily)

Example 4 with BlockFamily

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

the class NetworkSystemImpl method getServerInfoMessage.

private NetData.ServerInfoMessage getServerInfoMessage(String errorMessage) {
    NetData.ServerInfoMessage.Builder serverInfoMessageBuilder = NetData.ServerInfoMessage.newBuilder();
    serverInfoMessageBuilder.setTime(time.getGameTimeInMs());
    if (config.getServerMOTD() != null) {
        serverInfoMessageBuilder.setMOTD(config.getServerMOTD());
    }
    serverInfoMessageBuilder.setOnlinePlayersAmount(clientList.size());
    WorldProvider worldProvider = context.get(WorldProvider.class);
    if (worldProvider != null) {
        NetData.WorldInfo.Builder worldInfoBuilder = NetData.WorldInfo.newBuilder();
        worldInfoBuilder.setTime(worldProvider.getTime().getMilliseconds());
        worldInfoBuilder.setTitle(worldProvider.getTitle());
        serverInfoMessageBuilder.addWorldInfo(worldInfoBuilder);
    }
    WorldGenerator worldGen = context.get(WorldGenerator.class);
    if (worldGen != null) {
        serverInfoMessageBuilder.setReflectionHeight(worldGen.getWorld().getSeaLevel() + 0.5f);
    }
    for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
        if (!StandardModuleExtension.isServerSideOnly(module)) {
            serverInfoMessageBuilder.addModule(NetData.ModuleInfo.newBuilder().setModuleId(module.getId().toString()).setModuleVersion(module.getVersion().toString()).build());
        }
    }
    for (Map.Entry<String, Short> blockMapping : blockManager.getBlockIdMap().entrySet()) {
        serverInfoMessageBuilder.addBlockId(blockMapping.getValue());
        serverInfoMessageBuilder.addBlockName(blockMapping.getKey());
    }
    for (BlockFamily registeredBlockFamily : blockManager.listRegisteredBlockFamilies()) {
        serverInfoMessageBuilder.addRegisterBlockFamily(registeredBlockFamily.getURI().toString());
    }
    if (errorMessage != null && !errorMessage.isEmpty()) {
        serverInfoMessageBuilder.setErrorMessage(errorMessage);
    }
    serializeComponentInfo(serverInfoMessageBuilder);
    serializeEventInfo(serverInfoMessageBuilder);
    return serverInfoMessageBuilder.build();
}
Also used : WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) ByteString(com.google.protobuf.ByteString) ModuleManager(org.terasology.engine.core.module.ModuleManager) WorldProvider(org.terasology.engine.world.WorldProvider) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) Module(org.terasology.gestalt.module.Module) Map(java.util.Map) TIntLongMap(gnu.trove.map.TIntLongMap) TIntLongHashMap(gnu.trove.map.hash.TIntLongHashMap)

Example 5 with BlockFamily

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

the class NetClient method sendRegisteredBlocks.

private void sendRegisteredBlocks(NetData.NetMessage.Builder message) {
    synchronized (newlyRegisteredFamilies) {
        for (BlockFamily family : newlyRegisteredFamilies) {
            NetData.BlockFamilyRegisteredMessage.Builder blockRegMessage = NetData.BlockFamilyRegisteredMessage.newBuilder();
            for (Block block : family.getBlocks()) {
                blockRegMessage.addBlockUri(block.getURI().toString());
                blockRegMessage.addBlockId(block.getId());
            }
            message.addBlockFamilyRegistered(blockRegMessage);
        }
        newlyRegisteredFamilies.clear();
    }
}
Also used : Block(org.terasology.engine.world.block.Block) BlockFamily(org.terasology.engine.world.block.family.BlockFamily)

Aggregations

BlockFamily (org.terasology.engine.world.block.family.BlockFamily)15 Block (org.terasology.engine.world.block.Block)7 Vector3f (org.joml.Vector3f)5 LocationComponent (org.terasology.engine.logic.location.LocationComponent)5 ClientComponent (org.terasology.engine.network.ClientComponent)5 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)4 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)4 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)3 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)3 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)3 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)3 Iterator (java.util.Iterator)2 Vector3i (org.joml.Vector3i)2 ModuleManager (org.terasology.engine.core.module.ModuleManager)2 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)2 Side (org.terasology.engine.math.Side)2 BlockComponent (org.terasology.engine.world.block.BlockComponent)2 BlockManager (org.terasology.engine.world.block.BlockManager)2 BlockUri (org.terasology.engine.world.block.BlockUri)2 BlockFamilyDefinition (org.terasology.engine.world.block.loader.BlockFamilyDefinition)2