Files

60 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# potion_rain.js — q() (satır 160)
[← potion_rain.js](index.md) · [← Master](../../wiki.md)
Parça 5/11 · [önceki](q-4.md) · [sonraki](q-6.md)
```javascript
for (x = -r + cell / 2; x < r; x += cell) {
for (z = -r + cell / 2; z < r; z += cell) {
var d2 = x * x + z * z;
if (d2 > r * r) continue;
if (safe > 0 && d2 < safe * safe) continue;
cells.push([x, z]);
}
}
}
if (cells.length === 0) cells.push(safe > 0 ? [safe + 0.5, 0] : [0, 0]);
shuffle(cells);
return { cells: cells, cell: cell, idx: 0 };
}
function shuffle(a) {
for (var i = a.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var t = a[i]; a[i] = a[j]; a[j] = t;
}
}
function nextOffset(grid, safe) {
if (grid.idx >= grid.cells.length) {
shuffle(grid.cells);
grid.idx = 0;
}
var c = grid.cells[grid.idx++];
var x = c[0] + (Math.random() - 0.5) * grid.cell;
var z = c[1] + (Math.random() - 0.5) * grid.cell;
if (safe > 0 && x * x + z * z < safe * safe) { x = c[0]; z = c[1]; } // hucre kaymasi boslugu delmesin
return [x, z];
}
// Yagmurun merkezi: baktigin blok/entity (60 blok), bos havaya bakiyorsan
// bakis yonunde 60 blok ilerisi; "Etrafim" modunda oyuncunun kendisi
function findCenter(p, mode) {
var pos = p.getPosition();
if (mode === 1) return { x: pos.x, y: pos.y, z: pos.z };
var ray = p.rayTrace(LOOK_DIST);
if (ray && !ray.isMissed()) {
var h = ray.getHitPosition();
return { x: h.x, y: h.y, z: h.z };
}
var look = p.getLook();
return {
x: pos.x + look.x * LOOK_DIST,
y: pos.y + p.getEyeHeight() + look.y * LOOK_DIST,
z: pos.z + look.z * LOOK_DIST
};
}
```