Configure Bone Behavior
Single modification
// Get a hold of the ActiveModel you want to modify
ActiveModel model = ...
// Search for a bone called "head"
model.getBone("head").ifPresent(modelBone -> {
// Get the HEAD behavior of this bone
modelBone.getBoneBehavior(BoneBehaviorTypes.HEAD).ifPresent(head -> {
// Configure the bone behavior
head.setLocal(true);
});
});
Batch modification
// Get a hold of the ActiveModel you want to modify
ActiveModel model = ...
// Iterate through all bones on the model
model.getBones().forEach((s, modelBone) -> {
var provider = new HeldItem.StaticItemStackSupplier(new ItemStack(Material.CARVED_PUMPKIN));
// Get the ITEM behavior
modelBone.getBoneBehavior(BoneBehaviorTypes.ITEM).ifPresent(heldItem -> {
// Configure the bone behavior
heldItem.setItemProvider(provider);
});
});
Inverse kinematics and physics
IK chains and physics bones share the IK behavior. The example below ties the end
of a rope to an entity 1.2 blocks above its feet, then makes another rope heavier.
ActiveModel model = ...
model.getBone("rope_end").ifPresent(modelBone -> {
modelBone.getBoneBehavior(BoneBehaviorTypes.IK).ifPresent(ik -> {
ik.setTarget(entity, 1.2);
});
});
model.getBone("lantern").ifPresent(modelBone -> {
modelBone.getBoneBehavior(BoneBehaviorTypes.IK).ifPresent(ik -> {
ik.setGravity(30);
ik.setDamping(0.05f);
});
});
ik.setTarget(entity, modelId, boneId, yOffset) ties it to a bone of that entity's model instead, followed every tick.
modelId may be null to use the first of the entity's models that has the bone.
ActiveModel#addInverseKinematicsChain(root, tip, pole) and ActiveModel#removeInverseKinematicsChain(tip) create and
remove chains at runtime. The change is applied on the next model tick, so configure the tip bone after that.