Search in sources :

Example 6 with BlockItemFactory

use of org.terasology.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();
    Vector3f offset = characterLocation.getWorldDirection();
    offset.scale(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.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 7 with BlockItemFactory

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

the class BlockDropGrammarSystem method initialise.

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

Aggregations

BlockItemFactory (org.terasology.world.block.items.BlockItemFactory)7 EntityRef (org.terasology.entitySystem.entity.EntityRef)4 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)3 Command (org.terasology.logic.console.commandSystem.annotations.Command)3 DropItemEvent (org.terasology.logic.inventory.events.DropItemEvent)3 LocationComponent (org.terasology.logic.location.LocationComponent)3 Vector3f (org.terasology.math.geom.Vector3f)3 ClientComponent (org.terasology.network.ClientComponent)3 BlockFamily (org.terasology.world.block.family.BlockFamily)3 FastRandom (org.terasology.utilities.random.FastRandom)2 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1 TargetSystem (org.terasology.input.cameraTarget.TargetSystem)1 InventoryComponent (org.terasology.logic.inventory.InventoryComponent)1 ItemComponent (org.terasology.logic.inventory.ItemComponent)1 BlockExplorer (org.terasology.world.block.BlockExplorer)1