@Override public BlockFamily getFromString(String representation) { return blockManager.getBlockFamily(representation); }
@Override public BlockFamily parse(String raw) { Preconditions.checkNotNull(raw, "'raw' must not be null!"); return CoreRegistry.get(BlockManager.class).getBlockFamily(raw); }
if (def.get().isFreeform()) { if (shapeUriParam == null) { blockFamily = blockManager.getBlockFamily(new BlockUri(def.get().getUrn(), new ResourceUrn("engine:cube"))); } else { Set<ResourceUrn> resolvedShapeUris = Assets.resolveAssetUri(shapeUriParam, BlockShape.class); blockFamily = blockManager.getBlockFamily(new BlockUri(def.get().getUrn(), resolvedShapeUris.iterator().next())); blockFamily = blockManager.getBlockFamily(new BlockUri(def.get().getUrn()));
Optional<BlockFamilyDefinition> def = Assets.get(matchingUris.iterator().next(), BlockFamilyDefinition.class); if (def.isPresent()) { BlockFamily blockFamily = blockManager.getBlockFamily(uri); Block block = blockManager.getBlock(blockFamily.getURI()); world.setBlock(targetLocation.position, block);
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, 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 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)); 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"));
EntityRef dropItem = blockItemFactory.newInstance(blockManager.getBlockFamily(dropParser.getDrop()), dropParser.getCount()); if (shouldDropToWorld(event, blockDamageModifierComponent, dropItem)) { createDrop(dropItem, locationComp.getWorldPosition(), true);
/** * 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."; }
@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 :)"; }
private BlockFamily createBlockFamily(String urn, Prefab prefab, AssetManager assetManager, BlockManager blockManager) { BlockFamilyDefinitionData data = new BlockFamilyDefinitionData(); data.setBlockFamily(HorizontalFamily.class); data.getBaseSection().getEntity().setKeepActive(true); data.getBaseSection().getEntity().setPrefab(prefab); assetManager.loadAsset(new ResourceUrn(urn), data, BlockFamilyDefinition.class); return blockManager.getBlockFamily(urn); }
offset.scale(5); spawnPos.add(offset); BlockFamily block = blockManager.getBlockFamily(blockName); if (block == null) { return "Sorry, your block is not found";