Skip to content

Commit

Permalink
Merge pull request #28 from KosmX/port_1.18
Browse files Browse the repository at this point in the history
Backport fixes to 1.18
  • Loading branch information
KosmX authored Nov 16, 2022
2 parents 309f129 + a6b67b0 commit f215a9a
Show file tree
Hide file tree
Showing 34 changed files with 269 additions and 95 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ If you want to add new entities, use [Geckolib](https://geckolib.com/#mods)

If you want to trigger simple animations from the server, you might want to use [Emotecraft's server-side API](https://github.com/KosmX/emotes/tree/dev/emotesAPI/src/main/java/io/github/kosmx/emotes/api/events/server).

## Official projects
**GitHub project** https://github.com/KosmX/minecraftPlayerAnimator
**Modrinth** https://modrinth.com/mod/playeranimator
**CurseForge** https://www.curseforge.com/minecraft/mc-mods/playeranimator
**KosmX's Maven (for API use)** https://maven.kosmx.dev/dev/kosmx/player-anim/
> Avoid downloading the library from other sources!

## Example mods
[Fabric example](https://github.com/KosmX/fabricPlayerAnimatorExample)
[Forge example](https://github.com/KosmX/forgePlayerAnimatorExample)
Expand All @@ -29,7 +37,7 @@ dependencies {
include modImplementation("dev.kosmx.player-anim:player-animation-lib-fabric:${project.player_anim}")
//You might want bendy-lib. playerAnimator will wrap it.
//include runtimeOnly("io.github.kosmx.bendy-lib:bendy-lib-fabric:${project.bendylib_version}")
//include modRuntimeOnly("io.github.kosmx.bendy-lib:bendy-lib-fabric:${project.bendylib_version}")
}
```
Expand Down Expand Up @@ -146,8 +154,13 @@ To load an animation, put the file(s) into `assets/modid/player_animation/`
Then you can get the animation with `dev.kosmx.playerAnim.minecraftApi.PlayerAnimationRegistry#getAnimation()`

## Notes
> GeckoLib is not guaranteed to work, but you can try! (It will work most of the time)
> [molang](https://docs.microsoft.com/minecraft/creator/reference/content/molangreference/) is not supported
GeckoLib is not guaranteed to work, but you can try! (It will work most of the time)
[molang](https://docs.microsoft.com/minecraft/creator/reference/content/molangreference/) is not supported
***
Do **not** shadow the library in your mod, this library can not be loaded multiple times safely. (even from different packages)
> The license would allow it, but it would break many things.
You may use `include`(fabric any version) or JarJar(forge 1.19.1+).



## If you have questions, feel free to ask on Discord:
Expand Down
14 changes: 12 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "0.12.0-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.0.+" apply false

//Publishing
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
Expand Down Expand Up @@ -28,7 +28,17 @@ allprojects {
name 'KosmX\'s maven'
url 'https://maven.kosmx.dev/'
}
mavenLocal()
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
*/
public class GeckoLibSerializer {
public static List<KeyframeAnimation> serialize(JsonObject node){
return readAnimations(node.get("animations").getAsJsonObject());
try {
return readAnimations(node.get("animations").getAsJsonObject());
} catch(NumberFormatException e) {
throw new JsonParseException(e);
}
}

private static List<KeyframeAnimation> readAnimations(JsonObject jsonEmotes){
Expand Down Expand Up @@ -79,7 +83,7 @@ private static void readBone(KeyframeAnimation.StateCollection stateCollection,
if(entry.getKey().equals("vector")){
readCollection(getRots(stateCollection), 0, Ease.LINEAR, entry.getValue().getAsJsonArray(), emoteData, false);
}
else {
else if (!entry.getKey().equals("easing")) {
int tick = (int) (Float.parseFloat(entry.getKey()) * 20);
if (entry.getValue().isJsonArray()) {
readCollection(getRots(stateCollection), tick, Ease.CONSTANT, entry.getValue().getAsJsonArray(), emoteData, false);
Expand All @@ -100,7 +104,7 @@ private static void readBone(KeyframeAnimation.StateCollection stateCollection,
jsonPosition.getAsJsonObject().entrySet().forEach(entry -> {
if(entry.getKey().equals("vector")){
readCollection(getOffs(stateCollection), 0, Ease.LINEAR, entry.getValue().getAsJsonArray(), emoteData, true);
}else {
}else if (!entry.getKey().equals("easing")) {
int tick = (int) (Float.parseFloat(entry.getKey()) * 20);
if (entry.getValue().isJsonArray()) {
readCollection(getOffs(stateCollection), tick, Ease.LINEAR, entry.getValue().getAsJsonArray(), emoteData, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import dev.kosmx.playerAnim.api.layered.IAnimation;
import dev.kosmx.playerAnim.core.util.Pair;
import dev.kosmx.playerAnim.core.util.Vec3f;
import org.jetbrains.annotations.ApiStatus;

/**
* Tool to easily play animation to the player.
* internal, do not use
*/
@ApiStatus.Internal
public class AnimationProcessor {
private final IAnimation animation;
private float tickDelta = 0f;
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ enabled_platforms=fabric,forge

archives_base_name=player-animation-lib
#Major: API break, Minor: non-breaking but significant, Patch: minor bugfix/change + MC implementation fix
mod_version=0.4.0-test1
mod_version=0.4.0-test4
maven_group=dev.kosmx.player-anim


Expand All @@ -14,4 +14,4 @@ fabric_api_version=0.58.0+1.18.2

forge_version=1.18.2-40.1.80

bendy_lib=2.1.1
bendy_lib=2.1.3-test2
1 change: 1 addition & 0 deletions minecraft/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
//modApi "dev.architectury:architectury:${rootProject.architectury_version}"

modCompileOnly "io.github.kosmx.bendy-lib:bendy-lib:${project.bendy_lib}"
modCompileOnly "maven.modrinth:3dskinlayers:1.5.2-fabric-1.19"

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package dev.kosmx.playerAnim.impl;

import dev.architectury.injectables.annotations.ExpectPlatform;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.concurrent.atomic.AtomicBoolean;

/**
* Helper Utility class
*/
@ApiStatus.Internal
public final class Helper {

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import dev.kosmx.playerAnim.api.IPlayer;
import dev.kosmx.playerAnim.impl.animation.AnimationApplier;
import org.jetbrains.annotations.ApiStatus;


@ApiStatus.Internal
public interface IAnimatedPlayer extends IPlayer {
AnimationApplier getAnimation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import dev.kosmx.playerAnim.core.impl.AnimationProcessor;
import dev.kosmx.playerAnim.core.util.SetableSupplier;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public interface IMutableModel {

void setEmoteSupplier(SetableSupplier<AnimationProcessor> emoteSupplier);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package dev.kosmx.playerAnim.impl;

import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public interface IPlayerModel {
void playerAnimator_prepForFirstPersonRender();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package dev.kosmx.playerAnim.impl;

import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public interface IUpperPartHelper {
boolean isUpperPart();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import dev.kosmx.playerAnim.core.util.Pair;
import dev.kosmx.playerAnim.core.util.Vec3f;
import net.minecraft.client.model.geom.ModelPart;
import org.jetbrains.annotations.ApiStatus;

@ApiStatus.Internal
public class AnimationApplier extends AnimationProcessor {
public AnimationApplier(IAnimation animation) {
super(animation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.core.Direction;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

@ApiStatus.Internal
public class BendHelper implements IBendHelper {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.core.Direction;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

@ApiStatus.Internal
public interface IBendHelper {

IBendHelper INSTANCE = Helper.isBendEnabled() ? new BendHelper() : new DummyBendable();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.kosmx.playerAnim.impl.compat.skinLayers;

import dev.kosmx.playerAnim.impl.IAnimatedPlayer;
import dev.kosmx.playerAnim.impl.IUpperPartHelper;
import dev.kosmx.playerAnim.impl.animation.IBendHelper;
import dev.tr7zw.skinlayers.api.LayerFeatureTransformerAPI;
import org.jetbrains.annotations.ApiStatus;
import org.slf4j.Logger;

@ApiStatus.Internal
public class SkinLayersTransformer {

public static void init(Logger logger) {
logger.info("Loading 3D skin compat");

LayerFeatureTransformerAPI.setLayerTransformer((player, matrixStack, modelPart) -> {
if (((IUpperPartHelper)modelPart).isUpperPart()) {
IBendHelper.rotateMatrixStack(matrixStack, ((IAnimatedPlayer) player).getAnimation().getBend("body"));
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package dev.kosmx.playerAnim.impl.mixin;

import dev.kosmx.playerAnim.impl.Helper;
import org.jetbrains.annotations.ApiStatus;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

@ApiStatus.Internal
public class MixinConfig implements IMixinConfigPlugin {

@Override
public void onLoad(String mixinPackage) {

}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (mixinClassName.endsWith("bendOnly") && !Helper.isBendEnabled()) {
return false;
}
return true;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import dev.kosmx.playerAnim.api.IPlayer;
import dev.kosmx.playerAnim.api.layered.AnimationStack;
import dev.kosmx.playerAnim.core.impl.event.Event;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.player.AbstractClientPlayer;

@Environment(EnvType.CLIENT)
public final class PlayerAnimationAccess {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import dev.kosmx.playerAnim.core.data.KeyframeAnimation;
import dev.kosmx.playerAnim.core.data.gson.AnimationSerializing;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
Expand Down Expand Up @@ -35,6 +37,7 @@
* <br><br>
* Extra animations can be added by ResourcePack(s) or other mods
*/
@Environment(EnvType.CLIENT)
public final class PlayerAnimationRegistry {

private static final HashMap<ResourceLocation, KeyframeAnimation> animations = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
package dev.kosmx.playerAnim.mixin;

import dev.kosmx.playerAnim.impl.IUpperPartHelper;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(RenderLayer.class)
public class FeatureRendererMixin implements IUpperPartHelper {
private boolean Emotecraft_isUpperPart = true;
@Unique
private boolean isUpperPart = true;


@Inject(method = "<init>", at = @At("RETURN"))
private void init(RenderLayerParent renderLayerParent, CallbackInfo ci) {
if (this.getClass().getPackageName().contains("skinlayers") && !this.getClass().getSimpleName().toLowerCase().contains("head")) {
isUpperPart = false;
}
}

@Override
public boolean isUpperPart() {
return this.Emotecraft_isUpperPart;
return this.isUpperPart;
}

@Override
public void setUpperPart(boolean bl) {
this.Emotecraft_isUpperPart = bl;
this.isUpperPart = bl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Compatibility issue: can not redirect {@link RenderLayer#render(PoseStack, MultiBufferSource, int, Entity, float, float, float, float, float, float)}
* I have to modify the matrixStack and do not forget to POP it!
*
* <p>
* I can inject into the enhanced for
* {@link List#iterator()} //initial push to keep in sync
* {@link Iterator#hasNext()} //to pop the matrix stack
Expand All @@ -37,9 +37,9 @@
* @param <M>
*/
@Mixin(LivingEntityRenderer.class)
public abstract class LivingEntityRenderRedirect<T extends Entity, M extends EntityModel<T>> extends EntityRenderer<T> implements RenderLayerParent<T, M> {
public abstract class LivingEntityRenderRedirect_bendOnly<T extends Entity, M extends EntityModel<T>> extends EntityRenderer<T> implements RenderLayerParent<T, M> {

protected LivingEntityRenderRedirect(EntityRendererProvider.Context context) {
protected LivingEntityRenderRedirect_bendOnly(EntityRendererProvider.Context context) {
super(context);
}

Expand Down
Loading

0 comments on commit f215a9a

Please sign in to comment.