mirror of
https://github.com/GeyserExtensionists/GeyserModelEngine.git
synced 2025-12-23 08:59:22 +00:00
custom entity
This commit is contained in:
@@ -88,7 +88,7 @@ public class EntityTask {
|
||||
public void run() {
|
||||
entity.remove();
|
||||
}
|
||||
}.runTaskLater(GeyserModelEngine.getInstance(), Math.min(Math.max(playAnimation(animation, 99) - 1, 0), 200));
|
||||
}.runTaskLater(GeyserModelEngine.getInstance(), Math.min(Math.max(playAnimation(animation, 99, 50f) - 1, 0), 200));
|
||||
} else {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
@@ -199,34 +199,32 @@ public class EntityTask {
|
||||
}
|
||||
|
||||
public void sendEntityData(Player player, int delay) {
|
||||
System.out.println("SEND CUSTOM ENTITY");
|
||||
PlayerUtils.setCustomEntity(player, model.getEntity().getEntityId(), "modelengine:" + model.getActiveModel().getBlueprint().getName());
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> {
|
||||
// PlayerUtils.sendCustomSkin(player, model.getEntity(), model.getActiveModel().getBlueprint().getName());
|
||||
playBedrockAnimation("animation." + model.getActiveModel().getBlueprint().getName() + "." + lastAnimation, looping);
|
||||
playBedrockAnimation("animation." + model.getActiveModel().getBlueprint().getName() + "." + lastAnimation, looping, 0f);
|
||||
sendHitBox(player);
|
||||
sendScale(player);
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> {
|
||||
sendHitBox(player);
|
||||
}, 8);
|
||||
}, delay);
|
||||
}
|
||||
|
||||
public void sendScale(Player player) {
|
||||
// todo?
|
||||
}
|
||||
|
||||
public void sendHitBoxToAll() {
|
||||
for (Player viewer : model.getViewers()) {
|
||||
if (model.getModeledEntity().getBase() instanceof BukkitEntity bukkitEntity) {
|
||||
@NotNull BoundingBox box = bukkitEntity.getOriginal().getBoundingBox();
|
||||
PlayerUtils.sendCustomHitBox(viewer, model.getEntity(), (float) box.getHeight(), (float) ((box.getWidthX() + box.getWidthZ()) / 2f));
|
||||
// huh i dont know how to deal with width
|
||||
}
|
||||
PlayerUtils.sendCustomHitBox(viewer, model.getEntity(), 0.01f, 0.01f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void sendHitBox(Player viewer) {
|
||||
if (model.getModeledEntity().getBase() instanceof BukkitEntity bukkitEntity) {
|
||||
@NotNull BoundingBox box = bukkitEntity.getOriginal().getBoundingBox();
|
||||
PlayerUtils.sendCustomHitBox(viewer, model.getEntity(), (float) box.getHeight(), (float) ((box.getWidthX() + box.getWidthZ()) / 2f));
|
||||
// huh i dont know how to deal with width
|
||||
}
|
||||
PlayerUtils.sendCustomHitBox(viewer, model.getEntity(), 0.01f, 0.01f);
|
||||
|
||||
}
|
||||
|
||||
public boolean hasAnimation(String animation) {
|
||||
@@ -234,7 +232,11 @@ public class EntityTask {
|
||||
BlueprintAnimation animationProperty = activeModel.getBlueprint().getAnimations().get(animation);
|
||||
return !(animationProperty == null);
|
||||
}
|
||||
|
||||
public int playAnimation(String animation, int p) {
|
||||
return playAnimation(animation, p, 5f);
|
||||
}
|
||||
public int playAnimation(String animation, int p, float blendTime) {
|
||||
|
||||
ActiveModel activeModel = model.getActiveModel();
|
||||
|
||||
@@ -282,9 +284,9 @@ public class EntityTask {
|
||||
|
||||
animationCooldown.set((int) (animationProperty.getLength() * 20));
|
||||
if (delaySend) {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> playBedrockAnimation("animation." + activeModel.getBlueprint().getName() + "." + animationProperty.getName(), looping), 2);
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> playBedrockAnimation("animation." + activeModel.getBlueprint().getName() + "." + animationProperty.getName(), looping, blendTime), 2);
|
||||
} else {
|
||||
playBedrockAnimation(id, looping);
|
||||
playBedrockAnimation(id, looping, blendTime);
|
||||
}
|
||||
}
|
||||
return animationCooldown.get();
|
||||
@@ -319,7 +321,7 @@ public class EntityTask {
|
||||
|
||||
|
||||
*/
|
||||
private void playBedrockAnimation(String animationId, boolean loop) {
|
||||
private void playBedrockAnimation(String animationId, boolean loop, float blendTime) {
|
||||
|
||||
// model.getViewers().forEach(viewer -> viewer.sendActionBar("CURRENT AN:" + animationId));
|
||||
|
||||
@@ -328,7 +330,7 @@ public class EntityTask {
|
||||
|
||||
Animation.AnimationBuilder animation = Animation.builder()
|
||||
.animation(animationId)
|
||||
.blendOutTime(0f)
|
||||
.blendOutTime(blendTime)
|
||||
.controller("controller.animation.armor_stand.wiggle");
|
||||
|
||||
if (loop) {
|
||||
|
||||
@@ -5,26 +5,14 @@ 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 me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.zimzaza4.geyserutils.spigot.api.PlayerUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.geysermc.floodgate.api.FloodgateApi;
|
||||
import re.imc.geysermodelengine.GeyserModelEngine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Getter
|
||||
@@ -82,22 +70,11 @@ public class ModelEntity {
|
||||
|
||||
public LivingEntity spawnEntity() {
|
||||
ModelEntity model = this;
|
||||
int lastEntityId = ReflectionManager.getNewEntityId();
|
||||
// int lastEntityId = ReflectionManager.getNewEntityId();
|
||||
// System.out.println("RID:" + entityId);
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (FloodgateApi.getInstance().isFloodgatePlayer(onlinePlayer.getUniqueId())) {
|
||||
PlayerUtils.setCustomEntity(onlinePlayer, lastEntityId + 1, "modelengine:" + model.getActiveModel().getBlueprint().getName());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
GeyserModelEngine.getInstance().setSpawningModelEntity(true);
|
||||
GeyserModelEngine.getInstance().setCurrentModel(model);
|
||||
entity = (LivingEntity) modeledEntity.getBase().getLocation().getWorld().spawnEntity(modeledEntity.getBase().getLocation(), GeyserModelEngine.getInstance().getModelEntityType());
|
||||
|
||||
int id = entity.getEntityId();
|
||||
|
||||
MODEL_ENTITIES.put(id, model);
|
||||
applyFeatures(entity, "model." + activeModel.getBlueprint().getName());
|
||||
|
||||
controllerEntity = new BukkitEntity(entity);
|
||||
return entity;
|
||||
}
|
||||
@@ -108,7 +85,7 @@ public class ModelEntity {
|
||||
}
|
||||
|
||||
|
||||
private void applyFeatures(LivingEntity display, String name) {
|
||||
public void applyFeatures(LivingEntity display, String name) {
|
||||
display.setGravity(false);
|
||||
display.setMaxHealth(2048);
|
||||
display.setHealth(2048);
|
||||
|
||||
Reference in New Issue
Block a user