Skip to content

Commit

Permalink
Replace fast_use_item flag with use_item_speed tool stat
Browse files Browse the repository at this point in the history
Now allows you to set any speed between 0% and 100% instead of always being 80%. Might allow some neat things in thing packs
  • Loading branch information
KnightMiner committed Feb 12, 2023
1 parent 00d73db commit 83fe723
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 23 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"stats": {
"base": {
"tconstruct:durability": 200.0,
"tconstruct:block_amount": 10.0
"tconstruct:block_amount": 10.0,
"tconstruct:use_item_speed": 0.8
}
},
"slots": {
Expand All @@ -14,10 +15,6 @@
{
"name": "tconstruct:blocking",
"level": 1
},
{
"name": "tconstruct:fast_use_item",
"level": 1
}
],
"modules": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ 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");
/** Modifier key to allow moving quickly while using an item */
/** @deprecated use {@link slimeknights.tconstruct.library.tools.stat.ToolStats#USE_ITEM_SPEED} */
@Deprecated
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 @@ -23,6 +23,8 @@ public class ToolStats {

/** Tools durability, determines how long it lasts */
public static final FloatToolStat DURABILITY = register(new FloatToolStat(name("durability"), 0xFF47CC47, 1, 1, Integer.MAX_VALUE, TinkerTags.Items.DURABILITY));
/** Movement speed percentage when using this item, applicable to charging tools, pulling back bows, and shield blocking among other actions */
public static final FloatToolStat USE_ITEM_SPEED = register(new FloatToolStat(name("use_item_speed"), 0xFF78A0CD, 0.2f, 0, 1, TinkerTags.Items.HELD));

// melee
/** Tools attack damage for melee */
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/slimeknights/tconstruct/tools/ToolClientEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@
import slimeknights.tconstruct.library.client.modifiers.TankModifierModel;
import slimeknights.tconstruct.library.modifiers.ModifierId;
import slimeknights.tconstruct.library.modifiers.ModifierManager;
import slimeknights.tconstruct.library.tools.helper.ModifierUtil;
import slimeknights.tconstruct.library.tools.item.IModifiable;
import slimeknights.tconstruct.library.tools.nbt.ToolStack;
import slimeknights.tconstruct.library.tools.stat.ToolStats;
import slimeknights.tconstruct.library.utils.HarvestTiers;
import slimeknights.tconstruct.library.utils.Util;
import slimeknights.tconstruct.tools.client.ArmorModelHelper;
Expand Down Expand Up @@ -266,11 +267,17 @@ private static void handleInput(MovementInputUpdateEvent event) {
Player player = event.getPlayer();
if (player.isUsingItem() && !player.isPassenger()) {
ItemStack using = player.getUseItem();
if (using.is(TinkerTags.Items.MODIFIABLE) && ModifierUtil.checkVolatileFlag(using, IModifiable.FAST_USE_ITEM)) {
if (using.is(TinkerTags.Items.HELD)) {
ToolStack tool = ToolStack.from(using);
// multiply by 5 to cancel out the vanilla 20%
float speed = 5 * (tool.getStats().get(ToolStats.USE_ITEM_SPEED));
// FAST_USE_ITEM was originally 80% move speed, since the stat defaults to 20% this makes it act the same as long as you don't modify the stat
if (tool.getVolatileData().getBoolean(IModifiable.FAST_USE_ITEM)) {
speed = Math.min(5, speed + 5 * 0.6f);
}
Input input = event.getInput();
// mostly cancel out future 0.2x, want 80% move speed instead of 20%
input.leftImpulse *= 4;
input.forwardImpulse *= 4;
input.leftImpulse *= speed;
input.forwardImpulse *= speed;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ 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 @@ -191,7 +191,6 @@ 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 @@ -424,11 +424,11 @@ TinkerTags.Blocks.TREE_LOGS, new TreeAOEIterator(0, 0),
define(ArmorDefinitions.TRAVELERS_SHIELD)
.stat(ToolStats.DURABILITY, 200)
.stat(ToolStats.BLOCK_AMOUNT, 10)
.stat(ToolStats.USE_ITEM_SPEED, 0.8f)
.startingSlots(SlotType.UPGRADE, 3)
.startingSlots(SlotType.DEFENSE, 2)
.startingSlots(SlotType.ABILITY, 1)
.trait(TinkerModifiers.blocking)
.trait(ModifierIds.fastUseItem)
.module(ToolModuleHooks.INTERACTION, new PreferenceSetInteraction(InteractionSource.RIGHT_CLICK, new SingleModifierPredicate(TinkerModifiers.blocking.getId())));

// plate armor
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/tconstruct/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2449,7 +2449,6 @@
"modifier.tconstruct.the_one_probe.description": "Shows information about the targeted block when held or on a helmet.",

"_comment": "Internal modifiers",
"modifier.tconstruct.fast_use_item": "Fast Use Item",
"modifier.tconstruct.overslime_friend": "Overslime Friend",


Expand Down Expand Up @@ -2496,6 +2495,8 @@
"tool_stat.tconstruct.attack_speed.description": "Base value for attack speed calculations.\nRoughly full strength attacks per second.",
"tool_stat.tconstruct.durability": "Durability: ",
"tool_stat.tconstruct.durability.description": "The base-value for durability calculations.\nUsually an integral part to the overall durability of a tool.",
"tool_stat.tconstruct.use_item_speed": "Use Item Speed: ",
"tool_stat.tconstruct.use_item_speed.description": "Movement speed multiplier when using an item, such as a bow or a shield.",

"stat.tconstruct.head": "Head",
"tool_stat.tconstruct.mining_speed": "Mining Speed: ",
Expand Down

0 comments on commit 83fe723

Please sign in to comment.