Add hook to allow items to customize the attack sweep range. (#7981)

This commit is contained in:
Sirttas authored and GitHub committed 2021-08-18 13:05:19 -07:00
1 parent 892c3669e0
commit bec9d6f534
4 files changed
+60 -11

No files matched your search

@@ -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<ToolAction> DEFAULT_HOE_ACTIONS = Stream.of(HOE_DIG /* TODO: , HOE_TILL */).collect(Collectors.toCollection(Sets::newIdentityHashSet));
public static final Set<ToolAction> DEFAULT_SHOVEL_ACTIONS = Stream.of(SHOVEL_DIG, SHOVEL_FLATTEN).collect(Collectors.toCollection(Sets::newIdentityHashSet));
public static final Set<ToolAction> DEFAULT_PICKAXE_ACTIONS = Stream.of(PICKAXE_DIG).collect(Collectors.toCollection(Sets::newIdentityHashSet));
public static final Set<ToolAction> DEFAULT_SWORD_ACTIONS = Stream.of(SWORD_DIG).collect(Collectors.toCollection(Sets::newIdentityHashSet));
public static final Set<ToolAction> DEFAULT_SWORD_ACTIONS = Stream.of(SWORD_DIG, SWORD_SWEEP).collect(Collectors.toCollection(Sets::newIdentityHashSet));
}
@@ -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);
}
}
@@ -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<CompoundTag>
{
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);
}
}