Skip to content

Commit

Permalink
Bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Dec 26, 2024
1 parent db40d5d commit 3e74e13
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package kr.toxicity.model.api.data.blueprint;

import kr.toxicity.model.api.BetterModel;
import kr.toxicity.model.api.data.raw.ModelAnimation;
import kr.toxicity.model.api.data.raw.ModelAnimator;
import kr.toxicity.model.api.data.raw.ModelKeyframe;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
import org.joml.Vector3f;

import java.util.*;

Expand Down Expand Up @@ -58,6 +60,7 @@ private static Map<String, BlueprintAnimator> newMap(@NotNull Map<String, Bluepr
for (long l : longSet) {
list.add(getFrame(frame, (int) l));
}
reduceFrame(list);
return processFrame(list);
}

Expand All @@ -75,6 +78,22 @@ private static Map<String, BlueprintAnimator> newMap(@NotNull Map<String, Bluepr
return list.getFirst();
}

private static void reduceFrame(@NotNull List<AnimationMovement> target) {
var iterator = target.iterator();
var l = 0L;
var f = BetterModel.inst().configManager().keyframeThreshold();
Vector3f beforeRot = new Vector3f();
while (iterator.hasNext()) {
var next = iterator.next();
var rot = next.rotation();
if (next.time() - l >= f || next.time() == 0 || (rot != null && new Vector3f(rot).sub(beforeRot).length() >= 45)) l = next.time();
else {
iterator.remove();
}
if (rot != null) beforeRot = rot;
}
}

private static @NotNull List<AnimationMovement> processFrame(@NotNull List<AnimationMovement> target) {
if (target.size() <= 1) return target;
var list = new ArrayList<AnimationMovement>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static final class Builder {
private final List<TimeVector> rotation = new ArrayList<>();

private static int checkSplit(Vector3f vector3f) {
return Math.round(vector3f.length() + 1);
return Math.round(vector3f.length() / 45 + 1);
}

public @NotNull Builder addFrame(@NotNull ModelKeyframe keyframe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public interface ConfigManager {
double maxSight();
double minSight();
boolean lockOnPlayAnimation();
long keyframeThreshold();
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ allprojects {
apply(plugin = "java")
apply(plugin = "kotlin")
group = "kr.toxicity.model"
version = "1.0.1"
version = "1.0.2"
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import dev.jorel.commandapi.executors.CommandExecutionInfo
import dev.jorel.commandapi.executors.PlayerCommandExecutor
import kr.toxicity.model.api.BetterModel.ReloadResult.*
import kr.toxicity.model.api.manager.CommandManager
import kr.toxicity.model.api.util.EntityUtil
import kr.toxicity.model.util.PLUGIN
import org.bukkit.entity.EntityType

Expand All @@ -29,9 +30,14 @@ object CommandManagerImpl : CommandManager, GlobalManagerImpl {
)
.executesPlayer(PlayerCommandExecutor { player, args ->
val n = args["name"] as String
val loc = player.location
ModelManagerImpl.renderer(n)
?.create(player.world.spawnEntity(player.location, EntityType.HUSK))
?.spawn(player)
?.let {
loc.getNearbyPlayers(EntityUtil.RENDER_DISTANCE).forEach { p ->
it.spawn(p)
}
}
?: run {
player.sendMessage("Unable to find this renderer: $n")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ object ConfigManagerImpl : ConfigManager, GlobalManagerImpl {
private var maxSight = 45.0
private var minSight = 5.0
private var lockOnPlayAnimation = true
private var keyframeThreshold = 2L

override fun item(): Material = item
override fun metrics(): Boolean = metrics != null
override fun sightTrace(): Boolean = sightTrace
override fun maxSight(): Double = maxSight
override fun minSight(): Double = minSight
override fun lockOnPlayAnimation(): Boolean = lockOnPlayAnimation
override fun keyframeThreshold(): Long = keyframeThreshold

override fun reload() {
val yaml = PluginConfiguration.CONFIG.create()
Expand All @@ -40,5 +42,6 @@ object ConfigManagerImpl : ConfigManager, GlobalManagerImpl {
maxSight = yaml.getDouble("max-sight", 45.0)
minSight = yaml.getDouble("min-sight", 5.0)
lockOnPlayAnimation = yaml.getBoolean("lock-on-play-animation", true)
keyframeThreshold = yaml.getLong("keyframe-threshold", 2).coerceAtLeast(1)
}
}
3 changes: 2 additions & 1 deletion core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ sight-trace: true
item: leather_horse_armor
max-sight: 45
min-sight: 5
lock-on-play-animation: true
lock-on-play-animation: true
keyframe-threshold: 2

0 comments on commit 3e74e13

Please sign in to comment.