1
1
package net .jeqo .bloons .balloon .single ;
2
2
3
3
import com .ticxo .modelengine .api .ModelEngineAPI ;
4
+ import com .ticxo .modelengine .api .animation .handler .AnimationHandler ;
5
+ import com .ticxo .modelengine .api .model .ActiveModel ;
4
6
import com .ticxo .modelengine .api .model .ModeledEntity ;
5
7
import lombok .Getter ;
6
8
import lombok .Setter ;
@@ -37,7 +39,11 @@ public class SingleBalloon extends BukkitRunnable {
37
39
private ArmorStand balloonArmorStand ;
38
40
public Chicken balloonChicken ;
39
41
42
+ /** MEG related variables **/
40
43
private ModeledEntity modeledEntity ;
44
+ private ActiveModel activeModel ;
45
+ private AnimationHandler animationHandler ;
46
+ private final String defaultIdleAnimationID = "idle" ;
41
47
42
48
private Location playerLocation ;
43
49
private Location moveLocation ;
@@ -122,6 +128,15 @@ public void run() {
122
128
this .teleport (playerLocation );
123
129
}
124
130
131
+ // If all parts of a MEG balloon exist and the idle animation exists and it isn't playing, play it
132
+ if (this .getAnimationHandler () != null ) {
133
+ if (this .getAnimationHandler ().getAnimation (this .getDefaultIdleAnimationID ()) != null ) {
134
+ if (!this .getAnimationHandler ().isPlayingAnimation (this .getDefaultIdleAnimationID ())) {
135
+ this .getAnimationHandler ().playAnimation (this .getDefaultIdleAnimationID (), 0.3 , 0.3 , 1 ,true );
136
+ }
137
+ }
138
+ }
139
+
125
140
this .setPlayerLocation (this .getPlayer ().getLocation ());
126
141
this .getPlayerLocation ().setYaw (playerLocation .getYaw ());
127
142
this .setTicks (this .getTicks () + 1 );
@@ -134,7 +149,8 @@ public void run() {
134
149
public synchronized void cancel () throws IllegalStateException {
135
150
if (this .getModeledEntity () != null ) {
136
151
// Remove the MEG model if it exists
137
- this .getModeledEntity ().removeModel (this .getBalloonType ().getMegModelID ());
152
+ ModeledEntity modeledEntity = ModelEngineAPI .getModeledEntity (this .getBalloonArmorStand ());
153
+ modeledEntity .removeModel (this .getBalloonType ().getMegModelID ());
138
154
}
139
155
this .getBalloonArmorStand ().remove ();
140
156
this .getBalloonChicken ().remove ();
@@ -234,7 +250,7 @@ public ItemStack getConfiguredBalloonVisual(String balloonID) {
234
250
public void initializeBalloonArmorStand () {
235
251
this .setBalloonArmorStand (this .getPlayerLocation ().getWorld ().spawn (this .getPlayerLocation (), ArmorStand .class ));
236
252
this .getBalloonArmorStand ().setBasePlate (false );
237
- this .getBalloonArmorStand ().setVisible (false );
253
+ this .getBalloonArmorStand ().setVisible (true );
238
254
this .getBalloonArmorStand ().setInvulnerable (true );
239
255
this .getBalloonArmorStand ().setCanPickupItems (false );
240
256
this .getBalloonArmorStand ().setGravity (false );
@@ -245,10 +261,20 @@ public void initializeBalloonArmorStand() {
245
261
this .getBalloonArmorStand ().getEquipment ().setHelmet (this .getBalloonVisual ());
246
262
} else {
247
263
try {
248
- this .setModeledEntity (ModelEngineAPI .createModeledEntity (this .getBalloonArmorStand ()));
249
- this .getModeledEntity ().addModel (ModelEngineAPI .createActiveModel (this .getBalloonType ().getMegModelID ()), true );
264
+ // Create the entity and tag it onto the armor stand
265
+ ModeledEntity modeledEntity = ModelEngineAPI .createModeledEntity (this .getBalloonArmorStand ());
266
+ ActiveModel activeModel = ModelEngineAPI .createActiveModel (this .getBalloonType ().getMegModelID ());
267
+
268
+ modeledEntity .addModel (activeModel , true );
269
+
270
+ // Set the animation handler to the one of the active model
271
+ this .setAnimationHandler (activeModel .getAnimationHandler ());
272
+
273
+ // If an idle animation exists, play it initially
274
+ this .getAnimationHandler ().playAnimation (this .getDefaultIdleAnimationID (), 0.3 , 0.3 , 1 ,true );
250
275
} catch (Exception e ) {
251
- Logger .logError ("An error occurred while creating the MEG model for the balloon " + this .getBalloonType ().getId () + "! This is most likely because the ID of the model doesn't exist in the meg-model-id field." );
276
+ Logger .logError ("An error occurred while creating the MEG model for the balloon " + this .getBalloonType ().getId () + "! This is because a MEG model error occurred." );
277
+ e .printStackTrace ();
252
278
}
253
279
}
254
280
this .getBalloonArmorStand ().customName (Component .text (BalloonConfiguration .BALLOON_ARMOR_STAND_ID ));
0 commit comments