Posted December 8, 20195 yr public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) { Entity entity = ModMath.getMouseOver(Minecraft.getMinecraft().getRenderPartialTicks(), 0); // Gets entity that entityLiving is looking at if (entity != null && entity instanceof EntityLiving) { ((EntityLiving)entity).attackEntityFrom(DamageSource.MAGIC, 2.0f); ((EntityLiving)entity).setRevengeTarget(entityLiving); } return stack; } Using item that has the implementation of the method above doesn't damage entity. Debugging it showed that attackEntityFrom() is called, code within if statement is executed but entity isn't attacked. I looked into Minecraft's files that use attackEntityFrom() and observed that they just call attackEntityFrom(), just one line of code(I assume that something else that can affect entity attacking process was called before attackEntityFrom() in that files). How can I solve this problem? How can I deal damage to entity?
December 8, 20195 yr Damaging the Entity (and all Entity related operations in general) must be done on the server side, yet your code is executing on the client (indicated by the usage of Minecraft class). You would need to send a packet to the server to inform it about the action, then damage the Entity on the server. Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
December 8, 20195 yr Author 2 hours ago, DavidM said: Damaging the Entity (and all Entity related operations in general) must be done on the server side, yet your code is executing on the client (indicated by the usage of Minecraft class). You would need to send a packet to the server to inform it about the action, then damage the Entity on the server. Can I just change ModMath.getMouseOver(…) to make it be able to work only on server. And put everything in if (!worldIn.isRemote). Will it work? Edited December 8, 20195 yr by AntonBespoiasov
December 8, 20195 yr Author I solved this problem. And I did it in pretty weird way. I add entity = worldIn.getEntityByID(entity.getEntityId()) after getting entity with ModMath.getMouseOver(…). The problem was in ModMath.getMouseOver(…).
December 9, 20195 yr 7 hours ago, AntonBespoiasov said: Can I just change ModMath.getMouseOver(…) to make it be able to work only on server. And put everything in if (!worldIn.isRemote). Will it work? No. You are still reaching across logical sides. Use packets. Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
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.