Skip to content

Commit

Permalink
add(relevant mixins + interfaces for animation)
Browse files Browse the repository at this point in the history
  • Loading branch information
JRepo42 committed Aug 26, 2023
1 parent d739e4a commit b97998b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package elocindev.shield_overhaul.mixin;


import com.mojang.authlib.GameProfile;
import dev.kosmx.playerAnim.api.layered.IAnimation;
import dev.kosmx.playerAnim.api.layered.ModifierLayer;
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationAccess;
import elocindev.shield_overhaul.util.IShieldAnimatedPlayer;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.network.encryption.PlayerPublicKey;
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(AbstractClientPlayerEntity.class)
public class ClientPlayerEntityMixin implements IShieldAnimatedPlayer {

//Unique annotation will rename private methods/fields if needed to avoid collisions.
@Unique
private final ModifierLayer<IAnimation> modAnimationContainer = new ModifierLayer<>();

/**
* Add the animation registration to the end of the constructor
* Or you can use {@link dev.kosmx.playerAnim.minecraftApi.PlayerAnimationAccess#REGISTER_ANIMATION_EVENT} event for this
*/
@Inject(method = "<init>", at = @At(value = "RETURN"))
private void init(ClientWorld world, GameProfile profile, PlayerPublicKey publicKey, CallbackInfo ci) {
//Mixin does not know (yet) that this will be merged with AbstractClientPlayerEntity
PlayerAnimationAccess.getPlayerAnimLayer((AbstractClientPlayerEntity) (Object)this).addAnimLayer(1000, modAnimationContainer); //Register the layer with a priority
//The priority will tell, how important is this animation compared to other mods. Higher number means higher priority
//Mods with higher priority will override the lower priority mods (if they want to animation anything)
}

/**
* Override the interface function, so we can use it in the future
*/
@Override
public ModifierLayer<IAnimation> shield_overhaul_getModAnimation() {
return modAnimationContainer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package elocindev.shield_overhaul.util;

import dev.kosmx.playerAnim.api.layered.IAnimation;
import dev.kosmx.playerAnim.api.layered.ModifierLayer;

public interface IShieldAnimatedPlayer {
ModifierLayer<IAnimation> shield_overhaul_getModAnimation();
}
3 changes: 2 additions & 1 deletion src/main/resources/shield_overhaul.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"ServerPlayerMixin",
"BackgroundRendererMixin"
"BackgroundRendererMixin",
"ClientPlayerEntityMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit b97998b

Please sign in to comment.