Skip to content

Commit

Permalink
Added bundle for visibility + color
Browse files Browse the repository at this point in the history
  • Loading branch information
OmeWillem committed Jul 5, 2024
1 parent 01985ec commit 68d6975
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
Binary file added libs/geyserutils-spigot-1.0-SNAPSHOT.jar
Binary file not shown.
38 changes: 24 additions & 14 deletions src/main/java/re/imc/geysermodelengine/model/EntityTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import re.imc.geysermodelengine.GeyserModelEngine;
import re.imc.geysermodelengine.listener.ModelListener;

import java.awt.*;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

Expand All @@ -48,6 +49,7 @@ public class EntityTask {
boolean removed = false;

float lastScale = -1.0f;
Color lastColor = null;
Map<ModelBone, Boolean> lastSet = new HashMap<>();


Expand Down Expand Up @@ -185,7 +187,6 @@ public void run() {
}
}


tick ++;
if (tick > 400) {
tick = 0;
Expand Down Expand Up @@ -213,9 +214,11 @@ public void run() {
Optional<Player> player = viewers.stream().findAny();
if (player.isEmpty()) return;

// somehow the scale needs more to update, for now just scale each tick lol
updateVisibility(player.get(), false);

// do not actually use this, atleast bundle these up ;(
sendScale(player.get(), true);
sendColor(player.get(), true);
}

public void sendEntityData(Player player, int delay) {
Expand Down Expand Up @@ -250,21 +253,35 @@ public void sendScale(Player player, boolean ignore) {
lastScale = average;
}

public void sendColor(Player player, boolean ignore) {
if (player == null) return;

Color color = new Color(model.getActiveModel().getDefaultTint().asARGB());
if (color.equals(lastColor)) return;

PlayerUtils.sendCustomColor(player, model.getEntity(), color);

if (ignore) return;
lastColor = color;
}

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)
Map<String, Boolean> updates = new HashMap<>();
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());
updates.put(model.getActiveModel().getBlueprint().getName() + ":" + name, bone.isVisible());
lastSet.replace(bone, bone.isVisible());
}

});

if (updates.isEmpty()) return;
PlayerUtils.sendBoolProperties(player, entity, updates);
}

private String unstripName(ModelBone bone) {
Expand Down Expand Up @@ -355,14 +372,7 @@ public int playAnimation(String animation, int p, float blendTime, boolean force
return animationCooldown.get();
}

/*
private void clearLoopAnimation() {
playStopBedrockAnimation(lastAnimation);
}
private void playStopBedrockAnimation(String animationId) {
public void playStopBedrockAnimation(String animationId) {

Entity entity = model.getEntity();
Set<Player> viewers = model.getViewers();
Expand All @@ -383,7 +393,7 @@ private void playStopBedrockAnimation(String animationId) {
}


*/

public void playBedrockAnimation(String animationId, Set<Player> viewers, boolean loop, float blendTime) {

// model.getViewers().forEach(viewer -> viewer.sendActionBar("CURRENT AN:" + animationId));
Expand Down

0 comments on commit 68d6975

Please sign in to comment.