Skip to content

Commit 5b1f7de

Browse files
committed
Bug fix.
1 parent d15a5b9 commit 5b1f7de

File tree

32 files changed

+297
-104
lines changed

32 files changed

+297
-104
lines changed

api/src/main/java/kr/toxicity/model/api/data/blueprint/BlueprintAnimation.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ private static void reduceFrame(@NotNull List<AnimationMovement> target) {
116116
private static @NotNull List<AnimationMovement> processFrame(@NotNull List<AnimationMovement> target) {
117117
if (target.size() <= 1) return target;
118118
var list = new ArrayList<AnimationMovement>();
119+
list.add(target.getFirst());
119120
for (int i = 1; i < target.size(); i++) {
120121
var get = target.get(i);
121122
list.add(get.time(get.time() - target.get(i - 1).time()));
@@ -130,8 +131,13 @@ private static void reduceFrame(@NotNull List<AnimationMovement> target) {
130131
public BlueprintAnimator.AnimatorIterator emptyLoopIterator() {
131132
return new BlueprintAnimator.AnimatorIterator() {
132133

133-
private int index = 0;
134+
@NotNull
135+
@Override
136+
public AnimationMovement first() {
137+
return new AnimationMovement(0, null, null, null);
138+
}
134139

140+
private int index = 0;
135141

136142
@Override
137143
public int index() {
@@ -175,6 +181,12 @@ public BlueprintAnimator.AnimatorIterator emptySingleIterator() {
175181

176182
private int index = 0;
177183

184+
@NotNull
185+
@Override
186+
public AnimationMovement first() {
187+
return new AnimationMovement(0, null, null, null);
188+
}
189+
178190
@Override
179191
public int index() {
180192
return index;

api/src/main/java/kr/toxicity/model/api/data/blueprint/BlueprintAnimator.java

+13
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ private Vector3f get(long min, TimeVector last, TimeVector newVec) {
154154
}
155155

156156
public interface AnimatorIterator extends Iterator<AnimationMovement> {
157+
@NotNull AnimationMovement first();
157158
void clear();
158159
int length();
159160
int index();
@@ -165,6 +166,12 @@ private class SingleIterator implements AnimatorIterator {
165166

166167
private int index = 0;
167168

169+
@NotNull
170+
@Override
171+
public AnimationMovement first() {
172+
return keyFrame.getFirst();
173+
}
174+
168175
@Override
169176
public int index() {
170177
return index;
@@ -199,6 +206,12 @@ private class LoopIterator implements AnimatorIterator {
199206

200207
private int index = 0;
201208

209+
@NotNull
210+
@Override
211+
public AnimationMovement first() {
212+
return keyFrame.getFirst();
213+
}
214+
202215
@Override
203216
public int index() {
204217
return index;

api/src/main/java/kr/toxicity/model/api/data/blueprint/BlueprintTexture.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public record BlueprintTexture(
3838
}
3939

4040
public boolean isAnimatedTexture() {
41-
return uvHeight != 0 && uvWidth != 0 && image.getHeight() / uvHeight / (image.getWidth() / uvWidth) > 1;
41+
return uvHeight != 0 && uvWidth != 0 && image.getHeight() / uvHeight / Math.max(image.getWidth() / uvWidth, 1) > 1;
4242
}
4343

4444
public @NotNull JsonObject toMcmeta() {

api/src/main/java/kr/toxicity/model/api/data/renderer/AnimationModifier.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,26 @@
77
/**
88
* A modifier of animation.
99
*/
10-
public record AnimationModifier(Supplier<Boolean> predicate, int start, int end) {
10+
public record AnimationModifier(Supplier<Boolean> predicate, int start, int end, float speed) {
1111
/**
1212
* Creates modifier
1313
*
1414
* @param predicate animation predicate
1515
* @param start start time
1616
* @param end end time
17+
* @param speed speed
1718
*/
18-
public AnimationModifier(Supplier<Boolean> predicate, int start, int end) {
19+
public AnimationModifier(Supplier<Boolean> predicate, int start, int end, float speed) {
1920
this.predicate = FunctionUtil.memoizeTick(predicate);
2021
this.start = start;
2122
this.end = end;
23+
this.speed = speed;
2224
}
2325

24-
public static final AnimationModifier DEFAULT = new AnimationModifier(() -> true, 0, 0);
26+
public int speed(int original) {
27+
return Math.round((float) original / speed);
28+
}
29+
30+
public static final AnimationModifier DEFAULT = new AnimationModifier(() -> true, 1, 0, 1F);
31+
public static final AnimationModifier DEFAULT_LOOP = new AnimationModifier(() -> true, 4, 4, 1F);
2532
}

api/src/main/java/kr/toxicity/model/api/data/renderer/BlueprintRenderer.java

+35-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import kr.toxicity.model.api.data.blueprint.ModelBlueprint;
55
import kr.toxicity.model.api.tracker.EntityTracker;
66
import kr.toxicity.model.api.tracker.PlayerTracker;
7+
import kr.toxicity.model.api.tracker.TrackerModifier;
78
import kr.toxicity.model.api.tracker.VoidTracker;
89
import lombok.Getter;
910
import lombok.RequiredArgsConstructor;
@@ -52,11 +53,21 @@ public final class BlueprintRenderer {
5253
* @return entity tracker
5354
*/
5455
public @NotNull EntityTracker create(@NotNull Entity entity) {
56+
return create(entity, TrackerModifier.DEFAULT);
57+
}
58+
/**
59+
* Gets or creates tracker by entity.
60+
* @param entity target
61+
* @param modifier modifier
62+
* @return entity tracker
63+
*/
64+
public @NotNull EntityTracker create(@NotNull Entity entity, @NotNull TrackerModifier modifier) {
5565
var tracker = EntityTracker.tracker(entity.getUniqueId());
5666
if (tracker != null) return tracker;
5767
return new EntityTracker(
5868
entity,
59-
instance(null, entity.getLocation())
69+
instance(null, entity.getLocation()),
70+
modifier
6071
);
6172
}
6273

@@ -66,11 +77,21 @@ public final class BlueprintRenderer {
6677
* @return player limb tracker
6778
*/
6879
public @NotNull EntityTracker createPlayerLimb(@NotNull Player player) {
80+
return createPlayerLimb(player, TrackerModifier.DEFAULT);
81+
}
82+
/**
83+
* Gets or creates tracker by player
84+
* @param player player
85+
* @param modifier modifier
86+
* @return player limb tracker
87+
*/
88+
public @NotNull EntityTracker createPlayerLimb(@NotNull Player player, @NotNull TrackerModifier modifier) {
6989
var tracker = EntityTracker.tracker(player.getUniqueId());
7090
if (tracker != null) return tracker;
7191
return new PlayerTracker(
7292
player,
73-
instance(player, player.getLocation())
93+
instance(player, player.getLocation()),
94+
modifier
7495
);
7596
}
7697

@@ -81,7 +102,18 @@ public final class BlueprintRenderer {
81102
* @return void tracker
82103
*/
83104
public @NotNull VoidTracker create(@NotNull UUID uuid, @NotNull Location location) {
84-
return new VoidTracker(uuid, instance(null, location), location);
105+
return create(uuid, TrackerModifier.DEFAULT, location);
106+
}
107+
108+
/**
109+
* Creates tracker by location.
110+
* @param uuid uuid
111+
* @param modifier modifier
112+
* @param location location
113+
* @return void tracker
114+
*/
115+
public @NotNull VoidTracker create(@NotNull UUID uuid, @NotNull TrackerModifier modifier, @NotNull Location location) {
116+
return new VoidTracker(uuid, instance(null, location), modifier, location);
85117
}
86118

87119
private @NotNull RenderInstance instance(@Nullable Player player, @NotNull Location location) {

api/src/main/java/kr/toxicity/model/api/data/renderer/RenderInstance.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import kr.toxicity.model.api.data.blueprint.BlueprintAnimation;
66
import kr.toxicity.model.api.entity.RenderedEntity;
77
import kr.toxicity.model.api.entity.TrackerMovement;
8+
import kr.toxicity.model.api.nms.EntityAdapter;
89
import kr.toxicity.model.api.nms.HitBoxListener;
910
import kr.toxicity.model.api.nms.PacketBundler;
1011
import kr.toxicity.model.api.nms.PlayerChannelHandler;
1112
import kr.toxicity.model.api.script.ScriptProcessor;
1213
import lombok.Getter;
1314
import org.bukkit.Location;
14-
import org.bukkit.entity.Entity;
1515
import org.bukkit.entity.Player;
1616
import org.bukkit.inventory.ItemStack;
1717
import org.jetbrains.annotations.ApiStatus;
@@ -64,7 +64,7 @@ public void spawnFilter(@NotNull Predicate<Player> spawnFilter) {
6464
this.spawnFilter = this.spawnFilter.and(spawnFilter);
6565
}
6666

67-
public void createHitBox(@NotNull Entity entity, @NotNull Predicate<RenderedEntity> predicate, @Nullable HitBoxListener listener) {
67+
public void createHitBox(@NotNull EntityAdapter entity, @NotNull Predicate<RenderedEntity> predicate, @Nullable HitBoxListener listener) {
6868
for (RenderedEntity value : entityMap.values()) {
6969
value.createHitBox(entity, predicate, listener);
7070
}
@@ -144,7 +144,7 @@ public void tint(boolean toggle) {
144144

145145

146146
public boolean animateLoop(@NotNull String animation) {
147-
return animateLoop(e -> true, animation, AnimationModifier.DEFAULT, () -> {});
147+
return animateLoop(e -> true, animation, AnimationModifier.DEFAULT_LOOP, () -> {});
148148
}
149149

150150
public boolean animateSingle(@NotNull String animation) {
@@ -181,7 +181,7 @@ public boolean animateSingle(@NotNull Predicate<RenderedEntity> filter, @NotNull
181181
public boolean replaceLoop(@NotNull Predicate<RenderedEntity> filter, @NotNull String target, @NotNull String animation) {
182182
var get = animationMap.get(animation);
183183
if (get == null) return false;
184-
scriptProcessor.replaceLoop(get.script(), AnimationModifier.DEFAULT);
184+
scriptProcessor.replaceLoop(get.script(), AnimationModifier.DEFAULT_LOOP);
185185
for (RenderedEntity value : entityMap.values()) {
186186
value.replaceLoop(filter, target, animation, get);
187187
}

api/src/main/java/kr/toxicity/model/api/entity/RenderedEntity.java

+33-19
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import kr.toxicity.model.api.data.renderer.RendererGroup;
99
import kr.toxicity.model.api.nms.*;
1010
import lombok.Getter;
11+
import lombok.RequiredArgsConstructor;
1112
import lombok.Setter;
1213
import org.bukkit.Location;
1314
import org.bukkit.Material;
14-
import org.bukkit.entity.Entity;
1515
import org.bukkit.entity.ItemDisplay;
1616
import org.bukkit.inventory.ItemStack;
1717
import org.bukkit.util.Transformation;
@@ -97,7 +97,7 @@ public RenderedEntity(
9797
* @param listener hit box listener
9898
*/
9999
@ApiStatus.Internal
100-
public void createHitBox(@NotNull Entity entity, @NotNull Predicate<RenderedEntity> predicate, @Nullable HitBoxListener listener) {
100+
public void createHitBox(@NotNull EntityAdapter entity, @NotNull Predicate<RenderedEntity> predicate, @Nullable HitBoxListener listener) {
101101
var h = group.getHitBox();
102102
if (h != null && predicate.test(this)) {
103103
var l = listener;
@@ -206,13 +206,14 @@ public void lastMovement(@NotNull TrackerMovement movement) {
206206
}
207207

208208
public void move(@NotNull TrackerMovement movement, @NotNull PacketBundler bundler) {
209+
updateAnimation();
209210
var d = display;
210211
if (delay <= 0) {
211212
var f = frame();
212213
delay = f;
213214
var entityMovement = lastTransform = (lastMovement = movement.copy()).plus(relativeOffset().plus(defaultPosition));
214215
if (d != null) {
215-
d.frame(Math.max(f, ANIMATION_THRESHOLD));
216+
d.frame(f <= 0 ? 0 : Math.max(f, ANIMATION_THRESHOLD));
216217
setup(entityMovement);
217218
d.send(bundler);
218219
}
@@ -221,7 +222,6 @@ public void move(@NotNull TrackerMovement movement, @NotNull PacketBundler bundl
221222
for (RenderedEntity e : children.values()) {
222223
e.move(movement, bundler);
223224
}
224-
updateAnimation();
225225
}
226226
public void forceUpdate(@NotNull PacketBundler bundler) {
227227
var d = display;
@@ -263,11 +263,11 @@ public void defaultPosition(@NotNull Vector3f movement) {
263263
}
264264

265265
private int frame() {
266-
return keyFrame != null ? (int) keyFrame.time() : parent != null ? parent.frame() : ANIMATION_THRESHOLD;
266+
return keyFrame != null ? (int) keyFrame.time() : parent != null ? parent.frame() : 1;
267267
}
268268

269269
private EntityMovement defaultFrame() {
270-
var k = keyFrame != null ? keyFrame.copyNotNull() : new AnimationMovement(0, new Vector3f(), new Vector3f(), new Vector3f());
270+
var k = keyFrame != null ? keyFrame.copyNotNull() : new AnimationMovement(1, new Vector3f(), new Vector3f(), new Vector3f());
271271
for (Consumer<AnimationMovement> consumer : movementModifier) {
272272
consumer.accept(k);
273273
}
@@ -368,7 +368,7 @@ public void replaceLoop(@NotNull Predicate<RenderedEntity> filter, @NotNull Stri
368368
synchronized (animators) {
369369
var v = animators.get(target);
370370
if (v != null) animators.replace(target, get != null ? new TreeIterator(parent, get.loopIterator(), v.modifier, v.removeTask) : new TreeIterator(parent, animator.emptyLoopIterator(), v.modifier, v.removeTask));
371-
else animators.replace(target, get != null ? new TreeIterator(parent, get.loopIterator(), AnimationModifier.DEFAULT, () -> {}) : new TreeIterator(parent, animator.emptyLoopIterator(), AnimationModifier.DEFAULT, () -> {}));
371+
else animators.replace(target, get != null ? new TreeIterator(parent, get.loopIterator(), AnimationModifier.DEFAULT_LOOP, () -> {}) : new TreeIterator(parent, animator.emptyLoopIterator(), AnimationModifier.DEFAULT_LOOP, () -> {}));
372372
}
373373
}
374374
children.values().forEach(c -> c.replaceLoop(filter, target, parent, animator));
@@ -409,12 +409,20 @@ public void togglePart(@NotNull PacketBundler bundler, @NotNull Predicate<Render
409409
}
410410
}
411411

412-
private record TreeIterator(
413-
String name,
414-
BlueprintAnimator.AnimatorIterator iterator,
415-
AnimationModifier modifier,
416-
Runnable removeTask
417-
) implements BlueprintAnimator.AnimatorIterator, Supplier<Boolean>, Runnable {
412+
@RequiredArgsConstructor
413+
private static class TreeIterator implements BlueprintAnimator.AnimatorIterator, Supplier<Boolean>, Runnable {
414+
private final String name;
415+
private final BlueprintAnimator.AnimatorIterator iterator;
416+
private final AnimationModifier modifier;
417+
private final Runnable removeTask;
418+
private boolean started = false;
419+
private boolean ended = false;
420+
421+
@NotNull
422+
@Override
423+
public AnimationMovement first() {
424+
return iterator.first();
425+
}
418426

419427
@Override
420428
public int index() {
@@ -438,21 +446,27 @@ public Boolean get() {
438446

439447
@Override
440448
public boolean hasNext() {
441-
return iterator.hasNext();
449+
return iterator.hasNext() || (modifier.end() > 0 && !ended);
442450
}
443451

444452
@Override
445453
public AnimationMovement next() {
446-
int i;
447-
if (index() == 0) i = modifier().start();
448-
else if (index() == lastIndex()) i = modifier().end();
449-
else i = 0;
454+
if (!started) {
455+
started = true;
456+
return first().time(modifier.start());
457+
}
458+
if (!iterator.hasNext()) {
459+
ended = true;
460+
return new AnimationMovement(modifier.end(), null, null, null);
461+
}
450462
var nxt = iterator.next();
451-
return i == 0 ? nxt : new AnimationMovement(i, null, null, null);
463+
var spd = modifier.speed((int) nxt.time());
464+
return nxt.time(Math.max(spd, 1));
452465
}
453466

454467
@Override
455468
public void clear() {
469+
started = ended = false;
456470
iterator.clear();
457471
}
458472

api/src/main/java/kr/toxicity/model/api/manager/ConfigManager.java

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public interface ConfigManager {
1818
@NotNull PackType packType();
1919
@NotNull String buildFolderLocation();
2020
boolean disableGeneratingLegacyModels();
21+
boolean followMobInvisibility();
2122

2223
enum PackType {
2324
FOLDER,

0 commit comments

Comments
 (0)