-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate inventory tick, done migrating hooks for now
Also make documentaton changes Only one not modified right now is processLoot, which I am considering just replacing with direct usages of global loot modifiers as that gives more flexability.
- Loading branch information
1 parent
40be4b9
commit 5a99461
Showing
8 changed files
with
216 additions
and
155 deletions.
There are no files selected for viewing
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
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
66 changes: 66 additions & 0 deletions
66
...slimeknights/tconstruct/library/modifiers/hook/interaction/InventoryTickModifierHook.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,66 @@ | ||
package slimeknights.tconstruct.library.modifiers.hook.interaction; | ||
|
||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.modifiers.TinkerHooks; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
import slimeknights.tconstruct.library.tools.nbt.ToolStack; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** Hook that runs while the tool is in the inventory */ | ||
public interface InventoryTickModifierHook { | ||
/** | ||
* Called when the stack updates in the player inventory | ||
* @param tool Current tool instance | ||
* @param modifier Modifier running the hook | ||
* @param world World containing tool | ||
* @param holder Entity holding tool | ||
* @param itemSlot Slot containing this tool. Note this may be from the hotbar, main inventory, or armor inventory | ||
* @param isSelected If true, this item is currently in the player's main hand | ||
* @param isCorrectSlot If true, this item is in the proper slot. For tools, that is main hand or off hand. For armor, this means its in the correct armor slot | ||
* @param stack Item stack instance to check other slots for the tool. Do not modify | ||
*/ | ||
void onInventoryTick(IToolStackView tool, ModifierEntry modifier, Level world, LivingEntity holder, int itemSlot, boolean isSelected, boolean isCorrectSlot, ItemStack stack); | ||
|
||
/** | ||
* Handles ticking a modifiable item that works when held. Armor uses different logic | ||
* @param stack Modifiable stack | ||
* @param worldIn World instance | ||
* @param entityIn Entity holding the tool | ||
* @param itemSlot Slot with the tool | ||
* @param isSelected If true, the tool is selected | ||
*/ | ||
static void heldInventoryTick(ItemStack stack, Level worldIn, Entity entityIn, int itemSlot, boolean isSelected) { | ||
// don't care about non-living, they skip most tool context | ||
if (entityIn instanceof LivingEntity) { | ||
ToolStack tool = ToolStack.from(stack); | ||
if (!worldIn.isClientSide) { | ||
tool.ensureHasData(); | ||
} | ||
List<ModifierEntry> modifiers = tool.getModifierList(); | ||
if (!modifiers.isEmpty()) { | ||
LivingEntity living = (LivingEntity) entityIn; | ||
// we pass in the stack for most custom context, but for the sake of armor it is easier to tell them that this is the correct slot for effects | ||
boolean isHeld = isSelected || living.getOffhandItem() == stack; | ||
for (ModifierEntry entry : modifiers) { | ||
entry.getHook(TinkerHooks.INVENTORY_TICK).onInventoryTick(tool, entry, worldIn, living, itemSlot, isSelected, isHeld, stack); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** Merger that runs all hooks one after another */ | ||
record AllMerger(Collection<InventoryTickModifierHook> modules) implements InventoryTickModifierHook { | ||
@Override | ||
public void onInventoryTick(IToolStackView tool, ModifierEntry modifier, Level world, LivingEntity holder, int itemSlot, boolean isSelected, boolean isCorrectSlot, ItemStack stack) { | ||
for (InventoryTickModifierHook module : modules) { | ||
module.onInventoryTick(tool, modifier, world, holder, itemSlot, isSelected, isCorrectSlot, stack); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.