Spawn / Drop item

The following code works for me. The player object is the player that ran the test command that executes this code.

ItemStack stack = this.game.getRegistry().createItemBuilder().itemType(ItemTypes.LAPIS_ORE).build();
Optional<Entity> optItem = player.getLocation().getExtent().createEntity(EntityTypes.ITEM, player.getLocation().getPosition());
if (optItem.isPresent()) {
    Item item = (Item) optItem.get();
    item.offer(Keys.REPRESENTED_ITEM, stack.createSnapshot());
    player.getWorld().spawnEntity(item, Cause.of(player));
}