--- title: 判斷操作 tags: math, number theory --- # 小數比較操作(Decimal Comparison Operations) 在Minecraft中一共有提供以下幾種比較操作的途徑: * 實體選擇器 Selector: * 座標(Position) : x, y, z * 角度(Rotation) : x_rotation, y_rotation * 區域(Local) : dx, dy, dz * 距離(Distance) : distance * 謂詞 Predicate: --- ### 核心概念 其最核心概念是將 $a\geq b$ 之類的關係改寫成 $a-b\geq0$, 也就是變成需要判斷的是 $a-b$ 與 $0$ 的相對關係 ### 舉例來說 比較兩數 $(a,b)=(50,40)$,嘗試進行 $a\geq b$ 的比較操作時, $(a-b=10)\geq0$,其結果為true 流程會類似: ```= data modify storage cal stack append 50.0 data modify storage cal stack append 40.0 function sub data merge entity @s Pos[1] from storage cal stack[-1] execute unless predicate math:is_positive run ... ``` ```= 將50放入stack 將40放入stack 執行sub(相減)操作:50-40 將sub的結果(10)存入Y座標中 如果從Y軸比較的距離值比0還要大,則執行... ``` 在predicate判斷Y座標是否為is_positive(包含0) ```json { "condition": "minecraft:entity_properties", "entity": "this", "predicate": { "location": { "position": { "y": { "min": 0.0 } } } } } ```