Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Implement the LivingDropsEvent event #96

Merged
merged 5 commits into from
Jun 23, 2020

Conversation

ZNixian
Copy link
Member

@ZNixian ZNixian commented Jun 21, 2020

Required for Curios, see #84.

This PR is largely comprised of two parts:

Firstly, it implements Entity.captureDrops in the patchwork-extensions module. This is a collection that can be set on an entity that will redirect all the ItemEntitys it would otherwise drop on the ground into said collection.

The second part (in the second commit) adds to LivingEntity to use this mechanism to catch all the items the LivingEntity drops when it dies, and pass it through an event to let mods alter the dropped items. Finally it spawns them if the event wasn't cancelled.

Note that the second part creates a dependency from patchwork-events-entity to patchwork-extensions, however it seemed like the most logical place to put both parts.

The second part does involve some hackery to access the looting level after the local variable has been dropped, passing it through a field (described in a JavaDoc comment). I could just call EnchantmentHelper.getLooting again, but we'd have to use this method anyway when we implement LootingLevelEvent.

@@ -101,6 +115,65 @@ private void hookHandleFallDamageCancel(float distance, float damageMultiplier,
}
}

/**
* Carry over the looting level between the two mixins for the drop method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the descriptive javadoc!

@ZNixian ZNixian mentioned this pull request Jun 21, 2020
15 tasks
@TheGlitch76 TheGlitch76 merged commit 929bf8d into PatchworkMC:master Jun 23, 2020
@ZNixian ZNixian deleted the living-drops-event branch June 23, 2020 02:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants