Jump to content

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


hhggtg3279
 Share

Recommended Posts

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);

       

    }

   

   

}

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm researching the how to create biomes in json. There is a great tool for creating the jsons online. Using the vanilla `river` biome, I want to essentially create a custom disk feature that mixes 3 blocks instead of a single-block provider. Any ideas on where to start with that?
    • I figured out what was wrong ... you can spot it pretty quick most likely: { "type": "minecraft:smelting", "ingredient": { "item": "minecraft:gold_nugget_ore" }, "result": "minecraft:gold_nugget", "experience": 0.25, "cookingtime": 150 }   ... so, after changing `minecraft` to `foundations` for all the custom items and all the recipes work. Well that's what copy/paste will get you. One last question about recipes, though. What does the following json key/value do in the game? "group": "copper_ingot"  
    • # Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # #      102.54.94.97     rhino.acme.com          # source server #       38.25.63.10     x.acme.com              # x client host # localhost name resolution is handled within DNS itself. #    127.0.0.1       localhost #    ::1             localhost ###0.0.0.0 apps.corel.com ###0.0.0.0 mc.corel.com 0.0.0.0 origin-mc.corel.com ###0.0.0.0 iws.corel.com
    • Is there a way to create a custom map marker for a custom structure/biome (same as a vanilla mansion)?
    • I’ve scrounged the Internet for solutions and found absolutely nothing that has worked for me I have posted my code in a GitHub Repository. I bet the culprit is somewhere in the Container or TileEntity classes (Furnace packages are in blocks/coke_furnace or blocks/foundry) PS I know I’m on 1.12.2 and that it’s not supported I don’t want to update my game or my code. Lol It’s my favorite version and the most widely modded. I don’t plan to release the mod, I’m just customizing my game to my will. I’ll send it to friends but that’s it.
  • Topics

×
×
  • Create New...

Important Information

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