Cammie's Combat Tweaks

Cammie's Combat Tweaks

35.7k Downloads

Shield bug cause player to be insta-killed

domanhthang2110 opened this issue ยท 4 comments

commented

When blocking with shield, especially with many mobs attacking you. Sometimes a mob will hit from the side and for whatever reason it insta-kill the player no matter the HP
This is my shield config (I messed with it a bit to see if it fix the problem but it doesn't)

"shields": {
		"canParry": false,
		"parryWithinTicks": 5,
		"disableWeaponOnParryTicks": 100,
		"disableShieldOnParryTicks": 20,
		"maxShieldArc": 360.0,
		"minTicksHasToBeUp": 10,
		"disableShieldOnLetGoTicks": 0,
		"maxDamageBlocked": 100.0
	},
commented

Actually, that's partly the problem (same could be achieved like this):

	@ModifyVariable(method = "damage", at = @At(value = "INVOKE",
			target = "Lnet/minecraft/entity/damage/DamageSource;isProjectile()Z"
	), ordinal = 0)
	public float modifyShieldDamageProtection(float amount, DamageSource source) {
		return Math.max(0, damageAmount - CombatTweaks.getConfig().shields.maxDamageBlocked);
	}

But there's another problem: the shield maxes out at a 180 degree arc because I'm dumb and bad at math, but I know how to fix it, so it'll be fixed sometime in the next release

commented

That is a horrific config, but I'll do a test in a bit to see if I can reproduce the bug and figure out what's wrong

commented

I just tested some more and it has something to do with the max damage blocked setting, when i set to 10 the bug cause me to take 10 dmg, and the config above is 100 so basically insta-kill
This video is an example when setting that to 20 dmg

2021-10-23.00-28-55-1.mp4
commented

I think I fixed it XD, all I do is adding a check in the damage calculation part whether if the returned damage is >= 0 or not to prevent negative value.
Not sure though, try doing it on your side

	@ModifyVariable(method = "damage", at = @At(value = "INVOKE",
			target = "Lnet/minecraft/entity/damage/DamageSource;isProjectile()Z"
	), ordinal = 0)
	public float modifyShieldDamageProtection(float amount, DamageSource source) {
		if((damageAmount - CombatTweaks.getConfig().shields.maxDamageBlocked) < 0) 
			return 0;
		else 
			return damageAmount - CombatTweaks.getConfig().shields.maxDamageBlocked;
	}