Skip to content

Commit 8e21026

Browse files
author
IanTapply22
committed
Implement idle animations
1 parent 4642438 commit 8e21026

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

src/main/java/net/jeqo/bloons/balloon/single/SingleBalloon.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package net.jeqo.bloons.balloon.single;
22

33
import com.ticxo.modelengine.api.ModelEngineAPI;
4+
import com.ticxo.modelengine.api.animation.handler.AnimationHandler;
5+
import com.ticxo.modelengine.api.model.ActiveModel;
46
import com.ticxo.modelengine.api.model.ModeledEntity;
57
import lombok.Getter;
68
import lombok.Setter;
@@ -37,7 +39,11 @@ public class SingleBalloon extends BukkitRunnable {
3739
private ArmorStand balloonArmorStand;
3840
public Chicken balloonChicken;
3941

42+
/** MEG related variables **/
4043
private ModeledEntity modeledEntity;
44+
private ActiveModel activeModel;
45+
private AnimationHandler animationHandler;
46+
private final String defaultIdleAnimationID = "idle";
4147

4248
private Location playerLocation;
4349
private Location moveLocation;
@@ -122,6 +128,15 @@ public void run() {
122128
this.teleport(playerLocation);
123129
}
124130

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+
125140
this.setPlayerLocation(this.getPlayer().getLocation());
126141
this.getPlayerLocation().setYaw(playerLocation.getYaw());
127142
this.setTicks(this.getTicks() + 1);
@@ -134,7 +149,8 @@ public void run() {
134149
public synchronized void cancel() throws IllegalStateException {
135150
if (this.getModeledEntity() != null) {
136151
// 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());
138154
}
139155
this.getBalloonArmorStand().remove();
140156
this.getBalloonChicken().remove();
@@ -234,7 +250,7 @@ public ItemStack getConfiguredBalloonVisual(String balloonID) {
234250
public void initializeBalloonArmorStand() {
235251
this.setBalloonArmorStand(this.getPlayerLocation().getWorld().spawn(this.getPlayerLocation(), ArmorStand.class));
236252
this.getBalloonArmorStand().setBasePlate(false);
237-
this.getBalloonArmorStand().setVisible(false);
253+
this.getBalloonArmorStand().setVisible(true);
238254
this.getBalloonArmorStand().setInvulnerable(true);
239255
this.getBalloonArmorStand().setCanPickupItems(false);
240256
this.getBalloonArmorStand().setGravity(false);
@@ -245,10 +261,20 @@ public void initializeBalloonArmorStand() {
245261
this.getBalloonArmorStand().getEquipment().setHelmet(this.getBalloonVisual());
246262
} else {
247263
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);
250275
} 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();
252278
}
253279
}
254280
this.getBalloonArmorStand().customName(Component.text(BalloonConfiguration.BALLOON_ARMOR_STAND_ID));

0 commit comments

Comments
 (0)