mirror of
https://github.com/GeyserExtensionists/GeyserModelEngine.git
synced 2025-12-20 07:29:26 +00:00
Added a (okay) fix to show visibility and scale for each entity already existing. I also added authors.
This commit is contained in:
@@ -4,6 +4,7 @@ import com.google.common.base.Joiner;
|
|||||||
import com.ticxo.modelengine.api.animation.BlueprintAnimation;
|
import com.ticxo.modelengine.api.animation.BlueprintAnimation;
|
||||||
import com.ticxo.modelengine.api.entity.BaseEntity;
|
import com.ticxo.modelengine.api.entity.BaseEntity;
|
||||||
import com.ticxo.modelengine.api.entity.BukkitEntity;
|
import com.ticxo.modelengine.api.entity.BukkitEntity;
|
||||||
|
import com.ticxo.modelengine.api.generator.blueprint.BlueprintBone;
|
||||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||||
import com.ticxo.modelengine.api.model.bone.BoneBehaviorTypes;
|
import com.ticxo.modelengine.api.model.bone.BoneBehaviorTypes;
|
||||||
@@ -45,11 +46,11 @@ public class EntityTask {
|
|||||||
boolean firstAnimation = true;
|
boolean firstAnimation = true;
|
||||||
boolean spawnAnimationPlayed = false;
|
boolean spawnAnimationPlayed = false;
|
||||||
boolean removed = false;
|
boolean removed = false;
|
||||||
boolean registered = false;
|
|
||||||
|
|
||||||
float lastScale = -1.0f;
|
float lastScale = -1.0f;
|
||||||
Map<ModelBone, Boolean> lastSet = new HashMap<>();
|
Map<ModelBone, Boolean> lastSet = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
String lastAnimation = "";
|
String lastAnimation = "";
|
||||||
boolean looping = true;
|
boolean looping = true;
|
||||||
|
|
||||||
@@ -209,11 +210,12 @@ public class EntityTask {
|
|||||||
animationCooldown.decrementAndGet();
|
animationCooldown.decrementAndGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Player> player = model.getViewers().stream().findAny();
|
Optional<Player> player = viewers.stream().findAny();
|
||||||
if (player.isEmpty()) return;
|
if (player.isEmpty()) return;
|
||||||
|
|
||||||
sendScale(player.get());
|
// somehow the scale needs more to update, for now just scale each tick lol
|
||||||
updateVisibility(player.get());
|
updateVisibility(player.get(), false);
|
||||||
|
sendScale(player.get(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendEntityData(Player player, int delay) {
|
public void sendEntityData(Player player, int delay) {
|
||||||
@@ -226,14 +228,16 @@ public class EntityTask {
|
|||||||
playBedrockAnimation(lastAnimation, Set.of(player), looping, 0f);
|
playBedrockAnimation(lastAnimation, Set.of(player), looping, 0f);
|
||||||
}
|
}
|
||||||
sendHitBox(player);
|
sendHitBox(player);
|
||||||
sendScale(player);
|
sendScale(player, true);
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLaterAsynchronously(GeyserModelEngine.getInstance(), () -> {
|
||||||
sendHitBox(player);
|
sendHitBox(player);
|
||||||
|
sendScale(player, true);
|
||||||
|
updateVisibility(player, true);
|
||||||
}, 8);
|
}, 8);
|
||||||
}, delay);
|
}, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendScale(Player player) {
|
public void sendScale(Player player, boolean ignore) {
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
Vector3f scale = model.getActiveModel().getScale();
|
Vector3f scale = model.getActiveModel().getScale();
|
||||||
@@ -241,9 +245,38 @@ public class EntityTask {
|
|||||||
if (average == lastScale) return;
|
if (average == lastScale) return;
|
||||||
|
|
||||||
PlayerUtils.sendCustomScale(player, model.getEntity(), average);
|
PlayerUtils.sendCustomScale(player, model.getEntity(), average);
|
||||||
|
|
||||||
|
if (ignore) return;
|
||||||
lastScale = average;
|
lastScale = average;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateVisibility(Player player, boolean ignore) {
|
||||||
|
Entity entity = model.getEntity();
|
||||||
|
|
||||||
|
// pretty sure it gets set on the entity, so no need to send it for every single viewer (small pyramid btw)
|
||||||
|
model.getActiveModel().getBones().forEach((s,bone) -> {
|
||||||
|
if (!lastSet.containsKey(bone)) lastSet.put(bone, !bone.isVisible());
|
||||||
|
|
||||||
|
if (!lastSet.get(bone).equals(bone.isVisible()) || ignore) {
|
||||||
|
String name = unstripName(bone).toLowerCase();
|
||||||
|
PlayerUtils.sendBoolProperty(player,entity,
|
||||||
|
model.getActiveModel().getBlueprint().getName() + ":" + name, bone.isVisible());
|
||||||
|
lastSet.replace(bone, bone.isVisible());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private String unstripName(ModelBone bone) {
|
||||||
|
String name = bone.getBoneId();
|
||||||
|
if (bone.getBlueprintBone().getBehaviors().get("head") != null) {
|
||||||
|
if (!bone.getBlueprintBone().getBehaviors().get("head").isEmpty()) return "hi_" + name;
|
||||||
|
return "h_" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public void sendHitBoxToAll() {
|
public void sendHitBoxToAll() {
|
||||||
for (Player viewer : model.getViewers()) {
|
for (Player viewer : model.getViewers()) {
|
||||||
PlayerUtils.sendCustomHitBox(viewer, model.getEntity(), 0.01f, 0.01f);
|
PlayerUtils.sendCustomHitBox(viewer, model.getEntity(), 0.01f, 0.01f);
|
||||||
@@ -370,25 +403,6 @@ public class EntityTask {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateVisibility(Player player) {
|
|
||||||
Entity entity = model.getEntity();
|
|
||||||
|
|
||||||
// pretty sure it gets set on the entity, so no need to send it for every single viewer (small pyramid btw)
|
|
||||||
model.getActiveModel().getBones().forEach((s,bone) -> {
|
|
||||||
if (!lastSet.containsKey(bone)) lastSet.put(bone, !bone.isVisible());
|
|
||||||
|
|
||||||
if (!lastSet.get(bone).equals(bone.isVisible())) {
|
|
||||||
PlayerUtils.sendBoolProperty(player,entity,
|
|
||||||
model.getActiveModel().getBlueprint().getName() + ":" + bone.getBoneId().toLowerCase(), bone.isVisible());
|
|
||||||
lastSet.replace(bone, bone.isVisible());
|
|
||||||
|
|
||||||
Bukkit.getLogger().info(model.getActiveModel().getBlueprint().getName() + ":" + bone.getBoneId().toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private boolean canSee(Player player, Entity entity) {
|
private boolean canSee(Player player, Entity entity) {
|
||||||
if (!player.isOnline()) {
|
if (!player.isOnline()) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
name: GeyserModelEngine
|
name: GeyserModelEngine
|
||||||
version: '${project.version}'
|
version: '${project.version}'
|
||||||
main: re.imc.geysermodelengine.GeyserModelEngine
|
main: re.imc.geysermodelengine.GeyserModelEngine
|
||||||
|
authors:
|
||||||
|
- zimzaza4
|
||||||
|
- willem.dev
|
||||||
api-version: '1.19'
|
api-version: '1.19'
|
||||||
depend:
|
depend:
|
||||||
- ModelEngine
|
- ModelEngine
|
||||||
|
|||||||
Reference in New Issue
Block a user