Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeDamaged to EntityDamageEvent #9704

Closed
wants to merge 1 commit into from

Conversation

Cryptite
Copy link
Contributor

@Cryptite Cryptite commented Sep 10, 2023

My finest work yet. Just a simple way to fetch the time an EntityDamageEvent happened.

Unsure if we want to use things like epoch time still or whether we're trying to use things like ticks or other time measurements; happy to update as needed if so.

@Cryptite Cryptite requested a review from a team as a code owner September 10, 2023 13:07
@456dev
Copy link
Contributor

456dev commented Sep 10, 2023

is this different to calling System.currentTimeMillis(); in your event handler?
or maybe a stupid suggestion, if its useful here, wouldnt it be useful in every event, as an interface / smth

@electronicboy
Copy link
Member

I mean, for most intents and purposes, the difference will be minimal unless you're posting that off async; time millis is generally fast enough, so it's not a big deal but I don't exactly see an inherient advantage here; isn't this one of the things that mojang stores a timestamp for the packet?

@Malfrador
Copy link
Member

If there is ever API for DamageSources and the CombatTracker, I could see a timestamp added to each DamageSource being useful, because then time, involved entities, direction and type of each instance of damage received would be together.
But currently I fail to see the advantage over just listening to the event and storing the timestamp yourself.

Vanilla only tracks combat start and end time as well as the time since the last attack, not timestamps for individual damages.

@Cryptite
Copy link
Contributor Author

Cryptite commented Sep 10, 2023

is this different to calling System.currentTimeMillis(); in your event handler? or maybe a stupid suggestion, if its useful here, wouldnt it be useful in every event, as an interface / smth

The difference (for me) is that EntityDamageEvent is something that can be later accessed off an Entity with getLastDamageCause(), whereas most other events are instant and not stored.

But currently I fail to see the advantage over just listening to the event and storing the timestamp yourself.

Mostly it's because this is a trivial object addition to an event whereas one would need to start managing HashMaps etc for this which would certainly be (a little) more effort, memory cost, and the like. It's certainly not a vital addition but I could see it being useful for others. All else fails I'll just continue using it in my fork.

Like with above, considering that you can fetch getLastDamageCause() off an Entity at any point, being able to tell when that event happened can be useful.

@electronicboy
Copy link
Member

This is generally the weird area of "I can get the why" but, It feels weird to accept this for just a single set of events, but it would also be weird to shove it for all events. I think this gets into the pattern where people for years have just wanted a general form of mechanism to attach data to event objects

@ComputerNerd100
Copy link
Contributor

@SO-32
Copy link

SO-32 commented Oct 4, 2023

After rebasing, tested PR. Confirmed working

@Owen1212055
Copy link
Member

Yeah, I don't see the point in this. And in general, this API will need to be reworked for the whole proper damagecause system.

@Cryptite
Copy link
Contributor Author

Yeah, I don't see the point in this. And in general, this API will need to be reworked for the whole proper damagecause system.

If there were a DamageCause class object, rather than just an enum, that would be a nice place to put something like this.

@lynxplay
Copy link
Contributor

Yea I think I'll close this for now.

I 100% see the usecase for this, but yea, merging a temporary solution when we know we want a better one down the line seems rough for an API that wants to be backwards compatible if possible.

I am glad to see that the patch found a place in Slice however 😉

@lynxplay lynxplay closed this Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

8 participants