Posted December 3, 20177 yr 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"); } }
December 3, 20177 yr 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 December 3, 20177 yr 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.