use of net.minecraft.server.v1_11_R1.Item in project acidisland by tastybento.
the class NMSHandler method setBook.
@Override
public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
// Bukkit.getLogger().info(item.toString());
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
// BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag) contents.get("author")).getValue();
}
// Bukkit.getLogger().info("Author: " + author);
// bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag) contents.get("title")).getValue();
}
// Bukkit.getLogger().info("Title: " + title);
// bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
for (Tag s : loreTag) {
lore.add(((StringTag) s).getValue());
}
}
// Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_11_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
// Create the NMS Stack's NBT (item data)
NBTTagCompound tag = new NBTTagCompound();
// Set the book's title
tag.setString("title", title);
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
for (Tag s : pagesTag) {
pages.add(new NBTTagString(((StringTag) s).getValue()));
}
// Add the pages to the tag
tag.set("pages", pages);
}
// Apply the tag to the item
stack.setTag(tag);
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
return chestItem;
}
use of net.minecraft.server.v1_11_R1.Item in project MyPet by xXKeyleXx.
the class ConfigItem method load.
public void load(MaterialHolder material, String data) {
MinecraftKey key = new MinecraftKey(material.getLegacyName().getName());
Item item = Item.REGISTRY.get(key);
if (item == null) {
return;
}
net.minecraft.server.v1_8_R3.ItemStack is = new net.minecraft.server.v1_8_R3.ItemStack(item, 1, material.getLegacyName().getData());
if (data != null) {
NBTTagCompound tag = null;
String nbtString = data.trim();
if (nbtString.startsWith("{") && nbtString.endsWith("}")) {
try {
tag = MojangsonParser.parse(nbtString);
} catch (Exception e) {
MyPetApi.getLogger().warning("Error" + ChatColor.RESET + " in config: " + ChatColor.UNDERLINE + e.getLocalizedMessage() + ChatColor.RESET + " caused by:");
MyPetApi.getLogger().warning(item.getName() + " " + nbtString);
}
if (tag != null) {
is.setTag(tag);
}
}
}
this.item = CraftItemStack.asCraftMirror(is);
}
use of net.minecraft.server.v1_11_R1.Item in project askyblock by tastybento.
the class NMSHandler method setBook.
@Override
public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
// Bukkit.getLogger().info(item.toString());
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
// BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag) contents.get("author")).getValue();
}
// Bukkit.getLogger().info("Author: " + author);
// bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag) contents.get("title")).getValue();
}
// Bukkit.getLogger().info("Title: " + title);
// bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
for (Tag s : loreTag) {
lore.add(((StringTag) s).getValue());
}
}
// Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_11_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
// Create the NMS Stack's NBT (item data)
NBTTagCompound tag = new NBTTagCompound();
// Set the book's title
tag.setString("title", title);
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
for (Tag s : pagesTag) {
pages.add(new NBTTagString(((StringTag) s).getValue()));
}
// Add the pages to the tag
tag.set("pages", pages);
}
// Apply the tag to the item
stack.setTag(tag);
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
return chestItem;
}
use of net.minecraft.server.v1_11_R1.Item in project askyblock by tastybento.
the class NMSHandler method isPotion.
/* (non-Javadoc)
* @see com.wasteofplastic.askyblock.nms.NMSAbstraction#isPotion(org.bukkit.inventory.ItemStack)
*/
@Override
public boolean isPotion(ItemStack item) {
// Bukkit.getLogger().info("DEBUG:item = " + item);
if (item.getType().equals(Material.POTION)) {
net.minecraft.server.v1_11_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tag = stack.getTag();
/*
for (String list : tag.c()) {
Bukkit.getLogger().info("DEBUG: list = " + list);
}*/
if (tag != null && (!tag.getString("Potion").equalsIgnoreCase("minecraft:water") || tag.getString("Potion").isEmpty())) {
return true;
}
}
return false;
}
use of net.minecraft.server.v1_11_R1.Item in project powerbot by powerbot.
the class DrawItems method repaint.
public void repaint(final Graphics render) {
if (!ctx.game.loggedIn()) {
return;
}
render.setFont(new Font("Arial", 0, 10));
render.setColor(Color.green);
if (ctx.bank.opened()) {
final Component container = ctx.widgets.component(Constants.BANK_WIDGET, Constants.BANK_ITEMS);
final Rectangle r = container.viewportRect();
if (r != null) {
for (final Item item : ctx.bank.select()) {
final Component c = item.component();
if (c == null) {
continue;
}
final Rectangle r2 = c.boundingRect();
if (r2 == null) {
continue;
}
if (c.relativePoint().y == 0 || !r.contains(r2)) {
continue;
}
final Point p = c.screenPoint();
render.drawString(c.itemId() + "", p.x, p.y + c.height());
}
}
}
if (ctx.backpack.component().visible()) {
for (final Item item : ctx.backpack.select()) {
final Component c = item.component();
if (c == null) {
continue;
}
final Point p = c.screenPoint();
render.drawString(c.itemId() + "", p.x, p.y + c.height());
}
}
if (ctx.equipment.component().visible()) {
for (final Item item : ctx.equipment.select()) {
if (item == null) {
continue;
}
final Component c = item.component();
if (c == null) {
continue;
}
final Point p = c.screenPoint();
render.drawString(c.itemId() + "", p.x, p.y + c.height());
}
}
}
Aggregations