Search in sources :

Example 1 with BlockItemFactory

use of org.terasology.engine.world.block.items.BlockItemFactory 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 2 with BlockItemFactory

use of org.terasology.engine.world.block.items.BlockItemFactory in project Terasology by MovingBlocks.

the class CoreCommands method bulkDrop.

@Command(shortDescription = "Mass-drops the desired block however many times the player indicates", helpText = "First parameter indicates which block to drop, second parameter how many", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String bulkDrop(@Sender EntityRef sender, @CommandParam("blockName") String blockName, @CommandParam("value") int value) {
    // This is a loop which gives the particular amount of block the player wants to spawn
    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(3);
    spawnPos.add(5, 10, 0);
    BlockFamily block = blockManager.getBlockFamily(blockName);
    if (block == null) {
        return "Sorry, your block is not found";
    }
    BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
    if (value > 5000) {
        return "Value exceeds the maximum limit of 5000 blocks. your value: " + value + " blocks";
    }
    for (int i = 0; i < value; i++) {
        EntityRef blockItem = blockItemFactory.newInstance(block);
        blockItem.send(new DropItemEvent(spawnPos));
    }
    // this returns the block you have spawned and the amount
    return "Dropped " + value + " " + blockName + " Blocks :)";
}
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 BlockItemFactory

use of org.terasology.engine.world.block.items.BlockItemFactory 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(new Vector3f());
    Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
    offset.mul(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.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 4 with BlockItemFactory

use of org.terasology.engine.world.block.items.BlockItemFactory in project Terasology by MovingBlocks.

the class BlockCommands method initialise.

@Override
public void initialise() {
    blockItemFactory = new BlockItemFactory(entityManager);
    blockExplorer = new BlockExplorer(assetManager);
    targetSystem = new TargetSystem(blockRegistry, physics);
}
Also used : BlockItemFactory(org.terasology.engine.world.block.items.BlockItemFactory) BlockExplorer(org.terasology.engine.world.block.BlockExplorer) TargetSystem(org.terasology.engine.input.cameraTarget.TargetSystem)

Example 5 with BlockItemFactory

use of org.terasology.engine.world.block.items.BlockItemFactory in project Terasology by MovingBlocks.

the class BlockEntitySystem method initialise.

@Override
public void initialise() {
    blockItemFactory = new BlockItemFactory(entityManager);
    random = new FastRandom();
}
Also used : BlockItemFactory(org.terasology.engine.world.block.items.BlockItemFactory) FastRandom(org.terasology.engine.utilities.random.FastRandom)

Aggregations

BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)5 Vector3f (org.joml.Vector3f)3 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)3 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)3 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)3 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)3 LocationComponent (org.terasology.engine.logic.location.LocationComponent)3 ClientComponent (org.terasology.engine.network.ClientComponent)3 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)3 TargetSystem (org.terasology.engine.input.cameraTarget.TargetSystem)1 FastRandom (org.terasology.engine.utilities.random.FastRandom)1 BlockExplorer (org.terasology.engine.world.block.BlockExplorer)1