diff --git a/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch b/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch index 457fa1f65e..b28007b034 100644 --- a/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/player/Player.java.patch @@ -221,6 +221,26 @@ } f = f + f1; +@@ -1064,9 +_,7 @@ + double d0 = (double)(this.f_19787_ - this.f_19867_); + if (flag && !flag2 && !flag1 && this.f_19861_ && d0 < (double)this.m_6113_()) { + ItemStack itemstack = this.m_21120_(InteractionHand.MAIN_HAND); +- if (itemstack.m_41720_() instanceof SwordItem) { +- flag3 = true; +- } ++ flag3 = itemstack.canPerformAction(net.minecraftforge.common.ToolActions.SWORD_SWEEP); + } + + float f4 = 0.0F; +@@ -1097,7 +_,7 @@ + if (flag3) { + float f3 = 1.0F + EnchantmentHelper.m_44821_(this) * f; + +- for(LivingEntity livingentity : this.f_19853_.m_45976_(LivingEntity.class, p_36347_.m_142469_().m_82377_(1.0D, 0.25D, 1.0D))) { ++ for(LivingEntity livingentity : this.f_19853_.m_45976_(LivingEntity.class, this.m_21120_(InteractionHand.MAIN_HAND).getSweepHitBox(this, p_36347_))) { + if (livingentity != this && livingentity != p_36347_ && !this.m_7307_(livingentity) && (!(livingentity instanceof ArmorStand) || !((ArmorStand)livingentity).m_31677_()) && this.m_20280_(livingentity) < 9.0D) { + livingentity.m_147240_((double)0.4F, (double)Mth.m_14031_(this.m_146908_() * ((float)Math.PI / 180F)), (double)(-Mth.m_14089_(this.m_146908_() * ((float)Math.PI / 180F)))); + livingentity.m_6469_(DamageSource.m_19344_(this), f3); @@ -1139,13 +_,15 @@ EnchantmentHelper.m_44896_(this, p_36347_); ItemStack itemstack1 = this.m_21205_(); diff --git a/src/main/java/net/minecraftforge/common/ToolActions.java b/src/main/java/net/minecraftforge/common/ToolActions.java index bc9464eb22..30c5d2ed83 100644 --- a/src/main/java/net/minecraftforge/common/ToolActions.java +++ b/src/main/java/net/minecraftforge/common/ToolActions.java @@ -21,6 +21,7 @@ package net.minecraftforge.common; import com.google.common.collect.Sets; import net.minecraftforge.common.extensions.IForgeBlock; +import net.minecraftforge.common.extensions.IForgeItem; import java.util.Set; import java.util.stream.Collectors; @@ -73,6 +74,13 @@ public class ToolActions */ public static final ToolAction SHOVEL_FLATTEN = ToolAction.get("shovel_flatten"); + /** + * Used during player attack to figure out if a sweep attack should be performed + * + * @see {@link IForgeItem#getSweepHitBox} + */ + public static final ToolAction SWORD_SWEEP = ToolAction.get("sword_sweep"); + ///** // * Passed onto {@link IForgeBlock#getToolModifiedState} when a hoe wants to turn dirt into soil // */ @@ -84,5 +92,5 @@ public class ToolActions public static final Set DEFAULT_HOE_ACTIONS = Stream.of(HOE_DIG /* TODO: , HOE_TILL */).collect(Collectors.toCollection(Sets::newIdentityHashSet)); public static final Set DEFAULT_SHOVEL_ACTIONS = Stream.of(SHOVEL_DIG, SHOVEL_FLATTEN).collect(Collectors.toCollection(Sets::newIdentityHashSet)); public static final Set DEFAULT_PICKAXE_ACTIONS = Stream.of(PICKAXE_DIG).collect(Collectors.toCollection(Sets::newIdentityHashSet)); - public static final Set DEFAULT_SWORD_ACTIONS = Stream.of(SWORD_DIG).collect(Collectors.toCollection(Sets::newIdentityHashSet)); + public static final Set DEFAULT_SWORD_ACTIONS = Stream.of(SWORD_DIG, SWORD_SWEEP).collect(Collectors.toCollection(Sets::newIdentityHashSet)); } diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java b/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java index 3e93ea8780..1eb69ab863 100644 --- a/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java @@ -19,18 +19,17 @@ package net.minecraftforge.common.extensions; -import java.util.List; import java.util.Set; import java.util.function.Consumer; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.google.common.collect.Multimap; -import net.minecraft.tags.Tag; import net.minecraft.world.item.*; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Mob; @@ -51,7 +50,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.util.Mth; import net.minecraft.network.chat.Component; import net.minecraft.world.level.Level; -import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ToolAction; // TODO review most of the methods in this "patch" @@ -796,4 +794,18 @@ public interface IForgeItem { return self().canBeDepleted(); } + + /** + * Get a bounding box ({@link AABB}) of a sweep attack. + * + * @param statck the stack held by the player. + * @param player the performing the attack the attack. + * @param target the entity targeted by the attack. + * @return the bounding box. + */ + @Nonnull + default AABB getSweepHitBox(@Nonnull ItemStack stack, @Nonnull Player player, @Nonnull Entity target) + { + return target.getBoundingBox().inflate(1.0D, 0.25D, 1.0D); + } } diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeItemStack.java b/src/main/java/net/minecraftforge/common/extensions/IForgeItemStack.java index 9eabb584f7..438e410efb 100644 --- a/src/main/java/net/minecraftforge/common/extensions/IForgeItemStack.java +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeItemStack.java @@ -19,15 +19,13 @@ package net.minecraftforge.common.extensions; +import javax.annotation.Nonnull; import javax.annotation.Nullable; -import net.minecraft.tags.Tag; import net.minecraft.world.entity.monster.EnderMan; -import net.minecraft.world.item.Tier; import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.pattern.BlockInWorld; +import net.minecraft.world.phys.AABB; import net.minecraft.world.item.enchantment.Enchantment; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Mob; @@ -47,8 +45,6 @@ import net.minecraft.world.level.Level; import net.minecraftforge.common.ToolAction; import net.minecraftforge.common.capabilities.ICapabilitySerializable; -import java.util.List; - /* * Extension added to ItemStack that bounces to ItemSack sensitive Item methods. Typically this is just for convince. */ @@ -495,4 +491,17 @@ public interface IForgeItemStack extends ICapabilitySerializable { return self().getItem().elytraFlightTick(self(), entity, flightTicks); } + + /** + * Get a bounding box ({@link AABB}) of a sweep attack. + * + * @param player the performing the attack the attack. + * @param target the entity targeted by the attack. + * @return the bounding box. + */ + @Nonnull + default AABB getSweepHitBox(@Nonnull Player player, @Nonnull Entity target) + { + return self().getItem().getSweepHitBox(self(), player, target); + } }