Skip to content

Commit

Permalink
Ensure all interaction hooks are disabled when on cooldown
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Feb 4, 2023
1 parent bbf9685 commit 8d93f89
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,18 @@ static void beforeEntityInteract(EntityInteract event) {
return;
}
}
// actual interaction hook
ToolStack tool = ToolStack.from(stack);
Entity target = event.getTarget();
for (ModifierEntry entry : tool.getModifierList()) {
// exit on first successful result
InteractionResult result = entry.getHook(TinkerHooks.ENTITY_INTERACT).beforeEntityUse(tool, entry, player, target, hand, source);
if (result.consumesAction()) {
event.setCanceled(true);
event.setCancellationResult(result);
return;
if (!player.getCooldowns().isOnCooldown(stack.getItem())) {
// actual interaction hook
ToolStack tool = ToolStack.from(stack);
Entity target = event.getTarget();
for (ModifierEntry entry : tool.getModifierList()) {
// exit on first successful result
InteractionResult result = entry.getHook(TinkerHooks.ENTITY_INTERACT).beforeEntityUse(tool, entry, player, target, hand, source);
if (result.consumesAction()) {
event.setCanceled(true);
event.setCancellationResult(result);
return;
}
}
}
}
Expand All @@ -96,7 +98,7 @@ static void afterEntityInteract(EntityInteract event) {
Player player = event.getPlayer();
if (event.getItemStack().isEmpty() && !player.isSpectator()) {
ItemStack chestplate = player.getItemBySlot(EquipmentSlot.CHEST);
if (chestplate.is(TinkerTags.Items.INTERACTABLE_ARMOR)) {
if (chestplate.is(TinkerTags.Items.INTERACTABLE_ARMOR) && !player.getCooldowns().isOnCooldown(chestplate.getItem())) {
// from this point on, we are taking over interaction logic, to ensure chestplate hooks run in the right order
event.setCanceled(true);

Expand Down Expand Up @@ -162,7 +164,7 @@ static void chestplateInteractWithBlock(PlayerInteractEvent.RightClickBlock even
if (event.getItemStack().isEmpty() && !player.isSpectator()) {
// item must be a chestplate
ItemStack chestplate = player.getItemBySlot(EquipmentSlot.CHEST);
if (chestplate.is(TinkerTags.Items.INTERACTABLE_ARMOR)) {
if (chestplate.is(TinkerTags.Items.INTERACTABLE_ARMOR) && !player.getCooldowns().isOnCooldown(chestplate.getItem())) {
// no turning back, from this point we are fully in charge of interaction logic (since we need to ensure order of the hooks)

// begin interaction
Expand Down

0 comments on commit 8d93f89

Please sign in to comment.