Posted December 26, 20177 yr Hello Im trying to get this function. Especially the offhand.hitentity to work. Everytime I face a mob the item swings but doesn't hurt the mob and if I face away from the mob the game crashes. @SubscribeEvent public static void dualweild(MouseEvent event) { EntityLivingBase target = (EntityLivingBase) Minecraft.getMinecraft().pointedEntity; EntityPlayer player = Minecraft.getMinecraft().player; ItemStack mainhand = player.getHeldItemMainhand(); ItemStack offhand = player.getHeldItemOffhand(); //right mouse button is 1 if (event.getButton() == 1) { if (offhand.getItem() instanceof ItemKnife) { offhand.hitEntity(target, player); offhand.damageItem(1, player); player.swingArm(EnumHand.OFF_HAND); } else { return; } } }
December 26, 20177 yr If you crash, then please post the crash log. We cannot help you with what we cannot see. Use pastebin.com or github gist, and link the url here. I'm betting that you're getting a nullpointer exception. Your code runs on the belief that there is always an entity where you are looking... 95% of the time, that is incorrect. Also previously known as eAndPi. "Pi, is there a station coming up where we can board your train of thought?" -Kronnn Published Mods: Underworld Handy links: Vic_'s Forge events Own WIP Tutorials.
December 27, 20177 yr We need the crashlog. But probably it's due to this: EntityLivingBase target = (EntityLivingBase) Minecraft.getMinecraft().pointedEntity; offhand.hitEntity(target, player); You need to make sure that is not null. (As you mention, that would be the case when you not facing an entity) Now in Minecraft, you are able to swing weapons even without facing entities, so that's something you should look into.
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.