crwdns121897:0crwdne121897:0
crwdns121899:0crwdne121899:0
crwdns121901:0:javadoc:crwdnd121901:0:javadoc:crwdnd121901:0:javadoc:crwdne121901: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;
}
crwdns121903:0:javadoc:crwdne121903: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<EnchantmentType> enchantments = Sponge.getRegistry()
.getAllOf(EnchantmentType.class).stream().collect(Collectors.toList());
for (EnchantmentType enchantment : enchantments) {
enchantmentData.set(enchantmentData.enchantments()
.add(Enchantment.of(enchantment, 1000)));
}
superMegaAwesomeSword.offer(enchantmentData);
crwdns121905:0crwdne121905: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"));
crwdns121907:0crwdne121907:0
superMegaAwesomeSword.offer(Keys.UNBREAKABLE, true);
crwdns121909:0crwdne121909:0
crwdns121911:0crwdne121911:0
crwdns121913:0:doc:crwdnd121913:0:javadoc:crwdnd121913:0:javadoc:crwdnd121913:0:javadoc:crwdnd121913:0:javadoc:crwdnd121913:0:javadoc:crwdne121913: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.extent.Extent;
import java.util.Optional;
public void spawnItem(ItemStack superMegaAwesomeSword, Location<World> spawnLocation) {
Extent extent = spawnLocation.getExtent();
Entity item = extent.createEntity(EntityTypes.ITEM, spawnLocation.getPosition());
item.offer(Keys.REPRESENTED_ITEM, superMegaAwesomeSword.createSnapshot());
try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.PLACEMENT);
extent.spawnEntity(item);
}
}
crwdns121915:0crwdne121915:0
crwdns121917:0:javadoc:crwdnd121917:0:javadoc:crwdnd121917:0:javadoc:crwdne121917:0
import org.spongepowered.api.block.BlockState;
public ItemStack createStack(BlockState state) {
return ItemStack.builder().fromBlockState(state).build();
}