Skip to content

Commit

Permalink
allowed configuration of attack speeds for weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra-Myers committed May 27, 2023
1 parent 0b75c05 commit 40aea9f
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,59 @@ public class AtlasConfigModel {
@RangeConstraint(min = 0, max = 4)
public float bowUncertainty = 0.25F;
@RestartRequired
@RangeConstraint(min = 0, max = 10)
@RangeConstraint(min = 0, max = 1000)
public float swordAttackDamage = 1;
@RestartRequired
@RangeConstraint(min = 0, max = 10)
@RangeConstraint(min = 0, max = 1000)
public float axeAttackDamage = 2;
@RestartRequired
@RangeConstraint(min = 0, max = 10)
@RangeConstraint(min = 0, max = 1000)
public float baseHoeAttackDamage = 0;
@RestartRequired
@RangeConstraint(min = 0, max = 10)
@RangeConstraint(min = 0, max = 1000)
public float ironDiaHoeAttackDamage = 1;
@RestartRequired
@RangeConstraint(min = 0, max = 10)
@RangeConstraint(min = 0, max = 1000)
public float netheriteHoeAttackDamage = 2;
@RestartRequired
@RangeConstraint(min = 0, max = 10)
@RangeConstraint(min = 0, max = 1000)
public float tridentAttackDamage = 5;
@RestartRequired
@RangeConstraint(min = -1, max = 7.5)
public float swordAttackSpeed = 0.5F;
@RestartRequired
@RangeConstraint(min = -1, max = 7.5)
public float axeAttackSpeed = -0.5F;
@RestartRequired
@RangeConstraint(min = -1, max = 7.5)
public float woodenHoeAttackSpeed = -0.5F;
@RestartRequired
@RangeConstraint(min = -1, max = 7.5)
public float stoneHoeAttackSpeed = 0;
@RestartRequired
@RangeConstraint(min = -1, max = 7.5)
public float ironHoeAttackSpeed = 0.5F;
@RestartRequired
@RangeConstraint(min = -1, max = 7.5)
public float goldDiaNethHoeAttackSpeed = 1;
@RestartRequired
@RangeConstraint(min = -1, max = 7.5)
public float tridentAttackSpeed = -0.5F;
@RestartRequired
@RangeConstraint(min = -1, max = 7.5)
public float defaultAttackSpeed = 0F;
@RestartRequired
@RangeConstraint(min = -1, max = 7.5)
public float slowestToolAttackSpeed = -1F;
@RestartRequired
@RangeConstraint(min = -1, max = 7.5)
public float slowToolAttackSpeed = -0.5F;
@RestartRequired
@RangeConstraint(min = -1, max = 7.5)
public float fastToolAttackSpeed = 0.5F;
@RestartRequired
@RangeConstraint(min = -1, max = 7.5)
public float fastestToolAttackSpeed = 1F;
public static class UseDurations {
}
public static class Cooldowns {
Expand Down
51 changes: 30 additions & 21 deletions src/main/java/net/alexandra/atlas/atlas_combat/item/WeaponType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableMultimap;
import net.alexandra.atlas.atlas_combat.AtlasCombat;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
Expand Down Expand Up @@ -34,8 +35,7 @@ public void addCombatAttributes(Tier var1, ImmutableMultimap.Builder<Attribute,
float var5 = this.getReach();
float var6 = this.getBlockReach();
var2.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", var4, AttributeModifier.Operation.ADDITION));
if(AtlasCombat.CONFIG.attackSpeed())
var2.put(NewAttributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Weapon modifier", var3, AttributeModifier.Operation.ADDITION));
var2.put(NewAttributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Weapon modifier", var3, AttributeModifier.Operation.ADDITION));
if (var5 != 0.0F && AtlasCombat.CONFIG.attackReach()) {
var2.put(NewAttributes.ATTACK_REACH, new AttributeModifier(BASE_ATTACK_REACH_UUID, "Weapon modifier", var5, AttributeModifier.Operation.ADDITION));
}
Expand All @@ -61,35 +61,35 @@ public float getDamage(Tier var1) {
}
case SWORD -> {
if (bl) {
return var2 + AtlasCombat.CONFIG.swordAttackDamage();
return var2 + min(AtlasCombat.CONFIG.swordAttackDamage(), 0);
} else {
return var2 + AtlasCombat.CONFIG.swordAttackDamage() + 1.0F;
return var2 + min(AtlasCombat.CONFIG.swordAttackDamage(), 0) + 1.0F;
}
}
case AXE -> {
if(!AtlasCombat.CONFIG.ctsAttackBalancing()) {
return !isTier1 ? var1 == Tiers.NETHERITE ? 10 : 9 : 7;
} else if (bl) {
return var2 + AtlasCombat.CONFIG.axeAttackDamage();
return var2 + min(AtlasCombat.CONFIG.axeAttackDamage(), 0);
} else {
return var2 + AtlasCombat.CONFIG.axeAttackDamage() + 1.0F;
return var2 + min(AtlasCombat.CONFIG.axeAttackDamage(), 0) + 1.0F;
}
}
case LONGSWORD, HOE -> {
if (var1 != Tiers.IRON && var1 != Tiers.DIAMOND) {
if (var1 == Tiers.NETHERITE || var1.getLevel() >= 4) {
return var1 == Tiers.NETHERITE ? AtlasCombat.CONFIG.netheriteHoeAttackDamage() + modifier : AtlasCombat.CONFIG.netheriteHoeAttackDamage() + var2 - 4 + modifier;
return var1 == Tiers.NETHERITE ? min(AtlasCombat.CONFIG.netheriteHoeAttackDamage(), 0) + modifier : min(AtlasCombat.CONFIG.netheriteHoeAttackDamage(), 0) + var2 - 4 + modifier;
}

return AtlasCombat.CONFIG.baseHoeAttackDamage() + modifier;
return min(AtlasCombat.CONFIG.baseHoeAttackDamage(), 0) + modifier;
}
return AtlasCombat.CONFIG.ironDiaHoeAttackDamage() + modifier;
return min(AtlasCombat.CONFIG.ironDiaHoeAttackDamage(), 0) + modifier;
}
case SHOVEL -> {
return var2;
}
case TRIDENT -> {
return AtlasCombat.CONFIG.tridentAttackDamage() + modifier + (AtlasCombat.CONFIG.ctsAttackBalancing() ? 0 : 1);
return min(AtlasCombat.CONFIG.tridentAttackDamage(), 0) + modifier + (AtlasCombat.CONFIG.ctsAttackBalancing() ? 0 : 1);
}
default -> {
return 0.0F + modifier;
Expand All @@ -100,33 +100,36 @@ public float getDamage(Tier var1) {
public float getSpeed(Tier var1) {
switch (this) {
case KNIFE -> {
return 1.0F;
return AtlasCombat.CONFIG.goldDiaNethHoeAttackSpeed();
}
case LONGSWORD, SWORD -> {
return 0.5F;
return AtlasCombat.CONFIG.swordAttackSpeed();
}
case AXE, SHOVEL, TRIDENT -> {
return -0.5F;
case AXE, SHOVEL -> {
return AtlasCombat.CONFIG.axeAttackSpeed();
}
case TRIDENT -> {
return AtlasCombat.CONFIG.tridentAttackSpeed();
}
case HOE -> {
if (var1 == Tiers.WOOD) {
return -0.5F;
return AtlasCombat.CONFIG.woodenHoeAttackSpeed();
} else if (var1 == Tiers.IRON) {
return 0.5F;
return AtlasCombat.CONFIG.ironHoeAttackSpeed();
} else if (var1 == Tiers.DIAMOND) {
return 1.0F;
return AtlasCombat.CONFIG.goldDiaNethHoeAttackSpeed();
} else if (var1 == Tiers.GOLD) {
return 1.0F;
return AtlasCombat.CONFIG.goldDiaNethHoeAttackSpeed();
} else {
if (var1 == Tiers.NETHERITE || var1.getLevel() >= 4) {
return 1.0F;
return AtlasCombat.CONFIG.goldDiaNethHoeAttackSpeed();
}

return 0.0F;
return AtlasCombat.CONFIG.stoneHoeAttackSpeed();
}
}
default -> {
return 0.0F;
return AtlasCombat.CONFIG.defaultAttackSpeed();
}
}
}
Expand All @@ -149,4 +152,10 @@ public float getBlockReach() {
default -> 0.0F;
};
}
public static float min(float f, float j) {
if(f < j) {
return j;
}
return f;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.alexandra.atlas.atlas_combat.mixin;

import net.alexandra.atlas.atlas_combat.AtlasCombat;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.item.Item;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -24,19 +25,19 @@ public class AttributeModifierMixin {
private void injectChanges(UUID uUID, Supplier<String> supplier, double d, AttributeModifier.Operation operation, CallbackInfo ci) {
if (uUID == Item.BASE_ATTACK_SPEED_UUID) {
if(d >= 0) {
amount = 1.0F;
amount = AtlasCombat.CONFIG.fastestToolAttackSpeed();
} else if(d >= -1) {
amount = 0.5F;
amount = AtlasCombat.CONFIG.fastToolAttackSpeed();
} else if(d == -2) {
amount = 0;
amount = AtlasCombat.CONFIG.defaultAttackSpeed();
} else if(d >= -2.5) {
amount = 0.5;
amount = AtlasCombat.CONFIG.fastToolAttackSpeed();
} else if(d > -3) {
amount = 0;
amount = AtlasCombat.CONFIG.defaultAttackSpeed();
} else if (d > -3.5) {
amount = -0.5;
amount = AtlasCombat.CONFIG.slowToolAttackSpeed();
} else {
amount = -1;
amount = AtlasCombat.CONFIG.slowestToolAttackSpeed();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.google.common.collect.Multimap;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.alexandra.atlas.atlas_combat.AtlasCombat;
import net.alexandra.atlas.atlas_combat.config.AtlasConfig;
import net.alexandra.atlas.atlas_combat.extensions.*;
import net.alexandra.atlas.atlas_combat.item.NewAttributes;
import net.alexandra.atlas.atlas_combat.util.UtilClass;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -424,8 +426,15 @@ public void attackAir() {
@Override
public void resetAttackStrengthTicker(boolean hit) {
this.missedAttackRecovery = !hit;
if(!AtlasCombat.CONFIG.attackSpeed()) {
if(getAttribute(Attributes.ATTACK_SPEED).getValue() - 1.5 >= 10) {
return;
} else if(attackSpeedsMaxed()) {
return;
}
}
int var2 = (int) (this.getCurrentItemAttackStrengthDelay() * 2);
if (var2 > this.attackStrengthTicker && AtlasCombat.CONFIG.attackSpeed()) {
if (var2 > this.attackStrengthTicker) {
this.attackStrengthStartValue = var2;
this.attackStrengthTicker = this.attackStrengthStartValue;
}
Expand Down Expand Up @@ -551,4 +560,9 @@ public void setAttackStrengthTicker2(int value) {
this.attackStrengthStartValue = value;
player.attackStrengthTicker = this.attackStrengthStartValue;
}
public boolean attackSpeedsMaxed() {
AtlasConfig c = AtlasCombat.CONFIG;
UtilClass<Float> util = new UtilClass<>();
return util.compare(1.5F, c.swordAttackSpeed(), c.axeAttackSpeed(), c.woodenHoeAttackSpeed(), c.stoneHoeAttackSpeed(), c.ironHoeAttackSpeed(), c.goldDiaNethHoeAttackSpeed(), c.defaultAttackSpeed(), c.tridentAttackSpeed(), c.fastToolAttackSpeed(), c.fastestToolAttackSpeed(), c.slowToolAttackSpeed(), c.slowestToolAttackSpeed());
}
}
15 changes: 15 additions & 0 deletions src/main/java/net/alexandra/atlas/atlas_combat/util/UtilClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.alexandra.atlas.atlas_combat.util;

public class UtilClass<T> {
public UtilClass() {

}
@SafeVarargs
public final boolean compare(T comparatee, T... comparators) {
boolean bl = true;
for(T object : comparators) {
bl &= comparatee == object;
}
return bl;
}
}
18 changes: 15 additions & 3 deletions src/main/resources/assets/atlas_combat/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"text.config.atlas-combat-config.option.autoAttackAllowed": "Option for servers which will prevent using auto-attack on client",
"text.config.atlas-combat-config.option.axeReachBuff": "Raises axe reach to 3 as a balancing change",
"text.config.atlas-combat-config.option.attackReach": "Attack Reach Enabled",
"text.config.atlas-combat-config.option.attackSpeed": "Attack Speed Enabled",
"text.config.atlas-combat-config.option.attackSpeed": "If disabled and your tool grants attack speed of 10, will prevent attacks from resetting, allowing for spamming with that tool. If all speed configs are maxed out such that they all have a speed of 10, will also apply to every other item, and your fists.",
"text.config.atlas-combat-config.option.ctsAttackBalancing": "Determines whether or not weapons will deal less damage than they do in 1.9",
"text.config.atlas-combat-config.option.eatingInterruption": "Eating Interruption Enabled",
"text.config.atlas-combat-config.option.blockReach": "Block Reach Enabled",
Expand All @@ -59,8 +59,20 @@
"text.config.atlas-combat-config.option.bowUncertainty": "Bow Uncertainty AKA Accuracy",
"text.config.atlas-combat-config.option.swordAttackDamage": "Sword Damage Bonus",
"text.config.atlas-combat-config.option.axeAttackDamage": "Axe Damage Bonus",
"text.config.atlas-combat-config.option.baseHoeAttackDamage": "Wood, Stone, and Gold Hoe Damage Bonus",
"text.config.atlas-combat-config.option.baseHoeAttackDamage": "Wooden, Stone, and Gold Hoe Damage Bonus",
"text.config.atlas-combat-config.option.ironDiaHoeAttackDamage": "Iron and Diamond Hoe Damage Bonus",
"text.config.atlas-combat-config.option.netheriteHoeAttackDamage": "Netherite Hoe Damage Bonus",
"text.config.atlas-combat-config.option.tridentAttackDamage": "Trident Damage Bonus"
"text.config.atlas-combat-config.option.tridentAttackDamage": "Trident Damage Bonus",
"text.config.atlas-combat-config.option.swordAttackSpeed": "Sword Speed Offset",
"text.config.atlas-combat-config.option.axeAttackSpeed": "Axe Speed Offset",
"text.config.atlas-combat-config.option.woodenHoeAttackSpeed": "Wooden Hoe Speed Offset",
"text.config.atlas-combat-config.option.stoneHoeAttackSpeed": "Stone Hoe Speed Offset",
"text.config.atlas-combat-config.option.ironHoeAttackSpeed": "Iron Hoe Speed Offset",
"text.config.atlas-combat-config.option.goldDiaNethHoeAttackSpeed": "Golden, Diamond, Netherite Hoe Speed Offset",
"text.config.atlas-combat-config.option.tridentAttackSpeed": "Trident Speed Offset",
"text.config.atlas-combat-config.option.defaultAttackSpeed": "Default Weapon / Tool Speed Offset",
"text.config.atlas-combat-config.option.slowestToolAttackSpeed": "Slowest Auto-Corrected Modded Weapon / Tool Speed Offset",
"text.config.atlas-combat-config.option.slowToolAttackSpeed": "Slow Auto-Corrected Modded Weapon / Tool Speed Offset",
"text.config.atlas-combat-config.option.fastToolAttackSpeed": "Fast Auto-Corrected Modded Weapon / Tool Speed Offset",
"text.config.atlas-combat-config.option.fastestToolAttackSpeed": "Fastest Auto-Corrected Modded Weapon / Tool Speed Offset"
}

0 comments on commit 40aea9f

Please sign in to comment.