Skip to content

Commit 605d61d

Browse files
committed
fix: moveDuration
1 parent 5cd1031 commit 605d61d

File tree

31 files changed

+75
-50
lines changed

31 files changed

+75
-50
lines changed

api/src/main/java/kr/toxicity/model/api/nms/NMS.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ public interface NMS {
3737
default @NotNull ModelDisplay create(@NotNull Location location) {
3838
return create(location, 0, d -> {});
3939
}
40+
/**
41+
* Creates model display
42+
* @param location start location
43+
* @param initialConsumer initial consumer
44+
* @return model display
45+
*/
46+
default @NotNull ModelDisplay create(@NotNull Location location, @NotNull Consumer<ModelDisplay> initialConsumer) {
47+
return create(location, 0, initialConsumer);
48+
}
4049

4150
/**
4251
* Creates model display

api/src/main/java/kr/toxicity/model/api/tracker/EntityTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public EntityTracker(@NotNull EntityTrackerRegistry registry, @NotNull RenderPip
8282
.ifPresent(bone -> {
8383
var box = bone.getGroup().getHitBox();
8484
if (box == null) return;
85-
var shadow = BetterModel.plugin().nms().create(entity.getLocation());
85+
var shadow = BetterModel.plugin().nms().create(entity.getLocation(), d -> d.moveDuration(1));
8686
var baseScale = (float) (box.box().x() + box.box().z()) / 4F;
8787
tick(((t, s) -> {
8888
var wPos = bone.hitBoxPosition();

core/src/main/kotlin/kr/toxicity/model/manager/EntityManagerImpl.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import kr.toxicity.model.api.nms.ModelInteractionHand
1818
import kr.toxicity.model.api.pack.PackZipper
1919
import kr.toxicity.model.api.tracker.EntityTracker
2020
import kr.toxicity.model.api.tracker.EntityTrackerRegistry
21+
import kr.toxicity.model.api.tracker.TrackerUpdateAction
2122
import kr.toxicity.model.util.PLUGIN
2223
import kr.toxicity.model.util.registerListener
2324
import org.bukkit.entity.Entity
@@ -30,6 +31,7 @@ import org.bukkit.event.player.PlayerChangedWorldEvent
3031
import org.bukkit.event.player.PlayerInteractAtEntityEvent
3132
import org.bukkit.event.player.PlayerInteractEntityEvent
3233
import org.bukkit.event.player.PlayerQuitEvent
34+
import org.bukkit.event.player.PlayerToggleSneakEvent
3335
import org.bukkit.event.world.EntitiesLoadEvent
3436
import org.bukkit.event.world.EntitiesUnloadEvent
3537
import org.bukkit.inventory.EquipmentSlot
@@ -164,6 +166,13 @@ object EntityManagerImpl : EntityManager, GlobalManager {
164166
it.damageTint()
165167
}
166168
}
169+
@EventHandler
170+
fun PlayerToggleSneakEvent.sneak() {
171+
BetterModel.registryOrNull(player)?.trackers()?.forEach {
172+
it.update(TrackerUpdateAction.moveDuration(0))
173+
it.task { it.update(TrackerUpdateAction.moveDuration(3)) }
174+
}
175+
}
167176
}
168177
private val platformListener = if (BetterModel.IS_PAPER) PaperListener() else SpigotListener()
169178

nms/v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4/EntityData.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ internal val ITEM_DISPLAY_ID = ItemDisplay::class.java.accessors().map {
3333
it.id
3434
}
3535
internal val ITEM_SERIALIZER = ItemDisplay::class.java.accessors().first()
36-
internal val ITEM_ENTITY_DATA = (mutableListOf(SHARED_FLAG) + ITEM_DISPLAY_ID + DISPLAY_SET.subList(7, DISPLAY_SET.size).map { it.id }).toIntSet()
36+
internal val ITEM_ENTITY_DATA = buildList {
37+
add(SHARED_FLAG)
38+
addAll(ITEM_DISPLAY_ID)
39+
add(Display.DATA_POS_ROT_INTERPOLATION_DURATION_ID.id)
40+
DISPLAY_SET.subList(7, DISPLAY_SET.size).mapTo(this) { it.id }
41+
}.toIntSet()
3742

3843
@Suppress("UNCHECKED_CAST")
3944
private val DISPLAY_INTERPOLATION_DELAY = (DISPLAY_SET.first() as EntityDataAccessor<Int>).run {

nms/v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4/ModelDisplayImpl.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ internal class ModelDisplayImpl(
8383

8484
override fun spawn(showItem: Boolean, bundler: PacketBundler) {
8585
bundler += addPacket
86-
bundler += ClientboundSetEntityDataPacket(display.id, listOf(SynchedEntityData.DataValue(
87-
Display.DATA_POS_ROT_INTERPOLATION_DURATION_ID.id,
88-
Display.DATA_POS_ROT_INTERPOLATION_DURATION_ID.serializer,
89-
3
90-
)))
9186
}
9287

9388
override fun remove(bundler: PacketBundler) {

nms/v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4/ModelNametagImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal class ModelNametagImpl(
4444
EntityType.TEXT_DISPLAY,
4545
MinecraftServer.getServer().overworld()
4646
).apply {
47-
entityData[Display.DATA_POS_ROT_INTERPOLATION_DURATION_ID] = 3
47+
entityData[Display.DATA_POS_ROT_INTERPOLATION_DURATION_ID] = 1
4848
setTransformation(emptyTransformation)
4949
billboardConstraints = Display.BillboardConstraints.CENTER
5050
}

nms/v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4/NMSImpl.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ class NMSImpl : NMS {
308308
override fun createParallelBundler(threshold: Int): PacketBundler = parallelBundlerOf(threshold)
309309

310310
override fun create(location: Location, yOffset: Double, initialConsumer: Consumer<ModelDisplay>): ModelDisplay = ModelDisplayImpl(ItemDisplay(EntityType.ITEM_DISPLAY, (location.world as CraftWorld).handle).apply {
311+
entityData[Display.DATA_POS_ROT_INTERPOLATION_DURATION_ID] = 3
311312
billboardConstraints = Display.BillboardConstraints.FIXED
312313
valid = true
313314
moveTo(

nms/v1_21_R1/src/main/kotlin/kr/toxicity/model/nms/v1_21_R1/EntityData.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ internal val ITEM_DISPLAY_ID = ItemDisplay::class.java.accessors().map {
3333
it.id
3434
}
3535
internal val ITEM_SERIALIZER = ItemDisplay::class.java.accessors().first()
36-
internal val ITEM_ENTITY_DATA = (mutableListOf(SHARED_FLAG) + ITEM_DISPLAY_ID + DISPLAY_SET.subList(7, DISPLAY_SET.size).map { it.id }).toIntSet()
36+
internal val ITEM_ENTITY_DATA = buildList {
37+
add(SHARED_FLAG)
38+
addAll(ITEM_DISPLAY_ID)
39+
add(Display.DATA_POS_ROT_INTERPOLATION_DURATION_ID.id)
40+
DISPLAY_SET.subList(7, DISPLAY_SET.size).mapTo(this) { it.id }
41+
}.toIntSet()
3742

3843
@Suppress("UNCHECKED_CAST")
3944
private val DISPLAY_INTERPOLATION_DELAY = (DISPLAY_SET.first() as EntityDataAccessor<Int>).run {

nms/v1_21_R1/src/main/kotlin/kr/toxicity/model/nms/v1_21_R1/ModelDisplayImpl.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ internal class ModelDisplayImpl(
8383

8484
override fun spawn(showItem: Boolean, bundler: PacketBundler) {
8585
bundler += addPacket
86-
bundler += ClientboundSetEntityDataPacket(display.id, listOf(SynchedEntityData.DataValue(
87-
Display.DATA_POS_ROT_INTERPOLATION_DURATION_ID.id,
88-
Display.DATA_POS_ROT_INTERPOLATION_DURATION_ID.serializer,
89-
3
90-
)))
9186
}
9287

9388
override fun remove(bundler: PacketBundler) {

nms/v1_21_R1/src/main/kotlin/kr/toxicity/model/nms/v1_21_R1/ModelNametagImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal class ModelNametagImpl(
4444
EntityType.TEXT_DISPLAY,
4545
MinecraftServer.getServer().overworld()
4646
).apply {
47-
entityData[Display.DATA_POS_ROT_INTERPOLATION_DURATION_ID] = 3
47+
entityData[Display.DATA_POS_ROT_INTERPOLATION_DURATION_ID] = 1
4848
setTransformation(emptyTransformation)
4949
billboardConstraints = Display.BillboardConstraints.CENTER
5050
}

0 commit comments

Comments
 (0)