|
| 1 | +package world |
| 2 | + |
| 3 | +// EntityAnimation represents an animation that may be played on an entity from an active resource pack on |
| 4 | +// the client. |
| 5 | +type EntityAnimation struct { |
| 6 | + name string |
| 7 | + nextState string |
| 8 | + controller string |
| 9 | + stopCondition string |
| 10 | +} |
| 11 | + |
| 12 | +// NewEntityAnimation returns a new animation that can be played on an entity. If no controller or stop |
| 13 | +// condition is set, the animation will play for its full duration, including looping. Controllers can be set |
| 14 | +// to manage multiple states of animations. It is also possible to use vanilla animations/controllers if they |
| 15 | +// work for your entity, i.e. "animation.pig.baby_transform". |
| 16 | +func NewEntityAnimation(name string) EntityAnimation { |
| 17 | + return EntityAnimation{name: name} |
| 18 | +} |
| 19 | + |
| 20 | +// Name returns the name of the animation to be played. |
| 21 | +func (a EntityAnimation) Name() string { |
| 22 | + return a.name |
| 23 | +} |
| 24 | + |
| 25 | +// Controller returns the name of the controller to be used for the animation. |
| 26 | +func (a EntityAnimation) Controller() string { |
| 27 | + return a.controller |
| 28 | +} |
| 29 | + |
| 30 | +// WithController returns a copy of the EntityAnimation with the provided animation controller. An animation |
| 31 | +// controller with the same name must be defined in a resource pack for it to work. |
| 32 | +func (a EntityAnimation) WithController(controller string) EntityAnimation { |
| 33 | + a.controller = controller |
| 34 | + return a |
| 35 | +} |
| 36 | + |
| 37 | +// NextState returns the state to transition to after the animation has finished playing within the |
| 38 | +// animation controller. |
| 39 | +func (a EntityAnimation) NextState() string { |
| 40 | + return a.nextState |
| 41 | +} |
| 42 | + |
| 43 | +// WithNextState returns a copy of the EntityAnimation with the provided state to transition to after the |
| 44 | +// animation has finished playing within the animation controller. |
| 45 | +func (a EntityAnimation) WithNextState(state string) EntityAnimation { |
| 46 | + a.nextState = state |
| 47 | + return a |
| 48 | +} |
| 49 | + |
| 50 | +// StopCondition returns the condition that must be met for the animation to stop playing. This is often |
| 51 | +// a Molang expression that can be used to query various entity properties to determine when the animation |
| 52 | +// should stop playing. |
| 53 | +func (a EntityAnimation) StopCondition() string { |
| 54 | + return a.stopCondition |
| 55 | +} |
| 56 | + |
| 57 | +// WithStopCondition returns a copy of the EntityAnimation with the provided stop condition. The stop condition |
| 58 | +// is a Molang expression that can be used to query various entity properties to determine when the animation |
| 59 | +// should stop playing. |
| 60 | +func (a EntityAnimation) WithStopCondition(condition string) EntityAnimation { |
| 61 | + a.stopCondition = condition |
| 62 | + return a |
| 63 | +} |
0 commit comments