Skip to content

Commit

Permalink
Reworked support for Sweeping Edge
Browse files Browse the repository at this point in the history
  • Loading branch information
ZsoltMolnarrr committed May 4, 2023
1 parent c9c4444 commit 6361513
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.7.0

- Reworked support for Sweeping Edge

# 1.6.2

- Update claymore pose
Expand Down
7 changes: 0 additions & 7 deletions common/src/main/java/net/bettercombat/client/MathHelper.java

This file was deleted.

24 changes: 23 additions & 1 deletion common/src/main/java/net/bettercombat/config/ServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,29 @@ public class ServerConfig implements ConfigData {
(Note all hostile mobs hittable by default, this config is to fix faulty mobs)""")
public String[] hostile_player_vehicles = {"alexsmobs:crocodile"};
@Comment("Allows vanilla sweeping mechanic to work and Sweeping Edge enchantment")
public boolean allow_sweeping = true;
public boolean allow_vanilla_sweeping = false;
@Comment("Allows new sweeping mechanic (by Better Combat) to work, including Sweeping Edge enchantment")
public boolean allow_reworked_sweeping = true;
@Comment("""
The more additional targets a weapon swing hits, the weaker it will get.
Entities struck (+1) in a swing more than this, won't get weakened any further.
""")
public int reworked_sweeping_extra_target_count = 4;
@Comment("""
Determines how weak the attack becomes when striking `reworked_sweeping_extra_target_count + 1` targets.
Example values:
- `0.5` -50% damage
""")
public float reworked_sweeping_maximum_damage_penalty = 0.5F;
@Comment("""
The maximum level Sweeping Edge enchantment applied to the attackers weapon will restore this amount of penalty.
Example values:
- `0.5` restores 50% damage penalty when 3 levels are applied, so 16.66% when 1 level is applied
""")
public float reworked_sweeping_enchant_restores = 0.5F;
public boolean reworked_sweeping_plays_sound = true;
public boolean reworked_sweeping_emits_particles = true;
public boolean reworked_sweeping_sound_and_particles_only_for_swords = true;
@Comment("Allows client-side target search to ignore obstacles. WARNING! Setting this to `false` significantly increases the load on clients.")
public boolean allow_attacking_thru_walls = false;
@Comment("Applies movement speed multiplier while attacking. (Min: 0, Max: 1). Use `0` for a full stop while attacking. Use `1` for no movement speed penalty")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void post_Tick(CallbackInfo ci) {

@ModifyVariable(method = "attack", at = @At("STORE"), ordinal = 3)
private boolean disableSweeping(boolean value) {
if (BetterCombat.config.allow_sweeping) {
if (BetterCombat.config.allow_vanilla_sweeping) {
return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public class SweepingEnchantmentMixin {

@Inject(method = "getMaxLevel", at = @At("HEAD"), cancellable = true)
public void getMaxLevel_DisableSweeping(CallbackInfoReturnable<Integer> cir) {
if (BetterCombat.config == null || BetterCombat.config.allow_sweeping) {
if (BetterCombat.config == null
|| BetterCombat.config.allow_vanilla_sweeping
|| BetterCombat.config.allow_reworked_sweeping) {
return;
}
cir.setReturnValue(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.bettercombat.BetterCombat;
import net.bettercombat.api.MinecraftClient_BetterCombat;
import net.bettercombat.client.MathHelper;
import net.bettercombat.utils.MathHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
46 changes: 42 additions & 4 deletions common/src/main/java/net/bettercombat/network/ServerNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import net.bettercombat.logic.WeaponRegistry;
import net.bettercombat.logic.knockback.ConfigurableKnockback;
import net.bettercombat.mixin.LivingEntityAccessor;
import net.bettercombat.utils.MathHelp;
import net.bettercombat.utils.MathHelper;
import net.bettercombat.utils.SoundHelper;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.ItemEntity;
Expand All @@ -26,9 +28,12 @@
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.entity.projectile.PersistentProjectileEntity;
import net.minecraft.item.SwordItem;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import org.slf4j.Logger;

Expand All @@ -39,6 +44,10 @@ public class ServerNetwork {

private static PacketByteBuf configSerialized = PacketByteBufs.create();

private static final UUID COMBO_DAMAGE_MODIFIER_ID = UUID.randomUUID();
private static final UUID DUAL_WIELDING_MODIFIER_ID = UUID.randomUUID();
private static final UUID SWEEPING_MODIFIER_ID = UUID.randomUUID();

public static void initializeHandlers() {
configSerialized = Packets.ConfigSync.write(BetterCombat.config);
ServerPlayConnectionEvents.JOIN.register( (handler, sender, server) -> {
Expand Down Expand Up @@ -88,6 +97,7 @@ public static void initializeHandlers() {
((PlayerAttackProperties)player).setComboCount(request.comboCount());
Multimap<EntityAttribute, EntityAttributeModifier> comboAttributes = null;
Multimap<EntityAttribute, EntityAttributeModifier> dualWieldingAttributes = null;
Multimap<EntityAttribute, EntityAttributeModifier> sweepingModifiers = HashMultimap.create();
double range = 18.0;
if (attributes != null && attack != null) {
range = attributes.attackRange();
Expand All @@ -96,15 +106,15 @@ public static void initializeHandlers() {
double comboMultiplier = attack.damageMultiplier() - 1;
comboAttributes.put(
EntityAttributes.GENERIC_ATTACK_DAMAGE,
new EntityAttributeModifier(UUID.randomUUID(), "COMBO_DAMAGE_MULTIPLIER", comboMultiplier, EntityAttributeModifier.Operation.MULTIPLY_BASE));
new EntityAttributeModifier(COMBO_DAMAGE_MODIFIER_ID, "COMBO_DAMAGE_MULTIPLIER", comboMultiplier, EntityAttributeModifier.Operation.MULTIPLY_BASE));
player.getAttributes().addTemporaryModifiers(comboAttributes);

var dualWieldingMultiplier = PlayerAttackHelper.getDualWieldingAttackDamageMultiplier(player, hand) - 1;
if (dualWieldingMultiplier != 0) {
dualWieldingAttributes = HashMultimap.create();
dualWieldingAttributes.put(
EntityAttributes.GENERIC_ATTACK_DAMAGE,
new EntityAttributeModifier(UUID.randomUUID(), "DUAL_WIELDING_DAMAGE_MULTIPLIER", dualWieldingMultiplier, EntityAttributeModifier.Operation.MULTIPLY_TOTAL));
new EntityAttributeModifier(DUAL_WIELDING_MODIFIER_ID, "DUAL_WIELDING_DAMAGE_MULTIPLIER", dualWieldingMultiplier, EntityAttributeModifier.Operation.MULTIPLY_TOTAL));
player.getAttributes().addTemporaryModifiers(dualWieldingAttributes);
}

Expand All @@ -113,17 +123,42 @@ public static void initializeHandlers() {
}

SoundHelper.playSound(world, player, attack.swingSound());

if (BetterCombat.config.allow_reworked_sweeping && request.entityIds().length > 1) {
double multiplier = 1.0
- (BetterCombat.config.reworked_sweeping_maximum_damage_penalty / BetterCombat.config.reworked_sweeping_extra_target_count)
* Math.min(BetterCombat.config.reworked_sweeping_extra_target_count, request.entityIds().length - 1);
int sweepingLevel = EnchantmentHelper.getLevel(Enchantments.SWEEPING, hand.itemStack());
double sweepingSteps = BetterCombat.config.reworked_sweeping_enchant_restores / ((double)Enchantments.SWEEPING.getMaxLevel());
multiplier += sweepingLevel * sweepingSteps;
multiplier = Math.min(multiplier, 1);
sweepingModifiers.put(
EntityAttributes.GENERIC_ATTACK_DAMAGE,
new EntityAttributeModifier(SWEEPING_MODIFIER_ID, "SWEEPING_DAMAGE_MODIFIER", multiplier - 1, EntityAttributeModifier.Operation.MULTIPLY_TOTAL));
// System.out.println("Applied sweeping multiplier " + multiplier + " , sweepingSteps " + sweepingSteps + " , enchant bonus: " + (sweepingLevel * sweepingSteps));
player.getAttributes().addTemporaryModifiers(sweepingModifiers);

boolean playEffects = !BetterCombat.config.reworked_sweeping_sound_and_particles_only_for_swords
|| (hand.itemStack().getItem() instanceof SwordItem);
if (BetterCombat.config.reworked_sweeping_plays_sound && playEffects) {
world.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, player.getSoundCategory(), 1.0f, 1.0f);
}
if (BetterCombat.config.reworked_sweeping_emits_particles && playEffects) {
player.spawnSweepAttackParticles();
}
}
}

var attackCooldown = PlayerAttackHelper.getAttackCooldownTicksCapped(player);
var knockbackMultiplier = BetterCombat.config.knockback_reduced_for_fast_attacks
? MathHelp.clamp(attackCooldown / 12.5F, 0.1F, 1F)
? MathHelper.clamp(attackCooldown / 12.5F, 0.1F, 1F)
: 1F;
var lastAttackedTicks = ((LivingEntityAccessor)player).getLastAttackedTicks();
if (!useVanillaPacket) {
player.setSneaking(request.isSneaking());
}


for (int entityId: request.entityIds()) {
// getEntityById(entityId);
boolean isBossPart = false;
Expand Down Expand Up @@ -183,6 +218,9 @@ public static void initializeHandlers() {
if (dualWieldingAttributes != null) {
player.getAttributes().removeModifiers(dualWieldingAttributes);
}
if (!sweepingModifiers.isEmpty()) {
player.getAttributes().removeModifiers(sweepingModifiers);
}
((PlayerAttackProperties)player).setComboCount(-1);
});
});
Expand Down
7 changes: 0 additions & 7 deletions common/src/main/java/net/bettercombat/utils/MathHelp.java

This file was deleted.

22 changes: 22 additions & 0 deletions common/src/main/java/net/bettercombat/utils/MathHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.bettercombat.utils;

public class MathHelper {
// Generic
public static float clamp(float value, float min, float max) {
return Math.max(Math.min(value, max), min);
}

// Easing

public static double easeOutCubic(double number) {
return 1.0 - Math.pow(1.0 - number, 3);
}

public double easeInExpo(double x) {
return x == 0 ? 0 : Math.pow(2, 10 * x - 10);
}

public double easeOutExpo(double x) {
return x == 1 ? 1 : 1 - Math.pow(2, -10 * x);
}
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ yarn_mappings=1.19.4+build.1

# Loader
fabric_version=0.77.0+1.19.4
loader_version=0.14.11
loader_version=0.14.19
forge_version=45.0.43

# Mod Properties
mod_version=1.6.2
mod_version=1.7.0
maven_group=net
archives_base_name=bettercombat

Expand Down

0 comments on commit 6361513

Please sign in to comment.