Skip to content

Commit

Permalink
Merge pull request #317 from Smartin-b/1.20.1
Browse files Browse the repository at this point in the history
ReplayMod Compat
  • Loading branch information
ZsoltMolnarrr committed Jan 21, 2024
2 parents 9090f08 + 855b328 commit 62e8070
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 6 additions & 4 deletions common/src/main/java/net/bettercombat/client/ClientNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public static void initializeHandlers() {
final var packet = Packets.AttackAnimation.read(buf);
client.execute(() -> {
var entity = client.world.getEntityById(packet.playerId());
if (entity instanceof PlayerEntity) {
//This addition check is not required, ive tested without it,
//but it probably retriggers the animation and could lead to issues on servers with higher pings
if (entity instanceof PlayerEntity player && player != client.player) {
if (packet.animationName().equals(Packets.AttackAnimation.StopSymbol)) {
((PlayerAttackAnimatable)entity).stopAttackAnimation(packet.length());
((PlayerAttackAnimatable) entity).stopAttackAnimation(packet.length());
} else {
((PlayerAttackAnimatable)entity).playAttackAnimation(packet.animationName(), packet.animatedHand(), packet.length(), packet.upswing());
((PlayerAttackAnimatable) entity).playAttackAnimation(packet.animationName(), packet.animatedHand(), packet.length(), packet.upswing());
}
}
});
Expand All @@ -36,7 +38,7 @@ public static void initializeHandlers() {

var soundEvent = Registries.SOUND_EVENT.get(new Identifier(packet.soundId()));
var configVolume = BetterCombatClient.config.weaponSwingSoundVolume;
var volume = packet.volume() * ((float)Math.min(Math.max(configVolume, 0), 100) / 100F);
var volume = packet.volume() * ((float) Math.min(Math.max(configVolume, 0), 100) / 100F);
client.world.playSound(
packet.x(),
packet.y(),
Expand Down
12 changes: 11 additions & 1 deletion common/src/main/java/net/bettercombat/network/ServerNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.PersistentProjectileEntity;
import net.minecraft.item.SwordItem;
import net.minecraft.network.PacketByteBuf;
Expand All @@ -37,6 +38,7 @@
import net.minecraft.text.Text;
import org.slf4j.Logger;

import java.util.Collection;
import java.util.UUID;

public class ServerNetwork {
Expand All @@ -63,9 +65,17 @@ public static void initializeHandlers() {
}
final var packet = Packets.AttackAnimation.read(buf);
final var forwardBuffer = new Packets.AttackAnimation(player.getId(), packet.animatedHand(), packet.animationName(), packet.length(), packet.upswing()).write();
try {
//send info back for Replaymod Compat
if (ServerPlayNetworking.canSend(player, Packets.AttackAnimation.ID)) {
ServerPlayNetworking.send(player, Packets.AttackAnimation.ID, forwardBuffer);
}
} catch (Exception e){
e.printStackTrace();
}
PlayerLookup.tracking(player).forEach(serverPlayer -> {
try {
if (serverPlayer.getId() != player.getId() && ServerPlayNetworking.canSend(serverPlayer, Packets.AttackAnimation.ID)) {
if (ServerPlayNetworking.canSend(serverPlayer, Packets.AttackAnimation.ID)) {
ServerPlayNetworking.send(serverPlayer, Packets.AttackAnimation.ID, forwardBuffer);
}
} catch (Exception e){
Expand Down

0 comments on commit 62e8070

Please sign in to comment.