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.";
}
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();
}
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);
}
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);
}
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 :)";
}
Aggregations