-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmc-calc.html
More file actions
259 lines (220 loc) · 9.03 KB
/
Copy pathmc-calc.html
File metadata and controls
259 lines (220 loc) · 9.03 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MC Stronghold Finder</title>
<link href="https://fonts.googleapis.com/css2?family=VT323&display=swap" rel="stylesheet">
<style>
:root {
--mc-bg: #202020;
--mc-panel: #313131;
--mc-btn: #7E7E7E;
--mc-green: #55FF55;
--mc-red: #FF5555;
--mc-white: #FFFFFF;
}
body {
background-color: #121212;
color: var(--mc-white);
font-family: 'VT323', monospace;
display: flex;
flex-direction: column;
align-items: center;
margin: 0;
padding: 20px;
}
.container {
background-color: var(--mc-panel);
border: 4px solid #000;
padding: 20px;
width: 90%;
max-width: 500px;
box-shadow: 0 0 0 4px #555;
}
h1 { color: var(--mc-green); text-align: center; margin-top: 0; text-shadow: 2px 2px #000; }
.row { display: flex; gap: 10px; margin-bottom: 5px; align-items: center; }
.row label { width: 40px; text-align: right; font-size: 1.2rem; }
input {
flex: 1;
background: #000;
border: 2px solid #555;
color: var(--mc-white);
padding: 5px;
font-family: inherit;
font-size: 1.2rem;
}
.section-title { color: #FFFF55; border-bottom: 2px solid #555; margin: 15px 0 10px 0; }
button {
width: 100%;
margin-top: 20px;
padding: 10px;
font-family: inherit;
font-size: 1.5rem;
background: var(--mc-btn);
color: #fff;
border: 4px solid #000;
cursor: pointer;
text-shadow: 2px 2px #000;
box-shadow: inset 4px 4px 0 rgba(255,255,255,0.2), inset -4px -4px 0 rgba(0,0,0,0.2);
}
button:active { transform: translateY(2px); }
#result {
margin-top: 20px;
padding: 15px;
background: rgba(0,0,0,0.3);
border: 2px dashed #777;
font-size: 1.3rem;
white-space: pre-line;
}
/* 可视化画布样式 */
#visualizer {
margin-top: 20px;
background: #000;
border: 2px solid var(--mc-green);
display: none; /* 默认隐藏,计算成功后显示 */
}
</style>
</head>
<body>
<div class="container">
<h1>STRONGHOLD FINDER</h1>
<div class="section-title">Point 1 (第一次投掷)</div>
<div class="row"><label>X:</label><input type="number" id="x1"></div>
<div class="row"><label>Z:</label><input type="number" id="z1"></div>
<div class="row"><label>Yaw:</label><input type="number" id="yaw1"></div>
<div class="section-title">Point 2 (第二次投掷)</div>
<div class="row"><label>X:</label><input type="number" id="x2"></div>
<div class="row"><label>Z:</label><input type="number" id="z2"></div>
<div class="row"><label>Yaw:</label><input type="number" id="yaw2"></div>
<button onclick="calculate()">[ 计 算 坐 标 ]</button>
<div id="result"></div>
<canvas id="visualizer" width="460" height="300"></canvas>
</div>
<script>
function calculate() {
// 1. 获取输入
const x1 = parseFloat(document.getElementById('x1').value);
const z1 = parseFloat(document.getElementById('z1').value);
const yaw1 = parseFloat(document.getElementById('yaw1').value);
const x2 = parseFloat(document.getElementById('x2').value);
const z2 = parseFloat(document.getElementById('z2').value);
const yaw2 = parseFloat(document.getElementById('yaw2').value);
const resBox = document.getElementById('result');
const canvas = document.getElementById('visualizer');
if ([x1, z1, yaw1, x2, z2, yaw2].some(isNaN)) {
resBox.innerHTML = "<span style='color:var(--mc-red)'>❌ 请填写所有数值!</span>";
return;
}
// 2. 核心数学逻辑 (修正版)
// MC Yaw: 0=South(+Z), 90=West(-X), 180=North(-Z), -90=East(+X)
// 转换为弧度
const r1 = yaw1 * Math.PI / 180;
const r2 = yaw2 * Math.PI / 180;
// MC 方向向量 (单位向量)
// x增量 = -sin(yaw), z增量 = cos(yaw)
const v1x = -Math.sin(r1), v1z = Math.cos(r1);
const v2x = -Math.sin(r2), v2z = Math.cos(r2);
// 使用二维向量叉乘求交点 (P1 + t*V1 = P2 + u*V2)
// t = ((P2 - P1) x V2) / (V1 x V2)
// 二维叉乘 A x B = Ax*Bz - Az*Bx
const dx = x2 - x1;
const dz = z2 - z1;
// 分母: V1 x V2
const det = v1x * v2z - v1z * v2x;
// 检查平行
if (Math.abs(det) < 0.0001) {
resBox.innerHTML = "<span style='color:var(--mc-red)'>⚠️ 轨迹平行或重合,无法计算交点。<br>请移动至少100格并确保角度变化明显。</span>";
canvas.style.display = 'none';
return;
}
// 分子: (P2 - P1) x V2 = dx*v2z - dz*v2x
const t = (dx * v2z - dz * v2x) / det;
// 3. 计算结果
// 目标坐标
const targetX = x1 + t * v1x;
const targetZ = z1 + t * v1z;
// 距离 (相对于玩家当前位置 P2)
const dist = Math.sqrt(Math.pow(targetX - x2, 2) + Math.pow(targetZ - z2, 2));
// 4. 显示结果
resBox.innerHTML = `
<span style="color:var(--mc-green)">✅ 主世界目标 (Overworld)</span>
X: <b>${Math.round(targetX)}</b>
Z: <b>${Math.round(targetZ)}</b>
距离: ${Math.round(dist)} 格
<hr style="border:1px dashed #555">
<span style="color:#FF5555">🔥 下界传送门 (Nether)</span>
X: <b>${Math.round(targetX / 8)}</b>
Z: <b>${Math.round(targetZ / 8)}</b>
`;
// 5. 调用可视化绘图
drawVisuals(x1, z1, x2, z2, targetX, targetZ);
}
function drawVisuals(x1, z1, x2, z2, tx, tz) {
const canvas = document.getElementById('visualizer');
const ctx = canvas.getContext('2d');
canvas.style.display = 'block';
// 清空画布
ctx.fillStyle = '#000';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// 自动缩放逻辑:找出包含三个点(P1, P2, Target)的边界
const padding = 40;
const minX = Math.min(x1, x2, tx);
const maxX = Math.max(x1, x2, tx);
const minZ = Math.min(z1, z2, tz);
const maxZ = Math.max(z1, z2, tz);
const rangeX = maxX - minX || 1;
const rangeZ = maxZ - minZ || 1;
// 保持比例
const scale = Math.min(
(canvas.width - padding * 2) / rangeX,
(canvas.height - padding * 2) / rangeZ
);
// 坐标映射函数 (将 MC 坐标映射到 Canvas 坐标)
// Canvas Y轴向下,MC Z轴向下(南),所以方向一致,不需要反转Y轴,只需要平移缩放
function toCanvas(x, z) {
return {
x: padding + (x - minX) * scale,
y: padding + (z - minZ) * scale
};
}
const p1 = toCanvas(x1, z1);
const p2 = toCanvas(x2, z2);
const pt = toCanvas(tx, tz);
// 绘制网格背景
ctx.strokeStyle = '#222';
ctx.lineWidth = 1;
ctx.beginPath();
for(let i=0; i<canvas.width; i+=20) { ctx.moveTo(i,0); ctx.lineTo(i,canvas.height); }
for(let i=0; i<canvas.height; i+=20) { ctx.moveTo(0,i); ctx.lineTo(canvas.width,i); }
ctx.stroke();
// 绘制射线 1 (黄色)
ctx.strokeStyle = '#FFFF55';
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(p1.x, p1.y);
ctx.lineTo(pt.x, pt.y);
ctx.stroke();
// 绘制射线 2 (蓝色)
ctx.strokeStyle = '#55FFFF';
ctx.beginPath();
ctx.moveTo(p2.x, p2.y);
ctx.lineTo(pt.x, pt.y);
ctx.stroke();
// 绘制起点 P1
ctx.fillStyle = '#FFFF55';
ctx.beginPath(); ctx.arc(p1.x, p1.y, 4, 0, Math.PI*2); ctx.fill();
ctx.fillText("P1", p1.x + 5, p1.y - 5);
// 绘制起点 P2
ctx.fillStyle = '#55FFFF';
ctx.beginPath(); ctx.arc(p2.x, p2.y, 4, 0, Math.PI*2); ctx.fill();
ctx.fillText("P2", p2.x + 5, p2.y - 5);
// 绘制目标点 Target
ctx.fillStyle = '#55FF55';
ctx.beginPath(); ctx.arc(pt.x, pt.y, 6, 0, Math.PI*2); ctx.fill();
ctx.font = "16px monospace";
ctx.fillText("要塞", pt.x + 10, pt.y);
}
</script>
</body>
</html>