use of net.minecraft.server.v1_7_R4.NBTTagCompound in project Ublisk by Derkades.
the class Item method setNBTValue.
public Item setNBTValue(String key, boolean bool) {
NBTTagCompound compound = this.getNBT();
compound.setBoolean(key, bool);
return this.setNBT(compound);
}
use of net.minecraft.server.v1_7_R4.NBTTagCompound in project Ublisk by Derkades.
the class CustomItem method fromItem.
public static CustomItem fromItem(Item item) {
if (item.getType() != CUSTOM_ITEM) {
throw new IllegalArgumentException("The provided item is not a custom item.");
}
NBTTagCompound nbt = item.getNBT();
if (!nbt.hasKey(UbliskNBT.IDENTIFIER.toString())) {
throw new IllegalArgumentException("The provided item does not have an item identifier in its NBT");
}
String identifier = nbt.getString(UbliskNBT.IDENTIFIER.toString());
return new CustomItem(identifier, true);
}
use of net.minecraft.server.v1_7_R4.NBTTagCompound in project Ublisk by Derkades.
the class Sword method getItemStack.
@Override
public ItemStack getItemStack() {
Item item = new Item(this.getMaterial()).setName(this.getColoredName()).setLore(this.getLore());
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = new NBTTagCompound();
damage.setString("AttributeName", "generic.attackDamage");
damage.setString("Name", "generic.attackDamage");
damage.setDouble("Amount", this.getDamage());
damage.setInt("Operation", 1);
damage.setInt("UUIDLeast", 652);
damage.setInt("UUIDMost", 12098);
modifiers.add(damage);
if (this.getMovementSpeed() != -1) {
NBTTagCompound speed = new NBTTagCompound();
speed.setString("AttributeName", "generic.movementSpeed");
speed.setString("Name", "generic.movementSpeed");
speed.setDouble("Amount", this.getMovementSpeed());
speed.setInt("Operation", 1);
speed.setInt("UUIDLeast", 652);
speed.setInt("UUIDMost", 12098);
modifiers.add(speed);
}
if (this.getAttackSpeed().getValue() != -1) {
NBTTagCompound attackSpeed = new NBTTagCompound();
attackSpeed.setString("AttributeName", "generic.attackSpeed");
attackSpeed.setString("Name", "generic.attackSpeed");
attackSpeed.setDouble("Amount", this.getAttackSpeed().getValue());
attackSpeed.setInt("Operation", 1);
attackSpeed.setInt("UUIDLeast", 652);
attackSpeed.setInt("UUIDMost", 12098);
modifiers.add(attackSpeed);
}
if (this.getKnockbackResistance() != -1) {
NBTTagCompound knockback = new NBTTagCompound();
knockback.setString("AttributeName", "generic.knockbackResistance");
knockback.setString("Name", "generic.knockbackResistance");
knockback.setDouble("Amount", this.getKnockbackResistance());
knockback.setInt("Operation", 1);
knockback.setInt("UUIDLeast", 652);
knockback.setInt("UUIDMost", 12098);
modifiers.add(knockback);
}
NBTTagCompound compound = item.getNBT();
compound.set("AttributeModifiers", modifiers);
compound.setInt("HideFlags", 7);
compound.setBoolean("Unbreakable", true);
item.setNBT(compound);
item.setDamage(this.getDamage());
return item.getItemStack();
}
use of net.minecraft.server.v1_7_R4.NBTTagCompound in project MyPet by xXKeyleXx.
the class IconMenuInventory method createItemStack.
protected ItemStack createItemStack(IconMenuItem icon) {
ItemStack is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount(), (short) icon.getData()));
if (is == null) {
is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.SAPLING));
}
NBTTagList emptyList = new NBTTagList();
if (is.getTag() == null) {
is.setTag(new NBTTagCompound());
}
if (icon.getBukkitMeta() != null) {
try {
applyToItemMethhod.invoke(icon.getBukkitMeta(), is.getTag());
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
}
// remove item attributes like attack damage
is.getTag().set("AttributeModifiers", emptyList);
// add enchantment glowing
if (icon.isGlowing()) {
TagCompound enchTag = new TagCompound();
enchTag.put("id", new TagShort(2));
enchTag.put("lvl", new TagShort(1));
TagList enchList = new TagList();
enchList.addTag(enchTag);
is.getTag().set("ench", ItemStackNBTConverter.compoundToVanillaCompound(enchList));
is.getTag().setInt("HideFlags", 1);
} else {
is.getTag().remove("ench");
}
// Prepare display tag
NBTTagCompound display;
if (is.getTag().hasKey("display")) {
display = is.getTag().getCompound("display");
} else {
display = new NBTTagCompound();
is.getTag().set("display", display);
}
// set Title
if (!icon.getTitle().equals("")) {
display.setString("Name", icon.getTitle());
}
if (icon.getLore().size() > 0) {
// set Lore
NBTTagList loreTag = new NBTTagList();
display.set("Lore", loreTag);
for (String loreLine : icon.getLore()) {
loreTag.add(new NBTTagString(loreLine));
}
}
if (icon.hasMeta()) {
TagCompound tag = new TagCompound();
icon.getMeta().applyTo(tag);
NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
for (String key : vanillaTag.c()) {
is.getTag().set(key, vanillaTag.get(key));
}
}
if (icon.getTags() != null) {
NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(icon.getTags());
for (String key : vanillaTag.c()) {
is.getTag().set(key, vanillaTag.get(key));
}
}
return is;
}
use of net.minecraft.server.v1_7_R4.NBTTagCompound in project MyPet by xXKeyleXx.
the class ItemStackComparator method compareTagData.
public static boolean compareTagData(ItemStack i1, ItemStack i2) {
if (i1 == null || i2 == null) {
return false;
}
if (i1.hasItemMeta() && i2.hasItemMeta()) {
NBTTagCompound tag1 = CraftItemStack.asNMSCopy(i1).getTag();
NBTTagCompound tag2 = CraftItemStack.asNMSCopy(i2).getTag();
if (tag1 != null) {
if (tag1.equals(tag2)) {
return true;
} else {
i1 = CraftItemStack.asBukkitCopy(CraftItemStack.asNMSCopy(i1));
tag1 = CraftItemStack.asNMSCopy(i1).getTag();
return tag1.equals(tag2);
}
}
return false;
}
return i1.hasItemMeta() == i2.hasItemMeta();
}
Aggregations