This commit is contained in:
zimzaza4
2024-05-01 22:43:01 +08:00
parent 18b4008c9c
commit a9ed339af9
6 changed files with 179 additions and 60 deletions

View File

@@ -39,9 +39,10 @@ public class EntityTask {
boolean firstAnimation = true;
boolean spawnAnimationPlayed = false;
boolean removed = false;
String lastAnimation = "";
boolean looping = false;
boolean looping = true;
private BukkitRunnable syncTask;
@@ -68,54 +69,64 @@ public class EntityTask {
}
}
if (model.getEntity().isDead() && model.getModeledEntity().getBase().isAlive() && !model.getActiveModel().isRemoved()) {
if (!removed && model.getEntity().isDead() && model.getModeledEntity().getBase().isAlive() && !model.getActiveModel().isRemoved()) {
model.spawnEntity();
}
model.getEntity().setVisualFire(false);
model.teleportToModel();
}
public void runAsync() {
Entity entity = model.getEntity();
if (entity.isDead()) {
return;
}
Set<Player> viewers = model.getViewers();
ActiveModel activeModel = model.getActiveModel();
ModeledEntity modeledEntity = model.getModeledEntity();
if (activeModel.isRemoved() || !modeledEntity.getBase().isAlive()) {
if (!modeledEntity.getBase().isAlive()) {
if (!activeModel.isRemoved() && hasAnimation("death")) {
new BukkitRunnable() {
@Override
public void run() {
entity.remove();
}
}.runTaskLater(GeyserModelEngine.getInstance(), Math.min(Math.max(playAnimation("death", 999, 5f, true) - 3, 0), 200));
} else {
new BukkitRunnable() {
@Override
public void run() {
entity.remove();
}
}.runTask(GeyserModelEngine.getInstance());
}
if (!activeModel.isRemoved() && hasAnimation("death")) {
new BukkitRunnable() {
@Override
public void run() {
removed = true;
entity.remove();
}
}.runTaskLater(GeyserModelEngine.getInstance(), Math.min(Math.max(playAnimation("death", 999, 5f, true) - 3, 0), 200));
} else {
new BukkitRunnable() {
@Override
public void run() {
removed = true;
entity.remove();
}
}.runTask(GeyserModelEngine.getInstance());
}
ENTITIES.remove(modeledEntity.getBase().getEntityId());
MODEL_ENTITIES.remove(entity.getEntityId());
cancel();
return;
}
if (model.getEntity().isDead()) {
ENTITIES.remove(modeledEntity.getBase().getEntityId());
MODEL_ENTITIES.remove(entity.getEntityId());
cancel();
return;
}
/*
if (model.getEntity().isDead()) {
ENTITIES.remove(modeledEntity.getBase().getEntityId());
MODEL_ENTITIES.remove(entity.getEntityId());
cancel();
return;
}
*/
/*
if (waitingTick > 0) {
waitingTick--;
}
*/
if (!spawnAnimationPlayed) {
spawnAnimationPlayed = true;
}
if (tick > 1 && tick % 5 == 0) {
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
@@ -144,17 +155,6 @@ public class EntityTask {
}
}
if (!spawnAnimationPlayed) {
spawnAnimationPlayed = true;
if (hasAnimation("spawn")) {
playAnimation("spawn", 99);
} else {
playAnimation("idle", 0);
}
}
if (tick % 40 == 0) {
for (Player viewer : Set.copyOf(viewers)) {
@@ -204,10 +204,11 @@ public class EntityTask {
public void sendEntityData(Player player, int delay) {
// System.out.println("TYPE: " + "modelengine:" + model.getActiveModel().getBlueprint().getName().toLowerCase());
PlayerUtils.setCustomEntity(player, model.getEntity().getEntityId(), "modelengine:" + model.getActiveModel().getBlueprint().getName().toLowerCase());
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> {
// PlayerUtils.sendCustomSkin(player, model.getEntity(), model.getActiveModel().getBlueprint().getName());
if (looping) {
playBedrockAnimation("animation." + model.getActiveModel().getBlueprint().getName() + "." + lastAnimation, looping, 0f);
playBedrockAnimation(lastAnimation, Set.of(player), looping, 0f);
}
sendHitBox(player);
sendScale(player);
@@ -286,14 +287,14 @@ public class EntityTask {
// delaySend = true;
}
String id = "animation." + activeModel.getBlueprint().getName() + "." + animationProperty.getName();
String id = "animation." + activeModel.getBlueprint().getName().toLowerCase() + "." + animationProperty.getName().toLowerCase();
lastAnimation = id;
animationCooldown.set((int) (animationProperty.getLength() * 20));
if (delaySend) {
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> playBedrockAnimation("animation." + activeModel.getBlueprint().getName() + "." + animationProperty.getName(), looping, blendTime), 0);
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> playBedrockAnimation(id, model.getViewers(), looping, blendTime), 0);
} else {
playBedrockAnimation(id, looping, blendTime);
playBedrockAnimation(id, model.getViewers(), looping, blendTime);
}
}
return animationCooldown.get();
@@ -328,12 +329,11 @@ public class EntityTask {
*/
private void playBedrockAnimation(String animationId, boolean loop, float blendTime) {
public void playBedrockAnimation(String animationId, Set<Player> viewers, boolean loop, float blendTime) {
model.getViewers().forEach(viewer -> viewer.sendActionBar("CURRENT AN:" + animationId));
// model.getViewers().forEach(viewer -> viewer.sendActionBar("CURRENT AN:" + animationId));
Entity entity = model.getEntity();
Set<Player> viewers = model.getViewers();
Animation.AnimationBuilder animation = Animation.builder()
.animation(animationId)
@@ -383,6 +383,15 @@ public class EntityTask {
public void run(GeyserModelEngine instance, int i) {
String id = "";
ActiveModel activeModel = model.getActiveModel();
if (hasAnimation("spawn")) {
id = "animation." + activeModel.getBlueprint().getName().toLowerCase() + ".spawn";
} else {
id = "animation." + activeModel.getBlueprint().getName().toLowerCase() + ".idle";
}
lastAnimation = id;
sendHitBoxToAll();
syncTask = new BukkitRunnable() {
@Override

View File

@@ -1,13 +1,16 @@
package re.imc.geysermodelengine.model;
import com.google.common.collect.Sets;
import com.ticxo.modelengine.api.ModelEngineAPI;
import com.ticxo.modelengine.api.entity.BukkitEntity;
import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import re.imc.geysermodelengine.GeyserModelEngine;
import java.util.HashMap;
@@ -49,9 +52,9 @@ public class ModelEntity {
for (Player viewer : viewers) {
viewer.sendActionBar("X:" + modeledEntity.getXHeadRot() + ", Y:" + modeledEntity.getYHeadRot());
}
*/
entity.teleportAsync(location);
*/
ModelEngineAPI.getEntityHandler().setPosition(entity, location.getX(), location.getY(), location.getZ());
if (modeledEntity.getBase() instanceof BukkitEntity bukkitEntity && bukkitEntity.getOriginal() instanceof LivingEntity livingEntity) {
controllerEntity.getLookController().setHeadYaw(livingEntity.getEyeLocation().getYaw());
controllerEntity.getLookController().setPitch(livingEntity.getEyeLocation().getPitch());
@@ -89,7 +92,7 @@ public class ModelEntity {
display.setGravity(false);
display.setMaxHealth(2048);
display.setHealth(2048);
display.setMetadata("model_entity", new FixedMetadataValue(GeyserModelEngine.getInstance(), true));
//display.setInvulnerable(true);