use of net.minecraft.server.v1_16_R3.NBTTagList in project custom-items-gradle by knokko.
the class ItemAttributes method clearAttributes.
public static ItemStack clearAttributes(ItemStack original) {
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(original);
NBTTagCompound compound = nmsStack.hasTag() ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
setAttribute(modifiers, "dummy", 0, "dummyslot", 0);
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
return CraftItemStack.asBukkitCopy(nmsStack);
}
use of net.minecraft.server.v1_16_R3.NBTTagList in project custom-items-gradle by knokko.
the class ItemAttributes method getAttribute.
public static double getAttribute(ItemStack stack, String attribute) {
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
if (nmsStack.hasTag()) {
NBTTagCompound compound = nmsStack.getTag();
NBTTagList modifiers = compound.getList("AttributeModifiers", 10);
if (modifiers != null) {
for (int index = 0; index < modifiers.size(); index++) {
NBTTagCompound attributeTag = modifiers.get(index);
if (attributeTag.getString("AttributeName").equals(attribute))
return attributeTag.getDouble("Amount");
}
return Double.NaN;
} else
return Double.NaN;
} else
return Double.NaN;
}
use of net.minecraft.server.v1_16_R3.NBTTagList in project custom-items-gradle by knokko.
the class ItemAttributes method getAttributes.
public static Single[] getAttributes(ItemStack stack) {
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
if (nmsStack.hasTag()) {
NBTTagCompound compound = nmsStack.getTag();
NBTTagList modifiers = compound.getList("AttributeModifiers", 10);
if (modifiers != null) {
Single[] attributes = new Single[modifiers.size()];
for (int index = 0; index < modifiers.size(); index++) {
NBTTagCompound attributeTag = modifiers.get(index);
String attribute = attributeTag.getString("Name");
String slot = attributeTag.getString("Slot");
int operation = attributeTag.getInt("Operation");
double amount = attributeTag.getDouble("Amount");
attributes[index] = new Single(attribute, slot, operation, amount);
}
return attributes;
} else {
return new Single[0];
}
} else {
return new Single[0];
}
}
use of net.minecraft.server.v1_16_R3.NBTTagList in project custom-items-gradle by knokko.
the class ItemAttributes method createWithAttributes.
public static ItemStack createWithAttributes(Material type, int amount, Single... attributes) {
ItemStack original = new ItemStack(type, amount);
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(original);
NBTTagCompound compound = nmsStack.hasTag() ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
if (attributes.length == 0)
setAttribute(modifiers, "dummy", 0, "dummyslot", 0);
for (Single attribute : attributes) setAttribute(modifiers, attribute.attribute, attribute.value, attribute.slot, attribute.operation);
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
return CraftItemStack.asCraftMirror(nmsStack);
}
use of net.minecraft.server.v1_16_R3.NBTTagList in project custom-items-gradle by knokko.
the class ItemAttributes method listAttributes.
public static String[] listAttributes(ItemStack stack) {
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
if (nmsStack.hasTag()) {
NBTTagCompound compound = nmsStack.getTag();
NBTTagList modifiers = compound.getList("AttributeModifiers", 10);
if (modifiers != null) {
String[] attributes = new String[modifiers.size()];
for (int index = 0; index < modifiers.size(); index++) {
NBTTagCompound attributeTag = modifiers.get(index);
attributes[index] = attributeTag.getString("AttributeName") + ": " + attributeTag.getDouble("Amount");
}
return attributes;
} else
return null;
} else
return null;
}
Aggregations