mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
Add new tool action for shield blocking, replacing IForgeItem#isShield (#8055)
This commit is contained in:
1 parent
9d7f5dd32a
commit
b7379953d5
9 files changed
+132
-10
No files matched your search
@@ -109,6 +109,10 @@ public class ToolActions
|
||||
// */
|
||||
// TODO: public static final ToolAction HOE_TILL = ToolAction.get("till");
|
||||
|
||||
/**
|
||||
* A tool action corresponding to the 'block' action of shields.
|
||||
*/
|
||||
public static final ToolAction SHIELD_BLOCK = ToolAction.get("shield_block");
|
||||
|
||||
// Default actions supported by each tool type
|
||||
public static final Set<ToolAction> DEFAULT_AXE_ACTIONS = of(AXE_DIG, AXE_STRIP, AXE_SCRAPE, AXE_WAX_OFF);
|
||||
@@ -117,6 +121,7 @@ public class ToolActions
|
||||
public static final Set<ToolAction> DEFAULT_PICKAXE_ACTIONS = of(PICKAXE_DIG);
|
||||
public static final Set<ToolAction> DEFAULT_SWORD_ACTIONS = of(SWORD_DIG, SWORD_SWEEP);
|
||||
public static final Set<ToolAction> DEFAULT_SHEARS_ACTIONS = of(SHEARS_DIG, SHEARS_HARVEST, SHEARS_CARVE, SHEARS_DISARM);
|
||||
public static final Set<ToolAction> DEFAULT_SHIELD_ACTIONS = of(SHIELD_BLOCK);
|
||||
|
||||
private static Set<ToolAction> of(ToolAction... actions) {
|
||||
return Stream.of(actions).collect(Collectors.toCollection(Sets::newIdentityHashSet));
|
||||
|
||||
@@ -51,6 +51,7 @@ import net.minecraft.util.Mth;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.ToolActions;
|
||||
|
||||
// TODO review most of the methods in this "patch"
|
||||
public interface IForgeItem
|
||||
@@ -524,7 +525,8 @@ public interface IForgeItem
|
||||
*/
|
||||
default boolean canPerformAction(ItemStack stack, ToolAction toolAction)
|
||||
{
|
||||
return false;
|
||||
// Temporary patch to keep #isShield working until its removed; change to `return false` once removed
|
||||
return isShield(stack, null) && ToolActions.DEFAULT_SHIELD_ACTIONS.contains(toolAction);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -688,12 +690,15 @@ public interface IForgeItem
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this Item a shield
|
||||
* {@return {@code true} if this item is considered a shield}
|
||||
*
|
||||
* @param stack The ItemStack
|
||||
* @param entity The Entity holding the ItemStack
|
||||
* @return True if the ItemStack is considered a shield
|
||||
* @param stack the item stack
|
||||
* @param entity the entity holding the item stack
|
||||
* @deprecated To be removed in 1.18. Override {@link #canPerformAction(ItemStack, ToolAction)} and return
|
||||
* {@code true} if the passed in tool action is contained in {@link ToolActions#DEFAULT_SHIELD_ACTIONS} or is
|
||||
* equals to {@link ToolActions#SHIELD_BLOCK}.
|
||||
*/
|
||||
@Deprecated(since = "1.17.1", forRemoval = true)
|
||||
default boolean isShield(ItemStack stack, @Nullable LivingEntity entity)
|
||||
{
|
||||
return stack.getItem() == Items.SHIELD;
|
||||
|
||||
@@ -43,6 +43,7 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.ToolActions;
|
||||
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
|
||||
|
||||
/*
|
||||
@@ -207,11 +208,14 @@ public interface IForgeItemStack extends ICapabilitySerializable<CompoundTag>
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this Item a shield
|
||||
* {@return {@code true} if this item is considered a shield}
|
||||
*
|
||||
* @param entity The Entity holding the ItemStack
|
||||
* @return True if the ItemStack is considered a shield
|
||||
* @param entity the entity holding the item stack
|
||||
* @deprecated To be removed in 1.18. Call {@link #canPerformAction(ToolAction)} with
|
||||
* {@link ToolActions#SHIELD_BLOCK} instead.
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
@Deprecated(since = "1.17.1", forRemoval = true)
|
||||
default boolean isShield(@Nullable LivingEntity entity)
|
||||
{
|
||||
return self().getItem().isShield(self(), entity);
|
||||
|
||||
Reference in new issue
Block a user