Search in sources :

Example 1 with BlockItemFactory

use of org.terasology.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();
    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 2 with BlockItemFactory

use of org.terasology.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.world.block.items.BlockItemFactory) FastRandom(org.terasology.utilities.random.FastRandom)

Example 3 with BlockItemFactory

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

the class PlayerStartingInventorySystem method onPlayerSpawnedEvent.

@ReceiveEvent(components = InventoryComponent.class)
public void onPlayerSpawnedEvent(OnPlayerSpawnedEvent event, EntityRef player) {
    BlockItemFactory blockFactory = new BlockItemFactory(entityManager);
    // Goodie chest
    EntityRef chest = blockFactory.newInstance(blockManager.getBlockFamily("core:chest"));
    chest.addComponent(new InventoryComponent(30));
    inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:companion"), 99));
    inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:brick:engine:stair"), 99));
    inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:Tnt"), 99));
    inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("core:fuseShort"));
    inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("core:fuseLong"));
    inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("core:shallowRailgunTool"));
    inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("core:thoroughRailgunTool"));
    inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("core:railgunTool"));
    inventoryManager.giveItem(chest, EntityRef.NULL, entityManager.create("core:mrbarsack"));
    inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:Brick"), 99));
    inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:Ice"), 99));
    inventoryManager.giveItem(chest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:Plank"), 99));
    EntityRef doorItem = entityManager.create("core:door");
    ItemComponent doorItemComp = doorItem.getComponent(ItemComponent.class);
    doorItemComp.stackCount = 20;
    doorItem.saveComponent(doorItemComp);
    inventoryManager.giveItem(chest, EntityRef.NULL, doorItem);
    // Inner goodie chest
    EntityRef innerChest = blockFactory.newInstance(blockManager.getBlockFamily("core:Chest"));
    innerChest.addComponent(new InventoryComponent(30));
    inventoryManager.giveItem(innerChest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:lava"), 99));
    inventoryManager.giveItem(innerChest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:water"), 99));
    inventoryManager.giveItem(innerChest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:Iris"), 99));
    inventoryManager.giveItem(innerChest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:Dandelion"), 99));
    inventoryManager.giveItem(innerChest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:Tulip"), 99));
    inventoryManager.giveItem(innerChest, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:YellowFlower"), 99));
    // Place inner chest into outer chest
    inventoryManager.giveItem(chest, EntityRef.NULL, innerChest);
    inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("core:pickaxe"));
    inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("core:axe"));
    inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("core:shovel"));
    inventoryManager.giveItem(player, EntityRef.NULL, blockFactory.newInstance(blockManager.getBlockFamily("core:Torch"), 99));
    inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("core:explodeTool"));
    inventoryManager.giveItem(player, EntityRef.NULL, entityManager.create("core:railgunTool"));
    inventoryManager.giveItem(player, EntityRef.NULL, chest);
}
Also used : InventoryComponent(org.terasology.logic.inventory.InventoryComponent) ItemComponent(org.terasology.logic.inventory.ItemComponent) BlockItemFactory(org.terasology.world.block.items.BlockItemFactory) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 4 with BlockItemFactory

use of org.terasology.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.world.block.items.BlockItemFactory) BlockExplorer(org.terasology.world.block.BlockExplorer) TargetSystem(org.terasology.input.cameraTarget.TargetSystem)

Example 5 with BlockItemFactory

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

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