Skip to content

Commit

Permalink
[21.1] Pass along interaction had to ItemStack.onEntitySwing (#1499)
Browse files Browse the repository at this point in the history
  • Loading branch information
ApexModder authored Sep 5, 2024
1 parent baae120 commit 0303531
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
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) {
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

0 comments on commit 0303531

Please sign in to comment.