Add cooldowns (using the vanilla mechanic) to various consumable items

This commit is contained in:
Electroblob77
2020-05-17 00:32:02 +01:00
parent ef39757229
commit 4739d9f9fc
6 changed files with 27 additions and 7 deletions
@@ -190,6 +190,9 @@ public class ItemScroll extends Item implements ISpellCastingItem, IWorkbenchIte
// Scrolls are consumed upon successful use in survival mode
if(!spell.isContinuous && !caster.isCreative()) stack.shrink(1);
// Now uses the vanilla cooldown mechanic to prevent spamming of spells
if(!spell.isContinuous) caster.getCooldownTracker().setCooldown(this, spell.getCooldown());
}
return true;
@@ -201,21 +204,29 @@ public class ItemScroll extends Item implements ISpellCastingItem, IWorkbenchIte
@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase user, int timeLeft){
// Consumes a continuous spell scroll when a player in survival mode stops using it.
if(Spell.byMetadata(stack.getItemDamage()).isContinuous
&& (!(user instanceof EntityPlayer) || !((EntityPlayer)user).isCreative())){
stack.shrink(1);
}
finishCasting(stack, user);
}
@Override
public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase user){
// Consumes a continuous spell scroll when the casting elapses whilst in use by a player in survival mode.
finishCasting(stack, user);
return stack;
}
private void finishCasting(ItemStack stack, EntityLivingBase user){
if(Spell.byMetadata(stack.getItemDamage()).isContinuous
&& (!(user instanceof EntityPlayer) || !((EntityPlayer)user).isCreative())){
stack.shrink(1);
Spell spell = Spell.byMetadata(stack.getItemDamage());
if(user instanceof EntityPlayer){
((EntityPlayer)user).getCooldownTracker().setCooldown(this, spell.getCooldown());
}
}
return stack;
}
@Override