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.

Featured Replies

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

 

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

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.