generated from TropheusJ/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
323 additions
and
376 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
161 changes: 161 additions & 0 deletions
161
...ilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ItemAbilities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/* | ||
* Copyright (c) Forge Development LLC and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package io.github.fabricators_of_create.porting_lib.tool; | ||
|
||
import com.google.common.collect.Sets; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.dispenser.BlockSource; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
public class ItemAbilities { | ||
/** | ||
* Exposed by axes to allow querying tool behaviours | ||
*/ | ||
public static final ItemAbility AXE_DIG = ItemAbility.get("axe_dig"); | ||
|
||
/** | ||
* Exposed by pickaxes to allow querying tool behaviours | ||
*/ | ||
public static final ItemAbility PICKAXE_DIG = ItemAbility.get("pickaxe_dig"); | ||
|
||
/** | ||
* Exposed by shovels to allow querying tool behaviours | ||
*/ | ||
public static final ItemAbility SHOVEL_DIG = ItemAbility.get("shovel_dig"); | ||
|
||
/** | ||
* Exposed by hoes to allow querying tool behaviours | ||
*/ | ||
public static final ItemAbility HOE_DIG = ItemAbility.get("hoe_dig"); | ||
|
||
/** | ||
* Exposed by swords to allow querying tool behaviours | ||
*/ | ||
public static final ItemAbility SWORD_DIG = ItemAbility.get("sword_dig"); | ||
|
||
/** | ||
* Exposed by shears to allow querying tool behaviours | ||
*/ | ||
public static final ItemAbility SHEARS_DIG = ItemAbility.get("shears_dig"); | ||
|
||
/** | ||
* Passed onto {@link IBlockExtension#getToolModifiedState} when an axe wants to strip a log | ||
*/ | ||
public static final ItemAbility AXE_STRIP = ItemAbility.get("axe_strip"); | ||
|
||
/** | ||
* Passed onto {@link IBlockExtension#getToolModifiedState} when an axe wants to scrape oxidization off copper | ||
*/ | ||
public static final ItemAbility AXE_SCRAPE = ItemAbility.get("axe_scrape"); | ||
|
||
/** | ||
* Passed onto {@link IBlockExtension#getToolModifiedState} when an axe wants to remove wax out of copper | ||
*/ | ||
public static final ItemAbility AXE_WAX_OFF = ItemAbility.get("axe_wax_off"); | ||
|
||
/** | ||
* Passed onto {@link IBlockExtension#getToolModifiedState} when a shovel wants to turn dirt into path | ||
*/ | ||
public static final ItemAbility SHOVEL_FLATTEN = ItemAbility.get("shovel_flatten"); | ||
|
||
/** | ||
* Passed onto {@link IBlockExtension#getToolModifiedState} when a shovel wants to douse a campfire | ||
*/ | ||
public static final ItemAbility SHOVEL_DOUSE = ItemAbility.get("shovel_douse"); | ||
|
||
/** | ||
* Used during player attack to figure out if a sweep attack should be performed | ||
* | ||
* @see IItemExtension#getSweepHitBox | ||
*/ | ||
public static final ItemAbility SWORD_SWEEP = ItemAbility.get("sword_sweep"); | ||
|
||
/** | ||
* This action is exposed by shears and corresponds to a harvest action that is triggered with a right click on a block that supports such behaviour. | ||
* Example: Right click with shears on a beehive with honey level 5 to harvest it. | ||
* | ||
* @see CommonHooks#tryDispenseShearsHarvestBlock(BlockSource, ItemStack, ServerLevel, BlockPos) | ||
*/ | ||
public static final ItemAbility SHEARS_HARVEST = ItemAbility.get("shears_harvest"); | ||
|
||
/** | ||
* This action is exposed by shears and corresponds to a harvest action that is triggered with a right click on armored wolves. | ||
*/ | ||
public static final ItemAbility SHEARS_REMOVE_ARMOR = ItemAbility.get("shears_remove_armor"); | ||
|
||
/** | ||
* This action is exposed by shears and corresponds to a carve action that is triggered with a right click on a block that supports such behaviour. | ||
* Example: Right click with shears on a pumpkin to carve it. | ||
*/ | ||
public static final ItemAbility SHEARS_CARVE = ItemAbility.get("shears_carve"); | ||
|
||
/** | ||
* This action is exposed by shears and corresponds to a disarm action that is triggered by breaking a block that supports such behaviour. | ||
* Example: Breaking a trip wire with shears to disarm it. | ||
*/ | ||
public static final ItemAbility SHEARS_DISARM = ItemAbility.get("shears_disarm"); | ||
|
||
/** | ||
* This action is exposed by shears and corresponds to a trim action that is triggered with a right click on a block that supports such behavior. | ||
* Example: Right click with shears on a {@link net.minecraft.world.level.block.GrowingPlantHeadBlock growing plant} to stop it from growing. | ||
*/ | ||
public static final ItemAbility SHEARS_TRIM = ItemAbility.get("shears_trim"); | ||
|
||
/** | ||
* Passed onto {@link IBlockExtension#getToolModifiedState} when a hoe wants to turn dirt into soil | ||
*/ | ||
public static final ItemAbility HOE_TILL = ItemAbility.get("till"); | ||
|
||
/** | ||
* An item ability corresponding to the 'block' action of shields. | ||
* Items should expose this item ability in order to enable damage blocking when the item is being "used". | ||
*/ | ||
public static final ItemAbility SHIELD_BLOCK = ItemAbility.get("shield_block"); | ||
|
||
/** | ||
* This action corresponds to right-clicking the fishing rod to reel it in after earlier casting. | ||
* Needed for modded fishing rods so that the FishingHook entity can properly function. | ||
*/ | ||
public static final ItemAbility FISHING_ROD_CAST = ItemAbility.get("fishing_rod_cast"); | ||
|
||
/** | ||
* Exposed by trident-like items to allow querying tool behaviours for items that can be thrown like Tridents. | ||
*/ | ||
public static final ItemAbility TRIDENT_THROW = ItemAbility.get("trident_throw"); | ||
|
||
/** | ||
* Exposed by brushes to allow querying tool behaviours for items that can brush Suspicious Blocks. | ||
*/ | ||
public static final ItemAbility BRUSH_BRUSH = ItemAbility.get("brush_brush"); | ||
|
||
/** | ||
* Passed onto {@link IBlockExtension#getToolModifiedState} when flint and steel or fire charge want to light a campfire/candle/cake. | ||
* Note that dispensers with flint and steel will also use this but will have no player. | ||
*/ | ||
public static final ItemAbility FIRESTARTER_LIGHT = ItemAbility.get("firestarter_light"); | ||
|
||
// Default actions supported by each tool type | ||
public static final Set<ItemAbility> DEFAULT_AXE_ACTIONS = of(AXE_DIG, AXE_STRIP, AXE_SCRAPE, AXE_WAX_OFF); | ||
public static final Set<ItemAbility> DEFAULT_HOE_ACTIONS = of(HOE_DIG, HOE_TILL); | ||
public static final Set<ItemAbility> DEFAULT_SHOVEL_ACTIONS = of(SHOVEL_DIG, SHOVEL_FLATTEN, SHOVEL_DOUSE); | ||
public static final Set<ItemAbility> DEFAULT_PICKAXE_ACTIONS = of(PICKAXE_DIG); | ||
public static final Set<ItemAbility> DEFAULT_SWORD_ACTIONS = of(SWORD_DIG, SWORD_SWEEP); | ||
public static final Set<ItemAbility> DEFAULT_SHEARS_ACTIONS = of(SHEARS_DIG, SHEARS_HARVEST, SHEARS_REMOVE_ARMOR, SHEARS_CARVE, SHEARS_DISARM, SHEARS_TRIM); | ||
public static final Set<ItemAbility> DEFAULT_SHIELD_ACTIONS = of(SHIELD_BLOCK); | ||
public static final Set<ItemAbility> DEFAULT_FISHING_ROD_ACTIONS = of(FISHING_ROD_CAST); | ||
public static final Set<ItemAbility> DEFAULT_TRIDENT_ACTIONS = of(TRIDENT_THROW); | ||
public static final Set<ItemAbility> DEFAULT_BRUSH_ACTIONS = of(BRUSH_BRUSH); | ||
public static final Set<ItemAbility> DEFAULT_FLINT_ACTIONS = of(FIRESTARTER_LIGHT); | ||
public static final Set<ItemAbility> DEFAULT_FIRECHARGE_ACTIONS = of(FIRESTARTER_LIGHT); | ||
|
||
private static Set<ItemAbility> of(ItemAbility... actions) { | ||
return Stream.of(actions).collect(Collectors.toCollection(Sets::newIdentityHashSet)); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ItemAbility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.github.fabricators_of_create.porting_lib.tool; | ||
|
||
import com.mojang.serialization.Codec; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public final class ItemAbility { | ||
private static final Map<String, ItemAbility> actions = new ConcurrentHashMap<>(); | ||
|
||
public static Codec<ItemAbility> CODEC = Codec.STRING.xmap(ItemAbility::get, ItemAbility::name); | ||
|
||
/** | ||
* Returns all registered actions. | ||
* This collection can be kept around, and will update itself in response to changes to the map. | ||
* See {@link ConcurrentHashMap#values()} for details. | ||
*/ | ||
public static Collection<ItemAbility> getActions() { | ||
return Collections.unmodifiableCollection(actions.values()); | ||
} | ||
|
||
/** | ||
* Gets or creates a new ItemAbility for the given name. | ||
*/ | ||
public static ItemAbility get(String name) { | ||
return actions.computeIfAbsent(name, ItemAbility::new); | ||
} | ||
|
||
/** | ||
* Returns the name of this item ability | ||
*/ | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ItemAbility[" + name + "]"; | ||
} | ||
|
||
private final String name; | ||
|
||
/** | ||
* Use {@link #get(String)} to get or create a ItemAbility | ||
*/ | ||
private ItemAbility(String name) { | ||
this.name = name; | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
...rting_lib/tool/addons/ToolActionItem.java → ...rting_lib/tool/addons/ToolActionItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
package io.github.fabricators_of_create.porting_lib.tool.addons; | ||
|
||
import io.github.fabricators_of_create.porting_lib.tool.ToolAction; | ||
import io.github.fabricators_of_create.porting_lib.tool.ToolActions; | ||
import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; | ||
import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
public interface ToolActionItem { | ||
/** | ||
* Queries if an item can perform the given action. | ||
* See {@link ToolActions} for a description of each stock action | ||
* See {@link ItemAbilities} for a description of each stock action | ||
* @param stack The stack being used | ||
* @param toolAction The action being queried | ||
* @return True if the stack can perform the action | ||
*/ | ||
default boolean canPerformAction(ItemStack stack, ToolAction toolAction) { | ||
default boolean canPerformAction(ItemStack stack, ItemAbility toolAction) { | ||
return false; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...java/io/github/fabricators_of_create/porting_lib/tool/extensions/ItemStackExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.github.fabricators_of_create.porting_lib.tool.extensions; | ||
|
||
import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; | ||
import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; | ||
|
||
public interface ItemStackExtensions { | ||
/** | ||
* Queries if an item can perform the given action. | ||
* See {@link ItemAbilities} for a description of each stock action | ||
* | ||
* @param itemAbility The action being queried | ||
* @return True if the stack can perform the action | ||
*/ | ||
default boolean canPerformAction(ItemAbility itemAbility) { | ||
return self().getItem().canPerformAction(self(), itemAbility); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...ool/extensions/VanillaToolActionItem.java → ...ool/extensions/VanillaToolActionItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package io.github.fabricators_of_create.porting_lib.tool.extensions; | ||
|
||
import io.github.fabricators_of_create.porting_lib.tool.ToolAction; | ||
import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
public interface VanillaToolActionItem { | ||
boolean port_lib$canPerformAction(ItemStack stack, ToolAction toolAction); | ||
boolean port_lib$canPerformAction(ItemStack stack, ItemAbility toolAction); | ||
} |
Oops, something went wrong.