-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1669 lines (1449 loc) · 91.2 KB
/
Copy pathindex.html
File metadata and controls
1669 lines (1449 loc) · 91.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<title>Revethere's Blog</title>
<meta name="author" content="Revethere" />
<meta name="description" content="Could it be MAGIC~" />
<meta name="keywords" content="Revethere, Minecraft, INTP, KPOP, Code" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
/>
<link rel="icon" href="/images/avatar.jpg" />
<link rel="preconnect" href="https://s4.zstatic.net" />
<script src="https://s4.zstatic.net/ajax/libs/vue/3.3.7/vue.global.prod.min.js"></script>
<link rel="stylesheet" href="https://s4.zstatic.net/ajax/libs/font-awesome/6.4.2/css/all.min.css" />
<link rel="preconnect" href="https://fonts.googleapis.cn" />
<link rel="preconnect" href="https://fonts.gstatic.cn" crossorigin />
<link
rel="stylesheet"
href="https://fonts.googleapis.cn/css2?family=Fira+Code:wght@400;500;600;700&family=Lexend:wght@400;500;600;700;800;900&family=Noto+Sans+SC:wght@400;500;600;700;800;900&display=swap"
/>
<script> const mixins = {}; </script>
<script src="https://polyfill.alicdn.com/v3/polyfill.min.js?features=default"></script>
<script src="https://s4.zstatic.net/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="https://s4.zstatic.net/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js"></script>
<link
rel="stylesheet"
href="https://s4.zstatic.net/ajax/libs/highlight.js/11.9.0/styles/github.min.css"
/>
<script src="/js/lib/highlight.js"></script>
<script src="https://s4.zstatic.net/ajax/libs/KaTeX/0.16.9/katex.min.js"></script>
<script src="https://s4.zstatic.net/ajax/libs/KaTeX/0.16.9/contrib/auto-render.min.js"></script>
<link rel="stylesheet" href="https://s4.zstatic.net/ajax/libs/KaTeX/0.16.9/katex.min.css" />
<script src="/js/lib/math.js"></script>
<script src="/js/lib/preview.js"></script>
<script src="/js/lib/home.js"></script>
<link rel="stylesheet" href="/css/main.css" />
<meta name="generator" content="Hexo 7.3.0"></head>
<body>
<div id="layout">
<transition name="fade">
<div id="loading" v-show="loading">
<div id="loading-circle">
<h2>LOADING</h2>
<p>加载过慢请开启缓存 浏览器默认开启</p>
<img src="/images/loading.gif" />
</div>
</div>
</transition>
<div id="menu" :class="{ hidden: hiddenMenu, 'menu-color': menuColor}">
<nav id="desktop-menu">
<div id="menu-indicator"></div>
<a class="title" href="/">
<span>REVETHERE'S BLOG</span>
</a>
<a href="/">
<i class="fa-solid fa-house fa-fw"></i>
<span> Home</span>
</a>
<a href="/about">
<i class="fa-solid fa-id-card fa-fw"></i>
<span> About</span>
</a>
<a href="/archives">
<i class="fa-solid fa-box-archive fa-fw"></i>
<span> Archives</span>
</a>
<a href="/categories">
<i class="fa-solid fa-bookmark fa-fw"></i>
<span> Categories</span>
</a>
<a href="/tags">
<i class="fa-solid fa-tags fa-fw"></i>
<span> Tags</span>
</a>
<a href="/logs">
<i class="fa-solid fa-clock-rotate-left fa-fw"></i>
<span> Logs</span>
</a>
<a href="/friends">
<i class="fa-solid fa-link fa-fw"></i>
<span> Friends</span>
</a>
</nav>
<nav id="mobile-menu">
<div class="title" @click="showMenuItems = !showMenuItems">
<i class="fa-solid fa-bars fa-fw"></i>
<span> REVETHERE'S BLOG</span>
</div>
<transition name="slide">
<div class="items" v-show="showMenuItems">
<a href="/">
<div class="item">
<div style="min-width: 20px; max-width: 50px; width: 10%">
<i class="fa-solid fa-house fa-fw"></i>
</div>
<div style="min-width: 100px; max-width: 150%; width: 20%">Home</div>
</div>
</a>
<a href="/about">
<div class="item">
<div style="min-width: 20px; max-width: 50px; width: 10%">
<i class="fa-solid fa-id-card fa-fw"></i>
</div>
<div style="min-width: 100px; max-width: 150%; width: 20%">About</div>
</div>
</a>
<a href="/archives">
<div class="item">
<div style="min-width: 20px; max-width: 50px; width: 10%">
<i class="fa-solid fa-box-archive fa-fw"></i>
</div>
<div style="min-width: 100px; max-width: 150%; width: 20%">Archives</div>
</div>
</a>
<a href="/categories">
<div class="item">
<div style="min-width: 20px; max-width: 50px; width: 10%">
<i class="fa-solid fa-bookmark fa-fw"></i>
</div>
<div style="min-width: 100px; max-width: 150%; width: 20%">Categories</div>
</div>
</a>
<a href="/tags">
<div class="item">
<div style="min-width: 20px; max-width: 50px; width: 10%">
<i class="fa-solid fa-tags fa-fw"></i>
</div>
<div style="min-width: 100px; max-width: 150%; width: 20%">Tags</div>
</div>
</a>
<a href="/logs">
<div class="item">
<div style="min-width: 20px; max-width: 50px; width: 10%">
<i class="fa-solid fa-clock-rotate-left fa-fw"></i>
</div>
<div style="min-width: 100px; max-width: 150%; width: 20%">Logs</div>
</div>
</a>
<a href="/friends">
<div class="item">
<div style="min-width: 20px; max-width: 50px; width: 10%">
<i class="fa-solid fa-link fa-fw"></i>
</div>
<div style="min-width: 100px; max-width: 150%; width: 20%">Friends</div>
</div>
</a>
</div>
</transition>
</nav>
</div>
<transition name="fade">
<div id="menu-curtain" @click="showMenuItems = !showMenuItems" v-show="showMenuItems"></div>
</transition>
<div id="main" :class="loading ? 'into-enter-from': 'into-enter-active'">
<div id="home-head">
<div
id="home-background"
ref="homeBackground"
data-images="/images/background_01.png,/images/background_02.png,/images/background_03.png,/images/background_04.png,/images/background_05.png,/images/background_06.png,/images/background_08.png,/images/background_09.png,/images/background_10.png"
></div>
<div id="home-info" @click="homeClick">
<span class="loop"></span>
<span class="loop"></span>
<span class="loop"></span>
<span class="loop"></span>
<span class="info">
<div class="wrap">
<h1>Revethere's Blog</h1>
<h3>分享一些超级有用的芝士</h3>
<h5>Could it be MAGIC~</h5>
</div>
</span>
</div>
</div>
<div
id="home-posts-wrap"
ref="homePostsWrap"
true
>
<div id="home-posts">
<div class="post" data-has-more="true" data-single="true">
<a href="/posts/academic@ed-of-minecraft-entity-mm-eqs/">
<h2 class="post-title">『Minecraft 实体运动公式拓展推导』</h2>
</a>
<div class="category-and-date">
<span class="category">
<a href="/categories/%E7%90%86%E8%AE%BA/">
<span class="icon">
<i class="fa-solid fa-bookmark fa-fw"></i>
</span>
理论
</a>
</span>
<span class="date">
<span class="icon">
<i class="fa-solid fa-calendar fa-fw"></i>
</span>
2025/12/14
</span>
</div>
<div class="description">
<div class="excerpt-content" v-pre>
<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>本文内容包含大量数学与物理公式,需要具备一定的数理基础阅读。</p>
<p>因为一些客观因素博客中的<strong>部分公式并不完全</strong>,建议下载 PDF 版本(见附件)食用更佳。</p>
<h2 id="实体基本运动公式"><a href="#实体基本运动公式" class="headerlink" title="实体基本运动公式"></a>实体基本运动公式</h2><h3 id="一些必要参数及定义"><a href="#一些必要参数及定义" class="headerlink" title="一些必要参数及定义"></a>一些必要参数及定义</h3><ul>
<li>速度:$v_H$、$v_Y$,表示实体在水平、垂直上的速度。</li>
<li>初始垂直速度:$v_{Y, 1}$,取决于跳跃速度或服务器垂直击退参数。</li>
<li>方块滑度系数:$f_S$。</li>
<li>移动乘数:$k_M$。</li>
<li>效果乘数:$k_E$。</li>
<li>速度阈值:$v_{th} = 0.005 \text{ m/tick}$,当实体在某条轴上的速度经衰减后小于该值时,对应轴上的速度归零,仅保留加速度(1.9 及以上版本阈值变为 $0.003 \text{ m/tick}$)。</li>
</ul>
<h3 id="水平运动递推公式"><a href="#水平运动递推公式" class="headerlink" title="水平运动递推公式"></a>水平运动递推公式</h3><ul>
<li><strong>水平地面速度公式:</strong>$$v_{H, t} = \underbrace{v_{H, t-1} \times f_{s, t-1} \times 0.91} _ \text{动量保留} + \underbrace{0.1 \times \left( \frac{0.6}{f_{s, t}}\right)^3 \times k_M \times k_E} _ \text{加速度}\tag{1.2.1}$$</li>
<li><strong>水平空中速度公式:</strong>$$v_{H, t} = \underbrace{v_{H, t-1} \times 0.91} _ \text{动量保留} + \underbrace{0.02 \times k_M} _\text{加速度} \tag{1.2.2}$$</li>
<li><strong>水平空中飞行公式:</strong>$$v_{H, t} = \underbrace{v_{H, t-1} \times 0.91} _ \text{动量保留} + \underbrace{0.05 \times k_{M-fly}}_\text{加速度} \tag{1.2.3}$$</li>
</ul>
<h3 id="垂直运动递推公式"><a href="#垂直运动递推公式" class="headerlink" title="垂直运动递推公式"></a>垂直运动递推公式</h3><ul>
<li><strong>垂直速度公式:</strong>$$v_{Y, t} = \left( v_{Y, t-1} - \mathop{0.08} \limits_\text{重力} \right) \times \mathop{0.98}\limits_\text{阻力} \tag{1.3.1}$$</li>
</ul>
<p><strong>为了方便表示,后文中设公式 (1.2.1)、公式 (1.2.2)、公式 (1.2.3) 中所有动量保留项的系数为 $\alpha$,加速度项为 $\beta$。公式 (1.3.1) 展开后同理。</strong></p>
<h2 id="稳态(渐进)速度推导"><a href="#稳态(渐进)速度推导" class="headerlink" title="稳态(渐进)速度推导"></a>稳态(渐进)速度推导</h2><h3 id="经典力学下的运动"><a href="#经典力学下的运动" class="headerlink" title="经典力学下的运动"></a>经典力学下的运动</h3><p>$$\frac{dv}{dt} = a - fv \tag{2.1.1}$$</p>
<p>$$v = v_0 e^{-ft} + \frac{a}{f} (1 - e^{-ft})\tag{2.1.2}$$</p>
<p>$$\frac{v}{v_0} = \lim\limits_{t_0 \to 0} (1 - f t_0)^{\frac{t}{t_0}}, a = 0\tag{2.1.3}$$</p>
<p>其余见 <a href="https://revethere.github.io/posts/academic@min-kb-click-freq-lower-bound/"><a href="https://revethere.github.io/posts/academic@min-kb-click-freq-lower-bound/">『低版本 pvp 中玩家最优 kb 的点击频率下限分析』</a></a> 中 『经典力学下的运动』小结,这里不过多阐述。</p>
<h3 id="水平稳态(渐进)速度"><a href="#水平稳态(渐进)速度" class="headerlink" title="水平稳态(渐进)速度"></a>水平稳态(渐进)速度</h3><p>假设实体在运动过程中所有状态不变($f_S$ 为常数),原递推式为一阶线性差分方程:$$v_t = \alpha , v_{t-1} + \beta \tag{2.2.1}$$</p>
<p>齐次方程 $v_t^{(h)} = \alpha v_{t-1}^{(h)}$ 的解为 $v_t^{(h)} = C \alpha^t$。由于非齐次项 $\beta$ 为常数,设其特解为 $K$,代入原方程 (2.2.1) 得:$$K = \alpha K + \beta$$</p>
<p>即 $K = \frac{\beta}{1 - \alpha}, \ \alpha \neq 1$,特解为:$$v_t^{(p)} = \frac{\beta}{1 - \alpha}$$</p>
<p>方程 (2.2.1) 的通解为齐次解与特解之和:$$v_t = C \alpha^t + \frac{\beta}{1 - \alpha}$$</p>
<p>当 $t = 0$:$$v_0 = C + \frac{\beta}{1 - \alpha}$$</p>
<p>将 $C = v_0 - \frac{\beta}{1 - \alpha}$ 代入通解得:$$v_t = \left( v_0 - \frac{\beta}{1 - \alpha} \right) \alpha^t + \frac{\beta}{1 - \alpha} = v_0 \alpha^t + \beta \frac{1 - \alpha^t}{1 - \alpha} \tag{2.2.2}$$</p>
<p>由于 $|\alpha| < 1$ 恒成立,该方程收敛。当 $t \to \infty$,稳态速度:$$v_{\infty} = \frac{\beta}{1 - \alpha}$$</p>
<p>代入 $\alpha = 0.91 f_s$ 和 $\beta = 0.1 \left( \frac{0.6}{f_s} \right)^3 k_M k_E$ 得:$$\boxed{v_{\infty} = \frac{0.1 \left( \frac{0.6}{f_s} \right)^3 k_M k_E}{1 - 0.91 f_s}} \tag{2.2.3}$$</p>
<h3 id="水平飞行稳态(渐进)速度"><a href="#水平飞行稳态(渐进)速度" class="headerlink" title="水平飞行稳态(渐进)速度"></a>水平飞行稳态(渐进)速度</h3><p>这里提供另一种的推导方法。</p>
<p>已知每刻(tick)的时间长度 $\Delta t = 0.05s$,对于连续的时间 $t$ 与刻数 $n$:$$t = n \Delta t, \ v(t) \approx v_n$$</p>
<p>将原递推方程移项得到:$$v_n - v_{n - 1} = (\alpha - 1) v_{n - 1} + \beta$$</p>
<p>同时除以 $\Delta t$:$$\frac{v_n - v_{n - 1}}{\Delta t} = \frac{(\alpha - 1) v_{n - 1}}{\Delta t} + \frac{\beta}{\Delta t}$$</p>
<p>令:$$f = \frac{1 - \alpha}{\Delta t}, \ a = \frac{\beta}{\Delta t}$$</p>
<p>得到微分方程 (2.1.2),其积分因子 $\mu(t) = e^{ft}$。两边同时乘以 $\mu(t)$:</p>
<p>$$e^{ft} \frac{dv}{dt} + f e^{ft} v = a e^{ft}$$</p>
<p>$$\frac{d}{dt} \left( e^{ft} v \right) = a e^{ft}$$</p>
<p>对 $t$ 积分:$$e^{ft} v = \int a e^{ft} , dt = \frac{a}{f} e^{ft} + C$$</p>
<p>两边除以 $e^{ft}$,得到:$$v = \frac{a}{f} + C e^{-ft}$$</p>
<p>初始时 $v(0) = v_0$,则将常数 $C = v_0 - \frac{a}{f}$ 代入通解得到公式 (2.1.2)。当 $t \to \infty$,稳态速度:$$v_{\infty} = \frac{a}{f} = \frac{\beta}{1 - \alpha}$$</p>
<p>代入 $\alpha = 0.91$ 和 $\beta = 0.05 k_{M-fly}$ 得:$$\boxed{v_{\infty} = \frac{0.05 k_{M-fly}}{0.09}} \tag{2.2.4}$$</p>
<h3 id="部分状态下的稳态速度"><a href="#部分状态下的稳态速度" class="headerlink" title="部分状态下的稳态速度"></a>部分状态下的稳态速度</h3><table>
<thead>
<tr>
<th>状态</th>
<th>$k_M$</th>
<th>$k_{M-fly}$</th>
<th>$k_E$</th>
<th>$f_S$</th>
<th>$v_{\infty} \ (\text{m/s})$</th>
</tr>
</thead>
<tbody><tr>
<td>地面正常移动</td>
<td>$1.0 \times 0.98$</td>
<td>/</td>
<td>$1.0 \times 1.0$</td>
<td>$0.6$</td>
<td>$4.317$</td>
</tr>
<tr>
<td>地面正常疾跑</td>
<td>$1.3 \times 0.98$</td>
<td>/</td>
<td>$1.0 \times 1.0$</td>
<td>$0.6$</td>
<td>$5.612$</td>
</tr>
<tr>
<td>地面斜 $45°$ 疾跑</td>
<td>$1.3 \times 1.0$</td>
<td>/</td>
<td>$1.0 \times 1.0$</td>
<td>$0.6$</td>
<td>$5.727$</td>
</tr>
<tr>
<td>地面正常疾跑(速度 II)</td>
<td>$1.3 \times 0.98$</td>
<td>/</td>
<td>$1.4 \times 1.0$</td>
<td>$0.6$</td>
<td>$7.857$</td>
</tr>
<tr>
<td>地面斜 $45°$ 疾跑(速度 II)</td>
<td>$1.3 \times 1.0$</td>
<td>/</td>
<td>$1.4 \times 1.0$</td>
<td>$0.6$</td>
<td>$8.018$</td>
</tr>
<tr>
<td>空中正常移动飞行</td>
<td>/</td>
<td>$1$</td>
<td>/</td>
<td>/</td>
<td>$10.889$</td>
</tr>
<tr>
<td>空中正常疾跑飞行</td>
<td>/</td>
<td>$2$</td>
<td>/</td>
<td>/</td>
<td>$21.778$</td>
</tr>
</tbody></table>
<h2 id="垂直稳态(渐进)速度"><a href="#垂直稳态(渐进)速度" class="headerlink" title="垂直稳态(渐进)速度"></a>垂直稳态(渐进)速度</h2><h3 id="自由落体终端速度"><a href="#自由落体终端速度" class="headerlink" title="自由落体终端速度"></a>自由落体终端速度</h3><p>前文的推导过程已经很详细了,因此这部分只给出结论。</p>
<p>根据公式 (1.3.1) 得到终端速度:$$\boxed{v_{\infty} = -3.920 \text{ m/tick} = -78.400 \text{ m/s}}\tag{2.4.1}$$</p>
<h2 id="位移相关公式推导"><a href="#位移相关公式推导" class="headerlink" title="位移相关公式推导"></a>位移相关公式推导</h2><h3 id="单一方向位移与时间关系推导"><a href="#单一方向位移与时间关系推导" class="headerlink" title="单一方向位移与时间关系推导"></a>单一方向位移与时间关系推导</h3><p>位移 $s(t)$ 为前 $t$ 个速度之和:$$s(t) = \sum_{i=0}^{t-1} v_i$$</p>
<p>根据位移与速度关系式 (2.2.2),代入 $v_i$:$$s(t) = \sum_{i = 0}^{t - 1} \left( \alpha^i v_0 + \beta \frac{1 - \alpha^i}{1 - \alpha} \right) = v_0 \sum_{i = 0}^{t - 1} \alpha^i + \frac{\beta}{1 - \alpha} \sum_{i = 0}^{t-1} (1 - \alpha^i)$$</p>
<p>分别计算两个求和:</p>
<p>$$\sum_{i = 0}^{t-1} \alpha^i = \frac{1 - \alpha^t}{1 - \alpha}$$</p>
<p>$$\sum_{i = 0}^{t - 1} (1 - \alpha^i) =\sum_{i = 0}^{t - 1} 1 - \sum_{i = 0}^{t - 1} \alpha^i = t - \frac{1 - \alpha^t}{1 - \alpha}$$</p>
<p>即:$$s(t) = v_0 \frac{1 - \alpha^t}{1 - \alpha} + \frac{\beta}{1 - \alpha} \left( t - \frac{1 - \alpha^t}{1 - \alpha} \right)$$</p>
<p>整理并化简:$$\boxed{s(t) = \left( \frac{v_0}{1 - \alpha} - \frac{\beta}{(1 - \alpha)^2} \right) (1 - \alpha^t) + \frac{\beta}{1 - \alpha} t}\tag{3.1.1}$$</p>
<h3 id="跳跃过程中水平与垂直位移关系函数推导"><a href="#跳跃过程中水平与垂直位移关系函数推导" class="headerlink" title="跳跃过程中水平与垂直位移关系函数推导"></a>跳跃过程中水平与垂直位移关系函数推导</h3><p>疾跑跳跃时水平速度会增加 0.2,但在这里不讨论初速度的问题。</p>
<p>将公式 (1.3.1) 中对应的 $\alpha$ 和 $\beta$ 代入公式 (3.1.1) 中:$$y(t) = \left( \frac{v_0}{1 - 0.98} - \frac{0.0784}{(1 - 0.98) ^ 2}\right) (1 - 0.98^t) + \frac{0.0784}{1 - 0.98} t$$</p>
<p>化简后得到:$$y(t) = \left( \frac{v_0}{0.98} + 4 \right) 0.98^t - 3.92$$</p>
<p>令 $K = \frac{v_0}{0.98} + 4,\ i = 0.98^t$:</p>
<p>$$y = K i - 3.92$$</p>
<p>则:$$i = \frac{y + 3.92}{K}$$</p>
<p>$$t = \log_{0.98} i = \frac{\ln i}{\ln 0.98}$$</p>
<p>若公式 (3.1.1) 表示水平移动的速度与时间关系,令:$$\gamma =\frac{v_0}{1 - \alpha} - \frac{\beta}{(1 - \alpha)^2},\ \delta = \frac{\beta}{1 - \alpha}$$</p>
<p>则:$$x(t) = \gamma (1 - \alpha^t) + \delta t \tag{3.2.1}$$</p>
<p>将 $\alpha^t$ 用 $i$ 表示:$$\alpha^t = e^{t \ln \alpha} = e^{\frac{\ln i \ln \alpha}{\ln 0.98}} = i^{\frac{\ln \alpha}{\ln 0.98}}$$</p>
<p>将 $\alpha^t$ 代入公式 (3.2.1) 得:$$x = \gamma (1 - i^{\frac{\ln \alpha}{\ln 0.98}}) + \delta \frac{\ln i}{\ln 0.98}$$</p>
<p>再代入 $i$:$$x = \gamma\left( 1 - \left( \frac{y + 3.92}{K} \right)^{\frac{\ln \alpha}{\ln 0.98}}\right) + \delta \frac{\ln \left(\frac{y + 3.92}{K} \right)}{\ln 0.98} \tag{3.2.2}$$</p>
<p>将 $\gamma = \frac{v_0}{1 - \alpha} - \frac{\beta}{(1 - \alpha)^2},\ \delta = \frac{\beta}{1 - \alpha}, \ \alpha = 0.91, \ \beta = 0.02 k_M, \ K = \frac{v_0}{0.98} + 4 $ 代入公式 (3.2.2) 得:$$x = \left( \frac{v_0}{0.09} - \frac{0.02 k_M}{0.0081} \right) \left[ 1 - \left( \frac{y + 3.92}{\frac{v_0}{0.98} + 4}\right) ^ {\frac{\ln 0.91}{\ln 0.98}} \right] + \frac{0.02 k_M}{0.09 \ln 0.98} \ln \left( \frac{y + 3.92}{\frac{v_0}{0.98} + 4} \right) $$</p>
<p>再略微化简一下:$$\boxed{x = \frac{100}{81}(9v_0 - 2k_M) \left[ 1 - 0.91 \left( \frac{y + 3.92}{v_0 + 3.92} \right)^ {\frac{\ln 0.91}{\ln 0.98}} \right] + \frac{2k_M}{9} \left( 1 + \log_{0.98} \left( \frac{y + 3.92}{v_0 + 3.92} \right) \right) } \tag{3.2.3}$$</p>
<h2 id="附件"><a href="#附件" class="headerlink" title="附件"></a>附件</h2><p><a target="_blank" rel="noopener" href="https://github.com/Revethere/Files/blob/master/BlogFiles/academic%40ed-of-minecraft-entity-mm-eqs/Minecraft%20%E5%AE%9E%E4%BD%93%E8%BF%90%E5%8A%A8%E5%85%AC%E5%BC%8F%E6%8B%93%E5%B1%95%E6%8E%A8%E5%AF%BC.pdf">Minecraft 实体运动公式拓展推导.pdf</a></p>
<h2 id="更新日志"><a href="#更新日志" class="headerlink" title="更新日志"></a>更新日志</h2><p>25.12.14 $\LaTeX$ 写完 PDF 附件</p>
<p>25.12.21 抽空复制粘贴稍微改了一下文章同步到博客</p>
<p><strong>持续更新</strong></p>
</div>
</div>
<div class="post-tags">
<span class="icon">
<i class="fa-solid fa-tags fa-fw"></i>
</span>
<span class="tag">
<a href="/tags/Minecraft/" style="color: #ffa2c4">Minecraft</a>
</span>
<span class="tag">
<a href="/tags/%E6%95%B0%E5%AD%A6/" style="color: #00bcd4">数学</a>
</span>
</div>
<div class="more-center" @click="toggleExpand">
<span class="more-text">MORE</span>
<span class="more-icon"><i class="fa-solid fa-chevron-down"></i></span>
</div>
<div class="collapse-arrow" @click="toggleExpand" title="收起文章">
<i class="fa-solid fa-chevron-up"></i>
</div>
</div>
<div class="post" data-has-more="true" data-single="true">
<a href="/posts/academic@min-kb-click-freq-lower-bound/">
<h2 class="post-title">『低版本 pvp 中玩家最优 kb 的点击频率下限分析』</h2>
</a>
<div class="category-and-date">
<span class="category">
<a href="/categories/%E7%90%86%E8%AE%BA/">
<span class="icon">
<i class="fa-solid fa-bookmark fa-fw"></i>
</span>
理论
</a>
</span>
<span class="date">
<span class="icon">
<i class="fa-solid fa-calendar fa-fw"></i>
</span>
2025/10/18
</span>
</div>
<div class="description">
<div class="excerpt-content" v-pre>
<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>⚠️<strong>硬核警告</strong>⚠️</p>
<p>英译版见<a href="https://revethere.github.io/posts/academic@min-kb-click-freq-lower-bound-en/">『Minimum KB Click Frequency Lower Bound Analysis』</a>.</p>
<p>本文包含大量数学公式和代码分析,建议具备一定理论基础阅读。</p>
<p>欢迎各位大佬指正🥰。</p>
<p><del>嗯……AI 帮了点小忙,还是挺好看出来的,对吧。</del></p>
<hr>
<h2 id="物理学框架下的-Minecraft-实体运动"><a href="#物理学框架下的-Minecraft-实体运动" class="headerlink" title="物理学框架下的 Minecraft 实体运动"></a>物理学框架下的 Minecraft 实体运动</h2><h3 id="经典力学下的运动"><a href="#经典力学下的运动" class="headerlink" title="经典力学下的运动"></a>经典力学下的运动</h3><p>$$\frac{dv}{dt} = a - fv \tag{1.1.1}$$</p>
<p>$$v = v_0 e^{-ft} + \frac{a}{f} (1 - e^{-ft}) \tag{1.1.2}$$</p>
<p>$$\frac{v}{v_0} = \lim\limits_{t_0 \to 0} (1 - f t_0)^{\frac{t}{t_0}}, a = 0 \tag{1.1.3}$$</p>
<p>公式 (1.1.1) 描述了物体在恒定驱动力和正比于速度的阻力共同作用下,速度从变化逐渐达到稳定平衡的动态过程。这也是后续所有公式推导的基础。</p>
<p>公式 (1.1.2) 是通过求解公式 (1.1.1) 得到的精确解(通解)。其描述了在任何初始速度 $v_0$ 和任何驱动力 $a$ 的情况下,速度随时间变化的完整规律。</p>
<p>公式 (1.1.3) 则是将驱动力 $a=0$ 时的特殊情况代入公式 (1.1.2) 得到的结果。表明物体仅在阻力作用下,速度从初值 $v_0$ 开始指数衰减到零的过程。</p>
<blockquote>
<p>其中,$f$ 为阻力系数。</p>
</blockquote>
<blockquote>
<p>但是,Minecraft 是以 tick(后续将称为 gt)为单位进行离散更新,即 $dt$ 和 $t_0$ 的最小值为 1gt,不能无限趋近于 0。因此这一规则在游戏中不能精确实现。</p>
</blockquote>
<h3 id="Mojang-对于实体运动的实现"><a href="#Mojang-对于实体运动的实现" class="headerlink" title="Mojang 对于实体运动的实现"></a>Mojang 对于实体运动的实现</h3><p>以下是实体在水平和空中运动源代码简化版。已删去不必要和不相关的代码。</p>
<ul>
<li><p>在 <code>net/minecraft/entity/EntityLivingBase.java</code> 中:</p>
<pre><code class="java">public void moveEntityWithHeading(float strafe, float forward) {
/**
* 环境检测与移动类型判断
* isInWater()、isInLava()、isFlying
* 水、岩浆、梯子等特殊状态移动处理(else if)
*/
float f4 = 0.91F; // 惯性系数
if (this.onGround) {
f4 = this.worldObj.getBlockState(
new BlockPos(
MathHelper.floor_double(this.posX),
MathHelper.floor_double(this.getEntityBoundingBox().minY) - 1,
MathHelper.floor_double(this.posZ)
)
)
.getBlock()
.slipperiness * 0.91F;
} // 获取下方方块滑度(后续将 slipperiness 称为滑度系数)
float f = 0.16277136F / (f4 * f4 * f4);
/**
* (0.6*0.91)^3 = 0.16277136
* 移动系数
*/
float f5;
if (this.onGround) f5 = this.getAIMoveSpeed() * f;
/**
* f5 = this.landMovementFactor * f;
* landMovementFactor 基础情况下为 0.1,疾跑时*1.3,受药水效果影响
*/
else f5 = this.jumpMovementFactor;
/**
* jumpMovementFactor = 0.02;
* 疾跑时*1.3,与药水效果无关
*/
this.moveFlying(strafe, forward, f5); // 速度计算
// 重新计算 f4
// 嗯···屎山代码这一块(
this.moveEntity(this.motionX, this.motionY, this.motionZ); // 实体移动
// 未加载区块重力处理
this.motionY -= 0.08D; // 重力
this.motionY *= 0.9800000190734863D; // 空气阻力
this.motionX *= (double)f4; this.motionZ *= (double)f4; // 摩擦力(水平)
// 玩家肢体动画更新
}
</code></pre>
</li>
<li><p>方块的滑度系数在 <code>net/minecraft/block/Block.java</code> 等文件中定义:</p>
<pre><code class="java">// Block.java
public class Block {
// 其它方块属性
public float slipperiness;
public Block(Material blockMaterialIn, MapColor blockMapColorIn) {
// 其它属性初始化
this.slipperiness = 0.6F;
}
}
// BlockIce.java
public class BlockIce extends BlockBreakable {
public BlockIce() {
this.slipperiness = 0.98F;
}
} // 冰
//BlockPackedIce.java
public class BlockPackedIce extends Block {
public BlockPackedIce() {
this.slipperiness = 0.98F;
}
} // 浮冰
// BlockSlime.java
public class BlockSlime extends BlockBreakable {
public BlockSlime() {
this.slipperiness = 0.8F;
}
} // 史莱姆块
</code></pre>
<p>滑度系数将用 $f_s$ 在后续的公式推导中来表示。</p>
<blockquote>
<p>特别地,蓝冰在 1.13 被加入,滑度为 0.989。此处仅作补充。</p>
</blockquote>
</li>
<li><p>实体在地面的移速(通过 <code>getAIMoveSpeed()</code> 函数返回,本质上是变量 <code>landMovementFactor</code> 的值)在文件 <code>net/minecraft/entity/EntityLivingBase.java</code> 定义:</p>
<pre><code class="java">public abstract class EntityLivingBase extends Entity {
private float landMovementFactor;
public float getAIMoveSpeed() {
return this.landMovementFactor;
}
}
</code></pre>
<p>其基本值在 <code>net/minecraft/entity/player/PlayerCapabilities.java</code> 给出:</p>
<pre><code class="java">public class PlayerCapabilities {
private float walkSpeed = 0.1F;
}
</code></pre>
<p>疾跑状态的修饰在 <code>net/minecraft/entity/EntityLivingBase.java</code> 中定义:</p>
<pre><code class="java">public abstract class EntityLivingBase extends Entity {
private static final AttributeModifier sprintingSpeedBoostModifier =
(new AttributeModifier(
sprintingSpeedBoostModifierUUID,
"Sprinting speed boost",
0.30000001192092896D,
2
)).setSaved(false);
}
</code></pre>
<p>疾跑速度则是通过 <code>net/minecraft/entity/ai/attributes/ModifiableAttributeInstance.java</code> 中的方法实现:</p>
<pre><code class="java">private double computeValue() {
double d0 = this.getBaseValue(); // 属性基本值获取
for (AttributeModifier attributemodifier : this.func_180375_b(0)) {
d0 += attributemodifier.getAmount();
}
double d1 = d0;
for (AttributeModifier attributemodifier1 : this.func_180375_b(1)) {
d1 += d0 * attributemodifier1.getAmount();
}
for (AttributeModifier attributemodifier2 : this.func_180375_b(2)) {
d1 *= 1.0D + attributemodifier2.getAmount();
}
// 三种类型修饰叠加
return this.genericAttribute.clampValue(d1);
}
</code></pre>
<p>实体在空中的移速(<code>jumpMovementFactor</code>)在 <code>net/minecraft/entity/EntityLivingBase.java</code> 中定义:</p>
<pre><code class="java">public abstract class EntityLivingBase extends Entity {
public float jumpMovementFactor = 0.02F;
}
</code></pre>
<p>疾跑时在 <code>net/minecraft/entity/player/EntityPlayer.java</code> 中更新:</p>
<pre><code class="java">public abstract class EntityPlayer extends EntityLivingBase {
public void onLivingUpdate() {
if (this.isSprinting()) {
this.jumpMovementFactor = (float)(
(double)this.jumpMovementFactor +
(double)this.speedInAir * 0.3D
);
}
}
}
</code></pre>
<p><del>屎山代码这两种运动实现还不一样 ):</del></p>
</li>
<li><p>实体的「motion」在 <code>net/minecraft/entity/Entity.java</code> 中更新:</p>
<pre><code class="java">public void moveFlying(float strafe, float forward, float friction) {
float f = strafe * strafe + forward * forward;
if (f >= 1.0E-4F) {
f = MathHelper.sqrt_float(f); // 模长为 1 的单位向量
if (f < 1.0F) {
f = 1.0F; // 避免斜向速度异常
}
f = friction / f;
strafe = strafe * f;
forward = forward * f;
// 摩擦系数应用
float f1 = MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F);
float f2 = MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F);
this.motionX += (double)(strafe * f2 - forward * f1);
this.motionZ += (double)(forward * f2 + strafe * f1);
// 2D 旋转矩阵
}
}
</code></pre>
<p><code>strafe</code> 和 <code>forward</code> 变量在 <code>net/minecraft/util/MovementInputFromOptions.java</code> 中获取按键输入更新:</p>
<pre><code class="java">public void updatePlayerMoveState() {
this.moveStrafe = 0.0F;
this.moveForward = 0.0F;
if (this.gameSettings.keyBindForward.isKeyDown()) {
++this.moveForward;
}
if (this.gameSettings.keyBindBack.isKeyDown()) {
--this.moveForward;
}
if (this.gameSettings.keyBindLeft.isKeyDown()) {
++this.moveStrafe;
}
if (this.gameSettings.keyBindRight.isKeyDown()) {
--this.moveStrafe;
}
// 其它按键事件
/**
* 潜行事件
* moveStrafe 和 moveForward 乘以 0.3
*/
}
</code></pre>
</li>
</ul>
<p>通过分析上述代码实现可以得知:</p>
<p>实体在水平方向上的「motion 属性」,在数值上等于当前速度向量在<strong>各坐标轴的分量乘以对应的阻力系数</strong>(垂直方向上的「motion」计算略有不同)。</p>
<p>若将 $t_0$ 时间内的「motion」视为平均速度 $M$,那么「motion」与阻力系数的乘积在物理意义上表示在该时间段内阻力对实体产生的<strong>冲量</strong>。</p>
<blockquote>
<p>实体的「motion 属性」本质上是实体运动计算过程中的中间量,仅在游戏执行 <code>moveFlying()</code> 函数计算后,「motion 属性」可被视为实体的速度(或该时间段内的平均速度近似值)。</p>
</blockquote>
<h3 id="线性运动公式推导"><a href="#线性运动公式推导" class="headerlink" title="线性运动公式推导"></a>线性运动公式推导</h3><p>为了方便理解公式,在这里定义一些必要参数:</p>
<ul>
<li>速度:$v_H$、$v_Y$,实体在水平与垂直上的速度。</li>
<li>初始垂直速度:$v_{Y,1}$,取决于跳跃速度或服务器垂直击退参数。</li>
<li>滑度系数:$f_s = 0.6$(空气中不受该阻力影响)。</li>
<li>移动乘数:$k_M = 1.3 \times 0.98 = 1.274$(停止状态下为 0)。</li>
<li>效果乘数:$k_E = 1 \times 1 = 1$.</li>
<li>动量阈值:$v_{th} = 0.005$,当实体在某条轴上的速度经衰减后小于该值时,对应轴上的速度归零。</li>
</ul>
<p>由此推导得到实体运动的递推关系(主要参考 <a target="_blank" rel="noopener" href="https://www.mcpk.wiki/wiki/Main_Page">Minecraft Parkour Wiki</a>):</p>
<ul>
<li><p><strong>地面水平速度公式:</strong>$$v_{H,t} = \underbrace{v_{H,t-1} \times f_{s, t-1} \times 0.91} _ \text{动量保留} + \underbrace{0.1 \times \left( \frac{0.6}{f_{s,t}}\right)^3 \times k_M \times k_E} _ \text{加速度} \tag{1.3.1}$$</p>
</li>
<li><p><strong>空中水平速度公式:</strong>$$v_{H,t} = \underbrace{v_{H,t-1} \times 0.91} _ \text{动量保留} + \underbrace{0.02 \times k_M} _ \text{加速度} \tag{1.3.2}$$</p>
</li>
<li><p><strong>垂直速度公式:</strong>$$v_{Y,t} = ( v_{Y,t-1} - \mathop{0.08}\limits_\text{重力} ) \times \mathop{0.98}\limits_\text{阻力} \tag{1.3.3}$$</p>
</li>
</ul>
<blockquote>
<p>考虑到实际应用场景,上述推导中大部分系数或乘数均使用特殊值。</p>
</blockquote>
<blockquote>
<p>在后续『最优 kb 的点击频率下限分析』章节中,将加入点击行为对速度的影响机制。</p>
</blockquote>
<hr>
<h2 id="鼠标点击分析"><a href="#鼠标点击分析" class="headerlink" title="鼠标点击分析"></a>鼠标点击分析</h2><h3 id="双击延迟"><a href="#双击延迟" class="headerlink" title="双击延迟"></a>双击延迟</h3><p>经测试,鼠标双击的触发延迟主要分布在 $[16, 27]\ \mathrm{ms}$ 区间范围内,受硬件性能、驱动程序、系统环境等影响,在不同的测试环境下略有差异。</p>
<p>若两次点击分别落在相邻的 tick 中,则称为「有效双击」。</p>
<h3 id="有效双击的概率计算"><a href="#有效双击的概率计算" class="headerlink" title="有效双击的概率计算"></a>有效双击的概率计算</h3><p>设第一次点击的时间为 $T$,服从区间 $[0,50]$ 上的均匀分布:$$T \sim \mathcal{U}(0,50)$$</p>
<p>双击延迟为 $D$,服从区间 $[16,27]$ 上的均匀分布:$$D \sim \mathcal{U}(16,27)$$</p>
<p>则「有效双击」的概率:$$P(T + D \geq 50)$$</p>
<p>$T$ 和 $D$ 相互独立,其联合概率密度函数为:</p>
<p>$$f_{T,D}(t,d) = \frac{1}{50} \times \frac{1}{11} = \frac{1}{550},\ t \in [0,50],\ d \in [16,27]$$</p>
<p>展开积分并计算所求概率:</p>
<p>$$P(T + D \geq 50) = \iint\limits_{t + d \geq 50} f_{T,D}(t, d)\ dt\ dd = \int_{16}^{27} \int_{50 - d}^{50} \frac{1}{550}\ dt\ dd = \frac{473}{1100} = \frac{43}{100}$$</p>
<p><strong>即「有效双击」的触发概率为 43%.</strong></p>
<p>如果你不想阅读这部分略微令人头皮发麻的积分还可以通过条件期望来推导该概率:</p>
<p>$$P(T + D \geq 50) = P(T \geq 50 - D) = E[P(T \geq 50 - D \mid D)]$$</p>
<p>对于固定的 $D,\ T \sim \mathcal{U}(0, 50)$,且 $50 - D \in [23, 34] \subseteq [0, 50]$,有:</p>
<p>$$P(T \geq 50 - D \mid D) = \frac{50 - (50 - D)}{50} = \frac{D}{50}$$</p>
<p>得到:</p>
<p>$$P(T + D \geq 50) = E\left[\frac{D}{50}\right] = \frac{1}{50} E[D] = \frac{1}{50} \times \frac{16 + 27}{2} = \frac{43}{100}$$</p>
<p>与积分计算的结果一致。</p>
<p>🧠☠️</p>
<hr>
<h2 id="击退算法杂谈"><a href="#击退算法杂谈" class="headerlink" title="击退算法杂谈"></a>击退算法杂谈</h2><h3 id="原版击退算法"><a href="#原版击退算法" class="headerlink" title="原版击退算法"></a>原版击退算法</h3><p>当玩家攻击时调用 <code>net/minecraft/entity/player/EntityPlayer.java</code> 文件中的 <code>attackTargetEntityWithCurrentItem()</code> 函数处理该过程:</p>
<pre><code class="java">public abstract class EntityPlayer extends EntityLivingBase {
public void attackTargetEntityWithCurrentItem(Entity targetEntity) {
/**
* 可攻击检查
* 基础伤害计算
* 附魔伤害计算
*/
int i = 0;
i = i + EnchantmentHelper.getKnockbackModifier(this);
if (this.isSprinting()) {
++i;
}
// 击退效果计算
/**
* 伤害有效性检查
* 暴击判断
* 火焰附加
*/
double d0 = targetEntity.motionX;
double d1 = targetEntity.motionY;
double d2 = targetEntity.motionZ;
boolean flag2 = targetEntity.attackEntityFrom(DamageSource.causePlayerDamage(this), f);
// 伤害应用
if (flag2) {
if (i > 0) {
targetEntity.addVelocity(
(double)(-MathHelper.sin(
this.rotationYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F),
0.1D,
(double)(MathHelper.cos(
this.rotationYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F)
); // 第二阶段击退计算
this.motionX *= 0.6D;
this.motionZ *= 0.6D;
this.setSprinting(false);
// 攻击者减速并取消疾跑状态
}
if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged) {
((EntityPlayerMP)targetEntity).playerNetServerHandler.sendPacket(
new S12PacketEntityVelocity(targetEntity)
);
targetEntity.velocityChanged = false;
targetEntity.motionX = d0;
targetEntity.motionY = d1;
targetEntity.motionZ = d2;
} // 避免重复叠加击退
/**
* 伤害成功后续处理
* 攻击失败处理
*/
}
}
</code></pre>
<pre><code class="java">// net/minecraft/entity/EntityLivingBase.java
public abstract class EntityLivingBase extends Entity {
public boolean attackEntityFrom(DamageSource source, float amount) {
/**
* 检查实体是否对特定伤害源免疫
* 客户端检查
* 死亡检查
* 特殊伤害免疫(抗火)
* 装备减伤
* 伤害刻(特别地,该时间段内更高的伤害会覆盖原有伤害)
* 攻击者判断
* 视觉更新(伤害动画)
*/
double d1 = entity.posX - this.posX;
double d0;
for(d0 = entity.posZ - this.posZ;
d1 * d1 + d0 * d0 < 1.0E-4D;
d0 = (Math.random() - Math.random()) * 0.01D) {
d1 = (Math.random() - Math.random()) * 0.01D;
} // 距离过近的随机击退
this.attackedAtYaw = (float)(
MathHelper.atan2(d0, d1) * 180.0D / Math.PI
- (double)this.rotationYaw
);
this.knockBack(entity, amount, d1, d0); // 执行击退
// 其它操作
}
public void knockBack(Entity entityIn, float amount, double d0, double d1) {
if (this.rand.nextDouble() >= this.getEntityAttribute(
SharedMonsterAttributes.knockbackResistance).getAttributeValue()) {
this.isAirBorne = true;
float f = MathHelper.sqrt_double(d0 * d0 + d1 * d1);
float f1 = 0.4F;
this.motionX /= 2.0D;
this.motionY /= 2.0D;
this.motionZ /= 2.0D;
// 受击者速度衰减
this.motionX -= d0 / (double)f * (double)f1;
this.motionY += (double)f1;
this.motionZ -= d1 / (double)f * (double)f1;
// 第一阶段击退计算
if (this.motionY > 0.4000000059604645D) {
this.motionY = 0.4000000059604645D;
} // 垂直击退上限
}
}
}
</code></pre>
<pre><code class="java">// net/minecraft/entity/Entity.java
public abstract class Entity implements ICommandSender {
protected void setBeenAttacked() {
this.velocityChanged = true;
}
public boolean attackEntityFrom(DamageSource source, float amount) {
if (this.isEntityInvulnerable(source)) {
return false;
} else {
this.setBeenAttacked();
return false;
}
}
}
</code></pre>
<p>为了更清晰地理解击退机制,在这里定义以下参数:</p>
<ul>
<li><code>horizontal</code>:基础水平击退。对应 <code>knockBack()</code> 函数中的 <code>f1</code> 变量,默认值为 0.4</li>
<li><code>vertical</code>:基础垂直击退。其数值与基础水平击退相同,为 0.4</li>
<li><code>horizontalExtra</code>:额外水平击退。仅考虑疾跑的因素,即 <code>i = 1</code>,值为 0.5</li>
<li><code>verticalExtra</code>:额外垂直击退。<code>addVelocity()</code> 函数中的叠加固定额外垂直击退,默认值为 0.1</li>
<li><code>verticalLimit</code>:垂直击退上限。<code>motionY</code> 的最大值 0.4</li>
<li><code>friction</code>:暂无合适的译法。表示玩家受击时各轴的速度衰减(区别于方块的 friction),默认值为 2.0</li>
</ul>
<p>基于上述代码分析可知玩家受到的击退效果主要分为两个阶段:</p>
<ul>
<li><strong>击退的第一阶段:</strong>仅与双方在 XZ 轴上的相对位置相关。</li>
<li><strong>击退的第二阶段</strong>:仅与攻击者的偏航角(yaw)和攻击者的状态(本文只考虑疾跑)相关。</li>
</ul>
<h3 id="MMC-击退算法"><a href="#MMC-击退算法" class="headerlink" title="MMC 击退算法"></a>MMC 击退算法</h3><p>本小节重点讨论与原版击退算法不同之处。</p>
<blockquote>
<p> 详细实现见 <a target="_blank" rel="noopener" href="https://github.com/Revethere/Files/blob/master/BlogFiles/academic%40how-does-kb-work-exactly/How%20MMC%20Knockback%20Actually%20Works.pdf">How MMC Knockback Actually Works</a>.</p>
</blockquote>
<p>MMC 引入了以下新的或修改的参数:</p>
<pre><code class="java">totalHorizontal = 0.8835d // 总水平击退
totalVertical = 0.9055d // 总垂直击退
rangeFactor = 0.035d // 距离影响系数
maxReduction = 0.4d // 最大距离减免
startRange = 3.0d // 距离减免起始计算距离
idleReduction = 0.6d // 基础击退倍率
attackBuffer = 1 // 攻击缓存
// 计算后的实际值
horizontal = totalHorizontal * idleReduction // 基础水平击退
horizontalExtra = totalHorizontal * (1 - idleReduction) // 额外水平击退
vertical = totalVertical * 0.4d // 基础垂直击退
verticalExtra = 0.0d // 额外垂直击退
verticalLimit = 0.4d // 垂直击退上限
attackerSlowdown = 0.6d
friction = 0.0d
</code></pre>
<p>不难看出:</p>
<ul>
<li><code>idleReduction</code> 决定了基础水平击退和额外水平击退的大小,并与 <code>totalHorizontal</code> 的值紧密相关。</li>
<li><code>verticalExtra</code> 的值归零,即玩家的垂直击退固定。</li>
<li><code>attackBuffer</code> 提供伤害刻结束前的攻击窗口。</li>
<li>增加了 <code>rangeFactor</code>、<code>maxReduction</code>、<code>startRange</code> 参数用于减免由于延迟造成的远距离攻击注册的击退。</li>
</ul>
<blockquote>
<p>特别地,当 <code>friction = 0.0</code> 时,受击者的动量归零,即击退完全覆盖原速度。</p>
</blockquote>
<p>第一阶段击退算法:</p>
<pre><code class="java">void firstStage(EntityLiving attacker, EntityLiving victim) {
// 省略部分伪代码
double distance = Math.sqrt(distanceX * distanceX + distanceZ * distanceZ);
double rangeReduction = calculateRangeReduction(distance)
double modifiedHorizontal = horizontal - rangeReduction // 远距离击退衰减
double magnitude = Math.sqrt(distanceX * distanceX + distanceZ * distanceZ)
victim.motX -= (distanceX / magnitude) * (modifiedHorizontal * 0.5d)
victim.motZ -= (distanceZ / magnitude) * (modifiedHorizontal * 0.5d)
double yaw = Math.toRadians(attacker.yaw)
victim.motX += -Math.sin(yaw) * (modifiedHorizontal * 0.5d)
victim.motZ += Math.cos(yaw) * (modifiedHorizontal * 0.5d)
}
</code></pre>
<p>与原版不同的是,MMC 算法中第一阶段的击退同时与玩家的相对位置和攻击者的偏航角相关(占比各 50%)。并增加了 <code>calculateRangeReduction()</code> 函数用于减免远距离击退。</p>
<p>第二阶段击退算法与第一阶段相似:</p>
<pre><code class="java">void secondStage(EntityLiving attacker, EntityLiving victim, int knockbackEnchantLevel) {
// 省略部分伪代码
if (extraKBMult > 0) {
double distanceX = attacker.locX - victim.locX
double distanceZ = attacker.locZ - victim.locZ
double distance = Math.sqrt(distanceX * distanceX + distanceZ * distanceZ)
double modifiedExtraHorizontal = horizontalExtra * extraKBMult // 额外击退
double magnitude = Math.sqrt(distanceX * distanceX + distanceZ * distanceZ)
victim.motX -= (distanceX / magnitude) * (modifiedExtraHorizontal * 0.5d)
victim.motZ -= (distanceZ / magnitude) * (modifiedExtraHorizontal * 0.5d)
double yaw = Math.toRadians(attacker.yaw)
victim.motX += -Math.sin(yaw) * (modifiedExtraHorizontal * 0.5d)
victim.motZ += Math.cos(yaw) * (modifiedExtraHorizontal * 0.5d)
}
}
</code></pre>
<p>额外水平击退由 <code>horizontalExtra</code> 参数和 <code>extraKBMult</code> 共同决定。并保持与第一阶段相同的 50/50 分配。</p>
<hr>
<h2 id="最优-kb-的点击频率下限分析"><a href="#最优-kb-的点击频率下限分析" class="headerlink" title="最优 kb 的点击频率下限分析"></a>最优 kb 的点击频率下限分析</h2><hr>
<h2 id="一起来品鉴赤石-Mojang-的代码"><a href="#一起来品鉴赤石-Mojang-的代码" class="headerlink" title="一起来品鉴赤石 Mojang 的代码"></a>一起来<del>品鉴</del>赤石 Mojang 的代码</h2><hr>
<h2 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h2><p><a target="_blank" rel="noopener" href="https://www.mcpk.wiki/wiki/Movement_Formulas">运动公式 - Minecraft Parkour Wiki</a></p>
<p><a target="_blank" rel="noopener" href="https://github.com/Revethere/Files/blob/master/BlogFiles/academic%40how-does-kb-work-exactly/How%20MMC%20Knockback%20Actually%20Works.pdf">How MMC Knockback Actually Works</a></p>
<p><a target="_blank" rel="noopener" href="https://pages.carm.cc/dev/knockback-study.html">对我的世界中PVP击退的研究报告 - LSeng, CarmJos</a></p>
<p><a target="_blank" rel="noopener" href="https://www.bilibili.com/opus/175537636967628180">关于修正并改进 xwj 的 MC 实体运动公式 —— 适用于MC中所有实体 - Bio-Hazard</a></p>
<p><a target="_blank" rel="noopener" href="http://lovexyn0827.space/mcdocs/docs/Minecraft%E5%AE%9E%E4%BD%93%E8%BF%90%E5%8A%A8%E7%A0%94%E7%A9%B6%E4%B8%8E%E5%BA%94%E7%94%A8/0-Minecraft%E5%AE%9E%E4%BD%93%E8%BF%90%E5%8A%A8%E7%9B%B8%E5%85%B3%E7%A0%94%E7%A9%B6%E4%B8%8E%E5%BA%94%E7%94%A8.html">Minecraft 实体运动研究与应用 - lovexyn0827</a></p>
<p><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=o-a0szldhs8">The ULTIMATE Guide to PING - sceyna</a></p>
<p><a target="_blank" rel="noopener" href="https://github.com/Marcelektro/MCP-919">MCP-919 ( Fully decompiled )</a></p>
<p><a target="_blank" rel="noopener" href="https://github.com/CobbleSword/NachoSpigot">NachoSpigot</a></p>
<h2 id="致谢"><a href="#致谢" class="headerlink" title="致谢"></a>致谢</h2><p><a target="_blank" rel="noopener" href="https://space.bilibili.com/298238084">蔚蓝天空Azure_Sky</a></p>
<p><a target="_blank" rel="noopener" href="https://space.bilibili.com/165837583">时代地产</a></p>
<h2 id="附件"><a href="#附件" class="headerlink" title="附件"></a>附件</h2><h2 id="更新日志"><a href="#更新日志" class="headerlink" title="更新日志"></a>更新日志</h2><p>25.11.30 - 发布已基本写完的三章</p>
</div>
</div>
<div class="post-tags">
<span class="icon">
<i class="fa-solid fa-tags fa-fw"></i>
</span>
<span class="tag">
<a href="/tags/Minecraft/" style="color: #03a9f4">Minecraft</a>
</span>
<span class="tag">
<a href="/tags/sumo/" style="color: #ffa2c4">sumo</a>
</span>
<span class="tag">
<a href="/tags/Java/" style="color: #ff7d73">Java</a>
</span>
</div>
<div class="more-center" @click="toggleExpand">
<span class="more-text">MORE</span>
<span class="more-icon"><i class="fa-solid fa-chevron-down"></i></span>
</div>
<div class="collapse-arrow" @click="toggleExpand" title="收起文章">
<i class="fa-solid fa-chevron-up"></i>
</div>
</div>
<div class="post" data-has-more="true" data-single="true">
<a href="/posts/introduction@rewind-mod-redefine-video-recording/">