PocketMine-MP icon indicating copy to clipboard operation
PocketMine-MP copied to clipboard

Anvil Damage Implementation

Open nathanswanson opened this issue 3 years ago • 13 comments

Introduction

When a player or an entity has an anvil drop on them no damage is applied to same entity.

Relevant issues

Issues 4437

Changes

API changes

No API Changes.

Behavioural changes

  • Anvils now create falling damage at a max of 40HP. The damage is linked to the tick rate so odd behavior is limited.
  • EntityDamageEvent has been updated to contain "CAUSE_FALLING_ANVIL"
  • PlayerDeathEvent translation factory now has anvil death message.

Nathan was squashed by an anvil

Backwards compatibility

Unlikely to have any issues.

Follow-up

  • Falling Block types could benefit to having an event to handle collisions for plugins.
  • Sound when anvil finishes falling.
  • Anvil functionality.
  • Anvil piston behavior.

Requires translations:

Name Value in eng.ini
death.attack.anvil {%a} was squashed by an anvil

Tests

Game Implementation so no PHPUnit test used. I tested it by dropping anvils at various heights on me and all mobs implemented.

nathanswanson avatar Sep 17 '21 03:09 nathanswanson

PHP CS Fixer is not working on my PHP Storm so for now I will try to fix manually.

nathanswanson avatar Sep 17 '21 15:09 nathanswanson

Why does code style fail? on the actual php file its one line, on the log it shows + then -.

Also I made it so the autotranslation key is generated for the anvil death event. But now I get a generated code consistency error.

nathanswanson avatar Sep 17 '21 21:09 nathanswanson

Why does code style fail? on the actual php file its one line, on the log it shows + then -.

You've left trailing whitespace on the line. Blank lines shouldn't have any indentation.

Also I made it so the autotranslation key is generated for the anvil death event. But now I get a generated code consistency error.

You haven't added the string to the language file.

dktapps avatar Sep 17 '21 21:09 dktapps

You need to submit a pull request to the master branch of this repo to add the string to eng.ini: https://github.com/pmmp/Language

Once that's done, the resources/locale submodule should be updated and the translation APIs regenerated.

dktapps avatar Sep 17 '21 21:09 dktapps

I added the PR. This PR should be good to go after that translation is merged.

nathanswanson avatar Sep 17 '21 22:09 nathanswanson

Ideally I wanted to implement the damage code into the anvil class but having a falling block makes is a little more tricky. I put the code in the FallingBlock->onGround() method.

nathanswanson avatar Sep 19 '21 16:09 nathanswanson

After debugging workspace I FINALLY got my checkers to all work now.

nathanswanson avatar Sep 20 '21 19:09 nathanswanson

Strange, my coding checker didn't detect /** var */ as a problem and ill fix, regardless this PR cannot be merged until language/pmmp gets pulled so I recommend this be marked as on hold or whatever equivalent

nathanswanson avatar Sep 20 '21 19:09 nathanswanson

You can pull it yourself, if you want to.

cd resources/locale
git checkout master
git pull
cd ../..
git add resources/locale

and then commit as you would normally.

dktapps avatar Sep 20 '21 20:09 dktapps

Alright what about something like this then, fallable now has a method that is called when a falling entity hits the ground.

nathanswanson avatar Sep 20 '21 21:09 nathanswanson

Wearing a helmet reduces the damage by 1⁄4, but this costs durability on the helmet

Idk if there is a BlockSolidifyEvent of some sorts, it would be useful to invoke it with the falling block's block and the resulting block being the damaged block, so plugins can cancel the breaking.

Plus anvil destruction https://minecraft.fandom.com/wiki/Anvil#Becoming_damaged

inxomnyaa avatar Sep 22 '21 06:09 inxomnyaa

Wearing a helmet reduces the damage by 1⁄4, but this costs durability on the helmet

Idk if there is a BlockSolidifyEvent of some sorts, it would be useful to invoke it with the falling block's block and the resulting block being the damaged block, so plugins can cancel the breaking.

Plus anvil destruction https://minecraft.fandom.com/wiki/Anvil#Becoming_damaged

While adding the helmet damage makes sense I feel like the rest of the listed implementations here are unrelated to the PR.

nathanswanson avatar Sep 22 '21 10:09 nathanswanson

Note: Latest change exposes Living::damageItem()

nathanswanson avatar Sep 22 '21 19:09 nathanswanson

Closing due to lack of activity.

dktapps avatar Jan 09 '23 20:01 dktapps