Creating a Physics Entity

In order for an entity to behave using realistic physics, you'll need to implement EntityPhysicsElement into your existing entity class. Here's an example similar to the example mod:

public class MyCustomPhysicsEntity extends Entity implements EntityPhysicsElement {
    private final EntityRigidBody rigidBody = new EntityRigidBody(this);

    public MyCustomPhysicsEntity (EntityType<?> entityType, World world) {
        super(entityType, world);
        this.rigidBody.setMass(10); // 10 kg
    }

    @Override
    public ElementRigidBody getRigidBody() {
        return this.rigidBody;
    }
}

Last updated