mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-16 01:55:15 +00:00
Merge pull request #1911 from Flaxbeard/rework_discount
Reworked getFullDiscountForTools and ManaDiscountEvent
This commit is contained in:
commit
3dfebeba01
7 files changed
+52
-14
No files matched your search
@@ -10,6 +10,8 @@
|
||||
*/
|
||||
package vazkii.botania.api.mana;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -20,12 +22,18 @@ import net.minecraft.item.ItemStack;
|
||||
*/
|
||||
public interface IManaDiscountArmor {
|
||||
|
||||
@Deprecated
|
||||
default float getDiscount(ItemStack stack, int slot, EntityPlayer player) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mana discount that this piece of armor provides. This is added
|
||||
* together to create the full discount.
|
||||
* Gets the mana discount that this piece of armor provides for the specified
|
||||
* tool. This is added together to create the full discount.
|
||||
* Value is to be from 0.0 to 1.0. 0.1 is 10% discount, as an example.
|
||||
* You can also return negative values to make tools cost more.
|
||||
*/
|
||||
public float getDiscount(ItemStack stack, int slot, EntityPlayer player);
|
||||
|
||||
default float getDiscount(ItemStack stack, int slot, EntityPlayer player, @Nullable ItemStack tool) {
|
||||
return getDiscount(stack, slot, player);
|
||||
}
|
||||
}
|
||||
@@ -10,17 +10,32 @@
|
||||
*/
|
||||
package vazkii.botania.api.mana;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
public class ManaDiscountEvent extends Event {
|
||||
|
||||
private final EntityPlayer entityPlayer;
|
||||
private float discount;
|
||||
|
||||
public ManaDiscountEvent(EntityPlayer entityPlayer, float discount) {
|
||||
private ItemStack tool;
|
||||
|
||||
public ManaDiscountEvent(EntityPlayer entityPlayer, float discount, @Nullable ItemStack tool) {
|
||||
this.entityPlayer = entityPlayer;
|
||||
this.discount = discount;
|
||||
this.tool = tool;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ManaDiscountEvent(EntityPlayer entityPlayer, float discount) {
|
||||
this(entityPlayer, discount, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getTool() {
|
||||
return tool;
|
||||
}
|
||||
|
||||
public EntityPlayer getEntityPlayer() {
|
||||
|
||||
@@ -16,6 +16,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -317,19 +319,24 @@ public final class ManaItemHandler {
|
||||
return requestManaExact(stack, player, cost, remove);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static float getFullDiscountForTools(EntityPlayer player) {
|
||||
return getFullDiscountForTools(player, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sum of all the discounts on IManaDiscountArmor items equipped
|
||||
* on the player passed in.
|
||||
* on the player passed in. This discount can vary based on what the passed tool is.
|
||||
*/
|
||||
public static float getFullDiscountForTools(EntityPlayer player) {
|
||||
public static float getFullDiscountForTools(EntityPlayer player, @Nullable ItemStack tool) {
|
||||
float discount = 0F;
|
||||
for(int i = 0; i < player.inventory.armorInventory.length; i++) {
|
||||
ItemStack armor = player.inventory.armorInventory[i];
|
||||
if(armor != null && armor.getItem() instanceof IManaDiscountArmor)
|
||||
discount += ((IManaDiscountArmor) armor.getItem()).getDiscount(armor, i, player);
|
||||
discount += ((IManaDiscountArmor) armor.getItem()).getDiscount(armor, i, player, tool);
|
||||
}
|
||||
|
||||
ManaDiscountEvent event = new ManaDiscountEvent(player, discount);
|
||||
ManaDiscountEvent event = new ManaDiscountEvent(player, discount, tool);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
discount = event.getDiscount();
|
||||
|
||||
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
package vazkii.botania.common.item.equipment.armor.elementium;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -22,7 +24,7 @@ public class ItemElementiumHelm extends ItemElementiumArmor implements IManaDisc
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDiscount(ItemStack stack, int slot, EntityPlayer player) {
|
||||
public float getDiscount(ItemStack stack, int slot, EntityPlayer player, @Nullable ItemStack tool) {
|
||||
return hasArmorSet(player) ? 0.1F : 0F;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -10,6 +10,8 @@
|
||||
*/
|
||||
package vazkii.botania.common.item.equipment.armor.manasteel;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -27,7 +29,7 @@ public class ItemManasteelHelm extends ItemManasteelArmor implements IManaDiscou
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDiscount(ItemStack stack, int slot, EntityPlayer player) {
|
||||
public float getDiscount(ItemStack stack, int slot, EntityPlayer player, @Nullable ItemStack tool) {
|
||||
return hasArmorSet(player) ? 0.1F : 0F;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -10,6 +10,8 @@
|
||||
*/
|
||||
package vazkii.botania.common.item.equipment.armor.manaweave;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
@@ -31,7 +33,7 @@ public class ItemManaweaveHelm extends ItemManaweaveArmor implements IManaDiscou
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDiscount(ItemStack stack, int slot, EntityPlayer player) {
|
||||
public float getDiscount(ItemStack stack, int slot, EntityPlayer player, @Nullable ItemStack tool) {
|
||||
return hasArmorSet(player) ? 0.35F : 0F;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -12,6 +12,8 @@ package vazkii.botania.common.item.equipment.armor.terrasteel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
@@ -64,7 +66,7 @@ public class ItemTerrasteelHelm extends ItemTerrasteelArmor implements IManaDisc
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDiscount(ItemStack stack, int slot, EntityPlayer player) {
|
||||
public float getDiscount(ItemStack stack, int slot, EntityPlayer player, @Nullable ItemStack tool) {
|
||||
return hasArmorSet(player) ? 0.2F : 0F;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user