Add metadata support to block/item list config options, fixes #353

This commit is contained in:
Electroblob77
2020-02-21 17:40:08 +00:00
parent d6b64b3576
commit df8fd21c0b
11 changed files with 85 additions and 43 deletions
@@ -11,9 +11,13 @@ import electroblob.wizardry.util.SpellModifiers;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.*;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Arrays;
@@ -32,7 +36,7 @@ public class ImbueWeapon extends Spell {
for(ItemStack stack : WizardryUtilities.getPrioritisedHotbarAndOffhand(caster)){
if(isSword(stack.getItem())
if(isSword(stack)
&& !EnchantmentHelper.getEnchantments(stack).containsKey(WizardryEnchantments.magic_sword)
&& WizardData.get(caster).getImbuementDuration(WizardryEnchantments.magic_sword) <= 0){
// The enchantment level as determined by the damage multiplier. The + 0.5f is so that
@@ -44,7 +48,7 @@ public class ImbueWeapon extends Spell {
WizardData.get(caster).setImbuementDuration(WizardryEnchantments.magic_sword,
(int)(getProperty(EFFECT_DURATION).floatValue() * modifiers.get(WizardryItems.duration_upgrade)));
}else if(isBow(stack.getItem())
}else if(isBow(stack)
&& !EnchantmentHelper.getEnchantments(stack).containsKey(WizardryEnchantments.magic_bow)
&& WizardData.get(caster).getImbuementDuration(WizardryEnchantments.magic_bow) <= 0){
// The enchantment level as determined by the damage multiplier. The + 0.5f is so that
@@ -77,13 +81,13 @@ public class ImbueWeapon extends Spell {
}
/** Returns true if the given item counts as a sword, i.e. it extends {@link ItemSword} or is in the whitelist. */
public static boolean isSword(Item item){
return item instanceof ItemSword || Arrays.asList(Wizardry.settings.swordItemWhitelist).contains(item.getRegistryName());
public static boolean isSword(ItemStack stack){
return stack.getItem() instanceof ItemSword || Arrays.asList(Wizardry.settings.swordItemWhitelist).contains(Pair.of(stack.getItem().getRegistryName(), stack.getMetadata()));
}
/** Returns true if the given item counts as a bow, i.e. it extends {@link ItemBow} or is in the whitelist. */
public static boolean isBow(Item item){
return item instanceof ItemBow || Arrays.asList(Wizardry.settings.bowItemWhitelist).contains(item.getRegistryName());
public static boolean isBow(ItemStack stack){
return stack.getItem() instanceof ItemBow || Arrays.asList(Wizardry.settings.bowItemWhitelist).contains(Pair.of(stack.getItem().getRegistryName(), stack.getMetadata()));
}
}