Jump to content

Recommended Posts

Posted

So I made a staff and it shoots fireballs! I am trying to make it so that when the uses hits 30 it disappears and it works, but the charges are going down in increments of two instead of one like I want, any idea whats causing it?

Spoiler

public class ItemStaffFireball extends ItemSword implements IHasModel {
    private int x = 0;
    
    
    public ItemStaffFireball(String name, ToolMaterial material) {
        super(ItemInit.TOOL_STAFF);
        setUnlocalizedName(name);
        setRegistryName(name);
        setCreativeTab(CreativeTabs.TOOLS);

        
        ItemInit.ITEMS.add(this);
    }
    
    public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
        if(!world.isRemote) {
            {
                    
                Vec3d look = player.getLookVec();
                EntityLargeFireball fireball2 = new EntityLargeFireball(world, player, 1, 1, 1);
                fireball2.setPosition(
                        player.posX + look.x * 5,
                        player.posY + look.y * 5,
                        player.posZ + look.z * 5);
                fireball2.accelerationX = look.x * 0.1;
                fireball2.accelerationY = look.y * 0.1;
                fireball2.accelerationZ = look.z * 0.1;
                world.spawnEntity(fireball2);
                }
            }
        x++;
        System.out.println("Charges Left:" + (30-x));
        if(x == 30) {
            

        return new ActionResult(EnumActionResult.SUCCESS, ItemStack.EMPTY);
    }
        else {
            return new ActionResult(EnumActionResult.SUCCESS, player.getHeldItem(hand));
            
        }
    }
    
    
    @Override
    public void registerModels(){
        Main.proxy.registerItemRenderer(this, 0, "inventory");
        }
}

 

Posted (edited)
30 minutes ago, dragonbonez said:

 private int x = 0;

No, bad modder, no cookie.

Items are singletons, there exists exactly one instance of this class, and right now in your tests, the code is being called twice:

Once on the server thread

Once on the client thread

And each time it's deducting 1 from your counter (1 + 1 = 2).

 

If you want to store information on a stack (like....number of charges) you need to use metadata or capabilities on the itemstack.

Edited by Draco18s

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.

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...

×   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.

Announcements



×
×
  • Create New...

Important Information

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