-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add EntityLandEvent #14204
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
Open
Clexus
wants to merge
4
commits into
PaperMC:main
Choose a base branch
from
Clexus:land
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add EntityLandEvent #14204
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
84 changes: 84 additions & 0 deletions
84
paper-api/src/main/java/io/papermc/paper/event/entity/EntityLandEvent.java
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,84 @@ | ||
| package io.papermc.paper.event.entity; | ||
|
|
||
| import org.bukkit.block.Block; | ||
| import org.bukkit.entity.Entity; | ||
| import org.bukkit.event.Cancellable; | ||
| import org.bukkit.event.HandlerList; | ||
| import org.bukkit.event.entity.EntityEvent; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * Called when an {@link Entity} lands on the block after falling. | ||
| * This event is called before {@link org.bukkit.event.entity.EntityDamageEvent}, {@link org.bukkit.event.entity.EntityChangeBlockEvent}, {@link org.bukkit.event.player.PlayerInteractEvent} | ||
| * and {@link org.bukkit.event.entity.EntityInteractEvent}. | ||
| */ | ||
| @NullMarked | ||
| public class EntityLandEvent extends EntityEvent implements Cancellable { | ||
|
|
||
| private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
|
|
||
| private final Block block; | ||
| private boolean cancelled; | ||
| private double fallDistance; | ||
|
|
||
| public EntityLandEvent(final Entity entity, final Block block, double fallDistance) { | ||
| super(entity); | ||
| this.block = block; | ||
| this.fallDistance = fallDistance; | ||
| } | ||
|
|
||
| @Override | ||
| public HandlerList getHandlers() { | ||
| return HANDLER_LIST; | ||
| } | ||
|
|
||
| public static HandlerList getHandlerList() { | ||
| return HANDLER_LIST; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the block that the entity landed on. | ||
| * | ||
| * @return the block that the entity landed on | ||
| */ | ||
| public Block getBlock() { | ||
| return this.block; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isCancelled() { | ||
| return this.cancelled; | ||
| } | ||
|
|
||
| /** | ||
| * Sets whether to cancel the landing, cancelling this event will prevent | ||
| * the entity from taking fall damage and interact with the block. (ex: break turtle egg) | ||
| * | ||
| * @param cancel true if the event should be cancelled, false otherwise | ||
| */ | ||
| @Override | ||
| public void setCancelled(final boolean cancel) { | ||
| this.cancelled = cancel; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the fall distance of the entity before landing. | ||
| * | ||
| * @return the fall distance | ||
| */ | ||
| public double getFallDistance() { | ||
| return fallDistance; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the fall distance of the entity before landing. | ||
| * Fall distance in the event is used to calculate fall damage and | ||
| * the chance of transforming {@link org.bukkit.Material#FARMLAND} to {@link org.bukkit.Material#DIRT} and | ||
| * the type of falling sound when the entity lands on {@link org.bukkit.Material#POWDER_SNOW}. | ||
| * | ||
| * @param fallDistance the fall distance | ||
| */ | ||
| public void setFallDistance(final double fallDistance) { | ||
| this.fallDistance = fallDistance; | ||
| } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -170,6 +170,27 @@ | |
| } | ||
|
|
||
| public void setPlacedBy(final Level level, final BlockPos pos, final BlockState state, final @Nullable LivingEntity by, final ItemStack itemStack) { | ||
| @@ -488,8 +_,18 @@ | ||
| } | ||
|
|
||
| public void fallOn(final Level level, final BlockState state, final BlockPos pos, final Entity entity, final double fallDistance) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this should be marked as final, that way all callers need to use the explict overriden method, the new method can probably be protected, see what others say here I guess |
||
| - entity.causeFallDamage(fallDistance, 1.0F, entity.damageSources().fall()); | ||
| - } | ||
| + fallOn(level, state, pos, entity, fallDistance, true); // Paper - Add EntityLandEvent | ||
| + } | ||
| + | ||
| + // Paper start - Add EntityLandEvent | ||
| + public void fallOn(final Level level, final BlockState state, final BlockPos pos, final Entity entity, final double fallDistance, boolean callEvent) { | ||
| + double distance = callEvent ? org.bukkit.craftbukkit.event.CraftEventFactory.callEntityLandEvent(level, pos, entity, fallDistance) : fallDistance; | ||
| + if(distance == -1){ | ||
| + return; | ||
| + } | ||
| + entity.causeFallDamage(distance, 1.0F, entity.damageSources().fall()); | ||
| + } | ||
| + // Paper end - Add EntityLandEvent | ||
|
|
||
| public float getBounceRestitution() { | ||
| return this.bounceRestitution; | ||
| @@ -613,12 +_,20 @@ | ||
| return this.builtInRegistryHolder; | ||
| } | ||
|
|
||
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
14 changes: 14 additions & 0 deletions
14
paper-server/patches/sources/net/minecraft/world/level/block/HayBlock.java.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,14 @@ | ||
| --- a/net/minecraft/world/level/block/HayBlock.java | ||
| +++ b/net/minecraft/world/level/block/HayBlock.java | ||
| @@ -23,6 +_,10 @@ | ||
|
|
||
| @Override | ||
| public void fallOn(final Level level, final BlockState state, final BlockPos pos, final Entity entity, final double fallDistance) { | ||
| - entity.causeFallDamage(fallDistance, 0.2F, level.damageSources().fall()); | ||
| + double distance = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityLandEvent(level, pos, entity, fallDistance); // Paper start - Add EntityLandEvent | ||
| + if(distance == -1){ | ||
| + return; | ||
| + } | ||
| + entity.causeFallDamage(distance, 0.2F, level.damageSources().fall()); // Paper end - Add EntityLandEvent | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
paper-server/patches/sources/net/minecraft/world/level/block/HoneyBlock.java.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
14 changes: 11 additions & 3 deletions
14
...r-server/patches/sources/net/minecraft/world/level/block/PointedDripstoneBlock.java.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
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
16 changes: 16 additions & 0 deletions
16
paper-server/patches/sources/net/minecraft/world/level/block/SlimeBlock.java.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,16 @@ | ||
| --- a/net/minecraft/world/level/block/SlimeBlock.java | ||
| +++ b/net/minecraft/world/level/block/SlimeBlock.java | ||
| @@ -21,8 +_,12 @@ | ||
|
|
||
| @Override | ||
| public void fallOn(final Level level, final BlockState state, final BlockPos pos, final Entity entity, final double fallDistance) { | ||
| + double distance = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityLandEvent(level, pos, entity, fallDistance); // Paper start - Add EntityLandEvent | ||
| + if(distance == -1){ | ||
| + return; | ||
| + } | ||
| if (!entity.isSuppressingBounce()) { | ||
| - entity.causeFallDamage(fallDistance, 0.0F, level.damageSources().fall()); | ||
| + entity.causeFallDamage(distance, 0.0F, level.damageSources().fall()); // Paper end - Add EntityLandEvent | ||
| } | ||
| } | ||
|
|
17 changes: 17 additions & 0 deletions
17
paper-server/patches/sources/net/minecraft/world/level/block/TurtleEggBlock.java.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
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
Oops, something went wrong.
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.