Skip to content
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

[21.1] Pass along interaction had to ItemStack.onEntitySwing #1499

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion patches/net/minecraft/world/entity/LivingEntity.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@

public void swing(InteractionHand p_21012_, boolean p_21013_) {
+ ItemStack stack = this.getItemInHand(p_21012_);
+ if (!stack.isEmpty() && stack.onEntitySwing(this)) return;
+ if (!stack.isEmpty() && stack.onEntitySwing(this, p_21012_)) return;
if (!this.swinging || this.swingTime >= this.getCurrentSwingDuration() / 2 || this.swingTime < 0) {
this.swingTime = -1;
this.swinging = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -336,12 +337,25 @@ default ResourceLocation getArmorTexture(ItemStack stack, Entity entity, Equipme
* Called when a entity tries to play the 'swing' animation.
*
* @param entity The entity swinging the item.
* @return True to cancel any further processing by EntityLiving
* @return True to cancel any further processing by {@link LivingEntity}
* @deprecated To be replaced with hand sensitive version in 21.2
* @see #onEntitySwing(ItemStack, LivingEntity, InteractionHand)
*/
@Deprecated(forRemoval = true, since = "21.1")
default boolean onEntitySwing(ItemStack stack, LivingEntity entity) {
ApexModder marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

/**
* Called when a entity tries to play the 'swing' animation.
*
* @param entity The entity swinging the item.
* @return True to cancel any further processing by {@link LivingEntity}
*/
default boolean onEntitySwing(ItemStack stack, LivingEntity entity, InteractionHand hand) {
return onEntitySwing(stack, entity);
}

/**
* Return the itemDamage represented by this ItemStack. Defaults to the Damage
* entry in the stack NBT, but can be overridden here for other sources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
Expand Down Expand Up @@ -217,12 +218,26 @@ default boolean canDisableShield(ItemStack shield, LivingEntity entity, LivingEn
* Called when a entity tries to play the 'swing' animation.
*
* @param entity The entity swinging the item.
* @return True to cancel any further processing by EntityLiving
* @return True to cancel any further processing by {@link LivingEntity}
* @deprecated To be replaced with hand sensitive version in 21.2
* @see #onEntitySwing(LivingEntity, InteractionHand)
*/
@Deprecated(forRemoval = true, since = "21.1")
default boolean onEntitySwing(LivingEntity entity) {
return self().getItem().onEntitySwing(self(), entity);
}

/**
* Called when a entity tries to play the 'swing' animation.
*
* @param entity The entity swinging the item.
* @param hand The hand the item is held in.
* @return True to cancel any further processing by {@link LivingEntity}
*/
default boolean onEntitySwing(LivingEntity entity, InteractionHand hand) {
return self().getItem().onEntitySwing(self(), entity, hand);
}

/**
* Called when an entity stops using an item item for any reason.
*
Expand Down
Loading