mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 18:57:32 +00:00
Re-added hasEnchant, addEnchant, setAttribute, getAttribute, hasAttribute, getLore, and setLore to ScriptItemStack after they were lost in a commit A LONG TIME AGO
This commit is contained in:
1 parent
00557df9a7
commit
f2da93451f
1 file changed
+125
@@ -1,9 +1,14 @@
|
||||
package noppes.npcs.scripted;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -145,6 +150,126 @@ public class ScriptItemStack implements IItemStack {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addEnchant(int id, int strength) {
|
||||
Enchantment ench = Enchantment.enchantmentsList[id];
|
||||
if (ench == null) {
|
||||
throw new CustomNPCsException("Unknown enchant id:" + id, new Object[0]);
|
||||
} else {
|
||||
this.item.addEnchantment(ench, strength);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAttribute(String name, double value) {
|
||||
NBTTagCompound compound = this.item.getTagCompound();
|
||||
if (compound == null) {
|
||||
this.item.setTagCompound(compound = new NBTTagCompound());
|
||||
}
|
||||
|
||||
NBTTagList nbttaglist = compound.getTagList("AttributeModifiers", 10);
|
||||
NBTTagList newList = new NBTTagList();
|
||||
|
||||
NBTTagCompound nbttagcompound;
|
||||
for(int i = 0; i < nbttaglist.tagCount(); ++i) {
|
||||
nbttagcompound = nbttaglist.getCompoundTagAt(i);
|
||||
if (!nbttagcompound.getString("AttributeName").equals(name)) {
|
||||
newList.appendTag(nbttagcompound);
|
||||
}
|
||||
}
|
||||
|
||||
if (value != 0.0D) {
|
||||
AttributeModifier attributeModifier = new AttributeModifier(name, value, 0);
|
||||
nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setString("Name", attributeModifier.getName());
|
||||
nbttagcompound.setDouble("Amount", attributeModifier.getAmount());
|
||||
nbttagcompound.setInteger("Operation", attributeModifier.getOperation());
|
||||
nbttagcompound.setLong("UUIDMost", attributeModifier.getID().getMostSignificantBits());
|
||||
nbttagcompound.setLong("UUIDLeast", attributeModifier.getID().getLeastSignificantBits());
|
||||
nbttagcompound.setString("AttributeName", name);
|
||||
newList.appendTag(nbttagcompound);
|
||||
}
|
||||
|
||||
compound.setTag("AttributeModifiers", newList);
|
||||
}
|
||||
|
||||
public double getAttribute(String name) {
|
||||
NBTTagCompound compound = this.item.getTagCompound();
|
||||
if (compound == null) {
|
||||
return 0.0D;
|
||||
} else {
|
||||
Multimap<String, AttributeModifier> map = this.item.getAttributeModifiers();
|
||||
Iterator var4 = map.entries().iterator();
|
||||
|
||||
while(var4.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry)var4.next();
|
||||
if (((String)entry.getKey()).equals(name)) {
|
||||
AttributeModifier mod = (AttributeModifier)entry.getValue();
|
||||
return mod.getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
return 0.0D;
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getLore() {
|
||||
NBTTagCompound compound = this.item.getTagCompound().getCompoundTag("display");
|
||||
if (compound != null && compound.func_150299_b("Lore") == 9) {
|
||||
NBTTagList nbttaglist = compound.getTagList("Lore", 8);
|
||||
if (nbttaglist.tagCount() < 1) {
|
||||
return new String[0];
|
||||
} else {
|
||||
List<String> lore = new ArrayList();
|
||||
|
||||
for(int i = 0; i < nbttaglist.tagCount(); ++i) {
|
||||
lore.add(nbttaglist.getStringTagAt(i));
|
||||
}
|
||||
|
||||
return (String[])((String[])lore.toArray(new String[lore.size()]));
|
||||
}
|
||||
} else {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
public void setLore(String[] lore) {
|
||||
NBTTagCompound compound = this.item.getTagCompound();
|
||||
if (compound == null) {
|
||||
this.item.setTagCompound(compound = new NBTTagCompound());
|
||||
}
|
||||
|
||||
NBTTagList nbttaglist = compound.getTagList("display", 10);
|
||||
NBTTagList newList = new NBTTagList();
|
||||
String[] var4 = lore;
|
||||
int var5 = lore.length;
|
||||
|
||||
for(int var6 = 0; var6 < var5; ++var6) {
|
||||
String s = var4[var6];
|
||||
newList.appendTag(new NBTTagString(s));
|
||||
}
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setTag("Lore", newList);
|
||||
compound.setTag("display", nbttagcompound);
|
||||
}
|
||||
|
||||
public boolean hasAttribute(String name) {
|
||||
NBTTagCompound compound = this.item.getTagCompound();
|
||||
if (compound == null) {
|
||||
return false;
|
||||
} else {
|
||||
NBTTagList nbttaglist = compound.getTagList("AttributeModifiers", 10);
|
||||
|
||||
for(int i = 0; i < nbttaglist.tagCount(); ++i) {
|
||||
NBTTagCompound c = nbttaglist.getCompoundTagAt(i);
|
||||
if (c.getString("AttributeName").equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.7.10d
|
||||
|
||||
Reference in new issue
Block a user