crwdns132219:0crwdne132219:0
crwdns132221:0crwdne132221:0
crwdns132223:0:javadoc:crwdnd132223:0:javadoc:crwdnd132223:0:javadoc:crwdne132223: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;
}
crwdns132225:0:javadoc:crwdne132225: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);
crwdns132227:0crwdne132227: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"));
crwdns132229:0crwdne132229:0
superMegaAwesomeSword.offer(Keys.UNBREAKABLE, true);
crwdns132231:0crwdne132231:0
crwdns132233:0crwdne132233:0
crwdns132235:0:doc:crwdnd132235:0:javadoc:crwdnd132235:0:javadoc:crwdnd132235:0:javadoc:crwdnd132235:0:javadoc:crwdnd132235:0:javadoc:crwdne132235: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());
}
}
crwdns132237:0crwdne132237:0
crwdns132239:0:javadoc:crwdnd132239:0:javadoc:crwdnd132239:0:javadoc:crwdne132239:0
import org.spongepowered.api.block.BlockState;
public ItemStack createStack(BlockState state) {
return ItemStack.builder().fromBlockState(state).build();
}