Skip to content

Commit

Permalink
Add soft compatibility with Spell Engine, disable idle animation whil…
Browse files Browse the repository at this point in the history
…e casting spells
  • Loading branch information
ZsoltMolnarrr committed Nov 1, 2023
1 parent 21386d9 commit 72a7853
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.8.2

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

# 1.8.1

- (Forge) fix hand swap deleting offhand item, when holding two handed items.
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(); }
}
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
8 changes: 8 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ repositories {
maven { url 'https://jitpack.io' }
maven { url 'https://maven.shedaniel.me' }
maven { url 'https://maven.terraformersmc.com' }
maven {
name = 'Modrinth'
url = 'https://api.modrinth.com/maven'
content {
includeGroup 'maven.modrinth'
}
}
}

dependencies {
Expand All @@ -42,6 +49,7 @@ dependencies {
// modImplementation(files("../fabric/run/mods/dev/player-animation-lib-fabric-${project.player_anim_version}.jar"))
shadowCommon(implementation ("com.github.ZsoltMolnarrr:TinyConfig:${project.tiny_config_version}"))
// modApi include("com.github.ZsoltMolnarrr:TinyConfig:${project.tiny_config_version}")
modCompileOnly("maven.modrinth:spell-engine:${project.spell_engine_version}")
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.bettercombat.fabric;

import net.bettercombat.Platform;
import net.bettercombat.fabric.client.SpellEngineCompatibility;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.player.PlayerEntity;

import static net.bettercombat.Platform.Type.FABRIC;

Expand All @@ -13,4 +15,8 @@ public static Platform.Type getPlatformType() {
public static boolean isModLoaded(String modid) {
return FabricLoader.getInstance().isModLoaded(modid);
}

public static boolean isCastingSpell(PlayerEntity player) {
return SpellEngineCompatibility.isCastingSpell(player);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.bettercombat.fabric.client;

import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.player.PlayerEntity;
import net.spell_engine.internals.casting.SpellCasterEntity;

public class SpellEngineCompatibility {
private static Boolean isLoaded = null;
public static boolean isCastingSpell(PlayerEntity player) {
if (isLoaded == null) {
isLoaded = FabricLoader.getInstance().isModLoaded("spell_engine");
}
if (isLoaded) {
// return (SpellCasterEntity) .isCastingSpell(player);
return ((SpellCasterEntity)player).getCurrentSpell() != null;
}
return false;
}
}
5 changes: 5 additions & 0 deletions forge/src/main/java/net/bettercombat/forge/PlatformImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.bettercombat.forge;

import net.bettercombat.Platform;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.fml.ModList;

import static net.bettercombat.Platform.Type.FORGE;
Expand All @@ -13,4 +14,8 @@ public static Platform.Type getPlatformType() {
public static boolean isModLoaded(String modid) {
return ModList.get().isLoaded(modid);
}

public static boolean isCastingSpell(PlayerEntity player) {
return false;
}
}
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ loader_version=0.14.21
forge_version=47.2.0

# Mod Properties
mod_version=1.8.1
mod_version=1.8.2
maven_group=net
archives_base_name=bettercombat

Expand All @@ -27,4 +27,5 @@ tiny_config_version=2.3.2
# Compatibility
mod_menu_version=7.0.1
#https://modrinth.com/mod/first-person-model/version/evkvoubL = 2.2.3-1.20
fpm_version=evkvoubL
fpm_version=evkvoubL
spell_engine_version=0.12.0+1.20.1

0 comments on commit 72a7853

Please sign in to comment.