Add right-click use for mana flasks - right-click while holding a mana flask to charge the emptiest item from the hotbar, offhand or armour slots
This commit is contained in:
@@ -71,4 +71,10 @@ public interface IManaStoringItem {
|
||||
default boolean isManaEmpty(ItemStack stack){
|
||||
return getMana(stack) == 0;
|
||||
}
|
||||
|
||||
/** Returns how full the given stack's mana is, as a fraction between 0 (empty) and 1 (full) */
|
||||
default float getFullness(ItemStack stack){
|
||||
return (float)getMana(stack) / getManaCapacity(stack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
package electroblob.wizardry.item;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.registry.WizardrySounds;
|
||||
import electroblob.wizardry.registry.WizardryTabs;
|
||||
import electroblob.wizardry.util.WizardryUtilities;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemManaFlask extends Item {
|
||||
@@ -49,4 +56,32 @@ public class ItemManaFlask extends Item {
|
||||
Wizardry.proxy.addMultiLineDescription(tooltip, "item." + Wizardry.MODID + ":mana_flask.desc", size.capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
|
||||
|
||||
ItemStack flask = player.getHeldItem(hand);
|
||||
|
||||
List<ItemStack> stacks = WizardryUtilities.getPrioritisedHotbarAndOffhand(player);
|
||||
stacks.addAll(player.inventory.armorInventory); // player#getArmorInventoryList() only returns an Iterable
|
||||
|
||||
// Find the chargeable item with the least mana
|
||||
ItemStack toCharge = stacks.stream()
|
||||
.filter(s -> s.getItem() instanceof IManaStoringItem && !((IManaStoringItem)s.getItem()).isManaFull(s))
|
||||
.min(Comparator.comparingDouble(s -> ((IManaStoringItem)s.getItem()).getFullness(s))).orElse(null);
|
||||
|
||||
if(toCharge != null){
|
||||
|
||||
((IManaStoringItem)toCharge.getItem()).rechargeMana(toCharge, size.capacity);
|
||||
|
||||
WizardryUtilities.playSoundAtPlayer(player, WizardrySounds.ITEM_MANA_FLASK_USE, 1, 1);
|
||||
WizardryUtilities.playSoundAtPlayer(player, WizardrySounds.ITEM_MANA_FLASK_RECHARGE, 0.7f, 1.1f);
|
||||
|
||||
if(!player.isCreative()) flask.shrink(1);
|
||||
|
||||
return new ActionResult<>(EnumActionResult.SUCCESS, flask);
|
||||
|
||||
}else{
|
||||
return new ActionResult<>(EnumActionResult.FAIL, flask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ public final class WizardrySounds {
|
||||
public static final SoundEvent ITEM_WAND_MELEE = createSound("item.wand.melee");
|
||||
public static final SoundEvent ITEM_ARMOUR_EQUIP_SILK = createSound("item.armour.equip_silk");
|
||||
public static final SoundEvent ITEM_PURIFYING_ELIXIR_DRINK = createSound("item.purifying_elixir.drink");
|
||||
public static final SoundEvent ITEM_MANA_FLASK_USE = createSound("item.mana_flask.use");
|
||||
public static final SoundEvent ITEM_MANA_FLASK_RECHARGE = createSound("item.mana_flask.recharge");
|
||||
|
||||
public static final SoundEvent ENTITY_BLACK_HOLE_AMBIENT = createSound("entity.black_hole.ambient");
|
||||
public static final SoundEvent ENTITY_BLACK_HOLE_VANISH = createSound("entity.black_hole.vanish");
|
||||
@@ -164,6 +166,8 @@ public final class WizardrySounds {
|
||||
event.getRegistry().register(ITEM_WAND_MELEE);
|
||||
event.getRegistry().register(ITEM_ARMOUR_EQUIP_SILK);
|
||||
event.getRegistry().register(ITEM_PURIFYING_ELIXIR_DRINK);
|
||||
event.getRegistry().register(ITEM_MANA_FLASK_USE);
|
||||
event.getRegistry().register(ITEM_MANA_FLASK_RECHARGE);
|
||||
|
||||
event.getRegistry().register(ENTITY_BLACK_HOLE_AMBIENT);
|
||||
event.getRegistry().register(ENTITY_BLACK_HOLE_VANISH);
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
"item.wand.melee": {"category": "player", "sounds": ["ebwizardry:effect1", "ebwizardry:effect2"]},
|
||||
"item.armour.equip_silk": {"category": "player", "sounds": ["item/armor/equip_leather1", "item/armor/equip_leather2", "item/armor/equip_leather3", "item/armor/equip_leather4", "item/armor/equip_leather5", "item/armor/equip_leather6"]},
|
||||
"item.purifying_elixir.drink": {"category": "player", "sounds": ["ebwizardry:buff_large"]},
|
||||
|
||||
"item.mana_flask.use": {"category": "player", "sounds": ["item/bottle/fill1", "item/bottle/fill2", "item/bottle/fill3", "item/bottle/fill4"]},
|
||||
"item.mana_flask.recharge": {"category": "player", "sounds": ["ebwizardry:conjure"]},
|
||||
|
||||
"entity.black_hole.ambient": {"category": "spells", "sounds": ["portal/portal"]},
|
||||
"entity.black_hole.vanish": {"category": "spells", "sounds": ["portal/trigger"]},
|
||||
"entity.bubble.pop": {"category": "spells", "sounds": ["random/pop"]},
|
||||
|
||||
Reference in New Issue
Block a user