mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-22 21:20:12 +00:00
Redesign the tool system to rely on the new vanilla tags. (#7970)
Changed: - ToolType is replaced with ToolAction, which can selectively represent which actions are supported by an item. - Added a canPerformAction method to query ToolActions. - Renamed canHarvestBlock to isCorrectToolForDrops to match vanilla. - Added TierSortingRegistry, which can be used to add custom tiers and supports sorting between vanilla or with other mods. How to use: For the breaking system there's 2 methods: - getDestroySpeed decides if an item *can* mine the block fast. Override if you have multiple tags or your item isn't a DiggerItem. - isCorrectToolForDrops decides if an item will get drops. Returning false will also slow down mining, regardless of getDestroySpeed. Override if you have type-dependant tiers or your item isn't a DiggerItem. For the tier system mods can just call `TierSortingRegistry.registerTier(tier, "name", List.of(lesser tiers), List.of(better tiers));` to register their tiers. There's helper methods to query tiers such as TierSortingRegsitry.isCorrectTierForDrops. The ToolActions solve 2 problems: 1. distinguishing which kind of digger an item can be 2. querying if the item can perform specific secondary actions. Any item can override `canPerformAction` to customize which actions it performs.
This commit is contained in:
1 parent
52d7df06da
commit
10b51f257f
34 files changed
+1012
-441
No files matched your search
@@ -91,7 +91,7 @@ import net.minecraftforge.client.event.ClientChatReceivedEvent;
|
||||
import net.minecraftforge.client.event.RenderBlockOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderBlockOverlayEvent.OverlayType;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.ToolType;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.capabilities.CapabilityDispatcher;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
@@ -361,9 +361,9 @@ public class ForgeEventFactory
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BlockState onToolUse(BlockState originalState, Level world, BlockPos pos, Player player, ItemStack stack, ToolType toolType)
|
||||
public static BlockState onToolUse(BlockState originalState, Level world, BlockPos pos, Player player, ItemStack stack, ToolAction toolAction)
|
||||
{
|
||||
BlockToolInteractEvent event = new BlockToolInteractEvent(world, pos, originalState, player, stack, toolType);
|
||||
BlockToolInteractEvent event = new BlockToolInteractEvent(world, pos, originalState, player, stack, toolAction);
|
||||
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getFinalState();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.ToolType;
|
||||
import net.minecraftforge.common.ToolAction;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
@@ -45,8 +45,6 @@ import com.google.common.collect.ImmutableList;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraftforge.eventbus.api.Event.HasResult;
|
||||
|
||||
public class BlockEvent extends Event
|
||||
{
|
||||
private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("forge.debugBlockEvent", "false"));
|
||||
@@ -92,7 +90,7 @@ public class BlockEvent extends Event
|
||||
super(world, pos, state);
|
||||
this.player = player;
|
||||
|
||||
if (state == null || !ForgeHooks.canHarvestBlock(state, player, world, pos)) // Handle empty block or player unable to break block scenario
|
||||
if (state == null || !ForgeHooks.isCorrectToolForDrops(state, player)) // Handle empty block or player unable to break block scenario
|
||||
{
|
||||
this.exp = 0;
|
||||
}
|
||||
@@ -445,16 +443,16 @@ public class BlockEvent extends Event
|
||||
|
||||
private final Player player;
|
||||
private final ItemStack stack;
|
||||
private final ToolType toolType;
|
||||
private final ToolAction toolAction;
|
||||
private BlockState state;
|
||||
|
||||
public BlockToolInteractEvent(LevelAccessor world, BlockPos pos, BlockState originalState, Player player, ItemStack stack, ToolType toolType)
|
||||
public BlockToolInteractEvent(LevelAccessor world, BlockPos pos, BlockState originalState, Player player, ItemStack stack, ToolAction toolAction)
|
||||
{
|
||||
super(world, pos, originalState);
|
||||
this.player = player;
|
||||
this.stack = stack;
|
||||
this.state = originalState;
|
||||
this.toolType = toolType;
|
||||
this.toolAction = toolAction;
|
||||
}
|
||||
|
||||
/**Gets the player using the tool.*/
|
||||
@@ -469,10 +467,10 @@ public class BlockEvent extends Event
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**Gets the current type of the tool being compared against.*/
|
||||
public ToolType getToolType()
|
||||
/**Gets the action being performed.*/
|
||||
public ToolAction getToolAction()
|
||||
{
|
||||
return toolType;
|
||||
return toolAction;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user