Skip to content

Commit

Permalink
Move logic that clears fast item use into interaction handler
Browse files Browse the repository at this point in the history
Ensures we do not need to implement a modifier every time we want that fix. Also will be needed for a future API improvement
Also reduce the timer on client equipment change watcher to remove stutter when the hook triggers
  • Loading branch information
KnightMiner committed Jan 31, 2023
1 parent f0e36d0 commit 688295b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "tconstruct:stat_boost",
"level_display": "tconstruct:default",
"flags": [
"tconstruct:fast_use_item"
],
"modifier_display": "never"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public interface IModifiable extends ItemLike {
ResourceLocation DEFER_OFFHAND = TConstruct.getResource("defer_offhand");
/** Modifier key to entirely disable tool interaction */
ResourceLocation NO_INTERACTION = TConstruct.getResource("no_interaction");
/** @deprecated use {@link slimeknights.tconstruct.tools.TinkerModifiers#fastUseItem} */
@Deprecated
/** Modifier key to allow moving quickly while using an item */
ResourceLocation FAST_USE_ITEM = TConstruct.getResource("fast_use_item");

/** Gets the definition of this tool for building and applying modifiers */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@
import slimeknights.tconstruct.tools.modifiers.slotless.OverslimeModifier;
import slimeknights.tconstruct.tools.modifiers.slotless.StatOverrideModifier;
import slimeknights.tconstruct.tools.modifiers.traits.DamageSpeedTradeModifier;
import slimeknights.tconstruct.tools.modifiers.traits.FastUseItemModifier;
import slimeknights.tconstruct.tools.modifiers.traits.general.CultivatedModifier;
import slimeknights.tconstruct.tools.modifiers.traits.general.DenseModifier;
import slimeknights.tconstruct.tools.modifiers.traits.general.EnderportingModifier;
Expand Down Expand Up @@ -288,7 +287,6 @@ public TinkerModifiers() {
public static final StaticModifier<OffhandedModifier> offhanded = MODIFIERS.register("offhanded", OffhandedModifier::new);
public static final StaticModifier<FarsightedModifier> farsighted = MODIFIERS.register("farsighted", FarsightedModifier::new);
public static final StaticModifier<NearsightedModifier> nearsighted = MODIFIERS.register("nearsighted", NearsightedModifier::new);
public static final StaticModifier<FastUseItemModifier> fastUseItem = MODIFIERS.register("fast_use_item", FastUseItemModifier::new);

// harvest
public static final StaticModifier<HasteModifier> haste = MODIFIERS.register("haste", HasteModifier::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class ModifierIds {

// internal
public static final ModifierId overslimeFriend = id("overslime_friend");
public static final ModifierId fastUseItem = id("fast_use_item");


// traits - tier 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ protected void addModifiers() {

// internal
addModifier(ModifierIds.overslimeFriend, StatBoostModifier.builder().addFlag(OverslimeModifier.KEY_OVERSLIME_FRIEND).modifierDisplay(ModifierDisplay.NEVER).build());
addModifier(ModifierIds.fastUseItem, StatBoostModifier.builder().addFlag(IModifiable.FAST_USE_ITEM).modifierDisplay(ModifierDisplay.NEVER).build());

// traits - tier 1
addModifier(ModifierIds.stringy, new Modifier());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ public static void fireCrossbow(IToolStackView tool, Player player, InteractionH
}
}

@Override
public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity living) {
ModifierUtil.finishUsingItem(living);
return super.finishUsingItem(stack, level, living);
}

@Override
public void releaseUsing(ItemStack bow, Level level, LivingEntity living, int chargeRemaining) {
ModifierUtil.finishUsingItem(living);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import slimeknights.tconstruct.library.events.ToolEquipmentChangeEvent;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.tools.context.EquipmentChangeContext;
import slimeknights.tconstruct.library.tools.helper.ModifierUtil;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -80,7 +81,7 @@ private static void attachCapability(AttachCapabilitiesEvent<Entity> event) {
/** Client side modifier hooks */
private static void onPlayerTick(PlayerTickEvent event) {
// only run for client side players every 5 ticks
if (event.phase == Phase.END && event.side == LogicalSide.CLIENT && event.player.tickCount % 5 == 0) {
if (event.phase == Phase.END && event.side == LogicalSide.CLIENT) {
event.player.getCapability(CAPABILITY).ifPresent(PlayerLastEquipment::update);
}
}
Expand All @@ -98,6 +99,10 @@ private static void runModifierHooks(LivingEntity entity, EquipmentSlot changedS
for (ModifierEntry entry : tool.getModifierList()) {
entry.getModifier().onUnequip(tool, entry.getLevel(), context);
}
// if you scrolled away, we really don't know whether you stopped using an item or not, luckily everything in this method can be safely run multiple times
if (!entity.isUsingItem()) {
ModifierUtil.finishUsingItem(entity);
}
}

// next, fire event to notify an item was added
Expand Down

This file was deleted.

0 comments on commit 688295b

Please sign in to comment.