-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Prioritise direct entity for Damager in damage event and avoid redundant causing entity #10275
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
Closed
Doc94
wants to merge
3
commits into
PaperMC:master
from
Doc94:fix/10273/damager-for-explosion-in-damage-events
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
patches/server/1048-Fix-CB-behaviours-in-DamageSource-for-DamageEvents.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: Doc <nachito94@msn.com> | ||
| Date: Thu, 22 Feb 2024 10:53:16 -0300 | ||
| Subject: [PATCH] Fix CB behaviours in DamageSource for DamageEvents | ||
|
|
||
|
|
||
| diff --git a/src/main/java/net/minecraft/world/damagesource/DamageSource.java b/src/main/java/net/minecraft/world/damagesource/DamageSource.java | ||
| index 1561b85a45f52a8162f43553f8485bfe084b8f1f..adb9be0c1cbfd524e26e2ff49e37c58fb3ef8751 100644 | ||
| --- a/src/main/java/net/minecraft/world/damagesource/DamageSource.java | ||
| +++ b/src/main/java/net/minecraft/world/damagesource/DamageSource.java | ||
| @@ -61,6 +61,7 @@ public class DamageSource { | ||
| } | ||
|
|
||
| public DamageSource customCausingEntity(Entity entity) { | ||
| + if (this.customCausingEntity != null || this.directEntity == entity || this.causingEntity == entity) return this; // Paper - avoid this method broke a few CB behaviours | ||
| DamageSource damageSource = this.cloneInstance(); | ||
| damageSource.customCausingEntity = entity; | ||
| return damageSource; | ||
| diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java | ||
| index d677759ac6b6d3cfe5a2af76dc1f0034b216ac2d..620dc20bda7a1959ff7c562e57e8b422650ce1d7 100644 | ||
| --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java | ||
| +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java | ||
| @@ -1082,6 +1082,11 @@ public class CraftEventFactory { | ||
| private static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSource source, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions, boolean cancelled) { | ||
| CraftDamageSource bukkitDamageSource = new CraftDamageSource(source); | ||
| Entity damager = source.getCausingEntity(); | ||
| + // Paper start - make damager prioritise the direct entity of damagesource | ||
| + if (bukkitDamageSource.isIndirect() && source.getDirectEntity() != null) { | ||
| + damager = source.getDirectEntity(); | ||
| + } | ||
| + // Paper end | ||
| if (source.is(DamageTypeTags.IS_EXPLOSION)) { | ||
| if (damager == null) { | ||
| return CraftEventFactory.callEntityDamageEvent(source.getDirectBlock(), entity, DamageCause.BLOCK_EXPLOSION, bukkitDamageSource, modifiers, modifierFunctions, cancelled, source.explodedBlockState); // Paper - Include BlockState for damage | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.