crwdns151543:0crwdne151543:0

crwdns151545:0crwdne151545:0

crwdns151547:0:javadoc:crwdnd151547:0:javadoc:crwdnd151547:0:javadoc:crwdne151547:0

import org.spongepowered.api.item.ItemTypes;
import org.spongepowered.api.item.inventory.ItemStack;

public ItemStack generateSword() {
    ItemStack superMegaAwesomeSword = ItemStack.builder()
        .itemType(ItemTypes.DIAMOND_SWORD).build();
    return superMegaAwesomeSword;
}

crwdns151549:0:javadoc:crwdne151549:0

import java.util.List;
import java.util.stream.Collectors;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.manipulator.mutable.item.EnchantmentData;
import org.spongepowered.api.data.meta.ItemEnchantment
import org.spongepowered.api.item.Enchantment;

EnchantmentData enchantmentData = superMegaAwesomeSword
    .getOrCreate(EnchantmentData.class).get();
final List<Enchantment> enchantments = Sponge.getRegistry()
    .getAllOf(Enchantment.class).stream().collect(Collectors.toList());

for (Enchantment enchantment : enchantments) {
    enchantmentData.set(enchantmentData.enchantments()
        .add(new ItemEnchantment(enchantment, 1000)));
}
superMegaAwesomeSword.offer(enchantmentData);

crwdns151551:0crwdne151551:0

import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;

superMegaAwesomeSword.offer(Keys.DISPLAY_NAME, Text.of(
    TextColors.BLUE, "SUPER ",
    TextColors.GOLD, "MEGA ",
    TextColors.DARK_AQUA, "AWESOME ",
    TextColors.AQUA, "Diamond Sword"));

crwdns151553:0crwdne151553:0

superMegaAwesomeSword.offer(Keys.UNBREAKABLE, true);

crwdns151555:0crwdne151555:0

crwdns151557:0crwdne151557:0

crwdns151559:0:doc:crwdnd151559:0:javadoc:crwdnd151559:0:javadoc:crwdnd151559:0:javadoc:crwdnd151559:0:javadoc:crwdnd151559:0:javadoc:crwdne151559:0

import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.entity.spawn.EntitySpawnCause;
import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.Extent;

import java.util.Optional;

public void spawnItem(ItemStack superMegaAwesomeSword, Location<World> spawnLocation) {
    Extent extent = spawnLocation.getExtent();
    Optional<Entity> optional = extent
        .createEntity(EntityTypes.ITEM, spawnLocation.getPosition());
    if (optional.isPresent()) {
        Entity item = optional.get();
        item.offer(Keys.REPRESENTED_ITEM, superMegaAwesomeSword.createSnapshot());
        extent.spawnEntity(item, Cause.source(EntitySpawnCause.builder()
            .entity(item).type(SpawnTypes.PLUGIN).build()).build());
    }
}

crwdns151561:0crwdne151561:0

crwdns151563:0:javadoc:crwdnd151563:0:javadoc:crwdnd151563:0:javadoc:crwdne151563:0

import org.spongepowered.api.block.BlockState;

public ItemStack createStack(BlockState state) {
    return ItemStack.builder().fromBlockState(state).build();
}