Added ManaProficiencyEvent and reworked IManaProficiencyArmor to work on a per-rod basis

This commit is contained in:
Flaxbeard committed 2016-10-04 17:48:21 -05:00
1 parent 92f758adb7
commit c4c409dc1f
3 files changed
+78 -5

No files matched your search

@@ -10,10 +10,14 @@
*/
package vazkii.botania.api.item;
import javax.annotation.Nullable;
import vazkii.botania.api.mana.ManaProficiencyEvent;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
/**
* An armor item that implements this gives the player wearing it mana proficiency, by
@@ -24,22 +28,42 @@ import net.minecraft.item.ItemStack;
*/
public interface IManaProficiencyArmor {
public boolean shouldGiveProficiency(ItemStack stack, EntityEquipmentSlot slot, EntityPlayer player);
@Deprecated
default boolean shouldGiveProficiency(ItemStack armorStack, EntityEquipmentSlot slot, EntityPlayer player) {
return false;
}
default boolean shouldGiveProficiency(ItemStack armorStack, EntityEquipmentSlot slot, EntityPlayer player, @Nullable ItemStack rod) {
return shouldGiveProficiency(armorStack, slot, player);
}
public final static class Helper {
@Deprecated
public static boolean hasProficiency(EntityPlayer player) {
return hasProficiency(player, null);
}
public static boolean hasProficiency(EntityPlayer player, @Nullable ItemStack rod) {
boolean proficient = false;
for(EntityEquipmentSlot e: EntityEquipmentSlot.values()) {
if(e.getSlotType() != EntityEquipmentSlot.Type.ARMOR)
continue;
ItemStack armor = player.getItemStackFromSlot(e);
if(armor != null) {
Item item = armor.getItem();
if(item instanceof IManaProficiencyArmor && ((IManaProficiencyArmor) item).shouldGiveProficiency(armor, e, player))
return true;
if(item instanceof IManaProficiencyArmor && ((IManaProficiencyArmor) item).shouldGiveProficiency(armor, e, player, rod)) {
proficient = true;
break;
}
}
}
return false;
ManaProficiencyEvent event = new ManaProficiencyEvent(player, rod, proficient);
MinecraftForge.EVENT_BUS.post(event);
return event.isProficient();
}
}