Skip to content

Commit

Permalink
Switch from instanceof ItemShield to Item::isShield for enchantment c…
Browse files Browse the repository at this point in the history
…hecks
  • Loading branch information
KnightMiner committed Jul 27, 2019
1 parent a248516 commit 4b2e32c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemShield;
import net.minecraft.item.ItemStack;

import java.util.List;
Expand All @@ -21,7 +20,7 @@ public EnchantmentExtendedFire(Rarity rarityIn, EntityEquipmentSlot... slots) {
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack) {
Item item = stack.getItem();
return (Config.moreShieldEnchantments && item instanceof ItemShield)
return (Config.moreShieldEnchantments && item.isShield(stack, null))
|| (Config.axeEnchantmentTable && Config.axeWeaponEnchants && item instanceof ItemAxe)
|| super.canApplyAtEnchantingTable(stack);
}
Expand All @@ -36,7 +35,7 @@ public boolean canApply(ItemStack stack) {
public List<ItemStack> getEntityEquipment(EntityLivingBase entity) {
// shields in hand should not give fire, just on hit
List<ItemStack> items = super.getEntityEquipment(entity);
items.removeIf((stack) -> stack.getItem() instanceof ItemShield);
items.removeIf((stack) -> stack.getItem().isShield(stack, entity));
return items;
}

Expand Down
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemShield;
import net.minecraft.item.ItemStack;

import java.util.List;
Expand All @@ -21,7 +20,7 @@ public EnchantmentExtendedKnockback(Rarity rarityIn, EntityEquipmentSlot... slot
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack) {
Item item = stack.getItem();
return (Config.moreShieldEnchantments && item instanceof ItemShield)
return (Config.moreShieldEnchantments && item.isShield(stack, null))
|| (Config.axeEnchantmentTable && Config.axeWeaponEnchants && item instanceof ItemAxe)
|| super.canApplyAtEnchantingTable(stack);
}
Expand All @@ -36,7 +35,7 @@ public boolean canApply(ItemStack stack) {
public List<ItemStack> getEntityEquipment(EntityLivingBase entity) {
// shields in hand should not give knockback, just on hit
List<ItemStack> items = super.getEntityEquipment(entity);
items.removeIf((stack) -> stack.getItem() instanceof ItemShield);
items.removeIf((stack) -> stack.getItem().isShield(stack, entity));
return items;
}

Expand Down
Expand Up @@ -3,7 +3,6 @@
import net.minecraft.enchantment.EnchantmentProtection;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemShield;
import net.minecraft.item.ItemStack;

import java.util.List;
Expand All @@ -15,7 +14,7 @@ public EnchantmentShieldProtection(Rarity rarityIn, Type protectionTypeIn, Entit

@Override
public boolean canApplyAtEnchantingTable(ItemStack stack) {
return stack.getItem() instanceof ItemShield || super.canApplyAtEnchantingTable(stack);
return stack.getItem().isShield(stack, null) || super.canApplyAtEnchantingTable(stack);
}

@Override
Expand Down
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.enchantment.EnchantmentThorns;
import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemShield;
import net.minecraft.item.ItemStack;

public class EnchantmentShieldThorns extends EnchantmentThorns {
Expand All @@ -14,7 +13,7 @@ public EnchantmentShieldThorns(Rarity rarityIn, EntityEquipmentSlot... slots) {

@Override
public boolean canApplyAtEnchantingTable(ItemStack stack) {
return stack.getItem() instanceof ItemShield || super.canApplyAtEnchantingTable(stack);
return stack.getItem().isShield(stack, null) || super.canApplyAtEnchantingTable(stack);
}

@Override
Expand Down

0 comments on commit 4b2e32c

Please sign in to comment.