crwdns141469:0crwdne141469:0

crwdns141473:0crwdne141473:0

crwdns141475:0:javadoc:crwdnd141475:0:javadoc:crwdnd141475:0:javadoc:crwdne141475: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;
}

crwdns157077:0:javadoc:crwdne157077:0

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

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

public void withThousandEnchantmentLevel(ItemStack superMegaAwesomeSword){
    List<Enchantment> enchantments = RegistryTypes
        .ENCHANTMENT_TYPE
        .get()
        .stream()
        .filter(type -> type.canBeAppliedToStack(superMegaAwesomeSword))
        .map(type -> Enchantment.of(type, 1000))
        .collect(Collectors.toList());

    superMegaAwesomeSword.offer(Keys.APPLIED_ENCHANTMENTS);
}

crwdns141479:0crwdne141479:0

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.item.ItemTypes;

superMegaAwesomeSword.offer(Keys.DISPLAY_NAME, TextComponent.ofChildren(
    Component.text("SUPER ", NamedTextColor.BLUE),
    Component.text("MEGA ", NamedTextColor.GOLD),
    Component.text("AWESOME ", NamedTextColor.DARK_AQUA),
    ItemTypes.DIAMOND_SWORD.get().asComponent().color(NamedTextColor.AQUA));

crwdns141481:0crwdne141481:0

superMegaAwesomeSword.offer(Keys.UNBREAKABLE, true);

crwdns141483:0crwdne141483:0

crwdns141485:0crwdne141485:0

crwdns141487:0:doc:crwdnd141487:0:javadoc:crwdnd141487:0:javadoc:crwdnd141487:0:javadoc:crwdnd141487:0:javadoc:crwdnd141487:0:javadoc:crwdne141487:0

import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.event.CauseStackManager.StackFrame;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.server.ServerWorld;

import java.util.Optional;

public void spawnItem(ItemStack superMegaAwesomeSword, ServerLocation spawnLocation) {
    ServerWorld world = spawnLocation.world();
    Item item = world.createEntity(EntityTypes.ITEM, spawnLocation.getPosition());
    item.offer(Keys.REPRESENTED_ITEM, superMegaAwesomeSword.createSnapshot());

    try (StackFrame frame = Sponge.server().causeStackManager().pushCauseFrame()) {
        frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.PLACEMENT);
        word.spawnEntity(item);
    }
}

crwdns141489:0crwdne141489:0

crwdns141491:0:javadoc:crwdnd141491:0:javadoc:crwdnd141491:0:javadoc:crwdne141491:0

import org.spongepowered.api.block.BlockState;

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