Wrap properly damage source and deprecate Bukkit's lazy enum#8058
Wrap properly damage source and deprecate Bukkit's lazy enum#8058Lulu13022002 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
I have been working on a very similar api, and i'm fine if you would like to take any inspiration for how I handled this api here.
Owen1212055@9d78b6e#diff-d0659f5a1063f530efebfa22bb1dbbcd7918630c558ae382821988a5fbb8a38f
I'd really recommend expanding this api to allow you to "build" your own damage sources. Currently you allow this but it is locked behind an nms class, you need to expose it via the api.
See: https://canary.discord.com/channels/289587909051416579/925530366192779286/987522312674897940
Basically, you want api objects to be backed by an NMS damage source which can be used in things like damage methods. My current iteration allows you to simply implement the interface, but that should no longer be the case and it should only be possible to create sources via builders.
You currently also remove the damage cause api, you cannot do that and have to instead have backward compatibility for that old system. It should be noted that many damage cause do not have a corrisponding NMS damage source.
|
I have updated the PR with the following things:
|
Owen1212055
left a comment
There was a problem hiding this comment.
Getting closer here! Good work.
b9df384 to
2e5be8a
Compare
|
Once/if merged what will be its target version? |
|
I think i will target the latest version |
024b857 to
87e26d3
Compare
9166429 to
0361fee
Compare
|
Rebased and added more example in the initial comment for anyone interested. Also now the plugin API can't trigger issue like in the 8340, the incompatible association will now throw a sweet error in a precondition (only for the vanilla damage, the custom one made by builder can already break this limit). Only the plugin that abuse of the nms hurt method could or if paper/bukkit hasn't been updated properly when mc is updated. The test is now more simple and will not fail to static init the vanilla damage origin class like before (i don't even know how the build was green??). |
lynxplay
left a comment
There was a problem hiding this comment.
Initial review of the API.
Mostly focused on the javadocs, the type layout looks fine to me 👍
I'll have some more time next week to also review the impl.
bee13f4 to
a7f563c
Compare
66dde81 to
409d109
Compare
|
Rebased for 1.19.3 if (e.getOrigin().getType() == VanillaDamageType.CACTUS) {
if (e.getEntity() instanceof LivingEntity lv) {
e.setCancelled(true);
lv.damage(3, DamageOrigin.of(VanillaDamageType.CACTUS, e.getDamager().getLocation()).build());
// cactus damage are 1 point but this is just an example to show you that you need at least 3 point of damage
// if you want to hurt the shield otherwise the damage will always be blocked if well covered
lv.setNoDamageTicks(2 + (lv.getMaximumNoDamageTicks() / 2));
}
}There's also some changes for all the falling block derivated damage origin. They're now a EntityDamageOrigin (the entity will be the falling block before the fall). You should use the VanillaDamageOrigin preset if you don't know what to put in the builder. |
409d109 to
1efa3bd
Compare
ddb0065 to
63df663
Compare
6baf31a to
ab7f541
Compare
63df663 to
dadd660
Compare
ab7f541 to
6bee6ce
Compare
dadd660 to
b73a925
Compare
6bee6ce to
ee1c66e
Compare
b73a925 to
3d82fe5
Compare
1b1bf5a to
b68643a
Compare
b68643a to
dbdf3a8
Compare
e5fca8b to
27dd551
Compare
dbdf3a8 to
d6830cb
Compare
27dd551 to
2c627bc
Compare
85e9944 to
fba3767
Compare
fba3767 to
bb62fc9
Compare
|
It looks like there is nothing more to do for this PR. Most of the recent commits are rebases for newer MC version. What prevents it from being ready for review / unmarked as draft? Really hope to see this soon added into paper :) |
|
spigot has an upstream PR, but also this PR is waiting for some other PRs currently in review. |
2c627bc to
26a19a5
Compare
bb62fc9 to
d041367
Compare
1fe80ff to
956b5ef
Compare
Closes issue 7415
d041367 to
d8278f8
Compare

Closes #7415
Supersedes #7980
Bukkit has for years stored damage history into a single enum which loses 90% of available damage history and cause a bunch of issue about the future (when Mojang decide to add new damage source for example)
This PR wrap the whole nms DamageSource.
The main reasons of this changes
New API
With this PR you can create your own damage source using a builder
Example:
All damage origin must be categorized under a damage type and you can
create them in the methods called before the registries freeze in paper plugin
bootstrapper. Example:
The builder is already prefilled with the default values.
The name will be used as part of the translatable key when an entity died due to this damage cause
If you want to change the death message without using the default behaviour (using the damage type name as key) you needs to use a callback function in the damage origin builder.
All the damage types (including plugin/datapack made one) will be under the DAMAGE_TYPE registry
available with
RegistryAccess.registryAccess().getRegistry(RegistryKey.DAMAGE_TYPE)Note this registry will not be available during bootstrap so don't try to get the value found in the VanillaDamageTypes class to get their keys! Instead you can get them through the DamageTypeKeys class generated automatically. For now the damage type tags aren't supported yet by this task and are left untyped.
You can also get the hurting sound or if an entity is invulnerable to a specific damage origin and to create explosion with custom origin. The damage type tags are also available
Additionally the damage origin is now available into the EntityDeathEvent, PlayerDeathEvent, VehicleDamageEvent, VehicleDestroyEvent, PlayerAttackEntityCooldownResetEvent, EntityResurrectEvent and TameableDeathMessageEvent
However i have decided to not change how the events works basically only the cause changes but the same events will be called for the same entity/block/action
In the future we could probably get rid of the bukkit logic that enforce such damage to be a block damage or not and
that has issue with concurrency.
Credits:
Javadoc for bukkit api has been taken from linked PR