Skip to content

Commit

Permalink
Use common indices for variables in modifier formulas
Browse files Browse the repository at this point in the history
Ended up just duplicating a lot of them for slightly different names, made imports awkward in the provider
  • Loading branch information
KnightMiner committed Jan 11, 2024
1 parent 144bfd3 commit dd1d5ef
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
* Represents a modifier formula that may be either simple or complex.
*/
public sealed interface ModifierFormula permits PostFixFormula, SimpleLevelingFormula {
// common variable indexes, not required to use but make things easier
/** Variable index for the modifier level for the sake of the builder */
int LEVEL = 0;
/** Variable index for the original value the formula is computing */
int VALUE = 1;
/** Variable index for the common multiplier for this stat */
int MULTIPLIER = 2;
/** Variable index for the base value before modifiers changed anything */
int BASE_VALUE = 3;

/** Computes the level value for this formula, allows some optimizations to not compute level when not needed */
float computeLevel(IToolContext tool, ModifierEntry modifier);
Expand Down Expand Up @@ -67,11 +74,11 @@ interface FallbackFormula {
/** Formula that just returns the leveling value directly */
FallbackFormula IDENTITY = arguments -> arguments[LEVEL];
/** Formula adding the leveling value to the second argument, requires 1 additional argument */
FallbackFormula ADD = arguments -> arguments[LEVEL] + arguments[1];
FallbackFormula ADD = arguments -> arguments[LEVEL] + arguments[VALUE];
/** Formula for standard percent boosts, requires 1 additional argument */
FallbackFormula PERCENT = arguments -> arguments[1] * (1 + arguments[LEVEL]);
FallbackFormula PERCENT = arguments -> arguments[VALUE] * (1 + arguments[LEVEL]);
/** Formula for standard boosts, requires argument 1 to be the base value and argument 2 to be the multiplier */
FallbackFormula BOOST = arguments -> arguments[1] + arguments[LEVEL] * arguments[2];
FallbackFormula BOOST = arguments -> arguments[VALUE] + arguments[LEVEL] * arguments[MULTIPLIER];

/**
* Runs this formula
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ public record ConditionalMeleeDamageModule(
private static final List<ModifierHook<?>> DEFAULT_HOOKS = List.of(TinkerHooks.MELEE_DAMAGE, TinkerHooks.TOOLTIP);
/** Variables for the modifier formula */
private static final String[] VARIABLES = { "level", "damage", "multiplier", "base_damage" };
// variables for the formula
/** Damage from the previous conditional modifier */
public static final int DAMAGE = 1;
/** Damage multiplier from the tool */
public static final int MULTIPLIER = 2;
/** Damage before any conditional modifiers ran */
public static final int BASE_DAMAGE = 3;

@Nullable
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public record KnockbackModule(IJsonPredicate<LivingEntity> entity, ModifierFormu
private static final List<ModifierHook<?>> DEFAULT_HOOKS = List.of(TinkerHooks.MELEE_HIT);
/** Variables for the modifier formula */
private static final String[] VARIABLES = { "level", "knockback" };
/** Variable name for the knockback argument in this module */
public static final int KNOCKBACK = 1;
/** Fallback for the modifier formula */
private static final FallbackFormula FALLBACK_FORMULA = FallbackFormula.ADD;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ public record ConditionalMiningSpeedModule(IJsonPredicate<BlockState> block, IJs
private static final List<ModifierHook<?>> DEFAULT_HOOKS = List.of(TinkerHooks.BREAK_SPEED, TinkerHooks.TOOLTIP);
/** Variables for the modifier formula */
private static final String[] VARIABLES = { "level", "speed", "multiplier", "original_speed" };
/** Speed after modifiers ran */
public static final int NEW_SPEED = 1;
/** Mining speed multiplier */
public static final int MULTIPLIER = 2;
/** Speed before event listeners ran */
public static final int ORIGINAL_SPEED = 3;

@Nullable
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@

import static slimeknights.tconstruct.common.TinkerTags.Items.ARMOR;
import static slimeknights.tconstruct.library.json.math.ModifierFormula.LEVEL;
import static slimeknights.tconstruct.library.json.math.ModifierFormula.MULTIPLIER;
import static slimeknights.tconstruct.library.json.math.ModifierFormula.VALUE;
import static slimeknights.tconstruct.library.modifiers.modules.behavior.RepairModule.FACTOR;
import static slimeknights.tconstruct.library.modifiers.modules.combat.KnockbackModule.KNOCKBACK;

public class ModifierProvider extends AbstractModifierProvider {
public ModifierProvider(DataGenerator generator) {
Expand Down Expand Up @@ -209,7 +210,7 @@ protected void addModifiers() {
buildModifier(TinkerModifiers.padded)
.priority(75) // run after knockback
.addModule(KnockbackModule.builder().formula()
.variable(KNOCKBACK)
.variable(VALUE)
.constant(2).variable(LEVEL).power() // 2^LEVEL
.divide().build()); // KNOCKBACK / 2^LEVEL
buildModifier(ModifierIds.sticky)
Expand Down

0 comments on commit dd1d5ef

Please sign in to comment.