Posted October 22, 20186 yr My onItemRightClick event keeps going through twice, and even with diagnostics I can't find out why. Any help is appreciate, thank you! {note that many of the contents of this code are simply placeholders} .................................................................... public class BakugoQuirk extends ItemBase { public BakugoQuirk(String name) { super(name); this.setMaxDamage(500); this.isDamageable(); } public void onUpdate(ItemStack item, World worldIn, Entity playerIn) { if (item.getItemDamage() != 0) { item.setItemDamage(499); //Item damage gain per tick } } public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { ItemStack item = playerIn.getHeldItem(handIn); Vec3d aim = playerIn.getLookVec(); System.out.println("testing for first condition, ItemDamage is " + item.getItemDamage()); if(item.getItemDamage() == 0) { playerIn.sendMessage(new TextComponentString("100% charge attack")); EntityLargeFireball fireball = new EntityLargeFireball(worldIn, playerIn, 1,1,1); fireball.setPosition(playerIn.posX + aim.x * 1.5D, playerIn.posY + aim.y * 1.5D , playerIn.posZ + aim.z * 1.5D); fireball.accelerationX = aim.x * 0.1; fireball.accelerationY = aim.y * 0.1; fireball.accelerationZ = aim.z * 0.1; worldIn.spawnEntity(fireball); item.setItemDamage(499); System.out.println("ItemDamage is " + item.getItemDamage() + " after test"); } else if(item.getItemDamage() > 0) { System.out.println("Going into second condition with " + item.getItemDamage() + " Item Damage"); EntityLargeFireball fireball = new EntityLargeFireball(worldIn, playerIn, 1,1,1); fireball.setPosition(playerIn.posX + aim.x * 1.5D, playerIn.posY + aim.y * 1.5D , playerIn.posZ + aim.z * 1.5D); fireball.accelerationX = aim.x * 0.1; fireball.accelerationY = aim.y * 0.1; fireball.accelerationZ = aim.z * 0.1; worldIn.spawnEntity(fireball); playerIn.sendMessage(new TextComponentString("50%-100% charge attack")); item.setItemDamage(item.getMaxDamage() - 1); } return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, item); } EDIT {SOLVED}: Just ended up adding a broad "if (worldIn.isRemote == false )" over much of the code including the entity spawn and the chat message Edited October 24, 20186 yr by BigSpidey
October 23, 20186 yr The method is likely being called once on the server and once on the client. Add a println statement and check if world.isRemote is true or false. True means it's the client, false means it's the server. My guess is you probably need it to run on both sides, so there's no problem.
October 23, 20186 yr It’s also fired for both hands I believe Edited October 23, 20186 yr by Cadiboo About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
October 23, 20186 yr 7 hours ago, Cadiboo said: It’s also fired for both hands I believe You are confusing this method with the right click event. The event will indeed fire for both hands. The Item#onItemRightClick will only fire for the hand holding the item. 15 hours ago, BigSpidey said: worldIn.spawnEntity(fireball); You can't do this without first checking whether the side the action is happening on is a server. Otherwise it will create a "ghost" entity on the client that will stay there untill relog. As @Daeruin said 7 hours ago, Daeruin said: check if world.isRemote is true or false. True means it's the client, false means it's the server 15 hours ago, BigSpidey said: playerIn.sendMessage(new TextComponentString("100% charge attack")); Same with this, you need to check the side. Otherwise you are sending the message twice.
October 23, 20186 yr Author 3 hours ago, V0idWa1k3r said: You are confusing this method with the right click event. The event will indeed fire for both hands. The Item#onItemRightClick will only fire for the hand holding the item. You can't do this without first checking whether the side the action is happening on is a server. Otherwise it will create a "ghost" entity on the client that will stay there untill relog. As @Daeruin said Same with this, you need to check the side. Otherwise you are sending the message twice. Thanks to everyone here, I have solved the problem!
October 23, 20186 yr Please post your final code and mark the topic as solved to help people in the future About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
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.