Javisel Posted July 23, 2019 Share Posted July 23, 2019 I'm overriding the HityEntity method in Item to do something for the player. But for design choices/balancing I need to gate it behind weapon charge time. I'm trying to figure out how I can detect if an attack was done with full power to prevent spam clicking. I tried looking into EntityPlayer's and how it handles sweeping edge but I don't really understand it.Project Source Code Quote Link to comment Share on other sites More sharing options...
DavidM Posted July 23, 2019 Share Posted July 23, 2019 EntityPlayer#getCooledAttackStrength. Quote 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. Link to comment Share on other sites More sharing options...
Javisel Posted July 23, 2019 Author Share Posted July 23, 2019 14 hours ago, DavidM said: EntityPlayer#getCooledAttackStrength. I tried that, but it didn't work. Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted July 23, 2019 Share Posted July 23, 2019 6 hours ago, Javisel said: I tried that, but it didn't work. Provide which item you are working with you gave us no direction to the actual file(s) we are working with.How did you use EntityPlayer$getCooledAttackStrength? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
DavidM Posted July 24, 2019 Share Posted July 24, 2019 (edited) @Animefan8888 You're back! @Javisel Post your code. That method gives the percentage of the attack cool down. Edited July 24, 2019 by DavidM Quote 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. Link to comment Share on other sites More sharing options...
Javisel Posted July 24, 2019 Author Share Posted July 24, 2019 14 hours ago, Animefan8888 said: Provide which item you are working with you gave us no direction to the actual file(s) we are working with.How did you use EntityPlayer$getCooledAttackStrength? 11 hours ago, DavidM said: @Animefan8888 You're back! @Javisel Post your code. That method gives the percentage of the attack cool down. Sorry my bad. Here's a link to the item: Link Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted July 24, 2019 Share Posted July 24, 2019 14 hours ago, DavidM said: You're back! Yeah college and other more important stuff started taking all of my time, now it's time to learn all this new forge code base. ? 1 Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Animefan8888 Posted July 24, 2019 Share Posted July 24, 2019 3 hours ago, Javisel said: Sorry my bad. Here's a link to the item: Link Your problem is here. if (player.getCooledAttackStrength(0) == 0.0F) { 0.0F would be it hasn't recharged at all 1.0F would be fully recharged and 0.5F would be half of full Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Javisel Posted July 24, 2019 Author Share Posted July 24, 2019 27 minutes ago, Animefan8888 said: Your problem is here. if (player.getCooledAttackStrength(0) == 0.0F) { 0.0F would be it hasn't recharged at all 1.0F would be fully recharged and 0.5F would be half of full I've tried both numbers and it won't work. I'm trying to figure out if it was swung with 1.0F power, not if it is currently at 0.5f or 1.0F power. Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted July 24, 2019 Share Posted July 24, 2019 27 minutes ago, Javisel said: I've tried both numbers and it won't work. I'm trying to figure out if it was swung with 1.0F power, not if it is currently at 0.5f or 1.0F power. I see the problem after a little time debugging. Item#hitEntity is called after the LivingEntity#ticksSinceLastSwing is reset to 0. So using PlayerEntity#getCooledAttackStrength won't work. Your best bet is to either create a capability to store an integer in either your Item/ItemStack or the player. I suggest the player if you are going to use the cooldown more than once. And just count the ticks since a swing. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Javisel Posted July 24, 2019 Author Share Posted July 24, 2019 3 hours ago, Animefan8888 said: I see the problem after a little time debugging. Item#hitEntity is called after the LivingEntity#ticksSinceLastSwing is reset to 0. So using PlayerEntity#getCooledAttackStrength won't work. Your best bet is to either create a capability to store an integer in either your Item/ItemStack or the player. I suggest the player if you are going to use the cooldown more than once. And just count the ticks since a swing. Do you think it'd be possible to use getCooldownPeriod() somehow? I've tried but that hasn't worked. So i'm wondering if my implementation is incorrect and if there's a better way Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted July 24, 2019 Share Posted July 24, 2019 Just now, Javisel said: getCooldownPeriod() This tells you how long the cooldown should be not how long has passed. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Javisel Posted July 25, 2019 Author Share Posted July 25, 2019 On 7/24/2019 at 4:45 PM, Animefan8888 said: This tells you how long the cooldown should be not how long has passed. Oh, my bad. What about Sweeping Edge? The sweep effect is only activated when the swing was done with full strength. I took a look at the code for it in EntityPlayer and couldn't really understand it or replicate it's effects. Is it impossible to do so? Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted July 26, 2019 Share Posted July 26, 2019 3 hours ago, Javisel said: Oh, my bad. What about Sweeping Edge? The sweep effect is only activated when the swing was done with full strength. I took a look at the code for it in EntityPlayer and couldn't really understand it or replicate it's effects. Is it impossible to do so? Sweeping edge happens earlier in the execution order. Now maybe you can use LivingDamageEvent(I think that is the name) which might be early enough in the execution, maybe it even has a field that tells you about the cool down I'm not sure, but worth a try. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
DavidM Posted July 26, 2019 Share Posted July 26, 2019 (edited) LivingDamageEvent is triggered before the attack deals damage. LivingDamageEvent#getSource returns the damage source, which, if is an instance of EntityDamageSource (when an entity inflicts the damage), will record the entity that dealt the damage, and can be obtained with EntityDamageSource#getTrueSource. If the return entity is an instance of EntityPlayer, you can get the attack cool down with EntityPlayer#getCooldownPeriod or EntityPlayer#getCooledAttackStrength. Edited July 26, 2019 by DavidM Quote 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. Link to comment Share on other sites More sharing options...
Animefan8888 Posted July 26, 2019 Share Posted July 26, 2019 1 minute ago, DavidM said: If the return entity is an instance of EntityPlayer, you can get the attack cool down with EntityPlayer#getCooldownPeriod or EntityPlayer#getCooledAttackStrength. Yes I understand that, my idea was maybe they added a Field to the LivingDamageEvent that contained the value or something related, its unlikely. Also do you know if this event is pushed before the EntityLiving#ticksSinceLastSwing is reset to 0. Because if it isnt then EntityPlayer#getCooledAttackStrength wont work. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
DavidM Posted July 26, 2019 Share Posted July 26, 2019 3 minutes ago, Animefan8888 said: if this event is pushed before the EntityLiving#ticksSinceLastSwing is reset to 0 My bad. Just checked and realized LivingDamageEvent is triggered after calculations, but before the damage applies. It is probably triggered after the ticksSinceLastSwing is reset to 0. Quote 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. Link to comment Share on other sites More sharing options...
DavidM Posted July 26, 2019 Share Posted July 26, 2019 (edited) Try subscribing to AttackEntityEvent. AttackEntityEvent fires before the cool down reset. Overriding IForgeItem#onLeftClickEntity should also work. Edited July 26, 2019 by DavidM 1 Quote 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. Link to comment Share on other sites More sharing options...
Javisel Posted July 26, 2019 Author Share Posted July 26, 2019 9 minutes ago, DavidM said: Try subscribing to AttackEntityEvent. AttackEntityEvent fires before the cool down reset. Overriding IForgeItem#onLeftClickEntity should also work. I'll try these suggestions, thank you Quote Link to comment Share on other sites More sharing options...
Javisel Posted July 26, 2019 Author Share Posted July 26, 2019 1 hour ago, DavidM said: Try subscribing to AttackEntityEvent. AttackEntityEvent fires before the cool down reset. Overriding IForgeItem#onLeftClickEntity should also work. I tried it. It works! Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.