Add cooldowns (using the vanilla mechanic) to various consumable items
This commit is contained in:
@@ -29,6 +29,8 @@ public class ItemFirebomb extends Item {
|
|||||||
|
|
||||||
player.playSound(WizardrySounds.ENTITY_FIREBOMB_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
player.playSound(WizardrySounds.ENTITY_FIREBOMB_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||||
|
|
||||||
|
player.getCooldownTracker().setCooldown(this, 20);
|
||||||
|
|
||||||
if(!world.isRemote){
|
if(!world.isRemote){
|
||||||
EntityFirebomb firebomb = new EntityFirebomb(world);
|
EntityFirebomb firebomb = new EntityFirebomb(world);
|
||||||
firebomb.aim(player, 1);
|
firebomb.aim(player, 1);
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ public class ItemManaFlask extends Item {
|
|||||||
WizardryUtilities.playSoundAtPlayer(player, WizardrySounds.ITEM_MANA_FLASK_RECHARGE, 0.7f, 1.1f);
|
WizardryUtilities.playSoundAtPlayer(player, WizardrySounds.ITEM_MANA_FLASK_RECHARGE, 0.7f, 1.1f);
|
||||||
|
|
||||||
if(!player.isCreative()) flask.shrink(1);
|
if(!player.isCreative()) flask.shrink(1);
|
||||||
|
player.getCooldownTracker().setCooldown(this, 20);
|
||||||
|
|
||||||
return new ActionResult<>(EnumActionResult.SUCCESS, flask);
|
return new ActionResult<>(EnumActionResult.SUCCESS, flask);
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public class ItemPoisonBomb extends Item {
|
|||||||
|
|
||||||
player.playSound(WizardrySounds.ENTITY_POISON_BOMB_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
player.playSound(WizardrySounds.ENTITY_POISON_BOMB_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||||
|
|
||||||
|
player.getCooldownTracker().setCooldown(this, 20);
|
||||||
|
|
||||||
if(!world.isRemote){
|
if(!world.isRemote){
|
||||||
EntityPoisonBomb poisonbomb = new EntityPoisonBomb(world);
|
EntityPoisonBomb poisonbomb = new EntityPoisonBomb(world);
|
||||||
poisonbomb.aim(player, 1);
|
poisonbomb.aim(player, 1);
|
||||||
|
|||||||
@@ -190,6 +190,9 @@ public class ItemScroll extends Item implements ISpellCastingItem, IWorkbenchIte
|
|||||||
|
|
||||||
// Scrolls are consumed upon successful use in survival mode
|
// Scrolls are consumed upon successful use in survival mode
|
||||||
if(!spell.isContinuous && !caster.isCreative()) stack.shrink(1);
|
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;
|
return true;
|
||||||
@@ -201,21 +204,29 @@ public class ItemScroll extends Item implements ISpellCastingItem, IWorkbenchIte
|
|||||||
@Override
|
@Override
|
||||||
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase user, int timeLeft){
|
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.
|
// Consumes a continuous spell scroll when a player in survival mode stops using it.
|
||||||
if(Spell.byMetadata(stack.getItemDamage()).isContinuous
|
finishCasting(stack, user);
|
||||||
&& (!(user instanceof EntityPlayer) || !((EntityPlayer)user).isCreative())){
|
|
||||||
stack.shrink(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase user){
|
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.
|
// 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
|
if(Spell.byMetadata(stack.getItemDamage()).isContinuous
|
||||||
&& (!(user instanceof EntityPlayer) || !((EntityPlayer)user).isCreative())){
|
&& (!(user instanceof EntityPlayer) || !((EntityPlayer)user).isCreative())){
|
||||||
stack.shrink(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stack;
|
stack.shrink(1);
|
||||||
|
|
||||||
|
Spell spell = Spell.byMetadata(stack.getItemDamage());
|
||||||
|
|
||||||
|
if(user instanceof EntityPlayer){
|
||||||
|
((EntityPlayer)user).getCooldownTracker().setCooldown(this, spell.getCooldown());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public class ItemSmokeBomb extends Item {
|
|||||||
|
|
||||||
player.playSound(WizardrySounds.ENTITY_SMOKE_BOMB_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
player.playSound(WizardrySounds.ENTITY_SMOKE_BOMB_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||||
|
|
||||||
|
player.getCooldownTracker().setCooldown(this, 20);
|
||||||
|
|
||||||
if(!world.isRemote){
|
if(!world.isRemote){
|
||||||
EntitySmokeBomb smokebomb = new EntitySmokeBomb(world);
|
EntitySmokeBomb smokebomb = new EntitySmokeBomb(world);
|
||||||
smokebomb.aim(player, 1);
|
smokebomb.aim(player, 1);
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public class ItemSparkBomb extends Item {
|
|||||||
|
|
||||||
player.playSound(WizardrySounds.ENTITY_SPARK_BOMB_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
player.playSound(WizardrySounds.ENTITY_SPARK_BOMB_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
||||||
|
|
||||||
|
player.getCooldownTracker().setCooldown(this, 20);
|
||||||
|
|
||||||
if(!world.isRemote){
|
if(!world.isRemote){
|
||||||
EntitySparkBomb sparkBomb = new EntitySparkBomb(world);
|
EntitySparkBomb sparkBomb = new EntitySparkBomb(world);
|
||||||
sparkBomb.aim(player, 1);
|
sparkBomb.aim(player, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user