Make mana flasks take time to use
This commit is contained in:
@@ -5,14 +5,19 @@ import electroblob.wizardry.registry.WizardrySounds;
|
||||
import electroblob.wizardry.registry.WizardryTabs;
|
||||
import electroblob.wizardry.util.EntityUtils;
|
||||
import electroblob.wizardry.util.InventoryUtils;
|
||||
import electroblob.wizardry.util.ParticleBuilder;
|
||||
import electroblob.wizardry.util.ParticleBuilder.Type;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumAction;
|
||||
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.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -25,15 +30,17 @@ public class ItemManaFlask extends Item {
|
||||
|
||||
public enum Size {
|
||||
|
||||
SMALL(75, EnumRarity.COMMON),
|
||||
MEDIUM(700, EnumRarity.COMMON),
|
||||
LARGE(1400, EnumRarity.RARE);
|
||||
SMALL(75, 25, EnumRarity.COMMON),
|
||||
MEDIUM(700, 40, EnumRarity.COMMON),
|
||||
LARGE(1400, 60, EnumRarity.RARE);
|
||||
|
||||
public int capacity;
|
||||
public int useDuration;
|
||||
public EnumRarity rarity;
|
||||
|
||||
Size(int capacity, EnumRarity rarity){
|
||||
Size(int capacity, int useDuration, EnumRarity rarity){
|
||||
this.capacity = capacity;
|
||||
this.useDuration = useDuration;
|
||||
this.rarity = rarity;
|
||||
}
|
||||
}
|
||||
@@ -58,6 +65,16 @@ public class ItemManaFlask extends Item {
|
||||
Wizardry.proxy.addMultiLineDescription(tooltip, "item." + Wizardry.MODID + ":mana_flask.desc", size.capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumAction getItemUseAction(ItemStack stack){
|
||||
return EnumAction.BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxItemUseDuration(ItemStack stack){
|
||||
return size.useDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
|
||||
|
||||
@@ -66,25 +83,53 @@ public class ItemManaFlask extends Item {
|
||||
List<ItemStack> stacks = InventoryUtils.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);
|
||||
|
||||
EntityUtils.playSoundAtPlayer(player, WizardrySounds.ITEM_MANA_FLASK_USE, 1, 1);
|
||||
EntityUtils.playSoundAtPlayer(player, WizardrySounds.ITEM_MANA_FLASK_RECHARGE, 0.7f, 1.1f);
|
||||
|
||||
if(!player.isCreative()) flask.shrink(1);
|
||||
player.getCooldownTracker().setCooldown(this, 20);
|
||||
|
||||
if(stacks.stream().anyMatch(s -> s.getItem() instanceof IManaStoringItem && !((IManaStoringItem)s.getItem()).isManaFull(s))){
|
||||
player.setActiveHand(hand);
|
||||
return new ActionResult<>(EnumActionResult.SUCCESS, flask);
|
||||
|
||||
}else{
|
||||
return new ActionResult<>(EnumActionResult.FAIL, flask);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUsingTick(ItemStack stack, EntityLivingBase player, int count){
|
||||
if(player.world.isRemote){
|
||||
float f = count/(float)getMaxItemUseDuration(stack);
|
||||
Vec3d pos = player.getPositionEyes(0).subtract(0, 0.2, 0).add(player.getLookVec().scale(0.6));
|
||||
Vec3d delta = new Vec3d(0, 0.2 * f, 0).rotatePitch(count * 0.5f).rotateYaw((float)Math.toRadians(90 - player.rotationYawHead));
|
||||
ParticleBuilder.create(Type.DUST).pos(pos.add(delta)).vel(delta.scale(0.2)).time(12 + player.world.rand.nextInt(6))
|
||||
.clr(1, 1, 0.65f).fade(0.7f, 0, 1).spawn(player.world);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase entity){
|
||||
|
||||
if(entity instanceof EntityPlayer){
|
||||
|
||||
EntityPlayer player = (EntityPlayer)entity;
|
||||
|
||||
List<ItemStack> stacks = InventoryUtils.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);
|
||||
|
||||
EntityUtils.playSoundAtPlayer(player, WizardrySounds.ITEM_MANA_FLASK_USE, 1, 1);
|
||||
EntityUtils.playSoundAtPlayer(player, WizardrySounds.ITEM_MANA_FLASK_RECHARGE, 0.7f, 1.1f);
|
||||
|
||||
if(!player.isCreative()) stack.shrink(1);
|
||||
player.getCooldownTracker().setCooldown(this, 20);
|
||||
}
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user