mirror of
https://github.com/GeyserExtensionists/GeyserModelEngine.git
synced 2025-12-19 15:09:18 +00:00
huh
This commit is contained in:
@@ -69,7 +69,7 @@ public final class GeyserModelEngine extends JavaPlugin {
|
|||||||
private List<String> enablePartVisibilityModels = new ArrayList<>();
|
private List<String> enablePartVisibilityModels = new ArrayList<>();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(4);
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Plugin startup logic
|
// Plugin startup logic
|
||||||
@@ -108,10 +108,24 @@ public final class GeyserModelEngine extends JavaPlugin {
|
|||||||
|
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
scheduler.scheduleAtFixedRate(() -> {
|
scheduler.scheduleAtFixedRate(() -> {
|
||||||
try {
|
try {
|
||||||
for (Map<ActiveModel, ModelEntity> models : ModelEntity.ENTITIES.values()) {
|
for (Map<ActiveModel, ModelEntity> models : ModelEntity.ENTITIES.values()) {
|
||||||
models.values().forEach(ModelEntity::teleportToModel);
|
models.values().forEach(ModelEntity::teleportToModel);
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}, 10, entityPositionUpdatePeriod, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
|
|
||||||
|
scheduler.scheduleWithFixedDelay(() -> {
|
||||||
|
try {
|
||||||
|
for (Map<ActiveModel, ModelEntity> models : ModelEntity.ENTITIES.values()) {
|
||||||
|
models.values().forEach(model -> model.getTask().updateEntityProperties(model.getViewers(), false));
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
|
|||||||
@@ -114,16 +114,29 @@ public class ModelListener implements Listener {
|
|||||||
|
|
||||||
task.playAnimation("attack", 55);
|
task.playAnimation("attack", 55);
|
||||||
}
|
}
|
||||||
|
}|
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
|
public void onAnimationPlay(AnimationPlayEvent event) {
|
||||||
|
Map<ActiveModel, ModelEntity> map = ModelEntity.ENTITIES.get(event.getModel().getModeledEntity().getBase().getEntityId());
|
||||||
|
if (map == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ModelEntity model = map.get(event.getModel());
|
||||||
|
model.getTask().updateEntityProperties(model.getViewers(), false, event.getProperty().getName());
|
||||||
}
|
}
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onAnimationEnd(AnimationEndEvent event) {
|
public void onAnimationEnd(AnimationEndEvent event) {
|
||||||
|
Map<ActiveModel, ModelEntity> map = ModelEntity.ENTITIES.get(event.getModel().getModeledEntity().getBase().getEntityId());
|
||||||
|
if (map == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ModelEntity model = map.get(event.getModel());
|
||||||
|
model.getTask().updateEntityProperties(model.getViewers(), false, event.getProperty().);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
GeyserModelEngine.getInstance().getJoinedPlayer().put(event.getPlayer(), true);
|
GeyserModelEngine.getInstance().getJoinedPlayer().put(event.getPlayer(), true);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package re.imc.geysermodelengine.model;
|
package re.imc.geysermodelengine.model;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import com.ticxo.modelengine.api.animation.BlueprintAnimation;
|
import com.ticxo.modelengine.api.animation.BlueprintAnimation;
|
||||||
import com.ticxo.modelengine.api.animation.ModelState;
|
import com.ticxo.modelengine.api.animation.ModelState;
|
||||||
import com.ticxo.modelengine.api.animation.handler.AnimationHandler;
|
import com.ticxo.modelengine.api.animation.handler.AnimationHandler;
|
||||||
@@ -28,6 +29,7 @@ import re.imc.geysermodelengine.util.BooleanPacker;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static re.imc.geysermodelengine.model.ModelEntity.ENTITIES;
|
import static re.imc.geysermodelengine.model.ModelEntity.ENTITIES;
|
||||||
@@ -48,7 +50,7 @@ public class EntityTask {
|
|||||||
|
|
||||||
float lastScale = -1.0f;
|
float lastScale = -1.0f;
|
||||||
Color lastColor = null;
|
Color lastColor = null;
|
||||||
Map<String, Integer> lastIntSet = new HashMap<>();
|
Map<String, Integer> lastIntSet = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
// Map<String, Boolean> lastAnimPropertySet = new HashMap<>();
|
// Map<String, Boolean> lastAnimPropertySet = new HashMap<>();
|
||||||
private BukkitRunnable syncTask;
|
private BukkitRunnable syncTask;
|
||||||
@@ -110,7 +112,10 @@ public class EntityTask {
|
|||||||
// Optional<Player> player = viewers.stream().findAny();
|
// Optional<Player> player = viewers.stream().findAny();
|
||||||
// if (player.isEmpty()) return
|
// if (player.isEmpty()) return
|
||||||
|
|
||||||
updateEntityProperties(viewers, false);
|
if (viewers.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// do not actually use this, atleast bundle these up ;(
|
// do not actually use this, atleast bundle these up ;(
|
||||||
sendScale(viewers, false);
|
sendScale(viewers, false);
|
||||||
@@ -202,8 +207,9 @@ public class EntityTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void updateEntityProperties(Collection<Player> players, boolean ignore) {
|
public void updateEntityProperties(Collection<Player> players, boolean ignore, String... forceAnims) {
|
||||||
int entity = model.getEntity().getEntityId();
|
int entity = model.getEntity().getEntityId();
|
||||||
|
Set<String> forceAnimSet = Set.of(forceAnims);
|
||||||
|
|
||||||
Map<String, Boolean> boneUpdates = new HashMap<>();
|
Map<String, Boolean> boneUpdates = new HashMap<>();
|
||||||
Map<String, Boolean> animUpdates = new HashMap<>();
|
Map<String, Boolean> animUpdates = new HashMap<>();
|
||||||
@@ -231,25 +237,23 @@ public class EntityTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model.getActiveModel().getBlueprint().getAnimations().forEach((s, anim) -> {
|
model.getActiveModel().getBlueprint().getAnimations().forEach((s, anim) -> {
|
||||||
if (anim.isOverride() && model.getActiveModel().getAnimationHandler().isPlayingAnimation(s)) {
|
if (anim.isOverride() && (model.getActiveModel().getAnimationHandler().isPlayingAnimation(s) || forceAnimSet.contains(s))) {
|
||||||
overrideAnimUpdates.add(s);
|
overrideAnimUpdates.add(s);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
model.getActiveModel().getBlueprint().getAnimations().forEach((s, anim) -> {
|
model.getActiveModel().getBlueprint().getAnimations().forEach((s, anim) -> {
|
||||||
if (overrideAnimUpdates.isEmpty()) {
|
if (overrideAnimUpdates.isEmpty()) {
|
||||||
animUpdates.put(s, model.getActiveModel().getAnimationHandler().isPlayingAnimation(s));
|
animUpdates.put(s, model.getActiveModel().getAnimationHandler().isPlayingAnimation(s) || forceAnimSet.contains(s));
|
||||||
} else {
|
} else {
|
||||||
if (overrideAnimUpdates.contains(s)) {
|
if (overrideAnimUpdates.contains(s)) {
|
||||||
animUpdates.put(s, true);
|
animUpdates.put(s, true);
|
||||||
} else if (defaultAnims.contains(s)) {
|
} else if (defaultAnims.contains(s)) {
|
||||||
animUpdates.put(s, false);
|
animUpdates.put(s, false);
|
||||||
} else {
|
} else {
|
||||||
animUpdates.put(s, model.getActiveModel().getAnimationHandler().isPlayingAnimation(s));
|
animUpdates.put(s, model.getActiveModel().getAnimationHandler().isPlayingAnimation(s) || forceAnimSet.contains(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*f
|
/*f
|
||||||
if (!lastAnimProperty.equals(currentAnimProperty)) {
|
if (!lastAnimProperty.equals(currentAnimProperty)) {
|
||||||
|
|
||||||
@@ -283,7 +287,8 @@ public class EntityTask {
|
|||||||
if (intUpdates.equals(lastIntSet)) {
|
if (intUpdates.equals(lastIntSet)) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
lastIntSet = intUpdates;
|
lastIntSet.clear();
|
||||||
|
lastIntSet.putAll(intUpdates);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user