mirror of
https://github.com/GeyserExtensionists/GeyserModelEngine.git
synced 2025-12-19 15:09:18 +00:00
Animation controller properties
This commit is contained in:
@@ -37,16 +37,18 @@ public class EntityTask {
|
|||||||
AtomicInteger animationCooldown = new AtomicInteger(0);
|
AtomicInteger animationCooldown = new AtomicInteger(0);
|
||||||
AtomicInteger currentAnimationPriority = new AtomicInteger(0);
|
AtomicInteger currentAnimationPriority = new AtomicInteger(0);
|
||||||
|
|
||||||
boolean firstAnimation = true;
|
|
||||||
boolean spawnAnimationPlayed = false;
|
boolean spawnAnimationPlayed = false;
|
||||||
boolean removed = false;
|
boolean removed = false;
|
||||||
|
|
||||||
float lastScale = -1.0f;
|
float lastScale = -1.0f;
|
||||||
Color lastColor = null;
|
Color lastColor = null;
|
||||||
Map<ModelBone, Boolean> lastSet = new HashMap<>();
|
Map<ModelBone, Boolean> lastModelBoneSet = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
String lastAnimation = "";
|
String lastAnimation = "";
|
||||||
|
String currentAnimProperty = "anim_spawn";
|
||||||
|
String lastAnimProperty = "";
|
||||||
|
|
||||||
boolean looping = true;
|
boolean looping = true;
|
||||||
|
|
||||||
private BukkitRunnable syncTask;
|
private BukkitRunnable syncTask;
|
||||||
@@ -67,7 +69,7 @@ public class EntityTask {
|
|||||||
Set<Player> viewers = model.getViewers();
|
Set<Player> viewers = model.getViewers();
|
||||||
ActiveModel activeModel = model.getActiveModel();
|
ActiveModel activeModel = model.getActiveModel();
|
||||||
ModeledEntity modeledEntity = model.getModeledEntity();
|
ModeledEntity modeledEntity = model.getModeledEntity();
|
||||||
if (activeModel.isRemoved() || !modeledEntity.getBase().isAlive()) {
|
if (activeModel.isDestroyed() || activeModel.isRemoved() || !modeledEntity.getBase().isAlive()) {
|
||||||
if (!activeModel.isRemoved() && hasAnimation("death")) {
|
if (!activeModel.isRemoved() && hasAnimation("death")) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
@@ -91,20 +93,6 @@ public class EntityTask {
|
|||||||
cancel();
|
cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if (model.getEntity().isDead()) {
|
|
||||||
ENTITIES.remove(modeledEntity.getBase().getEntityId());
|
|
||||||
MODEL_ENTITIES.remove(entity.getEntityId());
|
|
||||||
cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
if (waitingTick > 0) {
|
|
||||||
waitingTick--;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!spawnAnimationPlayed) {
|
if (!spawnAnimationPlayed) {
|
||||||
spawnAnimationPlayed = true;
|
spawnAnimationPlayed = true;
|
||||||
@@ -120,18 +108,6 @@ public class EntityTask {
|
|||||||
if (!viewers.contains(onlinePlayer)) {
|
if (!viewers.contains(onlinePlayer)) {
|
||||||
sendSpawnPacket(onlinePlayer);
|
sendSpawnPacket(onlinePlayer);
|
||||||
viewers.add(onlinePlayer);
|
viewers.add(onlinePlayer);
|
||||||
/*
|
|
||||||
if (GeyserModelEngine.getInstance().getSkinSendDelay() > 0) {
|
|
||||||
sendEntityData(onlinePlayer, GeyserModelEngine.getInstance().getSkinSendDelay());
|
|
||||||
} else {
|
|
||||||
PlayerUtils.sendCustomSkin(onlinePlayer, model.getEntity(), activeModel.getBlueprint().getName());
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> {
|
|
||||||
sendHitBox(onlinePlayer);
|
|
||||||
}, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (viewers.contains(onlinePlayer)) {
|
if (viewers.contains(onlinePlayer)) {
|
||||||
@@ -149,15 +125,6 @@ public class EntityTask {
|
|||||||
if (!canSee(viewer, model.getEntity())) {
|
if (!canSee(viewer, model.getEntity())) {
|
||||||
viewers.remove(viewer);
|
viewers.remove(viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
if (GeyserModelEngine.isAlwaysSendSkin()) {
|
|
||||||
PlayerUtils.sendCustomSkin(viewer, model.getEntity(), activeModel.getBlueprint().getName());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,9 +144,11 @@ public class EntityTask {
|
|||||||
} else if (base.isJumping() && hasAnimation("jump")) {
|
} else if (base.isJumping() && hasAnimation("jump")) {
|
||||||
playAnimation("jump", 30);
|
playAnimation("jump", 30);
|
||||||
} else if (base.isWalking() && hasAnimation("walk")) {
|
} else if (base.isWalking() && hasAnimation("walk")) {
|
||||||
playAnimation("walk", 20);
|
setAnimationProperty("modelengine:anim_walk");
|
||||||
|
// playAnimation("walk", 20);
|
||||||
} else if (hasAnimation("idle")) {
|
} else if (hasAnimation("idle")) {
|
||||||
playAnimation("idle", 0);
|
// playAnimation("idle", 0);
|
||||||
|
setAnimationProperty("modelengine:anim_idle");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (animationCooldown.get() > 0) {
|
if (animationCooldown.get() > 0) {
|
||||||
@@ -189,7 +158,9 @@ public class EntityTask {
|
|||||||
Optional<Player> player = viewers.stream().findAny();
|
Optional<Player> player = viewers.stream().findAny();
|
||||||
if (player.isEmpty()) return;
|
if (player.isEmpty()) return;
|
||||||
|
|
||||||
updateVisibility(player.get(), false);
|
// i think properties need send to all players
|
||||||
|
// because lastSet
|
||||||
|
viewers.forEach(viewer -> updateEntityProperties(player.get(), false));
|
||||||
|
|
||||||
// do not actually use this, atleast bundle these up ;(
|
// do not actually use this, atleast bundle these up ;(
|
||||||
sendScale(player.get(), true);
|
sendScale(player.get(), true);
|
||||||
@@ -225,7 +196,7 @@ public class EntityTask {
|
|||||||
}
|
}
|
||||||
sendHitBox(player);
|
sendHitBox(player);
|
||||||
sendScale(player, true);
|
sendScale(player, true);
|
||||||
updateVisibility(player, true);
|
updateEntityProperties(player, true);
|
||||||
}, 8);
|
}, 8);
|
||||||
}, delay);
|
}, delay);
|
||||||
}
|
}
|
||||||
@@ -255,21 +226,29 @@ public class EntityTask {
|
|||||||
lastColor = color;
|
lastColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateVisibility(Player player, boolean ignore) {
|
public void setAnimationProperty(String currentAnimProperty) {
|
||||||
|
this.lastAnimProperty = currentAnimProperty;
|
||||||
|
this.currentAnimProperty = currentAnimProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateEntityProperties(Player player, boolean ignore) {
|
||||||
Entity entity = model.getEntity();
|
Entity entity = model.getEntity();
|
||||||
|
|
||||||
Map<String, Boolean> updates = new HashMap<>();
|
Map<String, Boolean> updates = new HashMap<>();
|
||||||
model.getActiveModel().getBones().forEach((s,bone) -> {
|
model.getActiveModel().getBones().forEach((s,bone) -> {
|
||||||
if (!lastSet.containsKey(bone)) lastSet.put(bone, !bone.isVisible());
|
if (!lastModelBoneSet.containsKey(bone)) lastModelBoneSet.put(bone, !bone.isVisible());
|
||||||
|
|
||||||
if (!lastSet.get(bone).equals(bone.isVisible()) || ignore) {
|
if (!lastModelBoneSet.get(bone).equals(bone.isVisible()) || ignore) {
|
||||||
String name = unstripName(bone).toLowerCase();
|
String name = unstripName(bone).toLowerCase();
|
||||||
updates.put(model.getActiveModel().getBlueprint().getName() + ":" + name, bone.isVisible());
|
updates.put(model.getActiveModel().getBlueprint().getName() + ":" + name, bone.isVisible());
|
||||||
lastSet.replace(bone, bone.isVisible());
|
lastModelBoneSet.replace(bone, bone.isVisible());
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
if (!lastAnimProperty.equals(currentAnimProperty)) {
|
||||||
|
updates.put(lastAnimProperty, false);
|
||||||
|
updates.put(currentAnimProperty, true);
|
||||||
|
}
|
||||||
if (updates.isEmpty()) return;
|
if (updates.isEmpty()) return;
|
||||||
PlayerUtils.sendBoolProperties(player, entity, updates);
|
PlayerUtils.sendBoolProperties(player, entity, updates);
|
||||||
}
|
}
|
||||||
@@ -324,17 +303,10 @@ public class EntityTask {
|
|||||||
} else if (animationCooldown.get() == 0) {
|
} else if (animationCooldown.get() == 0) {
|
||||||
play = true;
|
play = true;
|
||||||
}
|
}
|
||||||
boolean delaySend = false;
|
|
||||||
if (firstAnimation) {
|
|
||||||
delaySend = true;
|
|
||||||
firstAnimation = false;
|
|
||||||
}
|
|
||||||
boolean lastLoopState = looping;
|
|
||||||
looping = forceLoop || animationProperty.getLoopMode() == BlueprintAnimation.LoopMode.LOOP;;
|
looping = forceLoop || animationProperty.getLoopMode() == BlueprintAnimation.LoopMode.LOOP;;
|
||||||
|
|
||||||
if (lastAnimation.equals(animation)) {
|
if (lastAnimation.equals(animation)) {
|
||||||
if (looping) {
|
if (looping) {
|
||||||
// play = waitingTick == 1;
|
|
||||||
play = false;
|
play = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -342,23 +314,16 @@ public class EntityTask {
|
|||||||
|
|
||||||
|
|
||||||
if (play) {
|
if (play) {
|
||||||
|
setAnimationProperty("modelengine:anim_stop");
|
||||||
|
model.getViewers().forEach(viewer -> updateEntityProperties(viewer, true));
|
||||||
currentAnimationPriority.set(p);
|
currentAnimationPriority.set(p);
|
||||||
|
|
||||||
if (lastLoopState && !lastAnimation.equals(animation)) {
|
|
||||||
// clearLoopAnimation();
|
|
||||||
// delaySend = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String id = "animation." + activeModel.getBlueprint().getName().toLowerCase() + "." + animationProperty.getName().toLowerCase();
|
String id = "animation." + activeModel.getBlueprint().getName().toLowerCase() + "." + animationProperty.getName().toLowerCase();
|
||||||
lastAnimation = id;
|
lastAnimation = id;
|
||||||
|
|
||||||
animationCooldown.set((int) (animationProperty.getLength() * 20));
|
animationCooldown.set((int) (animationProperty.getLength() * 20));
|
||||||
if (delaySend) {
|
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> playBedrockAnimation(id, model.getViewers(), looping, blendTime), 0);
|
|
||||||
} else {
|
|
||||||
playBedrockAnimation(id, model.getViewers(), looping, blendTime);
|
playBedrockAnimation(id, model.getViewers(), looping, blendTime);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return animationCooldown.get();
|
return animationCooldown.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user