Skip to content

First-person limbs

Package com.inovactio.akumalib.client.firstperson (client only).

A partial morph draws the first-person hand through the base mod's HumanoidMorphModel.renderFirstPersonArm. Left alone, that path has three faults, and each one shows on screen:

  • the pose: a morph model is one instance shared by every player in the form, and its parts keep the pose of the last third-person frame. Crouching leaves the arm 3.2 px lower and a swing leaves it turned aside, so fur or claws come out shifted from the hand;
  • the Black Leg leg: with a morph, the base mod asks the model for the first-person limb. If the model answers false, vanilla draws the bare arm, not the leg of a Black Leg user;
  • the aura: the base mod gives an overlay (armament Haki, Diable Jambe) to the player's own limb only when no morph replaces the hand.

These classes fix all three. Before this, the code lived twice, once in InoFruits and once in Missing Missing no Mi.

Drawing a morph limb: FirstPersonLimbs

Each method puts every part back to its rest pose before drawing, and restores the third-person pose afterwards.

Method For
render(limb, adjust, stack, vertex, ...) a limb the form replaces entirely (a hybrid's arm)
keptArm(graft, adjust, side, stack, vertex, ...) a form that keeps the player's arm and puts something on it; with an aura it draws the arm itself and lays the aura over it
leg(graft, playerLeg, side, stack, vertex, ...) the first-person limb of a Black Leg user: the player's leg (unless playerLeg is false, when the form replaces the legs), with the form's part at its rest pose
graftedLeg(stack, vertex, ..., side, graftLeg) the same leg, for a part that sits on the player's leg and must take the leg's pose (toe claws)

adjust runs after the rest pose, for what a model changes per player (the slim-arm sleeve). keptArm, leg and graftedLeg return what renderFirstPersonArm should return; after render, return true.

@Override
public boolean renderFirstPersonArm(PoseStack stack, VertexConsumer vertex, int packedLight, int overlay,
                                    float red, float green, float blue, float alpha, HumanoidArm side,
                                    boolean isLeg) {
    if (isLeg) {
        return FirstPersonLimbs.leg(this.getLeg(side), true, side, stack, vertex, packedLight, overlay,
                red, green, blue, alpha);
    }
    return FirstPersonLimbs.keptArm(this.getArm(side), null, side, stack, vertex, packedLight, overlay,
            red, green, blue, alpha);
}

Two calls per hand

With an overlay showing, the base mod calls the model twice in the same hand render: the second call carries the overlay's buffer and colour. The library tells the two calls apart by itself, so answer both the same way.

A part glued to the hand: HandGraft

Some parts must follow the arm exactly as vanilla has just drawn it: nails, scissors, a rotor. For these, the model implements HandGraft and draws nothing for the arm in renderFirstPersonArm, answering false. The library listens to RenderArmEvent, lets vanilla draw the arm, lays the base mod's coating over it (scaled like the base mod's), and then calls:

public class ScissorsModel<T extends LivingEntity> extends HumanoidMorphModel<T> implements HandGraft {

    @Override
    public boolean graftOnHands(LivingEntity entity) {
        return true;                                  // false while the graft sits elsewhere
    }

    @Override
    public void renderGraftOn(LivingEntity entity, ModelPart playerArm, HumanoidArm side, PoseStack stack,
                              MultiBufferSource buffers, int packedLight, @Nullable AbilityOverlay coating) {
        // draw the part in playerArm's pose; lay `coating` over it too when it is not null
    }
}

ArmCoating answers which overlay the base mod shows on a limb: onMainArm(entity), onNailedLimb(entity) (the main arm, or the main leg of a Black Leg user) and isCoated(entity, side).

A skin on the arm: SkinSwaps

A race's skin colour or a hybrid's scales would stop at the first-person arm: no layer draws it. The skin given through SkinSwaps (see Decoys) is the one the whole player is drawn in, and the first-person arm too: vanilla draws that arm and its sleeve in it instead of the player's skin, with or without a morph's graft (under the graft, under Armament Haki). Since 6.1.0; ArmSkins is deprecated and still works, what it registers counting as a race's skin.

// client setup: the skin the player is drawn in, or null for none
SkinSwaps.register(SkinSwaps.FORM, player -> MySkinTint.texture(player));

The texture is a whole player skin: the arm and the sleeve are read at their usual places in it. It REPLACES the skin, never goes over it: the same faces drawn twice flicker (z-fighting).

Gestures in first person: ArmGestures

Vanilla draws the first-person arm at rest, whatever the body's pose: a technique's pose never shows there. ArmGestures draws the local player's arms posed by a table of keys while a technique plays, the gesture starting the same tick as the body's animation. One engine for every fruit (AkumaLib #880, from 22 copies in Missing Missing no Mi).

A fruit's gestures are an enum that implements ArmGesture: its length, and each arm's keys {tick, xRot, yRot, zRot, pushX, pushY, pushZ, ...}, eased between (smoothstep). A null arm is not drawn. loops() plays it again and again, held() keeps it at its last key; both stop when the animation that started them ends.

public enum Gesture implements ArmGesture {
    PUNCH(8, new float[][] {{0F, 0F, 0F, 0F, 0F, 0F, 0F}, {3F, -1.5F, 0.2F, 0F, 0F, 0.1F, 0F}, {8F, 0F, 0F, 0F, 0F, 0F, 0F}}, null);
    // ticks(), right(), left() return the fields
}

// each gesture with the body's animation that starts it
public static final ArmGestures<Gesture> ARMS = new ArmGestures<>(Map.of(MyAnimations.PUNCH, Gesture.PUNCH));

// client setup, once
ArmGestures.register(MyFirstPerson.ARMS);

The arm is vanilla's, in vanilla's empty-hand frame (ArmGestures.emptyArm), in the skin the whole player is drawn in (SkinSwaps: a race's colour stays on during a gesture). Left-handed players get it mirrored. play, hold and stop start and end a gesture by hand, for one that no animation starts.

What differs from fruit to fruit is a hook, overridden in an anonymous subclass:

Hook For
gestureFor(animation) a condition (only in a hybrid form), a gesture picked by the animation's length, something started with it
endsWithAnimation(gesture) every gesture cut with its pose, not only the held and looping ones
time(player, gesture, t) a key held while something lasts (a fist kept clenched on a pouch)
pose(gesture, mainHand, t) keys moved by code (a recoil)
model, skin, armLength another arm (a stone giant's), another skin, a child's short arm
afterimages(player, gesture) the arms drawn again behind themselves, translucent, in a tint
dress(arm) something laid on the arm just drawn: HandGrafts.dress(...) lays the coating and the active graft as on vanilla's arm
drawMore(gesture, view) something drawn after the arms (a raised leg, a cannon)