Jump to content

Checking if a player swung with full attack power


Javisel

Recommended Posts

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 

Link to comment
Share on other sites

EntityPlayer#getCooledAttackStrength.

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

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?

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

@Animefan8888 You're back!

 

@Javisel Post your code. That method gives the percentage of the attack cool down.

Edited by DavidM

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

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

Link to comment
Share on other sites

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. ?

  • Like 1

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

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

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

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.

Link to comment
Share on other sites

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.

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

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

 

Link to comment
Share on other sites

Just now, Javisel said:

getCooldownPeriod()

This tells you how long the cooldown should be not how long has passed.

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

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?

Link to comment
Share on other sites

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.

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

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 by DavidM

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

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.

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

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.

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

Try subscribing to AttackEntityEvent.

AttackEntityEvent fires before the cool down reset.

Overriding IForgeItem#onLeftClickEntity should also work.

Edited by DavidM
  • Thanks 1

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am not using hardcoded recipes, I'm using Vanilla's already existing code for leather armor dying. (via extending and implementing DyeableArmorItem / DyeableLeatherItem respectively) I have actually figured out that it's something to do with registering item colors to the ItemColors instance, but I'm trying to figure out where exactly in my mod's code I would be placing a call to the required event handler. Unfortunately the tutorial is criminally undescriptive. The most I've found is that it has to be done during client initialization. I'm currently trying to do the necessary setup via hijacking the item registry since trying to modify the item classes directly (via using SubscribeEvent in the item's constructor didn't work. Class so far: // mrrp mrow - mcmod item painter v1.0 - catzrule ch package catzadvitems.init; import net.minecraft.client.color.item.ItemColors; import net.minecraft.world.item.Item; import net.minecraftforge.registries.ObjectHolder; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.client.event.ColorHandlerEvent; import catzadvitems.item.DyeableWoolArmorItem; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Painter { @ObjectHolder("cai:dyeable_wool_chestplate") public static final Item W_CHEST = null; @ObjectHolder("cai:dyeable_wool_leggings") public static final Item W_LEGS = null; @ObjectHolder("cai:dyeable_wool_boots") public static final Item W_SOCKS = null; public Painter() { // left blank, idk if forge throws a fit if constructors are missing, not taking the chance of it happening. } @SubscribeEvent public static void init(FMLClientSetupEvent event) { new Painter(); } @Mod.EventBusSubscriber private static class ForgeBusEvents { @SubscribeEvent public static void registerItemColors(ColorHandlerEvent.Item event) { ItemColors col = event.getItemColors(); col.register(DyeableUnderArmorItem::getItemDyedColor, W_CHEST, W_LEGS, W_SOCKS); //placeholder for other dye-able items here later.. } } } (for those wondering, i couldn't think of a creative wool helmet name)
    • nvm found out it was because i had create h and not f
    • Maybe there's something happening in the 'leather armor + dye' recipe itself that would be updating the held item texture?
    • @SubscribeEvent public static void onRenderPlayer(RenderPlayerEvent.Pre e) { e.setCanceled(true); model.renderToBuffer(e.getPoseStack(), pBuffer, e.getPackedLight(), 0f, 0f, 0f, 0f, 0f); //ToaPlayerRenderer.render(); } Since getting the render method from a separate class is proving to be bit of a brick wall for me (but seems to be the solution in older versions of minecraft/forge) I've decided to try and pursue using the renderToBuffer method directly from the model itself. I've tried this route before but can't figure out what variables to feed it for the vertexConsumer and still can't seem to figure it out; if this is even a path to pursue.  The vanilla model files do not include any form of render methods, and seem to be fully constructed from their layer definitions? Their renderer files seem to take their layers which are used by the render method in the vanilla MobRenderer class. But for modded entities we @Override this function and don't have to feed the method variables because of that? I assume that the render method in the extended renderer takes the layer definitions from the renderer classes which take those from the model files. Or maybe instead of trying to use a render method I should be calling the super from the renderer like   new ToaPlayerRenderer(context, false); Except I'm not sure what I would provide for context? There's a context method in the vanilla EntityRendererProvider class which doesn't look especially helpful. I've been trying something like <e.getEntity(), model<e.getEntity()>> since that generally seems to be what is provided to the renderers for context, but I don't know if it's THE context I'm looking for? Especially since the method being called doesn't want to take this or variations of this.   In short; I feel like I'm super super close but I have to be missing something obvious? Maybe this insane inane ramble post will provide some insight into this puzzle?
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.