Skip to content

Commit

Permalink
Merge branch '1.20.1' into 1.20.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	common/src/main/java/net/bettercombat/network/ServerNetwork.java
#	gradle.properties
  • Loading branch information
ZsoltMolnarrr committed Apr 15, 2024
2 parents 11401e6 + 2b0583d commit 03ae32e
Show file tree
Hide file tree
Showing 25 changed files with 290 additions and 54 deletions.
26 changes: 22 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
# 1.8.5

- Add `javelin` keyword to fallback config #344
- Add italian translation, thanks to @mattiagre #347
- Improve spanish and mexican translations, thanks to @TheLegendofSaram #346

# 1.8.4

- Fix ReplayMod Compat, thanks to Smartin-b #317 #24
- Fix Pehkui Compatibility, thanks to Leximon #326
- Improve First Person Model compatibility #329

# 1.8.3

- Fix two-handed ranged weapons ignoring projectile held in the offhand slot

# 1.8.2

- Add soft compatibility with Spell Engine, disable idle animation while casting spells

# 1.8.1

- (1.20.2) Fix packet handling issues in multiplayer causing players to disconnect.
- (Forge) fix hand swap deleting offhand item, when holding two handed items.
- (Forge) Requires at least Forge 47.2.0

# 1.8.0

Expand All @@ -16,14 +38,10 @@ Added new presets:
- `crossbow_two_handed_heavy`

Other changes:
- (1.20.2) Fix packet handling issues preventing multiplayer, and rejoining a world in single player
- Fix corrupted fallback config causing crash
- Keep order of `player_relations` in server config
- Add Japanese translation, thanks to SAGA23456 #289
- Update Russian translation, thanks to mpustovoi #288
- (Forge) fix hand swap deleting offhand item, when holding two handed items.
- (Forge) Requires at least Forge 47.2.0
- (Forge) Fixed networking stack, thanks to YuRaNnNzZZ #295

# 1.7.4

Expand Down
39 changes: 32 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,41 @@ Add unique behaviour to your weapon, or just reuse a preset, using data files (a
- [x] Integrate any weapon from any mod by just creating data files

## Auxiliary features
- [X] Two-handed weapons ignore offhand slot
- [X] Movement speed reduction while attacking (Server configurable)
- [X] Attacking with dual wielded weapons (held weapons are used alternated, +20% attack speed while dual wielding, Server configurable)
- [X] Two-handed weapons ignore offhand slot (melee and ranged weapons also supported)
- [X] Movement speed reduction while attacking (Server configurable)
- [X] Cancel attack during upswing (aka "feint") (Client configurable)
- [X] Hold attack key to spam attack (Client configurable)
- [X] Target in hitbox indication (Client configurable)
- [X] Swing thru grass (Client configurable)
- [X] Can disable mining with weapons (Client configurable)
- [X] Sweeping Edge enchantment reworked
- [X] Sweeping Edge enchantment reworked

## Compatibility features
- [X] Dedicated compatibility (Add weapon attribute data files for individual items, to specify their animations and behaviour) aka JSON API
- [X] Fallback compatibility (Tries to automatically assign the correct type of weapon attributes to weapons without attribute file. Highly configurable)
- [ ] ~~NBT compatibility (Weapon attributes can be read from ItemStack NBT). For example:~~ (This feature does not work correctly in multiplayer)

### Dedicated compatibility

To be used by developers and modpack creators.

Assign weapon attribute to weapons individually, using data files (similar how item models are assigned), to specify their animations and behaviour.

This also known as JSON API. Read more about it at [Integrate your mod](#-integrate-your-mod) section.

### Fallback compatibility

To be used by players (requires knowledge of JSON and Regex).

Built into Better Combat, tries to automatically assign weapon attributes to items without attribute file, based on item id.

To change assignments, edit: `config/bettercombat/fallback_compatibility.json` file.

(Note: Fallback compatibility can only assign attributes to non-attributed weapons, it cannot override data file based assignments.)

### NBT compatibility

⚠️ This feature does not work correctly in multiplayer, currently.

Weapon attributes can be read from ItemStack NBT. For example:
```
/give @p minecraft:wooden_sword{weapon_attributes:'{"parent":"bettercombat:claymore"}'} 1
```
Expand Down Expand Up @@ -76,6 +97,11 @@ The next steps describe how to add dedicated compatibility for any item.

## Installation

Dependencies to resolve via gradle:
- [Cloth Config](https://shedaniel.gitbook.io/cloth-config/setup-cloth-config/cloth-config-fabric)
- [PlayerAnimator](https://github.com/KosmX/minecraftPlayerAnimator#include-in-your-dev-environment)
- [MixinExtras](https://github.com/LlamaLad7/MixinExtras)

### Fabric

Download the latest release version of the mod with all of its dependencies, and put them into `./run/mods` director.
Expand Down Expand Up @@ -106,7 +132,6 @@ dependencies {
implementation fg.deobf('maven.modrinth:better-combat:VERSION-forge')
}
```
Please note for both Forge and Fabric, [Cloth Config](https://shedaniel.gitbook.io/cloth-config/setup-cloth-config/cloth-config-fabric) and [playerAnimator](https://github.com/KosmX/minecraftPlayerAnimator#include-in-your-dev-environment) are required as well. Please see each link on how to add these to your dev environments.

## Prerequisite

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {

plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.3-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false
id "org.cadixdev.licenser" version "0.6.1"
id "io.github.juuxel.loom-quiltflower" version "1.7.+" apply false
id "me.shedaniel.unified-publishing" version "0.1.+" apply false
Expand Down
3 changes: 2 additions & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repositories {
dependencies {
modImplementation "net.fabricmc:fabric-loader:${rootProject.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}"
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:${project.mixin_extras_version}"))

modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") {
exclude(group: "net.fabricmc.fabric-api")
Expand All @@ -26,7 +27,7 @@ dependencies {
implementation ("com.github.ZsoltMolnarrr:TinyConfig:${project.tiny_config_version}")

modCompileOnly("com.terraformersmc:modmenu:${rootProject.mod_menu_version}") { transitive false }
modCompileOnly "maven.modrinth:first-person-model:${project.fpm_version}"
modCompileOnly("maven.modrinth:first-person-model:${project.fpm_version}")
}

architectury {
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/java/net/bettercombat/Platform.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.bettercombat;

import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.entity.player.PlayerEntity;

public class Platform {
public static final boolean Fabric;
Expand All @@ -23,4 +24,7 @@ protected static Type getPlatformType() {
public static boolean isModLoaded(String modid) {
throw new AssertionError();
}

@ExpectPlatform
public static boolean isCastingSpell(PlayerEntity player) { throw new AssertionError(); }
}
11 changes: 7 additions & 4 deletions common/src/main/java/net/bettercombat/client/ClientNetwork.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.bettercombat.client;

import net.bettercombat.BetterCombat;
import net.bettercombat.Platform;
import net.bettercombat.client.animation.PlayerAttackAnimatable;
import net.bettercombat.logic.WeaponRegistry;
import net.bettercombat.network.Packets;
Expand All @@ -16,11 +17,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) {
if (entity instanceof PlayerEntity player
// Avoid local playback, unless replay mod is loaded
&& (player != client.player || Platform.isModLoaded("replaymod")) ) {
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 +39,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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static void initialize() {
}
if (Platform.isModLoaded("pehkui")) {
usePehkui = true;
PehkuiHelper.load();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.bettercombat.compatibility;

import dev.tr7zw.firstperson.FirstPersonModelCore;
import dev.tr7zw.firstperson.api.FirstPersonAPI;

import java.util.function.Supplier;

public class FirstPersonModelHelper {
public static Supplier<Boolean> isDisabled() {
return (() -> {
return !FirstPersonModelCore.enabled;
return !FirstPersonAPI.isEnabled();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class PehkuiHelper {
private static final Method GET_SCALE;
private static final Map<Identifier, Object> SCALE_TYPES;

public static void load() {}

static
{
Method getScaleDataMethod = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static FallbackConfig createDefault() {
"fist|gauntlet",
"bettercombat:fist"),
new CompatibilitySpecifier(
"trident|impaled",
"trident|javelin|impaled",
"bettercombat:trident"),
new CompatibilitySpecifier(
"katana",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package net.bettercombat.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.RangedWeaponItem;
import net.minecraft.util.Hand;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(RangedWeaponItem.class)
public class RangedWeaponItemMixin {

/**
* FEATURE: Two-handed wielding
*
* Two-handed weapons (such as Heavy Crossbow) disable offhand slot.
* Disabled offhand slot returns `EMPTY` stack when queried using:
* - getStackInHand(Hand.OFF_HAND)
* - getOffHandStack()
*
* This causes two-handed ranged weapons to no longer prioritize offhand projectiles.
* This mixin fixes that.
*/

@WrapOperation(
method = "getHeldProjectile",
require = 0, // Make this optional, it is not worth crashing the game over
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getStackInHand(Lnet/minecraft/util/Hand;)Lnet/minecraft/item/ItemStack;"))
private static ItemStack getHeldProjectile_Wrapped_BetterCombat(
// Mixin Parameters
LivingEntity entity, Hand hand, Operation<ItemStack> original
// Context Parameters (not needed)
// LivingEntity entity, Predicate<ItemStack> predicate
) {
var originalResult = original.call(entity, hand); // Always call original first to allow others' side effects
if (entity instanceof PlayerEntity player) {
return player.getInventory().offHand.get(0);
} else {
return originalResult;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import dev.kosmx.playerAnim.core.util.Vec3f;
import dev.kosmx.playerAnim.impl.IAnimatedPlayer;
import net.bettercombat.BetterCombat;
import net.bettercombat.Platform;
import net.bettercombat.client.BetterCombatClient;
import net.bettercombat.client.animation.AnimationRegistry;
import net.bettercombat.client.animation.PlayerAttackAnimatable;
Expand Down Expand Up @@ -73,7 +74,11 @@ public void updateAnimationsOnTick() {
var mainHandStack = player.getMainHandStack();
// No pose during special activities

if (player.handSwinging || player.isSwimming() || player.isUsingItem() || CrossbowItem.isCharged(mainHandStack)) {
if (player.handSwinging // Official mapping name: `isHandBusy`
|| player.isSwimming()
|| player.isUsingItem()
|| Platform.isCastingSpell(player)
|| CrossbowItem.isCharged(mainHandStack)) {
mainHandBodyPose.setPose(null, isLeftHanded);
mainHandItemPose.setPose(null, isLeftHanded);
offHandBodyPose.setPose(null, isLeftHanded);
Expand Down
14 changes: 10 additions & 4 deletions common/src/main/java/net/bettercombat/network/ServerNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.bettercombat.mixin.LivingEntityAccessor;
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;
Expand All @@ -29,9 +28,7 @@
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;
Expand Down Expand Up @@ -62,10 +59,19 @@ public static void initializeHandlers() {
return;
}
final var packet = Packets.AttackAnimation.read(buf);

final var forwardBuffer = new Packets.AttackAnimation(player.getId(), packet.animatedHand(), packet.animationName(), packet.length(), packet.upswing());
try {
//send info back for Replaymod Compat
if (ServerPlayNetworking.canSend(player, Packets.AttackAnimation.ID)) {
ServerPlayNetworking.send(player, Packets.AttackAnimation.ID, forwardBuffer.write());
}
} 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.write());
}
} catch (Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"text.autoconfig.bettercombat.option.client.isSmoothAnimationTransitionEnabled": "Alisar transiciones animación",
"text.autoconfig.bettercombat.option.client.isSmoothAnimationTransitionEnabled.@Tooltip": "Las transiciones de animación de ataque se alisan a expensas de la fidelidad de la animación",
"text.autoconfig.bettercombat.option.client.isTooltipAttackRangeEnabled": "Tooltip del ítem: Alcance de golpe",
"text.autoconfig.bettercombat.option.client.isTooltipAttackRangeEnabled.@Tooltip": "Mostrar el valor del rango de ataque en la información sobre herramientas del arma"
"text.autoconfig.bettercombat.option.client.isTooltipAttackRangeEnabled.@Tooltip": "Mostrar el valor del rango de ataque en la información sobre herramientas del arma",
"text.autoconfig.bettercombat.option.client.weaponSwingSoundVolume" : "Porcentaje de volumen del sonido de blandiendo de arma",
"text.autoconfig.bettercombat.option.client.weaponSwingSoundVolume.@Tooltip" : "Cambiar el volumen de los sonidos de blandiendo de armas",
"text.autoconfig.bettercombat.option.client.isSweepingParticleEnabled" : "Mostrar partículas de blandiendo",
Expand Down
Loading

0 comments on commit 03ae32e

Please sign in to comment.