Added a better way to add enchantments. Because.

This commit is contained in:
Ellpeck 2015-09-24 21:00:53 +02:00
parent 8c60f4110b
commit e922db1c61
6 changed files with 20 additions and 14 deletions

View file

@ -364,10 +364,10 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
if(this.getEnergyStored(stack) >= use){ if(this.getEnergyStored(stack) >= use){
//Enchants the Drill depending on the Upgrades it has //Enchants the Drill depending on the Upgrades it has
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SILK_TOUCH)) if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SILK_TOUCH))
stack.addEnchantment(Enchantment.silkTouch, 1); ItemUtil.addEnchantment(stack, Enchantment.silkTouch, 1);
else{ else{
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE)) if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE))
stack.addEnchantment(Enchantment.fortune, this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE_II) ? 3 : 1); ItemUtil.addEnchantment(stack, Enchantment.fortune, this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE_II) ? 3 : 1);
} }
//Breaks the Blocks //Breaks the Blocks

View file

@ -79,7 +79,7 @@ public class ItemAxeFixedEnchants extends ItemAxeAA implements IToolTableRepairI
@Override @Override
public void onCreated(ItemStack stack, World world, EntityPlayer player){ public void onCreated(ItemStack stack, World world, EntityPlayer player){
for(EnchantmentCombo combo : this.enchantments){ for(EnchantmentCombo combo : this.enchantments){
stack.addEnchantment(combo.enchantment, combo.level); ItemUtil.addEnchantment(stack, combo.enchantment, combo.level);
} }
} }
@ -87,7 +87,7 @@ public class ItemAxeFixedEnchants extends ItemAxeAA implements IToolTableRepairI
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){ public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){
for(EnchantmentCombo combo : this.enchantments){ for(EnchantmentCombo combo : this.enchantments){
if(!ItemUtil.hasEnchantment(stack, combo.enchantment)){ if(!ItemUtil.hasEnchantment(stack, combo.enchantment)){
stack.addEnchantment(combo.enchantment, combo.level); ItemUtil.addEnchantment(stack, combo.enchantment, combo.level);
} }
} }
} }
@ -98,7 +98,7 @@ public class ItemAxeFixedEnchants extends ItemAxeAA implements IToolTableRepairI
public void getSubItems(Item item, CreativeTabs tab, List list){ public void getSubItems(Item item, CreativeTabs tab, List list){
ItemStack stack = new ItemStack(item); ItemStack stack = new ItemStack(item);
for(EnchantmentCombo combo : this.enchantments){ for(EnchantmentCombo combo : this.enchantments){
stack.addEnchantment(combo.enchantment, combo.level); ItemUtil.addEnchantment(stack, combo.enchantment, combo.level);
} }
list.add(stack); list.add(stack);
} }

View file

@ -79,7 +79,7 @@ public class ItemPickaxeFixedEnchants extends ItemPickaxeAA implements IToolTabl
@Override @Override
public void onCreated(ItemStack stack, World world, EntityPlayer player){ public void onCreated(ItemStack stack, World world, EntityPlayer player){
for(EnchantmentCombo combo : this.enchantments){ for(EnchantmentCombo combo : this.enchantments){
stack.addEnchantment(combo.enchantment, combo.level); ItemUtil.addEnchantment(stack, combo.enchantment, combo.level);
} }
} }
@ -87,7 +87,7 @@ public class ItemPickaxeFixedEnchants extends ItemPickaxeAA implements IToolTabl
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){ public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){
for(EnchantmentCombo combo : this.enchantments){ for(EnchantmentCombo combo : this.enchantments){
if(!ItemUtil.hasEnchantment(stack, combo.enchantment)){ if(!ItemUtil.hasEnchantment(stack, combo.enchantment)){
stack.addEnchantment(combo.enchantment, combo.level); ItemUtil.addEnchantment(stack, combo.enchantment, combo.level);
} }
} }
} }
@ -98,7 +98,7 @@ public class ItemPickaxeFixedEnchants extends ItemPickaxeAA implements IToolTabl
public void getSubItems(Item item, CreativeTabs tab, List list){ public void getSubItems(Item item, CreativeTabs tab, List list){
ItemStack stack = new ItemStack(item); ItemStack stack = new ItemStack(item);
for(EnchantmentCombo combo : this.enchantments){ for(EnchantmentCombo combo : this.enchantments){
stack.addEnchantment(combo.enchantment, combo.level); ItemUtil.addEnchantment(stack, combo.enchantment, combo.level);
} }
list.add(stack); list.add(stack);
} }

View file

@ -79,7 +79,7 @@ public class ItemShovelFixedEnchants extends ItemShovelAA implements IToolTableR
@Override @Override
public void onCreated(ItemStack stack, World world, EntityPlayer player){ public void onCreated(ItemStack stack, World world, EntityPlayer player){
for(EnchantmentCombo combo : this.enchantments){ for(EnchantmentCombo combo : this.enchantments){
stack.addEnchantment(combo.enchantment, combo.level); ItemUtil.addEnchantment(stack, combo.enchantment, combo.level);
} }
} }
@ -87,7 +87,7 @@ public class ItemShovelFixedEnchants extends ItemShovelAA implements IToolTableR
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){ public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){
for(EnchantmentCombo combo : this.enchantments){ for(EnchantmentCombo combo : this.enchantments){
if(!ItemUtil.hasEnchantment(stack, combo.enchantment)){ if(!ItemUtil.hasEnchantment(stack, combo.enchantment)){
stack.addEnchantment(combo.enchantment, combo.level); ItemUtil.addEnchantment(stack, combo.enchantment, combo.level);
} }
} }
} }
@ -98,7 +98,7 @@ public class ItemShovelFixedEnchants extends ItemShovelAA implements IToolTableR
public void getSubItems(Item item, CreativeTabs tab, List list){ public void getSubItems(Item item, CreativeTabs tab, List list){
ItemStack stack = new ItemStack(item); ItemStack stack = new ItemStack(item);
for(EnchantmentCombo combo : this.enchantments){ for(EnchantmentCombo combo : this.enchantments){
stack.addEnchantment(combo.enchantment, combo.level); ItemUtil.addEnchantment(stack, combo.enchantment, combo.level);
} }
list.add(stack); list.add(stack);
} }

View file

@ -79,7 +79,7 @@ public class ItemSwordFixedEnchants extends ItemSwordAA implements IToolTableRep
@Override @Override
public void onCreated(ItemStack stack, World world, EntityPlayer player){ public void onCreated(ItemStack stack, World world, EntityPlayer player){
for(EnchantmentCombo combo : this.enchantments){ for(EnchantmentCombo combo : this.enchantments){
stack.addEnchantment(combo.enchantment, combo.level); ItemUtil.addEnchantment(stack, combo.enchantment, combo.level);
} }
} }
@ -87,7 +87,7 @@ public class ItemSwordFixedEnchants extends ItemSwordAA implements IToolTableRep
public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){ public void onUpdate(ItemStack stack, World world, Entity player, int par4, boolean par5){
for(EnchantmentCombo combo : this.enchantments){ for(EnchantmentCombo combo : this.enchantments){
if(!ItemUtil.hasEnchantment(stack, combo.enchantment)){ if(!ItemUtil.hasEnchantment(stack, combo.enchantment)){
stack.addEnchantment(combo.enchantment, combo.level); ItemUtil.addEnchantment(stack, combo.enchantment, combo.level);
} }
} }
} }
@ -98,7 +98,7 @@ public class ItemSwordFixedEnchants extends ItemSwordAA implements IToolTableRep
public void getSubItems(Item item, CreativeTabs tab, List list){ public void getSubItems(Item item, CreativeTabs tab, List list){
ItemStack stack = new ItemStack(item); ItemStack stack = new ItemStack(item);
for(EnchantmentCombo combo : this.enchantments){ for(EnchantmentCombo combo : this.enchantments){
stack.addEnchantment(combo.enchantment, combo.level); ItemUtil.addEnchantment(stack, combo.enchantment, combo.level);
} }
list.add(stack); list.add(stack);
} }

View file

@ -81,6 +81,12 @@ public class ItemUtil{
return stack1 != null && stack2 != null && (stack1.isItemEqual(stack2) || (checkWildcard && stack1.getItem() == stack2.getItem() && (stack1.getItemDamage() == Util.WILDCARD || stack2.getItemDamage() == Util.WILDCARD))); return stack1 != null && stack2 != null && (stack1.isItemEqual(stack2) || (checkWildcard && stack1.getItem() == stack2.getItem() && (stack1.getItemDamage() == Util.WILDCARD || stack2.getItemDamage() == Util.WILDCARD)));
} }
public static void addEnchantment(ItemStack stack, Enchantment e, int level){
if(!hasEnchantment(stack, e)){
stack.addEnchantment(e, level);
}
}
public static void removeEnchantment(ItemStack stack, Enchantment e){ public static void removeEnchantment(ItemStack stack, Enchantment e){
NBTTagList ench = stack.getEnchantmentTagList(); NBTTagList ench = stack.getEnchantmentTagList();
if(ench != null){ if(ench != null){