Posted September 3, 20169 yr 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); } }
September 3, 20169 yr 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.
September 3, 20169 yr 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;
September 3, 20169 yr 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.
September 4, 20169 yr 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.
September 4, 20169 yr 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 } http://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.