Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Custom Projectile still firing even when there is no ammo in inventory 1.10.2

Featured Replies

Posted

Basically my item, which launches out my custom projectile, when I have arrows in my inventory it consumes them like it should, however when I don't have arrows, it still launches my projectile anyway when it should not

 

Projectile shooting item

 

package top.mod.item;

 

import javax.annotation.Nullable;

 

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.item.EntityEnderPearl;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.init.Items;

import net.minecraft.init.SoundEvents;

import net.minecraft.item.IItemPropertyGetter;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.item.ItemSword;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.stats.StatList;

import net.minecraft.util.ActionResult;

import net.minecraft.util.EnumActionResult;

import net.minecraft.util.EnumHand;

import net.minecraft.util.ResourceLocation;

import net.minecraft.util.SoundCategory;

import net.minecraft.world.World;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

 

public class ModBowPlatinum extends Item

{

    public ModBowPlatinum()

    {

    this.maxStackSize = 1;

    this.setMaxDamage(2284);

 

   

}

    public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)

    {

    playerIn.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("instant_health"), 75, 0));

        if (!worldIn.isRemote)

        {

            EntityPlatinum entityplatinum = new EntityPlatinum(worldIn, playerIn);

            entityplatinum.setHeadingFromThrower(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);

            worldIn.spawnEntityInWorld(entityplatinum);

           

            playerIn.inventory.clearMatchingItems(new ItemStack(Items.ARROW).getItem(), -1, 1, null);

        }

       

        itemStackIn.damageItem(1, playerIn);

 

 

        playerIn.addStat(StatList.getObjectUseStats(this));

        return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);

       

    }

   

   

}

 

 

Lets work this out.

 

Stepping through the method...

1) The player has right clicked with this item

2) We give the player instant health

3) World is the server, so we continue

4) Spawn a bullet entity and send it on its way

5) Subtract ammo from the player: oops it doesn't have any

6) Damage the item

 

Think about it for a minute.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

I don't understand but I tried this to check if it was successfully removed

playerIn.inventory.hasItemStack(new ItemStack(Items.ARROW)); {

float f = 1.2F;

I'm sorry, this is not a chat room, it's a forum. Don't bump your thread after an hour.

 

Point is:

Don't create the bullet entity unless the player has ammo.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

You are currently doing this:

 

1) The player has right clicked with this item

2) We give the player instant health

3) World is the server, so we continue

4) Spawn a bullet entity and send it on its way

5) Subtract ammo from the player: oops it doesn't have any

6) Damage the item

 

You create the bullet before ever checking if there's ammo.  And in fact, you don't check.  The two line snippet (that does basically nothing) does check, but isn't wrapped around anything important.  You need to reorder these steps and wrap the subtract ammo line into an if statement.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

That's not really ringing any bells, can you be a bit more specific.

Do you know how to use if-else statements? What Draco18s is saying is that if the ammo is in the inventory, the bullet entity will be fired, else nothing will happen

if () //if player has ammo in inventory
{
    //spawn entity
}

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.