Comments (3)
I'm pretty sure to problem lies in using wrong methods to set/get attack speed value.
When equipping enchanted weapon, attack speed is calculated from defaultValue, and then baseValue is set.
When deselecting weapon, calculation is based on current value (getValue()), which apparently does not equal baseValue. I've added logs and there's difference between "baseAttack * lvl" which is set as BaseValue and attack speed value get with getValue() method (e.g. baseAttack * lvl = 8.0, but ATTACK_SPEED.getValue() gives 5.5999999).
Changing to getting/setting only BaseValue seems to fix the problem.
I'm no Minecraft modder, just stumbled on this problem on my friend's server. So I do not know what is difference between getValue() and getBaseValue() in connection to attack speed attribute.
Other problem which might rise and needs consideration are other mods that might tinker with attack speed.
Below is fixed code (HandlerFasterAttack.java):
if (lvl > 0) {
if (enchantsCap.getFasterAttack() == 0) {
double baseAttack = Objects.requireNonNull(player.getAttribute(Attributes.ATTACK_SPEED)).getBaseValue(); //In my opinion baseAttack should be get from getBaseValue(), not getDefaultValue(), as other mods can tinker with attack speed
Objects.requireNonNull(player.getAttribute(Attributes.ATTACK_SPEED)).setBaseValue(baseAttack * lvl);
enchantsCap.setFasterAttack(lvl);
}
} else {
if (enchantsCap.getFasterAttack() != 0) {
double attackSpeed = Objects.requireNonNull(player.getAttribute(Attributes.ATTACK_SPEED)).getBaseValue(); //Here was getValue(), should be getBaseValue()
Objects.requireNonNull(player.getAttribute(Attributes.ATTACK_SPEED)).setBaseValue(attackSpeed / enchantsCap.getFasterAttack());
player.removeEffect(ModMobEffects.FASTER_ATTACK.get());
enchantsCap.setFasterAttack(0);
}
}
from ma-enchants.
I'm pretty sure to problem lies in using wrong methods to set/get attack speed value.
When equipping enchanted weapon, attack speed is calculated from defaultValue, and then baseValue is set. When deselecting weapon, calculation is based on current value (getValue()), which apparently does not equal baseValue. I've added logs and there's difference between "baseAttack * lvl" which is set as BaseValue and attack speed value get with getValue() method (e.g. baseAttack * lvl = 8.0, but ATTACK_SPEED.getValue() gives 5.5999999).
Changing to getting/setting only BaseValue seems to fix the problem.
I'm no Minecraft modder, just stumbled on this problem on my friend's server. So I do not know what is difference between getValue() and getBaseValue() in connection to attack speed attribute.
Other problem which might rise and needs consideration are other mods that might tinker with attack speed.
Below is fixed code (HandlerFasterAttack.java):
if (lvl > 0) { if (enchantsCap.getFasterAttack() == 0) { double baseAttack = Objects.requireNonNull(player.getAttribute(Attributes.ATTACK_SPEED)).getBaseValue(); //In my opinion baseAttack should be get from getBaseValue(), not getDefaultValue(), as other mods can tinker with attack speed Objects.requireNonNull(player.getAttribute(Attributes.ATTACK_SPEED)).setBaseValue(baseAttack * lvl); enchantsCap.setFasterAttack(lvl); } } else { if (enchantsCap.getFasterAttack() != 0) { double attackSpeed = Objects.requireNonNull(player.getAttribute(Attributes.ATTACK_SPEED)).getBaseValue(); //Here was getValue(), should be getBaseValue() Objects.requireNonNull(player.getAttribute(Attributes.ATTACK_SPEED)).setBaseValue(attackSpeed / enchantsCap.getFasterAttack()); player.removeEffect(ModMobEffects.FASTER_ATTACK.get()); enchantsCap.setFasterAttack(0); } }
Where can i add/change this? If it is HandlerFasterAttack.java i dont seem to be able to find it.
from ma-enchants.
The patch below seems to be working, I'm sure there is a better way to do this, unfortunately, I'm not a modder and I don't know forge API. I added attackSpeedPerLevel multiplier because weapon with no enchant gave the same attack speed as level 1 enchant which was weird and higher levels seemed too overpowered.
public class HandlerFasterAttack {
public static final double attackSpeedPerLevel = 0.375D;
private static double calcAttackSpeedMod(double enchant_lvl){
return 1.0D + (enchant_lvl * attackSpeedPerLevel);
}
public static void handlerPlayerTick(Player player) {
IPlayerCapability enchantsCap = PlayerUtil.getAliveEnchantsCapability(player);
if (enchantsCap == null) return;
ItemStack usedItem = player.getItemInHand(player.getUsedItemHand());
int enchant_lvl = usedItem.getEnchantmentLevel(ModEnchantments.FASTER_ATTACK.get());
int currentFasterAttackBuff_lvl = enchantsCap.getFasterAttack();
double currentAttackSpeedMod = HandlerFasterAttack.calcAttackSpeedMod(currentFasterAttackBuff_lvl);
var playerAttackSpeedObj = Objects.requireNonNull(player.getAttribute(Attributes.ATTACK_SPEED));
if (enchant_lvl > 0) {
if (currentFasterAttackBuff_lvl != enchant_lvl) {
double newAttackSpeedMod = HandlerFasterAttack.calcAttackSpeedMod(enchant_lvl);
if(enchantsCap.getFasterAttack() != 0){
playerAttackSpeedObj.setBaseValue(playerAttackSpeedObj.getBaseValue() / currentAttackSpeedMod);
}
double playerAttackSpeedBaseValue = playerAttackSpeedObj.getBaseValue();
playerAttackSpeedObj.setBaseValue(playerAttackSpeedBaseValue * newAttackSpeedMod);
enchantsCap.setFasterAttack(enchant_lvl);
}
} else {
if (enchantsCap.getFasterAttack() != 0) {
double playerAttackSpeedBaseValue = playerAttackSpeedObj.getBaseValue();
playerAttackSpeedObj.setBaseValue(playerAttackSpeedBaseValue / currentAttackSpeedMod);
player.removeEffect(ModMobEffects.FASTER_ATTACK.get());
enchantsCap.setFasterAttack(0);
}
}
}
}
I'm posting a link to the compiled version of the mod for those who don't want to build the entire project themselves and trust random people on the internet enough:
Google Drive - maenchants-1.19.2-6.0.0_1.jar
from ma-enchants.
Related Issues (20)
- Game crashes when use true shot on 1.16.5 HOT 2
- {1.18.1} game crashed after putting on boots with Blazing walker II HOT 2
- floating arrow causes crash (multiplayer dedicated server) HOT 3
- Block id or something is wrong HOT 1
- Can't join server when wearing Blaze Walker enchantment HOT 2
- many enchants don't work on newest version of forge 1.18.1 HOT 1
- Stone mending HOT 1
- Two enchantments are invalid HOT 2
- Inconsistency in Mod ID across versions causes compatibility issues HOT 1
- Melted Cobblestone Crash HOT 1
- [1.19.2 Forge] Add lang file entries for compat with Enchantment Description mod HOT 1
- [1.19.2 Forge] Switching between weapons with different Fastter Attack lvl doesn't changes attack speed. HOT 1
- Lumberjack not working properly/at all.
- Lumberjack not working at all
- 1.19.3 Issue: Faster Attack Causes Negative Attack Speeds HOT 1
- Paralysis still spawning in loot chests despite being disabled HOT 1
- Detonation w/ loaded crossbow issue
- [1.19.2-6.0.0] Broken combo enchant
- Config in 1.16.5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ma-enchants.