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:
David Quintana authored and GitHub committed 2021-08-10 15:45:08 -07:00
1 parent 52d7df06da
commit 10b51f257f
34 files changed
+1012 -441

No files matched your search

@@ -0,0 +1,88 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2021.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common;
import com.google.common.collect.Sets;
import net.minecraftforge.common.extensions.IForgeBlock;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ToolActions
{
/**
* Exposed by axes to allow querying tool behaviours
*/
public static final ToolAction AXE_DIG = ToolAction.get("axe_dig");
/**
* Exposed by pickaxes to allow querying tool behaviours
*/
public static final ToolAction PICKAXE_DIG = ToolAction.get("pickaxe_dig");
/**
* Exposed by shovels to allow querying tool behaviours
*/
public static final ToolAction SHOVEL_DIG = ToolAction.get("shovel_dig");
/**
* Exposed by shovels to allow querying tool behaviours
*/
public static final ToolAction HOE_DIG = ToolAction.get("hoe_dig");
/**
* Exposed by swords to allow querying tool behaviours
*/
public static final ToolAction SWORD_DIG = ToolAction.get("sword_dig");
/**
* Passed onto {@link IForgeBlock#getToolModifiedState} when an axe wants to strip a log
*/
public static final ToolAction AXE_STRIP = ToolAction.get("axe_strip");
/**
* Passed onto {@link IForgeBlock#getToolModifiedState} when an axe wants to scrape oxidization off copper
*/
public static final ToolAction AXE_SCRAPE = ToolAction.get("axe_scrape");
/**
* Passed onto {@link IForgeBlock#getToolModifiedState} when an axe wants to remove wax out of copper
*/
public static final ToolAction AXE_WAX_OFF = ToolAction.get("axe_wax_off");
/**
* Passed onto {@link IForgeBlock#getToolModifiedState} when a shovel wants to turn dirt into path
*/
public static final ToolAction SHOVEL_FLATTEN = ToolAction.get("shovel_flatten");
///**
// * Passed onto {@link IForgeBlock#getToolModifiedState} when a hoe wants to turn dirt into soil
// */
// TODO: public static final ToolAction HOE_TILL = ToolAction.get("till");
// Default actions supported by each tool type
public static final Set<ToolAction> DEFAULT_AXE_ACTIONS = Stream.of(AXE_DIG, AXE_STRIP, AXE_SCRAPE, AXE_WAX_OFF).collect(Collectors.toCollection(Sets::newIdentityHashSet));
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));
}