Compare commits
1 commit
next
...
fix-browse
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d802c4018 |
118 changed files with 1066 additions and 5556 deletions
|
|
@ -23,7 +23,6 @@
|
||||||
// ],
|
// ],
|
||||||
"@stylistic/arrow-spacing": "error",
|
"@stylistic/arrow-spacing": "error",
|
||||||
"@stylistic/block-spacing": "error",
|
"@stylistic/block-spacing": "error",
|
||||||
"@typescript-eslint/no-this-alias": "off",
|
|
||||||
"@stylistic/brace-style": [
|
"@stylistic/brace-style": [
|
||||||
"error",
|
"error",
|
||||||
"1tbs",
|
"1tbs",
|
||||||
|
|
|
||||||
2
.github/workflows/benchmark.yml
vendored
2
.github/workflows/benchmark.yml
vendored
|
|
@ -26,7 +26,7 @@ jobs:
|
||||||
uses: pnpm/action-setup@v4
|
uses: pnpm/action-setup@v4
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 22
|
node-version: 18
|
||||||
cache: "pnpm"
|
cache: "pnpm"
|
||||||
- name: Move Cypress to dependencies
|
- name: Move Cypress to dependencies
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
14
.github/workflows/release.yml
vendored
14
.github/workflows/release.yml
vendored
|
|
@ -49,20 +49,6 @@ jobs:
|
||||||
publish_dir: .vercel/output/static
|
publish_dir: .vercel/output/static
|
||||||
force_orphan: true
|
force_orphan: true
|
||||||
|
|
||||||
# Create CNAME file for custom domain
|
|
||||||
- name: Create CNAME file
|
|
||||||
run: echo "github.mcraft.fun" > .vercel/output/static/CNAME
|
|
||||||
|
|
||||||
- name: Deploy to mwc-mcraft-pages repository
|
|
||||||
uses: peaceiris/actions-gh-pages@v3
|
|
||||||
with:
|
|
||||||
personal_token: ${{ secrets.MCW_MCRAFT_PAGE_DEPLOY_TOKEN }}
|
|
||||||
external_repository: ${{ github.repository_owner }}/mwc-mcraft-pages
|
|
||||||
publish_dir: .vercel/output/static
|
|
||||||
publish_branch: main
|
|
||||||
destination_dir: docs
|
|
||||||
force_orphan: true
|
|
||||||
|
|
||||||
- name: Change index.html title
|
- name: Change index.html title
|
||||||
run: |
|
run: |
|
||||||
# change <title>Minecraft Web Client</title> to <title>Minecraft Web Client — Free Online Browser Version</title>
|
# change <title>Minecraft Web Client</title> to <title>Minecraft Web Client — Free Online Browser Version</title>
|
||||||
|
|
|
||||||
14
README.MD
14
README.MD
|
|
@ -14,6 +14,7 @@ For building the project yourself / contributing, see [Development, Debugging &
|
||||||
|
|
||||||
> **Note**: You can deploy it on your own server in less than a minute using a one-liner script from [Minecraft Everywhere repo](https://github.com/zardoy/minecraft-everywhere)
|
> **Note**: You can deploy it on your own server in less than a minute using a one-liner script from [Minecraft Everywhere repo](https://github.com/zardoy/minecraft-everywhere)
|
||||||
|
|
||||||
|
|
||||||
### Big Features
|
### Big Features
|
||||||
|
|
||||||
- Official Mineflayer [plugin integration](https://github.com/zardoy/mcraft-fun-mineflayer-plugin)! View / Control your bot remotely.
|
- Official Mineflayer [plugin integration](https://github.com/zardoy/mcraft-fun-mineflayer-plugin)! View / Control your bot remotely.
|
||||||
|
|
@ -54,9 +55,8 @@ Howerver, it's known that these browsers have issues:
|
||||||
|
|
||||||
### Versions Support
|
### Versions Support
|
||||||
|
|
||||||
Server versions 1.8 - 1.21.5 are supported.
|
Server versions 1.8 - 1.21.4 are supported.
|
||||||
First class versions (most of the features are tested on these versions):
|
First class versions (most of the features are tested on these versions):
|
||||||
|
|
||||||
- 1.19.4
|
- 1.19.4
|
||||||
- 1.21.4
|
- 1.21.4
|
||||||
|
|
||||||
|
|
@ -78,8 +78,6 @@ There is a builtin proxy, but you can also host your one! Just clone the repo, r
|
||||||
|
|
||||||
[](https://app.koyeb.com/deploy?name=minecraft-web-client&type=git&repository=zardoy%2Fminecraft-web-client&branch=next&builder=dockerfile&env%5B%5D=&ports=8080%3Bhttp%3B%2F)
|
[](https://app.koyeb.com/deploy?name=minecraft-web-client&type=git&repository=zardoy%2Fminecraft-web-client&branch=next&builder=dockerfile&env%5B%5D=&ports=8080%3Bhttp%3B%2F)
|
||||||
|
|
||||||
> **Note**: If you want to make **your own** Minecraft server accessible to web clients (without our proxies), you can use [mwc-proxy](https://github.com/zardoy/mwc-proxy) - a lightweight JS WebSocket proxy that runs on the same server as your Minecraft server, allowing players to connect directly via `wss://play.example.com`. `?client_mcraft` is added to the URL, so the proxy will know that it's this client.
|
|
||||||
|
|
||||||
Proxy servers are used to connect to Minecraft servers which use TCP protocol. When you connect connect to a server with a proxy, websocket connection is created between you (browser client) and the proxy server located in Europe, then the proxy connects to the Minecraft server and sends the data to the client (you) without any packet deserialization to avoid any additional delays. That said all the Minecraft protocol packets are processed by the client, right in your browser.
|
Proxy servers are used to connect to Minecraft servers which use TCP protocol. When you connect connect to a server with a proxy, websocket connection is created between you (browser client) and the proxy server located in Europe, then the proxy connects to the Minecraft server and sends the data to the client (you) without any packet deserialization to avoid any additional delays. That said all the Minecraft protocol packets are processed by the client, right in your browser.
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
|
|
@ -127,11 +125,11 @@ There is world renderer playground ([link](https://mcon.vercel.app/playground/))
|
||||||
|
|
||||||
However, there are many things that can be done in online production version (like debugging actual source code). Also you can access some global variables in the console and there are a few useful examples:
|
However, there are many things that can be done in online production version (like debugging actual source code). Also you can access some global variables in the console and there are a few useful examples:
|
||||||
|
|
||||||
- If you type `debugToggle`, press enter in console - It will enables all debug messages! Warning: this will start all packets spam.
|
- `localStorage.debug = '*'` - Enables all debug messages! Warning: this will start all packets spam.
|
||||||
Instead I recommend setting `options.debugLogNotFrequentPackets`. Also you can use `debugTopPackets` (with JSON.stringify) to see what packets were received/sent by name
|
Instead I recommend setting `options.debugLogNotFrequentPackets`. Also you can use `debugTopPackets` (with JSON.stringify) to see what packets were received/sent by name
|
||||||
|
|
||||||
- `bot` - Mineflayer bot instance. See Mineflayer documentation for more.
|
- `bot` - Mineflayer bot instance. See Mineflayer documentation for more.
|
||||||
- `world` - Three.js world instance, basically does all the rendering (part of renderer backend).
|
- `viewer` - Three.js viewer instance, basically does all the rendering.
|
||||||
- `world.sectionObjects` - Object with all active chunk sections (geometries) in the world. Each chunk section is a Three.js mesh or group.
|
- `world.sectionObjects` - Object with all active chunk sections (geometries) in the world. Each chunk section is a Three.js mesh or group.
|
||||||
- `debugSceneChunks` - The same as above, but relative to current bot position (e.g. 0,0 is the current chunk).
|
- `debugSceneChunks` - The same as above, but relative to current bot position (e.g. 0,0 is the current chunk).
|
||||||
- `debugChangedOptions` - See what options are changed. Don't change options here.
|
- `debugChangedOptions` - See what options are changed. Don't change options here.
|
||||||
|
|
@ -141,7 +139,7 @@ Instead I recommend setting `options.debugLogNotFrequentPackets`. Also you can u
|
||||||
|
|
||||||
- `nbt.simplify(someNbt)` - Simplifies nbt data, so it's easier to read.
|
- `nbt.simplify(someNbt)` - Simplifies nbt data, so it's easier to read.
|
||||||
|
|
||||||
The most useful thing in devtools is the watch expression. You can add any expression there and it will be re-evaluated in real time. For example, you can add `world.getCameraPosition()` to see the camera position and so on.
|
The most useful thing in devtools is the watch expression. You can add any expression there and it will be re-evaluated in real time. For example, you can add `camera.position` to see the camera position and so on.
|
||||||
|
|
||||||
<img src="./docs-assets/watch-expr.png" alt="Watch expression" width="480"/>
|
<img src="./docs-assets/watch-expr.png" alt="Watch expression" width="480"/>
|
||||||
|
|
||||||
|
|
@ -178,7 +176,6 @@ Server specific:
|
||||||
- `?lockConnect=true` - Only works then `ip` parameter is set. Disables cancel/save buttons and all inputs in the connect screen already set as parameters. Useful for integrates iframes.
|
- `?lockConnect=true` - Only works then `ip` parameter is set. Disables cancel/save buttons and all inputs in the connect screen already set as parameters. Useful for integrates iframes.
|
||||||
- `?autoConnect=true` - Only works then `ip` and `version` parameters are set and `allowAutoConnect` is `true` in config.json! Directly connects to the specified server. Useful for integrates iframes.
|
- `?autoConnect=true` - Only works then `ip` and `version` parameters are set and `allowAutoConnect` is `true` in config.json! Directly connects to the specified server. Useful for integrates iframes.
|
||||||
- `?serversList=<list_or_url>` - `<list_or_url>` can be a list of servers in the format `ip:version,ip` or a url to a json file with the same format (array) or a txt file with line-delimited list of server IPs.
|
- `?serversList=<list_or_url>` - `<list_or_url>` can be a list of servers in the format `ip:version,ip` or a url to a json file with the same format (array) or a txt file with line-delimited list of server IPs.
|
||||||
- `?addPing=<ping>` - Add a latency to both sides of the connection. Useful for testing ping issues. For example `?addPing=100` will add 200ms to your ping.
|
|
||||||
|
|
||||||
Single player specific:
|
Single player specific:
|
||||||
|
|
||||||
|
|
@ -235,4 +232,3 @@ Only during development:
|
||||||
|
|
||||||
- [https://github.com/ClassiCube/ClassiCube](ClassiCube - Better C# Rewrite) [DEMO](https://www.classicube.net/server/play/?warned=true)
|
- [https://github.com/ClassiCube/ClassiCube](ClassiCube - Better C# Rewrite) [DEMO](https://www.classicube.net/server/play/?warned=true)
|
||||||
- [https://m.eaglercraft.com/](EaglerCraft) - Eaglercraft runnable on mobile (real Minecraft in the browser)
|
- [https://m.eaglercraft.com/](EaglerCraft) - Eaglercraft runnable on mobile (real Minecraft in the browser)
|
||||||
- [js-minecraft](https://github.com/LabyStudio/js-minecraft) - An insanely well done clone from the graphical side that inspired many features here
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
here you can place custom textures for bundled files (blocks/items) e.g. blocks/stone.png
|
|
||||||
get file names from here (blocks/items) https://zardoy.github.io/mc-assets/
|
|
||||||
|
|
@ -1,237 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Web Input Debugger</title>
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
font-family: Arial, sans-serif;
|
|
||||||
padding: 20px;
|
|
||||||
background: #f0f0f0;
|
|
||||||
}
|
|
||||||
.key-container {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(3, 60px);
|
|
||||||
gap: 5px;
|
|
||||||
margin: 20px 0;
|
|
||||||
}
|
|
||||||
.key {
|
|
||||||
width: 60px;
|
|
||||||
height: 60px;
|
|
||||||
border: 2px solid #333;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
font-weight: bold;
|
|
||||||
background: white;
|
|
||||||
position: relative;
|
|
||||||
user-select: none;
|
|
||||||
}
|
|
||||||
.key.pressed {
|
|
||||||
background: #90EE90;
|
|
||||||
}
|
|
||||||
.key .duration {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 2px;
|
|
||||||
font-size: 10px;
|
|
||||||
}
|
|
||||||
.key .count {
|
|
||||||
position: absolute;
|
|
||||||
top: 2px;
|
|
||||||
right: 2px;
|
|
||||||
font-size: 10px;
|
|
||||||
}
|
|
||||||
.controls {
|
|
||||||
margin: 20px 0;
|
|
||||||
padding: 10px;
|
|
||||||
background: white;
|
|
||||||
border-radius: 5px;
|
|
||||||
}
|
|
||||||
.wasd-container {
|
|
||||||
position: relative;
|
|
||||||
width: 190px;
|
|
||||||
height: 130px;
|
|
||||||
}
|
|
||||||
#KeyW {
|
|
||||||
position: absolute;
|
|
||||||
left: 65px;
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
#KeyA {
|
|
||||||
position: absolute;
|
|
||||||
left: 0;
|
|
||||||
top: 65px;
|
|
||||||
}
|
|
||||||
#KeyS {
|
|
||||||
position: absolute;
|
|
||||||
left: 65px;
|
|
||||||
top: 65px;
|
|
||||||
}
|
|
||||||
#KeyD {
|
|
||||||
position: absolute;
|
|
||||||
left: 130px;
|
|
||||||
top: 65px;
|
|
||||||
}
|
|
||||||
.space-container {
|
|
||||||
margin-top: 20px;
|
|
||||||
}
|
|
||||||
#Space {
|
|
||||||
width: 190px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="controls">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" id="repeatMode"> Use keydown repeat mode (auto key-up after 150ms of no repeat)
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="wasd-container">
|
|
||||||
<div id="KeyW" class="key" data-code="KeyW">W</div>
|
|
||||||
<div id="KeyA" class="key" data-code="KeyA">A</div>
|
|
||||||
<div id="KeyS" class="key" data-code="KeyS">S</div>
|
|
||||||
<div id="KeyD" class="key" data-code="KeyD">D</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="key-container">
|
|
||||||
<div id="ControlLeft" class="key" data-code="ControlLeft">Ctrl</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="space-container">
|
|
||||||
<div id="Space" class="key" data-code="Space">Space</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
const keys = {};
|
|
||||||
const keyStats = {};
|
|
||||||
const pressStartTimes = {};
|
|
||||||
const keyTimeouts = {};
|
|
||||||
|
|
||||||
function initKeyStats(code) {
|
|
||||||
if (!keyStats[code]) {
|
|
||||||
keyStats[code] = {
|
|
||||||
pressCount: 0,
|
|
||||||
duration: 0,
|
|
||||||
startTime: 0
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateKeyVisuals(code) {
|
|
||||||
const element = document.getElementById(code);
|
|
||||||
if (!element) return;
|
|
||||||
|
|
||||||
const stats = keyStats[code];
|
|
||||||
if (keys[code]) {
|
|
||||||
element.classList.add('pressed');
|
|
||||||
const currentDuration = ((Date.now() - stats.startTime) / 1000).toFixed(1);
|
|
||||||
element.innerHTML = `${element.getAttribute('data-code').replace('Key', '').replace('Left', '')}<span class="duration">${currentDuration}s</span><span class="count">${stats.pressCount}</span>`;
|
|
||||||
} else {
|
|
||||||
element.classList.remove('pressed');
|
|
||||||
element.innerHTML = `${element.getAttribute('data-code').replace('Key', '').replace('Left', '')}<span class="count">${stats.pressCount}</span>`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function releaseKey(code) {
|
|
||||||
keys[code] = false;
|
|
||||||
if (pressStartTimes[code]) {
|
|
||||||
keyStats[code].duration += (Date.now() - pressStartTimes[code]) / 1000;
|
|
||||||
delete pressStartTimes[code];
|
|
||||||
}
|
|
||||||
updateKeyVisuals(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleKeyDown(event) {
|
|
||||||
const code = event.code;
|
|
||||||
const isRepeatMode = document.getElementById('repeatMode').checked;
|
|
||||||
|
|
||||||
initKeyStats(code);
|
|
||||||
|
|
||||||
// Clear any existing timeout for this key
|
|
||||||
if (keyTimeouts[code]) {
|
|
||||||
clearTimeout(keyTimeouts[code]);
|
|
||||||
delete keyTimeouts[code];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isRepeatMode) {
|
|
||||||
// In repeat mode, always handle the keydown
|
|
||||||
if (!keys[code] || event.repeat) {
|
|
||||||
keys[code] = true;
|
|
||||||
if (!event.repeat) {
|
|
||||||
// Only increment count on initial press, not repeats
|
|
||||||
keyStats[code].pressCount++;
|
|
||||||
keyStats[code].startTime = Date.now();
|
|
||||||
pressStartTimes[code] = Date.now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set timeout to release key if no repeat events come
|
|
||||||
keyTimeouts[code] = setTimeout(() => {
|
|
||||||
releaseKey(code);
|
|
||||||
}, 150);
|
|
||||||
} else {
|
|
||||||
// In normal mode, only handle keydown if key is not already pressed
|
|
||||||
if (!keys[code]) {
|
|
||||||
keys[code] = true;
|
|
||||||
keyStats[code].pressCount++;
|
|
||||||
keyStats[code].startTime = Date.now();
|
|
||||||
pressStartTimes[code] = Date.now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateKeyVisuals(code);
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleKeyUp(event) {
|
|
||||||
const code = event.code;
|
|
||||||
const isRepeatMode = document.getElementById('repeatMode').checked;
|
|
||||||
|
|
||||||
if (!isRepeatMode) {
|
|
||||||
releaseKey(code);
|
|
||||||
}
|
|
||||||
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize all monitored keys
|
|
||||||
const monitoredKeys = ['KeyW', 'KeyA', 'KeyS', 'KeyD', 'ControlLeft', 'Space'];
|
|
||||||
monitoredKeys.forEach(code => {
|
|
||||||
initKeyStats(code);
|
|
||||||
const element = document.getElementById(code);
|
|
||||||
if (element) {
|
|
||||||
element.innerHTML = `${element.getAttribute('data-code').replace('Key', '').replace('Left', '')}<span class="count">0</span>`;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Start visual updates
|
|
||||||
setInterval(() => {
|
|
||||||
monitoredKeys.forEach(code => {
|
|
||||||
if (keys[code]) {
|
|
||||||
updateKeyVisuals(code);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
// Event listeners
|
|
||||||
document.addEventListener('keydown', handleKeyDown);
|
|
||||||
document.addEventListener('keyup', handleKeyUp);
|
|
||||||
|
|
||||||
// Handle mode changes
|
|
||||||
document.getElementById('repeatMode').addEventListener('change', () => {
|
|
||||||
// Release all keys when switching modes
|
|
||||||
monitoredKeys.forEach(code => {
|
|
||||||
if (keys[code]) {
|
|
||||||
releaseKey(code);
|
|
||||||
}
|
|
||||||
if (keyTimeouts[code]) {
|
|
||||||
clearTimeout(keyTimeouts[code]);
|
|
||||||
delete keyTimeouts[code];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -10,20 +10,12 @@
|
||||||
{
|
{
|
||||||
"ip": "wss://play.mcraft.fun"
|
"ip": "wss://play.mcraft.fun"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ip": "wss://play.webmc.fun",
|
|
||||||
"name": "WebMC"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ip": "wss://ws.fuchsmc.net"
|
"ip": "wss://ws.fuchsmc.net"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ip": "wss://play2.mcraft.fun"
|
"ip": "wss://play2.mcraft.fun"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ip": "wss://play-creative.mcraft.fun",
|
|
||||||
"description": "Might be available soon, stay tuned!"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ip": "kaboom.pw",
|
"ip": "kaboom.pw",
|
||||||
"version": "1.20.3",
|
"version": "1.20.3",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
{
|
{
|
||||||
"alwaysReconnectButton": true,
|
"alwaysReconnectButton": true
|
||||||
"reportBugButtonWithReconnect": true,
|
|
||||||
"allowAutoConnect": true
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Minecraft Item Viewer</title>
|
|
||||||
<style>
|
|
||||||
body { margin: 0; overflow: hidden; }
|
|
||||||
canvas { display: block; }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script type="module" src="./three-item.ts"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,108 +0,0 @@
|
||||||
import * as THREE from 'three'
|
|
||||||
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
|
|
||||||
import itemsAtlas from 'mc-assets/dist/itemsAtlasLegacy.png'
|
|
||||||
import { createItemMeshFromCanvas, createItemMesh } from '../renderer/viewer/three/itemMesh'
|
|
||||||
|
|
||||||
// Create scene, camera and renderer
|
|
||||||
const scene = new THREE.Scene()
|
|
||||||
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
|
|
||||||
const renderer = new THREE.WebGLRenderer({ antialias: true })
|
|
||||||
renderer.setSize(window.innerWidth, window.innerHeight)
|
|
||||||
document.body.appendChild(renderer.domElement)
|
|
||||||
|
|
||||||
// Setup camera and controls
|
|
||||||
camera.position.set(0, 0, 3)
|
|
||||||
const controls = new OrbitControls(camera, renderer.domElement)
|
|
||||||
controls.enableDamping = true
|
|
||||||
|
|
||||||
// Background and lights
|
|
||||||
scene.background = new THREE.Color(0x333333)
|
|
||||||
const ambientLight = new THREE.AmbientLight(0xffffff, 0.7)
|
|
||||||
scene.add(ambientLight)
|
|
||||||
|
|
||||||
// Animation loop
|
|
||||||
function animate () {
|
|
||||||
requestAnimationFrame(animate)
|
|
||||||
controls.update()
|
|
||||||
renderer.render(scene, camera)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function setupItemMesh () {
|
|
||||||
try {
|
|
||||||
const loader = new THREE.TextureLoader()
|
|
||||||
const atlasTexture = await loader.loadAsync(itemsAtlas)
|
|
||||||
|
|
||||||
// Pixel-art configuration
|
|
||||||
atlasTexture.magFilter = THREE.NearestFilter
|
|
||||||
atlasTexture.minFilter = THREE.NearestFilter
|
|
||||||
atlasTexture.generateMipmaps = false
|
|
||||||
atlasTexture.wrapS = atlasTexture.wrapT = THREE.ClampToEdgeWrapping
|
|
||||||
|
|
||||||
// Extract the tile at x=2, y=0 (16x16)
|
|
||||||
const tileSize = 16
|
|
||||||
const tileX = 2
|
|
||||||
const tileY = 0
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas')
|
|
||||||
canvas.width = tileSize
|
|
||||||
canvas.height = tileSize
|
|
||||||
const ctx = canvas.getContext('2d')!
|
|
||||||
|
|
||||||
ctx.imageSmoothingEnabled = false
|
|
||||||
ctx.drawImage(
|
|
||||||
atlasTexture.image,
|
|
||||||
tileX * tileSize,
|
|
||||||
tileY * tileSize,
|
|
||||||
tileSize,
|
|
||||||
tileSize,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
tileSize,
|
|
||||||
tileSize
|
|
||||||
)
|
|
||||||
|
|
||||||
// Test both approaches - working manual extraction:
|
|
||||||
const meshOld = createItemMeshFromCanvas(canvas, { depth: 0.1 })
|
|
||||||
meshOld.position.x = -1
|
|
||||||
meshOld.rotation.x = -Math.PI / 12
|
|
||||||
meshOld.rotation.y = Math.PI / 12
|
|
||||||
scene.add(meshOld)
|
|
||||||
|
|
||||||
// And new unified function:
|
|
||||||
const atlasWidth = atlasTexture.image.width
|
|
||||||
const atlasHeight = atlasTexture.image.height
|
|
||||||
const u = (tileX * tileSize) / atlasWidth
|
|
||||||
const v = (tileY * tileSize) / atlasHeight
|
|
||||||
const sizeX = tileSize / atlasWidth
|
|
||||||
const sizeY = tileSize / atlasHeight
|
|
||||||
|
|
||||||
console.log('Debug texture coords:', {u, v, sizeX, sizeY, atlasWidth, atlasHeight})
|
|
||||||
|
|
||||||
const resultNew = createItemMesh(atlasTexture, {
|
|
||||||
u, v, sizeX, sizeY
|
|
||||||
}, {
|
|
||||||
faceCamera: false,
|
|
||||||
use3D: true,
|
|
||||||
depth: 0.1
|
|
||||||
})
|
|
||||||
|
|
||||||
resultNew.mesh.position.x = 1
|
|
||||||
resultNew.mesh.rotation.x = -Math.PI / 12
|
|
||||||
resultNew.mesh.rotation.y = Math.PI / 12
|
|
||||||
scene.add(resultNew.mesh)
|
|
||||||
|
|
||||||
animate()
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to create item mesh:', err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle window resize
|
|
||||||
window.addEventListener('resize', () => {
|
|
||||||
camera.aspect = window.innerWidth / window.innerHeight
|
|
||||||
camera.updateProjectionMatrix()
|
|
||||||
renderer.setSize(window.innerWidth, window.innerHeight)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Start
|
|
||||||
setupItemMesh()
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
<script type="module" src="three-labels.ts"></script>
|
|
||||||
<style>
|
|
||||||
body { margin: 0; }
|
|
||||||
canvas { display: block; }
|
|
||||||
</style>
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
import * as THREE from 'three'
|
|
||||||
import { FirstPersonControls } from 'three/addons/controls/FirstPersonControls.js'
|
|
||||||
import { createWaypointSprite, WAYPOINT_CONFIG } from '../renderer/viewer/three/waypointSprite'
|
|
||||||
|
|
||||||
// Create scene, camera and renderer
|
|
||||||
const scene = new THREE.Scene()
|
|
||||||
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
|
|
||||||
const renderer = new THREE.WebGLRenderer({ antialias: true })
|
|
||||||
renderer.setSize(window.innerWidth, window.innerHeight)
|
|
||||||
document.body.appendChild(renderer.domElement)
|
|
||||||
|
|
||||||
// Add FirstPersonControls
|
|
||||||
const controls = new FirstPersonControls(camera, renderer.domElement)
|
|
||||||
controls.lookSpeed = 0.1
|
|
||||||
controls.movementSpeed = 10
|
|
||||||
controls.lookVertical = true
|
|
||||||
controls.constrainVertical = true
|
|
||||||
controls.verticalMin = 0.1
|
|
||||||
controls.verticalMax = Math.PI - 0.1
|
|
||||||
|
|
||||||
// Position camera
|
|
||||||
camera.position.y = 1.6 // Typical eye height
|
|
||||||
camera.lookAt(0, 1.6, -1)
|
|
||||||
|
|
||||||
// Create a helper grid and axes
|
|
||||||
const grid = new THREE.GridHelper(20, 20)
|
|
||||||
scene.add(grid)
|
|
||||||
const axes = new THREE.AxesHelper(5)
|
|
||||||
scene.add(axes)
|
|
||||||
|
|
||||||
// Create waypoint sprite via utility
|
|
||||||
const waypoint = createWaypointSprite({
|
|
||||||
position: new THREE.Vector3(0, 0, -5),
|
|
||||||
color: 0xff0000,
|
|
||||||
label: 'Target',
|
|
||||||
})
|
|
||||||
scene.add(waypoint.group)
|
|
||||||
|
|
||||||
// Use built-in offscreen arrow from utils
|
|
||||||
waypoint.enableOffscreenArrow(true)
|
|
||||||
waypoint.setArrowParent(scene)
|
|
||||||
|
|
||||||
// Animation loop
|
|
||||||
function animate() {
|
|
||||||
requestAnimationFrame(animate)
|
|
||||||
|
|
||||||
const delta = Math.min(clock.getDelta(), 0.1)
|
|
||||||
controls.update(delta)
|
|
||||||
|
|
||||||
// Unified camera update (size, distance text, arrow, visibility)
|
|
||||||
const sizeVec = renderer.getSize(new THREE.Vector2())
|
|
||||||
waypoint.updateForCamera(camera.position, camera, sizeVec.width, sizeVec.height)
|
|
||||||
|
|
||||||
renderer.render(scene, camera)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle window resize
|
|
||||||
window.addEventListener('resize', () => {
|
|
||||||
camera.aspect = window.innerWidth / window.innerHeight
|
|
||||||
camera.updateProjectionMatrix()
|
|
||||||
renderer.setSize(window.innerWidth, window.innerHeight)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Add clock for controls
|
|
||||||
const clock = new THREE.Clock()
|
|
||||||
|
|
||||||
animate()
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import * as THREE from 'three'
|
import * as THREE from 'three'
|
||||||
|
import { loadThreeJsTextureFromBitmap } from '../renderer/viewer/lib/utils/skins'
|
||||||
|
|
||||||
// Create scene, camera and renderer
|
// Create scene, camera and renderer
|
||||||
const scene = new THREE.Scene()
|
const scene = new THREE.Scene()
|
||||||
|
|
|
||||||
15
package.json
15
package.json
|
|
@ -7,7 +7,6 @@
|
||||||
"dev-proxy": "node server.js",
|
"dev-proxy": "node server.js",
|
||||||
"start": "run-p dev-proxy dev-rsbuild watch-mesher",
|
"start": "run-p dev-proxy dev-rsbuild watch-mesher",
|
||||||
"start2": "run-p dev-rsbuild watch-mesher",
|
"start2": "run-p dev-rsbuild watch-mesher",
|
||||||
"start-metrics": "ENABLE_METRICS=true rsbuild dev",
|
|
||||||
"build": "pnpm build-other-workers && rsbuild build",
|
"build": "pnpm build-other-workers && rsbuild build",
|
||||||
"build-analyze": "BUNDLE_ANALYZE=true rsbuild build && pnpm build-other-workers",
|
"build-analyze": "BUNDLE_ANALYZE=true rsbuild build && pnpm build-other-workers",
|
||||||
"build-single-file": "SINGLE_FILE_BUILD=true rsbuild build",
|
"build-single-file": "SINGLE_FILE_BUILD=true rsbuild build",
|
||||||
|
|
@ -33,8 +32,7 @@
|
||||||
"run-all": "run-p start run-playground",
|
"run-all": "run-p start run-playground",
|
||||||
"build-playground": "rsbuild build --config renderer/rsbuild.config.ts",
|
"build-playground": "rsbuild build --config renderer/rsbuild.config.ts",
|
||||||
"watch-playground": "rsbuild dev --config renderer/rsbuild.config.ts",
|
"watch-playground": "rsbuild dev --config renderer/rsbuild.config.ts",
|
||||||
"update-git-deps": "tsx scripts/updateGitDeps.ts",
|
"update-git-deps": "tsx scripts/updateGitDeps.ts"
|
||||||
"request-data": "tsx scripts/requestData.ts"
|
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"prismarine",
|
"prismarine",
|
||||||
|
|
@ -54,7 +52,6 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dimaka/interface": "0.0.3-alpha.0",
|
"@dimaka/interface": "0.0.3-alpha.0",
|
||||||
"@floating-ui/react": "^0.26.1",
|
"@floating-ui/react": "^0.26.1",
|
||||||
"@monaco-editor/react": "^4.7.0",
|
|
||||||
"@nxg-org/mineflayer-auto-jump": "^0.7.18",
|
"@nxg-org/mineflayer-auto-jump": "^0.7.18",
|
||||||
"@nxg-org/mineflayer-tracker": "1.3.0",
|
"@nxg-org/mineflayer-tracker": "1.3.0",
|
||||||
"@react-oauth/google": "^0.12.1",
|
"@react-oauth/google": "^0.12.1",
|
||||||
|
|
@ -80,14 +77,14 @@
|
||||||
"esbuild-plugin-polyfill-node": "^0.3.0",
|
"esbuild-plugin-polyfill-node": "^0.3.0",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"filesize": "^10.0.12",
|
"filesize": "^10.0.12",
|
||||||
"flying-squid": "npm:@zardoy/flying-squid@^0.0.104",
|
"flying-squid": "npm:@zardoy/flying-squid@^0.0.62",
|
||||||
"framer-motion": "^12.9.2",
|
"framer-motion": "^12.9.2",
|
||||||
"fs-extra": "^11.1.1",
|
"fs-extra": "^11.1.1",
|
||||||
"google-drive-browserfs": "github:zardoy/browserfs#google-drive",
|
"google-drive-browserfs": "github:zardoy/browserfs#google-drive",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"mcraft-fun-mineflayer": "^0.1.23",
|
"mcraft-fun-mineflayer": "^0.1.23",
|
||||||
"minecraft-data": "3.98.0",
|
"minecraft-data": "3.92.0",
|
||||||
"minecraft-protocol": "github:PrismarineJS/node-minecraft-protocol#master",
|
"minecraft-protocol": "github:PrismarineJS/node-minecraft-protocol#master",
|
||||||
"mineflayer-item-map-downloader": "github:zardoy/mineflayer-item-map-downloader",
|
"mineflayer-item-map-downloader": "github:zardoy/mineflayer-item-map-downloader",
|
||||||
"mojangson": "^2.0.4",
|
"mojangson": "^2.0.4",
|
||||||
|
|
@ -157,7 +154,8 @@
|
||||||
"mc-assets": "^0.2.62",
|
"mc-assets": "^0.2.62",
|
||||||
"minecraft-inventory-gui": "github:zardoy/minecraft-inventory-gui#next",
|
"minecraft-inventory-gui": "github:zardoy/minecraft-inventory-gui#next",
|
||||||
"mineflayer": "github:zardoy/mineflayer#gen-the-master",
|
"mineflayer": "github:zardoy/mineflayer#gen-the-master",
|
||||||
"mineflayer-mouse": "^0.1.21",
|
"mineflayer-mouse": "^0.1.11",
|
||||||
|
"mineflayer-pathfinder": "^2.4.4",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"os-browserify": "^0.3.0",
|
"os-browserify": "^0.3.0",
|
||||||
"path-browserify": "^1.0.1",
|
"path-browserify": "^1.0.1",
|
||||||
|
|
@ -197,7 +195,6 @@
|
||||||
},
|
},
|
||||||
"pnpm": {
|
"pnpm": {
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"mineflayer": "github:zardoy/mineflayer#gen-the-master",
|
|
||||||
"@nxg-org/mineflayer-physics-util": "1.8.10",
|
"@nxg-org/mineflayer-physics-util": "1.8.10",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"vec3": "0.1.10",
|
"vec3": "0.1.10",
|
||||||
|
|
@ -205,7 +202,7 @@
|
||||||
"diamond-square": "github:zardoy/diamond-square",
|
"diamond-square": "github:zardoy/diamond-square",
|
||||||
"prismarine-block": "github:zardoy/prismarine-block#next-era",
|
"prismarine-block": "github:zardoy/prismarine-block#next-era",
|
||||||
"prismarine-world": "github:zardoy/prismarine-world#next-era",
|
"prismarine-world": "github:zardoy/prismarine-world#next-era",
|
||||||
"minecraft-data": "3.98.0",
|
"minecraft-data": "3.92.0",
|
||||||
"prismarine-provider-anvil": "github:zardoy/prismarine-provider-anvil#everything",
|
"prismarine-provider-anvil": "github:zardoy/prismarine-provider-anvil#everything",
|
||||||
"prismarine-physics": "github:zardoy/prismarine-physics",
|
"prismarine-physics": "github:zardoy/prismarine-physics",
|
||||||
"minecraft-protocol": "github:PrismarineJS/node-minecraft-protocol#master",
|
"minecraft-protocol": "github:PrismarineJS/node-minecraft-protocol#master",
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
diff --git a/src/client/chat.js b/src/client/chat.js
|
diff --git a/src/client/chat.js b/src/client/chat.js
|
||||||
index 0021870994fc59a82f0ac8aba0a65a8be43ef2f4..a53fceb843105ea2a1d88722b3fc7c3b43cb102a 100644
|
index 8d0869b150681574ad19292a026cce9f67a137ee..2efa2e6600f017b566155974cb9fb1856fa582f9 100644
|
||||||
--- a/src/client/chat.js
|
--- a/src/client/chat.js
|
||||||
+++ b/src/client/chat.js
|
+++ b/src/client/chat.js
|
||||||
@@ -116,7 +116,7 @@ module.exports = function (client, options) {
|
@@ -109,7 +109,7 @@ module.exports = function (client, options) {
|
||||||
for (const player of packet.data) {
|
for (const player of packet.data) {
|
||||||
if (player.chatSession) {
|
if (player.chatSession) {
|
||||||
client._players[player.uuid] = {
|
client._players[player.uuid] = {
|
||||||
|
|
@ -11,7 +11,7 @@ index 0021870994fc59a82f0ac8aba0a65a8be43ef2f4..a53fceb843105ea2a1d88722b3fc7c3b
|
||||||
publicKeyDER: player.chatSession.publicKey.keyBytes,
|
publicKeyDER: player.chatSession.publicKey.keyBytes,
|
||||||
sessionUuid: player.chatSession.uuid
|
sessionUuid: player.chatSession.uuid
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ module.exports = function (client, options) {
|
@@ -119,7 +119,7 @@ module.exports = function (client, options) {
|
||||||
|
|
||||||
if (player.crypto) {
|
if (player.crypto) {
|
||||||
client._players[player.uuid] = {
|
client._players[player.uuid] = {
|
||||||
|
|
@ -20,7 +20,7 @@ index 0021870994fc59a82f0ac8aba0a65a8be43ef2f4..a53fceb843105ea2a1d88722b3fc7c3b
|
||||||
publicKeyDER: player.crypto.publicKey,
|
publicKeyDER: player.crypto.publicKey,
|
||||||
signature: player.crypto.signature,
|
signature: player.crypto.signature,
|
||||||
displayName: player.displayName || player.name
|
displayName: player.displayName || player.name
|
||||||
@@ -196,7 +196,7 @@ module.exports = function (client, options) {
|
@@ -189,7 +189,7 @@ module.exports = function (client, options) {
|
||||||
if (mcData.supportFeature('useChatSessions')) {
|
if (mcData.supportFeature('useChatSessions')) {
|
||||||
const tsDelta = BigInt(Date.now()) - packet.timestamp
|
const tsDelta = BigInt(Date.now()) - packet.timestamp
|
||||||
const expired = !packet.timestamp || tsDelta > messageExpireTime || tsDelta < 0
|
const expired = !packet.timestamp || tsDelta > messageExpireTime || tsDelta < 0
|
||||||
|
|
@ -28,8 +28,8 @@ index 0021870994fc59a82f0ac8aba0a65a8be43ef2f4..a53fceb843105ea2a1d88722b3fc7c3b
|
||||||
+ const verified = false && !packet.unsignedChatContent && updateAndValidateSession(packet.senderUuid, packet.plainMessage, packet.signature, packet.index, packet.previousMessages, packet.salt, packet.timestamp) && !expired
|
+ const verified = false && !packet.unsignedChatContent && updateAndValidateSession(packet.senderUuid, packet.plainMessage, packet.signature, packet.index, packet.previousMessages, packet.salt, packet.timestamp) && !expired
|
||||||
if (verified) client._signatureCache.push(packet.signature)
|
if (verified) client._signatureCache.push(packet.signature)
|
||||||
client.emit('playerChat', {
|
client.emit('playerChat', {
|
||||||
globalIndex: packet.globalIndex,
|
plainMessage: packet.plainMessage,
|
||||||
@@ -362,7 +362,7 @@ module.exports = function (client, options) {
|
@@ -354,7 +354,7 @@ module.exports = function (client, options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,16 +38,16 @@ index 0021870994fc59a82f0ac8aba0a65a8be43ef2f4..a53fceb843105ea2a1d88722b3fc7c3b
|
||||||
options.timestamp = options.timestamp || BigInt(Date.now())
|
options.timestamp = options.timestamp || BigInt(Date.now())
|
||||||
options.salt = options.salt || 1n
|
options.salt = options.salt || 1n
|
||||||
|
|
||||||
@@ -407,7 +407,7 @@ module.exports = function (client, options) {
|
@@ -396,7 +396,7 @@ module.exports = function (client, options) {
|
||||||
message,
|
message,
|
||||||
timestamp: options.timestamp,
|
timestamp: options.timestamp,
|
||||||
salt: options.salt,
|
salt: options.salt,
|
||||||
- signature: (client.profileKeys && client._session) ? client.signMessage(message, options.timestamp, options.salt, undefined, acknowledgements) : undefined,
|
- signature: (client.profileKeys && client._session) ? client.signMessage(message, options.timestamp, options.salt, undefined, acknowledgements) : undefined,
|
||||||
+ signature: (client.profileKeys && client._session) ? await client.signMessage(message, options.timestamp, options.salt, undefined, acknowledgements) : undefined,
|
+ signature: (client.profileKeys && client._session) ? await client.signMessage(message, options.timestamp, options.salt, undefined, acknowledgements) : undefined,
|
||||||
offset: client._lastSeenMessages.pending,
|
offset: client._lastSeenMessages.pending,
|
||||||
checksum: computeChatChecksum(client._lastSeenMessages), // 1.21.5+
|
|
||||||
acknowledged
|
acknowledged
|
||||||
@@ -422,7 +422,7 @@ module.exports = function (client, options) {
|
})
|
||||||
|
@@ -410,7 +410,7 @@ module.exports = function (client, options) {
|
||||||
message,
|
message,
|
||||||
timestamp: options.timestamp,
|
timestamp: options.timestamp,
|
||||||
salt: options.salt,
|
salt: options.salt,
|
||||||
|
|
@ -57,7 +57,7 @@ index 0021870994fc59a82f0ac8aba0a65a8be43ef2f4..a53fceb843105ea2a1d88722b3fc7c3b
|
||||||
previousMessages: client._lastSeenMessages.map((e) => ({
|
previousMessages: client._lastSeenMessages.map((e) => ({
|
||||||
messageSender: e.sender,
|
messageSender: e.sender,
|
||||||
diff --git a/src/client/encrypt.js b/src/client/encrypt.js
|
diff --git a/src/client/encrypt.js b/src/client/encrypt.js
|
||||||
index 63cc2bd9615100bd2fd63dfe14c094aa6b8cd1c9..36df57d1196af9761d920fa285ac48f85410eaef 100644
|
index b9d21bab9faccd5dbf1975fc423fc55c73e906c5..99ffd76527b410e3a393181beb260108f4c63536 100644
|
||||||
--- a/src/client/encrypt.js
|
--- a/src/client/encrypt.js
|
||||||
+++ b/src/client/encrypt.js
|
+++ b/src/client/encrypt.js
|
||||||
@@ -25,7 +25,11 @@ module.exports = function (client, options) {
|
@@ -25,7 +25,11 @@ module.exports = function (client, options) {
|
||||||
|
|
@ -73,24 +73,41 @@ index 63cc2bd9615100bd2fd63dfe14c094aa6b8cd1c9..36df57d1196af9761d920fa285ac48f8
|
||||||
}
|
}
|
||||||
|
|
||||||
function onJoinServerResponse (err) {
|
function onJoinServerResponse (err) {
|
||||||
diff --git a/src/client/pluginChannels.js b/src/client/pluginChannels.js
|
diff --git a/src/client/play.js b/src/client/play.js
|
||||||
index 671eb452f31e6b5fcd57d715f1009d010160c65f..7f69f511c8fb97d431ec5125c851b49be8e2ab76 100644
|
index 559607f34e9a5b2b7809423f8ca4cd6746b60225..4dc1c3139438cc2729b05c57e57bd00252728f8a 100644
|
||||||
--- a/src/client/pluginChannels.js
|
--- a/src/client/play.js
|
||||||
+++ b/src/client/pluginChannels.js
|
+++ b/src/client/play.js
|
||||||
@@ -57,7 +57,7 @@ module.exports = function (client, options) {
|
@@ -53,7 +53,7 @@ module.exports = function (client, options) {
|
||||||
try {
|
client.write('configuration_acknowledged', {})
|
||||||
packet.data = proto.parsePacketBuffer(channel, packet.data).data
|
|
||||||
} catch (error) {
|
|
||||||
- client.emit('error', error)
|
|
||||||
+ client.emit('error', error, { customPayload: packet })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
client.state = states.CONFIGURATION
|
||||||
|
- client.on('select_known_packs', () => {
|
||||||
|
+ client.once('select_known_packs', () => {
|
||||||
|
client.write('select_known_packs', { packs: [] })
|
||||||
|
})
|
||||||
|
// Server should send finish_configuration on its own right after sending the client a dimension codec
|
||||||
diff --git a/src/client.js b/src/client.js
|
diff --git a/src/client.js b/src/client.js
|
||||||
index e369e77d055ba919e8f9da7b8e8b5dc879c74cf4..54bb9e6644388e9b6bd42b3012951875989cdf0c 100644
|
index 5c7a62b013daa69be91ec9e763b1f48ffe96ffa6..174d42a77740a937afcb106e1f39a9ee824a24b9 100644
|
||||||
--- a/src/client.js
|
--- a/src/client.js
|
||||||
+++ b/src/client.js
|
+++ b/src/client.js
|
||||||
@@ -111,7 +111,13 @@ class Client extends EventEmitter {
|
@@ -89,10 +89,12 @@ class Client extends EventEmitter {
|
||||||
|
parsed.metadata.name = parsed.data.name
|
||||||
|
parsed.data = parsed.data.params
|
||||||
|
parsed.metadata.state = state
|
||||||
|
- debug('read packet ' + state + '.' + parsed.metadata.name)
|
||||||
|
- if (debug.enabled) {
|
||||||
|
- const s = JSON.stringify(parsed.data, null, 2)
|
||||||
|
- debug(s && s.length > 10000 ? parsed.data : s)
|
||||||
|
+ if (!globalThis.excludeCommunicationDebugEvents?.includes(parsed.metadata.name)) {
|
||||||
|
+ debug('read packet ' + state + '.' + parsed.metadata.name)
|
||||||
|
+ if (debug.enabled) {
|
||||||
|
+ const s = JSON.stringify(parsed.data, null, 2)
|
||||||
|
+ debug(s && s.length > 10000 ? parsed.data : s)
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
if (this._hasBundlePacket && parsed.metadata.name === 'bundle_delimiter') {
|
||||||
|
if (this._mcBundle.length) { // End bundle
|
||||||
|
@@ -110,7 +112,13 @@ class Client extends EventEmitter {
|
||||||
this._hasBundlePacket = false
|
this._hasBundlePacket = false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -105,7 +122,7 @@ index e369e77d055ba919e8f9da7b8e8b5dc879c74cf4..54bb9e6644388e9b6bd42b3012951875
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -169,7 +175,10 @@ class Client extends EventEmitter {
|
@@ -168,7 +176,10 @@ class Client extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
const onFatalError = (err) => {
|
const onFatalError = (err) => {
|
||||||
|
|
@ -117,21 +134,25 @@ index e369e77d055ba919e8f9da7b8e8b5dc879c74cf4..54bb9e6644388e9b6bd42b3012951875
|
||||||
endSocket()
|
endSocket()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,6 +207,10 @@ class Client extends EventEmitter {
|
@@ -197,6 +208,8 @@ class Client extends EventEmitter {
|
||||||
serializer -> framer -> socket -> splitter -> deserializer */
|
serializer -> framer -> socket -> splitter -> deserializer */
|
||||||
if (this.serializer) {
|
if (this.serializer) {
|
||||||
this.serializer.end()
|
this.serializer.end()
|
||||||
+ setTimeout(() => {
|
|
||||||
+ this.socket?.end()
|
+ this.socket?.end()
|
||||||
+ this.socket?.emit('end')
|
+ this.socket?.emit('end')
|
||||||
+ }, 2000) // allow the serializer to finish writing
|
|
||||||
} else {
|
} else {
|
||||||
if (this.socket) this.socket.end()
|
if (this.socket) this.socket.end()
|
||||||
}
|
}
|
||||||
@@ -243,6 +256,7 @@ class Client extends EventEmitter {
|
@@ -238,8 +251,11 @@ class Client extends EventEmitter {
|
||||||
debug('writing packet ' + this.state + '.' + name)
|
|
||||||
debug(params)
|
write (name, params) {
|
||||||
}
|
if (!this.serializer.writable) { return }
|
||||||
|
- debug('writing packet ' + this.state + '.' + name)
|
||||||
|
- debug(params)
|
||||||
|
+ if (!globalThis.excludeCommunicationDebugEvents?.includes(name)) {
|
||||||
|
+ debug(`[${this.state}] from ${this.isServer ? 'server' : 'client'}: ` + name)
|
||||||
|
+ debug(params)
|
||||||
|
+ }
|
||||||
+ this.emit('writePacket', name, params)
|
+ this.emit('writePacket', name, params)
|
||||||
this.serializer.write({ name, params })
|
this.serializer.write({ name, params })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
277
pnpm-lock.yaml
generated
277
pnpm-lock.yaml
generated
|
|
@ -5,7 +5,6 @@ settings:
|
||||||
excludeLinksFromLockfile: false
|
excludeLinksFromLockfile: false
|
||||||
|
|
||||||
overrides:
|
overrides:
|
||||||
mineflayer: github:zardoy/mineflayer#gen-the-master
|
|
||||||
'@nxg-org/mineflayer-physics-util': 1.8.10
|
'@nxg-org/mineflayer-physics-util': 1.8.10
|
||||||
buffer: ^6.0.3
|
buffer: ^6.0.3
|
||||||
vec3: 0.1.10
|
vec3: 0.1.10
|
||||||
|
|
@ -13,7 +12,7 @@ overrides:
|
||||||
diamond-square: github:zardoy/diamond-square
|
diamond-square: github:zardoy/diamond-square
|
||||||
prismarine-block: github:zardoy/prismarine-block#next-era
|
prismarine-block: github:zardoy/prismarine-block#next-era
|
||||||
prismarine-world: github:zardoy/prismarine-world#next-era
|
prismarine-world: github:zardoy/prismarine-world#next-era
|
||||||
minecraft-data: 3.98.0
|
minecraft-data: 3.92.0
|
||||||
prismarine-provider-anvil: github:zardoy/prismarine-provider-anvil#everything
|
prismarine-provider-anvil: github:zardoy/prismarine-provider-anvil#everything
|
||||||
prismarine-physics: github:zardoy/prismarine-physics
|
prismarine-physics: github:zardoy/prismarine-physics
|
||||||
minecraft-protocol: github:PrismarineJS/node-minecraft-protocol#master
|
minecraft-protocol: github:PrismarineJS/node-minecraft-protocol#master
|
||||||
|
|
@ -23,7 +22,7 @@ overrides:
|
||||||
|
|
||||||
patchedDependencies:
|
patchedDependencies:
|
||||||
minecraft-protocol:
|
minecraft-protocol:
|
||||||
hash: 4ebdae314c68d01ce7879445c0b8bde5f90373abba8b66ed00d42e7a5f542f8b
|
hash: a8726e6981ddc3486262d981d1e2030f379901c055ac9c4bf3036b4149e860e0
|
||||||
path: patches/minecraft-protocol.patch
|
path: patches/minecraft-protocol.patch
|
||||||
mineflayer-item-map-downloader@1.2.0:
|
mineflayer-item-map-downloader@1.2.0:
|
||||||
hash: a731ebbace2d8790c973ab3a5ba33494a6e9658533a9710dd8ba36f86db061ad
|
hash: a731ebbace2d8790c973ab3a5ba33494a6e9658533a9710dd8ba36f86db061ad
|
||||||
|
|
@ -42,9 +41,6 @@ importers:
|
||||||
'@floating-ui/react':
|
'@floating-ui/react':
|
||||||
specifier: ^0.26.1
|
specifier: ^0.26.1
|
||||||
version: 0.26.28(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
version: 0.26.28(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||||
'@monaco-editor/react':
|
|
||||||
specifier: ^4.7.0
|
|
||||||
version: 4.7.0(monaco-editor@0.52.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
|
||||||
'@nxg-org/mineflayer-auto-jump':
|
'@nxg-org/mineflayer-auto-jump':
|
||||||
specifier: ^0.7.18
|
specifier: ^0.7.18
|
||||||
version: 0.7.18
|
version: 0.7.18
|
||||||
|
|
@ -121,8 +117,8 @@ importers:
|
||||||
specifier: ^10.0.12
|
specifier: ^10.0.12
|
||||||
version: 10.1.6
|
version: 10.1.6
|
||||||
flying-squid:
|
flying-squid:
|
||||||
specifier: npm:@zardoy/flying-squid@^0.0.104
|
specifier: npm:@zardoy/flying-squid@^0.0.62
|
||||||
version: '@zardoy/flying-squid@0.0.104(encoding@0.1.13)'
|
version: '@zardoy/flying-squid@0.0.62(encoding@0.1.13)'
|
||||||
framer-motion:
|
framer-motion:
|
||||||
specifier: ^12.9.2
|
specifier: ^12.9.2
|
||||||
version: 12.9.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
version: 12.9.2(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||||
|
|
@ -140,13 +136,13 @@ importers:
|
||||||
version: 4.17.21
|
version: 4.17.21
|
||||||
mcraft-fun-mineflayer:
|
mcraft-fun-mineflayer:
|
||||||
specifier: ^0.1.23
|
specifier: ^0.1.23
|
||||||
version: 0.1.23(encoding@0.1.13)(mineflayer@https://codeload.github.com/zardoy/mineflayer/tar.gz/dd3b1ff38506d6f72d90e8444186e4e75fe82659(encoding@0.1.13))
|
version: 0.1.23(encoding@0.1.13)(mineflayer@https://codeload.github.com/zardoy/mineflayer/tar.gz/1616261f727398d0b14359262726828d24797fcc(encoding@0.1.13))
|
||||||
minecraft-data:
|
minecraft-data:
|
||||||
specifier: 3.98.0
|
specifier: 3.92.0
|
||||||
version: 3.98.0
|
version: 3.92.0
|
||||||
minecraft-protocol:
|
minecraft-protocol:
|
||||||
specifier: github:PrismarineJS/node-minecraft-protocol#master
|
specifier: github:PrismarineJS/node-minecraft-protocol#master
|
||||||
version: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/bf89f7e86526c54d8c43f555d8f6dfa4948fd2d9(patch_hash=4ebdae314c68d01ce7879445c0b8bde5f90373abba8b66ed00d42e7a5f542f8b)(encoding@0.1.13)
|
version: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/6c2204a813690ead420e2b8c7f0ef32ca357d176(patch_hash=a8726e6981ddc3486262d981d1e2030f379901c055ac9c4bf3036b4149e860e0)(encoding@0.1.13)
|
||||||
mineflayer-item-map-downloader:
|
mineflayer-item-map-downloader:
|
||||||
specifier: github:zardoy/mineflayer-item-map-downloader
|
specifier: github:zardoy/mineflayer-item-map-downloader
|
||||||
version: https://codeload.github.com/zardoy/mineflayer-item-map-downloader/tar.gz/a8d210ecdcf78dd082fa149a96e1612cc9747824(patch_hash=a731ebbace2d8790c973ab3a5ba33494a6e9658533a9710dd8ba36f86db061ad)(encoding@0.1.13)
|
version: https://codeload.github.com/zardoy/mineflayer-item-map-downloader/tar.gz/a8d210ecdcf78dd082fa149a96e1612cc9747824(patch_hash=a731ebbace2d8790c973ab3a5ba33494a6e9658533a9710dd8ba36f86db061ad)(encoding@0.1.13)
|
||||||
|
|
@ -155,7 +151,7 @@ importers:
|
||||||
version: 2.0.4
|
version: 2.0.4
|
||||||
net-browserify:
|
net-browserify:
|
||||||
specifier: github:zardoy/prismarinejs-net-browserify
|
specifier: github:zardoy/prismarinejs-net-browserify
|
||||||
version: https://codeload.github.com/zardoy/prismarinejs-net-browserify/tar.gz/e754999ffdea67853bc9b10553b5e9908b40f618
|
version: https://codeload.github.com/zardoy/prismarinejs-net-browserify/tar.gz/17fb901e8ea480a52c8fd46373695be172be8aa5
|
||||||
node-gzip:
|
node-gzip:
|
||||||
specifier: ^1.1.2
|
specifier: ^1.1.2
|
||||||
version: 1.1.2
|
version: 1.1.2
|
||||||
|
|
@ -170,7 +166,7 @@ importers:
|
||||||
version: 6.1.1
|
version: 6.1.1
|
||||||
prismarine-provider-anvil:
|
prismarine-provider-anvil:
|
||||||
specifier: github:zardoy/prismarine-provider-anvil#everything
|
specifier: github:zardoy/prismarine-provider-anvil#everything
|
||||||
version: https://codeload.github.com/zardoy/prismarine-provider-anvil/tar.gz/1d548fac63fe977c8281f0a9a522b37e4d92d0b7(minecraft-data@3.98.0)
|
version: https://codeload.github.com/zardoy/prismarine-provider-anvil/tar.gz/1d548fac63fe977c8281f0a9a522b37e4d92d0b7(minecraft-data@3.92.0)
|
||||||
prosemirror-example-setup:
|
prosemirror-example-setup:
|
||||||
specifier: ^1.2.2
|
specifier: ^1.2.2
|
||||||
version: 1.2.3
|
version: 1.2.3
|
||||||
|
|
@ -345,10 +341,13 @@ importers:
|
||||||
version: https://codeload.github.com/zardoy/minecraft-inventory-gui/tar.gz/89c33d396f3fde4804c71f4be3c203ade1833b41(@types/react@18.3.18)(react@18.3.1)
|
version: https://codeload.github.com/zardoy/minecraft-inventory-gui/tar.gz/89c33d396f3fde4804c71f4be3c203ade1833b41(@types/react@18.3.18)(react@18.3.1)
|
||||||
mineflayer:
|
mineflayer:
|
||||||
specifier: github:zardoy/mineflayer#gen-the-master
|
specifier: github:zardoy/mineflayer#gen-the-master
|
||||||
version: https://codeload.github.com/zardoy/mineflayer/tar.gz/dd3b1ff38506d6f72d90e8444186e4e75fe82659(encoding@0.1.13)
|
version: https://codeload.github.com/zardoy/mineflayer/tar.gz/1616261f727398d0b14359262726828d24797fcc(encoding@0.1.13)
|
||||||
mineflayer-mouse:
|
mineflayer-mouse:
|
||||||
specifier: ^0.1.21
|
specifier: ^0.1.11
|
||||||
version: 0.1.21
|
version: 0.1.11
|
||||||
|
mineflayer-pathfinder:
|
||||||
|
specifier: ^2.4.4
|
||||||
|
version: 2.4.5
|
||||||
npm-run-all:
|
npm-run-all:
|
||||||
specifier: ^4.1.5
|
specifier: ^4.1.5
|
||||||
version: 4.1.5
|
version: 4.1.5
|
||||||
|
|
@ -436,7 +435,7 @@ importers:
|
||||||
version: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
version: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
||||||
prismarine-chunk:
|
prismarine-chunk:
|
||||||
specifier: github:zardoy/prismarine-chunk#master
|
specifier: github:zardoy/prismarine-chunk#master
|
||||||
version: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.98.0)
|
version: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.92.0)
|
||||||
prismarine-schematic:
|
prismarine-schematic:
|
||||||
specifier: ^1.2.0
|
specifier: ^1.2.0
|
||||||
version: 1.2.3
|
version: 1.2.3
|
||||||
|
|
@ -1992,16 +1991,6 @@ packages:
|
||||||
'@module-federation/webpack-bundler-runtime@0.11.2':
|
'@module-federation/webpack-bundler-runtime@0.11.2':
|
||||||
resolution: {integrity: sha512-WdwIE6QF+MKs/PdVu0cKPETF743JB9PZ62/qf7Uo3gU4fjsUMc37RnbJZ/qB60EaHHfjwp1v6NnhZw1r4eVsnw==}
|
resolution: {integrity: sha512-WdwIE6QF+MKs/PdVu0cKPETF743JB9PZ62/qf7Uo3gU4fjsUMc37RnbJZ/qB60EaHHfjwp1v6NnhZw1r4eVsnw==}
|
||||||
|
|
||||||
'@monaco-editor/loader@1.5.0':
|
|
||||||
resolution: {integrity: sha512-hKoGSM+7aAc7eRTRjpqAZucPmoNOC4UUbknb/VNoTkEIkCPhqV8LfbsgM1webRM7S/z21eHEx9Fkwx8Z/C/+Xw==}
|
|
||||||
|
|
||||||
'@monaco-editor/react@4.7.0':
|
|
||||||
resolution: {integrity: sha512-cyzXQCtO47ydzxpQtCGSQGOC8Gk3ZUeBXFAxD+CWXYFo5OqZyZUonFl0DwUlTyAfRHntBfw2p3w4s9R6oe1eCA==}
|
|
||||||
peerDependencies:
|
|
||||||
monaco-editor: '>= 0.25.0 < 1'
|
|
||||||
react: ^18.2.0
|
|
||||||
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
|
|
||||||
|
|
||||||
'@msgpack/msgpack@2.8.0':
|
'@msgpack/msgpack@2.8.0':
|
||||||
resolution: {integrity: sha512-h9u4u/jiIRKbq25PM+zymTyW6bhTzELvOoUd+AvYriWOAKpLGnIamaET3pnHYoI5iYphAHBI4ayx0MehR+VVPQ==}
|
resolution: {integrity: sha512-h9u4u/jiIRKbq25PM+zymTyW6bhTzELvOoUd+AvYriWOAKpLGnIamaET3pnHYoI5iYphAHBI4ayx0MehR+VVPQ==}
|
||||||
engines: {node: '>= 10'}
|
engines: {node: '>= 10'}
|
||||||
|
|
@ -3387,13 +3376,13 @@ packages:
|
||||||
resolution: {integrity: sha512-6xm38yGVIa6mKm/DUCF2zFFJhERh/QWp1ufm4cNUvxsONBmfPg8uZ9pZBdOmF6qFGr/HlT6ABBkCSx/dlEtvWg==}
|
resolution: {integrity: sha512-6xm38yGVIa6mKm/DUCF2zFFJhERh/QWp1ufm4cNUvxsONBmfPg8uZ9pZBdOmF6qFGr/HlT6ABBkCSx/dlEtvWg==}
|
||||||
engines: {node: '>=12 <14 || 14.2 - 14.9 || >14.10.0'}
|
engines: {node: '>=12 <14 || 14.2 - 14.9 || >14.10.0'}
|
||||||
|
|
||||||
'@zardoy/flying-squid@0.0.104':
|
'@zardoy/flying-squid@0.0.49':
|
||||||
resolution: {integrity: sha512-jGhQ7fn7o8UN+mUwZbt9674D37YLuBi+Au4TwKcopCA6huIQdHTFNl2e+0ZSTI5mnhN+NpyVoR3vmtH6L58vHQ==}
|
resolution: {integrity: sha512-Kt4wr5/R+44tcLU9gjuNG2an9weWeKEpIoKXfsgJN2GGQqdnbd5nBpxfGDdgZ9aMdFugsVW8BsyPZNhj9vbMXA==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
'@zardoy/flying-squid@0.0.49':
|
'@zardoy/flying-squid@0.0.62':
|
||||||
resolution: {integrity: sha512-Kt4wr5/R+44tcLU9gjuNG2an9weWeKEpIoKXfsgJN2GGQqdnbd5nBpxfGDdgZ9aMdFugsVW8BsyPZNhj9vbMXA==}
|
resolution: {integrity: sha512-M6icydO/yrmwevBhmgKcqEPC63AhWfU/Es9N/uadVrmKaxGm2FQMMLcybbutRYm1xZ6qsdxDUOUZnN56PsVwfQ==}
|
||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
|
|
@ -6444,12 +6433,6 @@ packages:
|
||||||
resolution: {integrity: sha512-RYZeD1+joNlPuUpi+tIWkbP0ieVJr+R6IFkI6/8juhSxx9zE4osoSmteybrfspGm8A6u+YbbY1epqRKEMwVR6Q==}
|
resolution: {integrity: sha512-RYZeD1+joNlPuUpi+tIWkbP0ieVJr+R6IFkI6/8juhSxx9zE4osoSmteybrfspGm8A6u+YbbY1epqRKEMwVR6Q==}
|
||||||
engines: {node: '>=18.0.0'}
|
engines: {node: '>=18.0.0'}
|
||||||
|
|
||||||
mc-bridge@0.1.3:
|
|
||||||
resolution: {integrity: sha512-H9jPt2xEU77itC27dSz3qazHYqN9qVsv4HgMPozg7RqQ1uwgXmEa+ojKIlDtXf/TLJsG6Kv4EbzGa8a1Wh72uA==}
|
|
||||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
|
||||||
peerDependencies:
|
|
||||||
minecraft-data: 3.98.0
|
|
||||||
|
|
||||||
mcraft-fun-mineflayer@0.1.23:
|
mcraft-fun-mineflayer@0.1.23:
|
||||||
resolution: {integrity: sha512-qmI1rQQ0Ro5zJdi99rClWLF+mS9JZffgNX2vyWWesS3Hsk3Xblp/8swYTJKHSaFpNgzkVfXV92fEIrBqeH6iKA==}
|
resolution: {integrity: sha512-qmI1rQQ0Ro5zJdi99rClWLF+mS9JZffgNX2vyWWesS3Hsk3Xblp/8swYTJKHSaFpNgzkVfXV92fEIrBqeH6iKA==}
|
||||||
version: 0.1.23
|
version: 0.1.23
|
||||||
|
|
@ -6658,8 +6641,8 @@ packages:
|
||||||
resolution: {integrity: sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==}
|
resolution: {integrity: sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==}
|
||||||
engines: {node: '>=4'}
|
engines: {node: '>=4'}
|
||||||
|
|
||||||
minecraft-data@3.98.0:
|
minecraft-data@3.92.0:
|
||||||
resolution: {integrity: sha512-JAPqJ/TZoxMUlAPPdWUh1v5wdqvYGFSZ4rW9bUtmaKBkGpomDSjw4V02ocBqbxKJvcTtmc5nM/LfN9/0DDqHrQ==}
|
resolution: {integrity: sha512-CGfO50svzm+pSRa4Mbq4owsmRKbPCNkSZ3MCOyH+epC7yNjh+PUhPQFHWq72O51qsY7pAB5qM/bJn1ncwG1J5g==}
|
||||||
|
|
||||||
minecraft-folder-path@1.2.0:
|
minecraft-folder-path@1.2.0:
|
||||||
resolution: {integrity: sha512-qaUSbKWoOsH9brn0JQuBhxNAzTDMwrOXorwuRxdJKKKDYvZhtml+6GVCUrY5HRiEsieBEjCUnhVpDuQiKsiFaw==}
|
resolution: {integrity: sha512-qaUSbKWoOsH9brn0JQuBhxNAzTDMwrOXorwuRxdJKKKDYvZhtml+6GVCUrY5HRiEsieBEjCUnhVpDuQiKsiFaw==}
|
||||||
|
|
@ -6668,9 +6651,9 @@ packages:
|
||||||
resolution: {tarball: https://codeload.github.com/zardoy/minecraft-inventory-gui/tar.gz/89c33d396f3fde4804c71f4be3c203ade1833b41}
|
resolution: {tarball: https://codeload.github.com/zardoy/minecraft-inventory-gui/tar.gz/89c33d396f3fde4804c71f4be3c203ade1833b41}
|
||||||
version: 1.0.1
|
version: 1.0.1
|
||||||
|
|
||||||
minecraft-protocol@https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/bf89f7e86526c54d8c43f555d8f6dfa4948fd2d9:
|
minecraft-protocol@https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/6c2204a813690ead420e2b8c7f0ef32ca357d176:
|
||||||
resolution: {tarball: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/bf89f7e86526c54d8c43f555d8f6dfa4948fd2d9}
|
resolution: {tarball: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/6c2204a813690ead420e2b8c7f0ef32ca357d176}
|
||||||
version: 1.62.0
|
version: 1.58.0
|
||||||
engines: {node: '>=22'}
|
engines: {node: '>=22'}
|
||||||
|
|
||||||
minecraft-wrap@1.6.0:
|
minecraft-wrap@1.6.0:
|
||||||
|
|
@ -6684,13 +6667,20 @@ packages:
|
||||||
resolution: {tarball: https://codeload.github.com/zardoy/mineflayer-item-map-downloader/tar.gz/a8d210ecdcf78dd082fa149a96e1612cc9747824}
|
resolution: {tarball: https://codeload.github.com/zardoy/mineflayer-item-map-downloader/tar.gz/a8d210ecdcf78dd082fa149a96e1612cc9747824}
|
||||||
version: 1.2.0
|
version: 1.2.0
|
||||||
|
|
||||||
mineflayer-mouse@0.1.21:
|
mineflayer-mouse@0.1.11:
|
||||||
resolution: {integrity: sha512-1XTVuw3twIrEcqQ1QRSB8NcStIUEZ+tbxiAG6rOrN/9M4thhtlS5PTJzFdmdrcYgWEBLvuOdJszaKE5zFfiXhg==}
|
resolution: {integrity: sha512-BL47pXZ1+92BA/7ym6KaJctEHKnL0up+tpuagVwSKJvAgibeqWQJJwDlNUWkOLvpnruRKDxMR5OB1hUXFoDNSg==}
|
||||||
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||||
|
|
||||||
mineflayer@https://codeload.github.com/zardoy/mineflayer/tar.gz/dd3b1ff38506d6f72d90e8444186e4e75fe82659:
|
mineflayer-pathfinder@2.4.5:
|
||||||
resolution: {tarball: https://codeload.github.com/zardoy/mineflayer/tar.gz/dd3b1ff38506d6f72d90e8444186e4e75fe82659}
|
resolution: {integrity: sha512-Jh3JnUgRLwhMh2Dugo4SPza68C41y+NPP5sdsgxRu35ydndo70i1JJGxauVWbXrpNwIxYNztUw78aFyb7icw8g==}
|
||||||
version: 8.0.0
|
|
||||||
|
mineflayer@4.30.0:
|
||||||
|
resolution: {integrity: sha512-GtW4hkijyZbSu5LKYYD89xZu+XY7OoP7IkrCnNEn6EdPm0+vr2THoJgFGKrlze9/81+T+P3E4qvJXNFiU/zeJg==}
|
||||||
|
engines: {node: '>=22'}
|
||||||
|
|
||||||
|
mineflayer@https://codeload.github.com/zardoy/mineflayer/tar.gz/1616261f727398d0b14359262726828d24797fcc:
|
||||||
|
resolution: {tarball: https://codeload.github.com/zardoy/mineflayer/tar.gz/1616261f727398d0b14359262726828d24797fcc}
|
||||||
|
version: 4.30.0
|
||||||
engines: {node: '>=22'}
|
engines: {node: '>=22'}
|
||||||
|
|
||||||
minimalistic-assert@1.0.1:
|
minimalistic-assert@1.0.1:
|
||||||
|
|
@ -6788,9 +6778,6 @@ packages:
|
||||||
mojangson@2.0.4:
|
mojangson@2.0.4:
|
||||||
resolution: {integrity: sha512-HYmhgDjr1gzF7trGgvcC/huIg2L8FsVbi/KacRe6r1AswbboGVZDS47SOZlomPuMWvZLas8m9vuHHucdZMwTmQ==}
|
resolution: {integrity: sha512-HYmhgDjr1gzF7trGgvcC/huIg2L8FsVbi/KacRe6r1AswbboGVZDS47SOZlomPuMWvZLas8m9vuHHucdZMwTmQ==}
|
||||||
|
|
||||||
monaco-editor@0.52.2:
|
|
||||||
resolution: {integrity: sha512-GEQWEZmfkOGLdd3XK8ryrfWz3AIP8YymVXiPHEdewrUq7mh0qrKrfHLNCXcbB6sTnMLnOZ3ztSiKcciFUkIJwQ==}
|
|
||||||
|
|
||||||
moo@0.5.2:
|
moo@0.5.2:
|
||||||
resolution: {integrity: sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==}
|
resolution: {integrity: sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==}
|
||||||
|
|
||||||
|
|
@ -6855,8 +6842,8 @@ packages:
|
||||||
neo-async@2.6.2:
|
neo-async@2.6.2:
|
||||||
resolution: {integrity: sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==}
|
resolution: {integrity: sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==}
|
||||||
|
|
||||||
net-browserify@https://codeload.github.com/zardoy/prismarinejs-net-browserify/tar.gz/e754999ffdea67853bc9b10553b5e9908b40f618:
|
net-browserify@https://codeload.github.com/zardoy/prismarinejs-net-browserify/tar.gz/17fb901e8ea480a52c8fd46373695be172be8aa5:
|
||||||
resolution: {tarball: https://codeload.github.com/zardoy/prismarinejs-net-browserify/tar.gz/e754999ffdea67853bc9b10553b5e9908b40f618}
|
resolution: {tarball: https://codeload.github.com/zardoy/prismarinejs-net-browserify/tar.gz/17fb901e8ea480a52c8fd46373695be172be8aa5}
|
||||||
version: 0.2.4
|
version: 0.2.4
|
||||||
|
|
||||||
nice-try@1.0.5:
|
nice-try@1.0.5:
|
||||||
|
|
@ -7387,7 +7374,7 @@ packages:
|
||||||
prismarine-biome@1.3.0:
|
prismarine-biome@1.3.0:
|
||||||
resolution: {integrity: sha512-GY6nZxq93mTErT7jD7jt8YS1aPrOakbJHh39seYsJFXvueIOdHAmW16kYQVrTVMW5MlWLQVxV/EquRwOgr4MnQ==}
|
resolution: {integrity: sha512-GY6nZxq93mTErT7jD7jt8YS1aPrOakbJHh39seYsJFXvueIOdHAmW16kYQVrTVMW5MlWLQVxV/EquRwOgr4MnQ==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
minecraft-data: 3.98.0
|
minecraft-data: 3.92.0
|
||||||
prismarine-registry: ^1.1.0
|
prismarine-registry: ^1.1.0
|
||||||
|
|
||||||
prismarine-block@https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9:
|
prismarine-block@https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9:
|
||||||
|
|
@ -7405,8 +7392,8 @@ packages:
|
||||||
prismarine-entity@2.5.0:
|
prismarine-entity@2.5.0:
|
||||||
resolution: {integrity: sha512-nRPCawUwf9r3iKqi4I7mZRlir1Ix+DffWYdWq6p/KNnmiXve+xHE5zv8XCdhZlUmOshugHv5ONl9o6ORAkCNIA==}
|
resolution: {integrity: sha512-nRPCawUwf9r3iKqi4I7mZRlir1Ix+DffWYdWq6p/KNnmiXve+xHE5zv8XCdhZlUmOshugHv5ONl9o6ORAkCNIA==}
|
||||||
|
|
||||||
prismarine-item@1.17.0:
|
prismarine-item@1.16.0:
|
||||||
resolution: {integrity: sha512-wN1OjP+f+Uvtjo3KzeCkVSy96CqZ8yG7cvuvlGwcYupQ6ct7LtNkubHp0AHuLMJ0vbbfAC0oZ2bWOgI1DYp8WA==}
|
resolution: {integrity: sha512-88Tz+/6HquYIsDuseae5G3IbqLeMews2L+ba2gX+p6K6soU9nuFhCfbwN56QuB7d/jZFcWrCYAPE5+UhwWh67w==}
|
||||||
|
|
||||||
prismarine-nbt@2.7.0:
|
prismarine-nbt@2.7.0:
|
||||||
resolution: {integrity: sha512-Du9OLQAcCj3y29YtewOJbbV4ARaSUEJiTguw0PPQbPBy83f+eCyDRkyBpnXTi/KPyEpgYCzsjGzElevLpFoYGQ==}
|
resolution: {integrity: sha512-Du9OLQAcCj3y29YtewOJbbV4ARaSUEJiTguw0PPQbPBy83f+eCyDRkyBpnXTi/KPyEpgYCzsjGzElevLpFoYGQ==}
|
||||||
|
|
@ -8337,7 +8324,6 @@ packages:
|
||||||
source-map@0.8.0-beta.0:
|
source-map@0.8.0-beta.0:
|
||||||
resolution: {integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==}
|
resolution: {integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==}
|
||||||
engines: {node: '>= 8'}
|
engines: {node: '>= 8'}
|
||||||
deprecated: The work that was done in this beta branch won't be included in future versions
|
|
||||||
|
|
||||||
sourcemap-codec@1.4.8:
|
sourcemap-codec@1.4.8:
|
||||||
resolution: {integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==}
|
resolution: {integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==}
|
||||||
|
|
@ -8395,9 +8381,6 @@ packages:
|
||||||
stacktrace-js@2.0.2:
|
stacktrace-js@2.0.2:
|
||||||
resolution: {integrity: sha512-Je5vBeY4S1r/RnLydLl0TBTi3F2qdfWmYsGvtfZgEI+SCprPppaIhQf5nGcal4gI4cGpCV/duLcAzT1np6sQqg==}
|
resolution: {integrity: sha512-Je5vBeY4S1r/RnLydLl0TBTi3F2qdfWmYsGvtfZgEI+SCprPppaIhQf5nGcal4gI4cGpCV/duLcAzT1np6sQqg==}
|
||||||
|
|
||||||
state-local@1.0.7:
|
|
||||||
resolution: {integrity: sha512-HTEHMNieakEnoe33shBYcZ7NX83ACUjCu8c40iOGEZsngj9zRnkqS9j1pqQPXwobB0ZcVTk27REb7COQ0UR59w==}
|
|
||||||
|
|
||||||
static-extend@0.1.2:
|
static-extend@0.1.2:
|
||||||
resolution: {integrity: sha512-72E9+uLc27Mt718pMHt9VMNiAL4LMsmDbBva8mxWUCkT07fSzEGMYUCk0XWY6lp0j6RBAG4cJ3mWuZv2OE3s0g==}
|
resolution: {integrity: sha512-72E9+uLc27Mt718pMHt9VMNiAL4LMsmDbBva8mxWUCkT07fSzEGMYUCk0XWY6lp0j6RBAG4cJ3mWuZv2OE3s0g==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
|
|
@ -9685,7 +9668,7 @@ snapshots:
|
||||||
'@babel/core': 7.26.9
|
'@babel/core': 7.26.9
|
||||||
'@babel/helper-compilation-targets': 7.26.5
|
'@babel/helper-compilation-targets': 7.26.5
|
||||||
'@babel/helper-plugin-utils': 7.26.5
|
'@babel/helper-plugin-utils': 7.26.5
|
||||||
debug: 4.4.1
|
debug: 4.4.0(supports-color@8.1.1)
|
||||||
lodash.debounce: 4.0.8
|
lodash.debounce: 4.0.8
|
||||||
resolve: 1.22.10
|
resolve: 1.22.10
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
|
|
@ -10310,7 +10293,7 @@ snapshots:
|
||||||
'@babel/parser': 7.26.9
|
'@babel/parser': 7.26.9
|
||||||
'@babel/template': 7.26.9
|
'@babel/template': 7.26.9
|
||||||
'@babel/types': 7.26.9
|
'@babel/types': 7.26.9
|
||||||
debug: 4.4.1
|
debug: 4.4.0(supports-color@8.1.1)
|
||||||
globals: 11.12.0
|
globals: 11.12.0
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
@ -11279,17 +11262,6 @@ snapshots:
|
||||||
'@module-federation/runtime': 0.11.2
|
'@module-federation/runtime': 0.11.2
|
||||||
'@module-federation/sdk': 0.11.2
|
'@module-federation/sdk': 0.11.2
|
||||||
|
|
||||||
'@monaco-editor/loader@1.5.0':
|
|
||||||
dependencies:
|
|
||||||
state-local: 1.0.7
|
|
||||||
|
|
||||||
'@monaco-editor/react@4.7.0(monaco-editor@0.52.2)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
|
|
||||||
dependencies:
|
|
||||||
'@monaco-editor/loader': 1.5.0
|
|
||||||
monaco-editor: 0.52.2
|
|
||||||
react: 18.3.1
|
|
||||||
react-dom: 18.3.1(react@18.3.1)
|
|
||||||
|
|
||||||
'@msgpack/msgpack@2.8.0': {}
|
'@msgpack/msgpack@2.8.0': {}
|
||||||
|
|
||||||
'@ndelangen/get-tarball@3.0.9':
|
'@ndelangen/get-tarball@3.0.9':
|
||||||
|
|
@ -11343,10 +11315,10 @@ snapshots:
|
||||||
'@nxg-org/mineflayer-trajectories@1.2.0(encoding@0.1.13)':
|
'@nxg-org/mineflayer-trajectories@1.2.0(encoding@0.1.13)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@nxg-org/mineflayer-util-plugin': 1.8.4
|
'@nxg-org/mineflayer-util-plugin': 1.8.4
|
||||||
minecraft-data: 3.98.0
|
minecraft-data: 3.92.0
|
||||||
mineflayer: https://codeload.github.com/zardoy/mineflayer/tar.gz/dd3b1ff38506d6f72d90e8444186e4e75fe82659(encoding@0.1.13)
|
mineflayer: 4.30.0(encoding@0.1.13)
|
||||||
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
||||||
prismarine-item: 1.17.0
|
prismarine-item: 1.16.0
|
||||||
prismarine-physics: https://codeload.github.com/zardoy/prismarine-physics/tar.gz/353e25b800149393f40539ec381218be44cbb03b
|
prismarine-physics: https://codeload.github.com/zardoy/prismarine-physics/tar.gz/353e25b800149393f40539ec381218be44cbb03b
|
||||||
vec3: 0.1.10
|
vec3: 0.1.10
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
|
|
@ -12891,7 +12863,7 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@typescript-eslint/typescript-estree': 6.1.0(typescript@5.5.4)
|
'@typescript-eslint/typescript-estree': 6.1.0(typescript@5.5.4)
|
||||||
'@typescript-eslint/utils': 6.1.0(eslint@8.57.1)(typescript@5.5.4)
|
'@typescript-eslint/utils': 6.1.0(eslint@8.57.1)(typescript@5.5.4)
|
||||||
debug: 4.4.1
|
debug: 4.4.0(supports-color@8.1.1)
|
||||||
eslint: 8.57.1
|
eslint: 8.57.1
|
||||||
ts-api-utils: 1.4.3(typescript@5.5.4)
|
ts-api-utils: 1.4.3(typescript@5.5.4)
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
|
|
@ -12909,7 +12881,7 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@typescript-eslint/types': 6.1.0
|
'@typescript-eslint/types': 6.1.0
|
||||||
'@typescript-eslint/visitor-keys': 6.1.0
|
'@typescript-eslint/visitor-keys': 6.1.0
|
||||||
debug: 4.4.1
|
debug: 4.4.0(supports-color@8.1.1)
|
||||||
globby: 11.1.0
|
globby: 11.1.0
|
||||||
is-glob: 4.0.3
|
is-glob: 4.0.3
|
||||||
semver: 7.7.1
|
semver: 7.7.1
|
||||||
|
|
@ -12923,7 +12895,7 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@typescript-eslint/types': 6.21.0
|
'@typescript-eslint/types': 6.21.0
|
||||||
'@typescript-eslint/visitor-keys': 6.21.0
|
'@typescript-eslint/visitor-keys': 6.21.0
|
||||||
debug: 4.4.1
|
debug: 4.4.0(supports-color@8.1.1)
|
||||||
globby: 11.1.0
|
globby: 11.1.0
|
||||||
is-glob: 4.0.3
|
is-glob: 4.0.3
|
||||||
minimatch: 9.0.3
|
minimatch: 9.0.3
|
||||||
|
|
@ -12938,7 +12910,7 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@typescript-eslint/types': 8.26.0
|
'@typescript-eslint/types': 8.26.0
|
||||||
'@typescript-eslint/visitor-keys': 8.26.0
|
'@typescript-eslint/visitor-keys': 8.26.0
|
||||||
debug: 4.4.1
|
debug: 4.4.0(supports-color@8.1.1)
|
||||||
fast-glob: 3.3.3
|
fast-glob: 3.3.3
|
||||||
is-glob: 4.0.3
|
is-glob: 4.0.3
|
||||||
minimatch: 9.0.5
|
minimatch: 9.0.5
|
||||||
|
|
@ -13094,7 +13066,7 @@ snapshots:
|
||||||
'@types/emscripten': 1.40.0
|
'@types/emscripten': 1.40.0
|
||||||
tslib: 1.14.1
|
tslib: 1.14.1
|
||||||
|
|
||||||
'@zardoy/flying-squid@0.0.104(encoding@0.1.13)':
|
'@zardoy/flying-squid@0.0.49(encoding@0.1.13)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@tootallnate/once': 2.0.0
|
'@tootallnate/once': 2.0.0
|
||||||
chalk: 5.4.1
|
chalk: 5.4.1
|
||||||
|
|
@ -13104,18 +13076,16 @@ snapshots:
|
||||||
exit-hook: 2.2.1
|
exit-hook: 2.2.1
|
||||||
flatmap: 0.0.3
|
flatmap: 0.0.3
|
||||||
long: 5.3.1
|
long: 5.3.1
|
||||||
mc-bridge: 0.1.3(minecraft-data@3.98.0)
|
minecraft-data: 3.92.0
|
||||||
minecraft-data: 3.98.0
|
minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/6c2204a813690ead420e2b8c7f0ef32ca357d176(patch_hash=a8726e6981ddc3486262d981d1e2030f379901c055ac9c4bf3036b4149e860e0)(encoding@0.1.13)
|
||||||
minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/bf89f7e86526c54d8c43f555d8f6dfa4948fd2d9(patch_hash=4ebdae314c68d01ce7879445c0b8bde5f90373abba8b66ed00d42e7a5f542f8b)(encoding@0.1.13)
|
|
||||||
mkdirp: 2.1.6
|
mkdirp: 2.1.6
|
||||||
node-gzip: 1.1.2
|
node-gzip: 1.1.2
|
||||||
node-rsa: 1.1.1
|
node-rsa: 1.1.1
|
||||||
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.92.0)
|
||||||
prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.98.0)
|
|
||||||
prismarine-entity: 2.5.0
|
prismarine-entity: 2.5.0
|
||||||
prismarine-item: 1.17.0
|
prismarine-item: 1.16.0
|
||||||
prismarine-nbt: 2.7.0
|
prismarine-nbt: 2.7.0
|
||||||
prismarine-provider-anvil: https://codeload.github.com/zardoy/prismarine-provider-anvil/tar.gz/1d548fac63fe977c8281f0a9a522b37e4d92d0b7(minecraft-data@3.98.0)
|
prismarine-provider-anvil: https://codeload.github.com/zardoy/prismarine-provider-anvil/tar.gz/1d548fac63fe977c8281f0a9a522b37e4d92d0b7(minecraft-data@3.92.0)
|
||||||
prismarine-windows: 2.9.0
|
prismarine-windows: 2.9.0
|
||||||
prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c
|
prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c
|
||||||
rambda: 9.4.2
|
rambda: 9.4.2
|
||||||
|
|
@ -13132,7 +13102,7 @@ snapshots:
|
||||||
- encoding
|
- encoding
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
'@zardoy/flying-squid@0.0.49(encoding@0.1.13)':
|
'@zardoy/flying-squid@0.0.62(encoding@0.1.13)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@tootallnate/once': 2.0.0
|
'@tootallnate/once': 2.0.0
|
||||||
chalk: 5.4.1
|
chalk: 5.4.1
|
||||||
|
|
@ -13142,16 +13112,16 @@ snapshots:
|
||||||
exit-hook: 2.2.1
|
exit-hook: 2.2.1
|
||||||
flatmap: 0.0.3
|
flatmap: 0.0.3
|
||||||
long: 5.3.1
|
long: 5.3.1
|
||||||
minecraft-data: 3.98.0
|
minecraft-data: 3.92.0
|
||||||
minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/bf89f7e86526c54d8c43f555d8f6dfa4948fd2d9(patch_hash=4ebdae314c68d01ce7879445c0b8bde5f90373abba8b66ed00d42e7a5f542f8b)(encoding@0.1.13)
|
minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/6c2204a813690ead420e2b8c7f0ef32ca357d176(patch_hash=a8726e6981ddc3486262d981d1e2030f379901c055ac9c4bf3036b4149e860e0)(encoding@0.1.13)
|
||||||
mkdirp: 2.1.6
|
mkdirp: 2.1.6
|
||||||
node-gzip: 1.1.2
|
node-gzip: 1.1.2
|
||||||
node-rsa: 1.1.1
|
node-rsa: 1.1.1
|
||||||
prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.98.0)
|
prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.92.0)
|
||||||
prismarine-entity: 2.5.0
|
prismarine-entity: 2.5.0
|
||||||
prismarine-item: 1.17.0
|
prismarine-item: 1.16.0
|
||||||
prismarine-nbt: 2.7.0
|
prismarine-nbt: 2.7.0
|
||||||
prismarine-provider-anvil: https://codeload.github.com/zardoy/prismarine-provider-anvil/tar.gz/1d548fac63fe977c8281f0a9a522b37e4d92d0b7(minecraft-data@3.98.0)
|
prismarine-provider-anvil: https://codeload.github.com/zardoy/prismarine-provider-anvil/tar.gz/1d548fac63fe977c8281f0a9a522b37e4d92d0b7(minecraft-data@3.92.0)
|
||||||
prismarine-windows: 2.9.0
|
prismarine-windows: 2.9.0
|
||||||
prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c
|
prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c
|
||||||
rambda: 9.4.2
|
rambda: 9.4.2
|
||||||
|
|
@ -14532,7 +14502,7 @@ snapshots:
|
||||||
detect-port@1.6.1:
|
detect-port@1.6.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
address: 1.2.2
|
address: 1.2.2
|
||||||
debug: 4.4.1
|
debug: 4.4.0(supports-color@8.1.1)
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
|
|
@ -14542,8 +14512,8 @@ snapshots:
|
||||||
|
|
||||||
diamond-square@https://codeload.github.com/zardoy/diamond-square/tar.gz/cfaad2d1d5909fdfa63c8cc7bc05fb5e87782d71:
|
diamond-square@https://codeload.github.com/zardoy/diamond-square/tar.gz/cfaad2d1d5909fdfa63c8cc7bc05fb5e87782d71:
|
||||||
dependencies:
|
dependencies:
|
||||||
minecraft-data: 3.98.0
|
minecraft-data: 3.92.0
|
||||||
prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.98.0)
|
prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.92.0)
|
||||||
prismarine-registry: 1.11.0
|
prismarine-registry: 1.11.0
|
||||||
random-seed: 0.3.0
|
random-seed: 0.3.0
|
||||||
vec3: 0.1.10
|
vec3: 0.1.10
|
||||||
|
|
@ -16139,7 +16109,7 @@ snapshots:
|
||||||
https-proxy-agent@4.0.0:
|
https-proxy-agent@4.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
agent-base: 5.1.1
|
agent-base: 5.1.1
|
||||||
debug: 4.4.1
|
debug: 4.4.0(supports-color@8.1.1)
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
|
|
@ -16986,17 +16956,13 @@ snapshots:
|
||||||
maxrects-packer: '@zardoy/maxrects-packer@2.7.4'
|
maxrects-packer: '@zardoy/maxrects-packer@2.7.4'
|
||||||
zod: 3.24.2
|
zod: 3.24.2
|
||||||
|
|
||||||
mc-bridge@0.1.3(minecraft-data@3.98.0):
|
mcraft-fun-mineflayer@0.1.23(encoding@0.1.13)(mineflayer@https://codeload.github.com/zardoy/mineflayer/tar.gz/1616261f727398d0b14359262726828d24797fcc(encoding@0.1.13)):
|
||||||
dependencies:
|
|
||||||
minecraft-data: 3.98.0
|
|
||||||
|
|
||||||
mcraft-fun-mineflayer@0.1.23(encoding@0.1.13)(mineflayer@https://codeload.github.com/zardoy/mineflayer/tar.gz/dd3b1ff38506d6f72d90e8444186e4e75fe82659(encoding@0.1.13)):
|
|
||||||
dependencies:
|
dependencies:
|
||||||
'@zardoy/flying-squid': 0.0.49(encoding@0.1.13)
|
'@zardoy/flying-squid': 0.0.49(encoding@0.1.13)
|
||||||
exit-hook: 2.2.1
|
exit-hook: 2.2.1
|
||||||
minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/bf89f7e86526c54d8c43f555d8f6dfa4948fd2d9(patch_hash=4ebdae314c68d01ce7879445c0b8bde5f90373abba8b66ed00d42e7a5f542f8b)(encoding@0.1.13)
|
minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/6c2204a813690ead420e2b8c7f0ef32ca357d176(patch_hash=a8726e6981ddc3486262d981d1e2030f379901c055ac9c4bf3036b4149e860e0)(encoding@0.1.13)
|
||||||
mineflayer: https://codeload.github.com/zardoy/mineflayer/tar.gz/dd3b1ff38506d6f72d90e8444186e4e75fe82659(encoding@0.1.13)
|
mineflayer: https://codeload.github.com/zardoy/mineflayer/tar.gz/1616261f727398d0b14359262726828d24797fcc(encoding@0.1.13)
|
||||||
prismarine-item: 1.17.0
|
prismarine-item: 1.16.0
|
||||||
ws: 8.18.1
|
ws: 8.18.1
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- bufferutil
|
- bufferutil
|
||||||
|
|
@ -17225,7 +17191,7 @@ snapshots:
|
||||||
micromark@4.0.2:
|
micromark@4.0.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/debug': 4.1.12
|
'@types/debug': 4.1.12
|
||||||
debug: 4.4.1
|
debug: 4.4.0(supports-color@8.1.1)
|
||||||
decode-named-character-reference: 1.1.0
|
decode-named-character-reference: 1.1.0
|
||||||
devlop: 1.1.0
|
devlop: 1.1.0
|
||||||
micromark-core-commonmark: 2.0.3
|
micromark-core-commonmark: 2.0.3
|
||||||
|
|
@ -17302,7 +17268,7 @@ snapshots:
|
||||||
|
|
||||||
min-indent@1.0.1: {}
|
min-indent@1.0.1: {}
|
||||||
|
|
||||||
minecraft-data@3.98.0: {}
|
minecraft-data@3.92.0: {}
|
||||||
|
|
||||||
minecraft-folder-path@1.2.0: {}
|
minecraft-folder-path@1.2.0: {}
|
||||||
|
|
||||||
|
|
@ -17313,7 +17279,7 @@ snapshots:
|
||||||
- '@types/react'
|
- '@types/react'
|
||||||
- react
|
- react
|
||||||
|
|
||||||
minecraft-protocol@https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/bf89f7e86526c54d8c43f555d8f6dfa4948fd2d9(patch_hash=4ebdae314c68d01ce7879445c0b8bde5f90373abba8b66ed00d42e7a5f542f8b)(encoding@0.1.13):
|
minecraft-protocol@https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/6c2204a813690ead420e2b8c7f0ef32ca357d176(patch_hash=a8726e6981ddc3486262d981d1e2030f379901c055ac9c4bf3036b4149e860e0)(encoding@0.1.13):
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node-rsa': 1.1.4
|
'@types/node-rsa': 1.1.4
|
||||||
'@types/readable-stream': 4.0.18
|
'@types/readable-stream': 4.0.18
|
||||||
|
|
@ -17322,7 +17288,7 @@ snapshots:
|
||||||
debug: 4.4.0(supports-color@8.1.1)
|
debug: 4.4.0(supports-color@8.1.1)
|
||||||
endian-toggle: 0.0.0
|
endian-toggle: 0.0.0
|
||||||
lodash.merge: 4.6.2
|
lodash.merge: 4.6.2
|
||||||
minecraft-data: 3.98.0
|
minecraft-data: 3.92.0
|
||||||
minecraft-folder-path: 1.2.0
|
minecraft-folder-path: 1.2.0
|
||||||
node-fetch: 2.7.0(encoding@0.1.13)
|
node-fetch: 2.7.0(encoding@0.1.13)
|
||||||
node-rsa: 0.4.2
|
node-rsa: 0.4.2
|
||||||
|
|
@ -17365,32 +17331,65 @@ snapshots:
|
||||||
|
|
||||||
mineflayer-item-map-downloader@https://codeload.github.com/zardoy/mineflayer-item-map-downloader/tar.gz/a8d210ecdcf78dd082fa149a96e1612cc9747824(patch_hash=a731ebbace2d8790c973ab3a5ba33494a6e9658533a9710dd8ba36f86db061ad)(encoding@0.1.13):
|
mineflayer-item-map-downloader@https://codeload.github.com/zardoy/mineflayer-item-map-downloader/tar.gz/a8d210ecdcf78dd082fa149a96e1612cc9747824(patch_hash=a731ebbace2d8790c973ab3a5ba33494a6e9658533a9710dd8ba36f86db061ad)(encoding@0.1.13):
|
||||||
dependencies:
|
dependencies:
|
||||||
mineflayer: https://codeload.github.com/zardoy/mineflayer/tar.gz/dd3b1ff38506d6f72d90e8444186e4e75fe82659(encoding@0.1.13)
|
mineflayer: 4.30.0(encoding@0.1.13)
|
||||||
sharp: 0.30.7
|
sharp: 0.30.7
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- encoding
|
- encoding
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
mineflayer-mouse@0.1.21:
|
mineflayer-mouse@0.1.11:
|
||||||
dependencies:
|
dependencies:
|
||||||
change-case: 5.4.4
|
change-case: 5.4.4
|
||||||
debug: 4.4.1
|
debug: 4.4.1
|
||||||
prismarine-item: 1.17.0
|
prismarine-item: 1.16.0
|
||||||
prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c
|
prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
mineflayer@https://codeload.github.com/zardoy/mineflayer/tar.gz/dd3b1ff38506d6f72d90e8444186e4e75fe82659(encoding@0.1.13):
|
mineflayer-pathfinder@2.4.5:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@nxg-org/mineflayer-physics-util': 1.8.10
|
minecraft-data: 3.92.0
|
||||||
minecraft-data: 3.98.0
|
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
||||||
minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/bf89f7e86526c54d8c43f555d8f6dfa4948fd2d9(patch_hash=4ebdae314c68d01ce7879445c0b8bde5f90373abba8b66ed00d42e7a5f542f8b)(encoding@0.1.13)
|
prismarine-entity: 2.5.0
|
||||||
prismarine-biome: 1.3.0(minecraft-data@3.98.0)(prismarine-registry@1.11.0)
|
prismarine-item: 1.16.0
|
||||||
|
prismarine-nbt: 2.7.0
|
||||||
|
prismarine-physics: https://codeload.github.com/zardoy/prismarine-physics/tar.gz/353e25b800149393f40539ec381218be44cbb03b
|
||||||
|
vec3: 0.1.10
|
||||||
|
|
||||||
|
mineflayer@4.30.0(encoding@0.1.13):
|
||||||
|
dependencies:
|
||||||
|
minecraft-data: 3.92.0
|
||||||
|
minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/6c2204a813690ead420e2b8c7f0ef32ca357d176(patch_hash=a8726e6981ddc3486262d981d1e2030f379901c055ac9c4bf3036b4149e860e0)(encoding@0.1.13)
|
||||||
|
prismarine-biome: 1.3.0(minecraft-data@3.92.0)(prismarine-registry@1.11.0)
|
||||||
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
||||||
prismarine-chat: 1.11.0
|
prismarine-chat: 1.11.0
|
||||||
prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.98.0)
|
prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.92.0)
|
||||||
prismarine-entity: 2.5.0
|
prismarine-entity: 2.5.0
|
||||||
prismarine-item: 1.17.0
|
prismarine-item: 1.16.0
|
||||||
|
prismarine-nbt: 2.7.0
|
||||||
|
prismarine-physics: https://codeload.github.com/zardoy/prismarine-physics/tar.gz/353e25b800149393f40539ec381218be44cbb03b
|
||||||
|
prismarine-recipe: 1.3.1(prismarine-registry@1.11.0)
|
||||||
|
prismarine-registry: 1.11.0
|
||||||
|
prismarine-windows: 2.9.0
|
||||||
|
prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c
|
||||||
|
protodef: 1.18.0
|
||||||
|
typed-emitter: 1.4.0
|
||||||
|
vec3: 0.1.10
|
||||||
|
transitivePeerDependencies:
|
||||||
|
- encoding
|
||||||
|
- supports-color
|
||||||
|
|
||||||
|
mineflayer@https://codeload.github.com/zardoy/mineflayer/tar.gz/1616261f727398d0b14359262726828d24797fcc(encoding@0.1.13):
|
||||||
|
dependencies:
|
||||||
|
'@nxg-org/mineflayer-physics-util': 1.8.10
|
||||||
|
minecraft-data: 3.92.0
|
||||||
|
minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/6c2204a813690ead420e2b8c7f0ef32ca357d176(patch_hash=a8726e6981ddc3486262d981d1e2030f379901c055ac9c4bf3036b4149e860e0)(encoding@0.1.13)
|
||||||
|
prismarine-biome: 1.3.0(minecraft-data@3.92.0)(prismarine-registry@1.11.0)
|
||||||
|
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
||||||
|
prismarine-chat: 1.11.0
|
||||||
|
prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.92.0)
|
||||||
|
prismarine-entity: 2.5.0
|
||||||
|
prismarine-item: 1.16.0
|
||||||
prismarine-nbt: 2.7.0
|
prismarine-nbt: 2.7.0
|
||||||
prismarine-physics: https://codeload.github.com/zardoy/prismarine-physics/tar.gz/353e25b800149393f40539ec381218be44cbb03b
|
prismarine-physics: https://codeload.github.com/zardoy/prismarine-physics/tar.gz/353e25b800149393f40539ec381218be44cbb03b
|
||||||
prismarine-recipe: 1.3.1(prismarine-registry@1.11.0)
|
prismarine-recipe: 1.3.1(prismarine-registry@1.11.0)
|
||||||
|
|
@ -17503,8 +17502,6 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
nearley: 2.20.1
|
nearley: 2.20.1
|
||||||
|
|
||||||
monaco-editor@0.52.2: {}
|
|
||||||
|
|
||||||
moo@0.5.2: {}
|
moo@0.5.2: {}
|
||||||
|
|
||||||
morgan@1.10.0:
|
morgan@1.10.0:
|
||||||
|
|
@ -17586,7 +17583,7 @@ snapshots:
|
||||||
|
|
||||||
neo-async@2.6.2: {}
|
neo-async@2.6.2: {}
|
||||||
|
|
||||||
net-browserify@https://codeload.github.com/zardoy/prismarinejs-net-browserify/tar.gz/e754999ffdea67853bc9b10553b5e9908b40f618:
|
net-browserify@https://codeload.github.com/zardoy/prismarinejs-net-browserify/tar.gz/17fb901e8ea480a52c8fd46373695be172be8aa5:
|
||||||
dependencies:
|
dependencies:
|
||||||
body-parser: 1.20.3
|
body-parser: 1.20.3
|
||||||
express: 4.21.2
|
express: 4.21.2
|
||||||
|
|
@ -18174,17 +18171,17 @@ snapshots:
|
||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
prismarine-biome@1.3.0(minecraft-data@3.98.0)(prismarine-registry@1.11.0):
|
prismarine-biome@1.3.0(minecraft-data@3.92.0)(prismarine-registry@1.11.0):
|
||||||
dependencies:
|
dependencies:
|
||||||
minecraft-data: 3.98.0
|
minecraft-data: 3.92.0
|
||||||
prismarine-registry: 1.11.0
|
prismarine-registry: 1.11.0
|
||||||
|
|
||||||
prismarine-block@https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9:
|
prismarine-block@https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9:
|
||||||
dependencies:
|
dependencies:
|
||||||
minecraft-data: 3.98.0
|
minecraft-data: 3.92.0
|
||||||
prismarine-biome: 1.3.0(minecraft-data@3.98.0)(prismarine-registry@1.11.0)
|
prismarine-biome: 1.3.0(minecraft-data@3.92.0)(prismarine-registry@1.11.0)
|
||||||
prismarine-chat: 1.11.0
|
prismarine-chat: 1.11.0
|
||||||
prismarine-item: 1.17.0
|
prismarine-item: 1.16.0
|
||||||
prismarine-nbt: 2.7.0
|
prismarine-nbt: 2.7.0
|
||||||
prismarine-registry: 1.11.0
|
prismarine-registry: 1.11.0
|
||||||
|
|
||||||
|
|
@ -18194,9 +18191,9 @@ snapshots:
|
||||||
prismarine-nbt: 2.7.0
|
prismarine-nbt: 2.7.0
|
||||||
prismarine-registry: 1.11.0
|
prismarine-registry: 1.11.0
|
||||||
|
|
||||||
prismarine-chunk@https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.98.0):
|
prismarine-chunk@https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.92.0):
|
||||||
dependencies:
|
dependencies:
|
||||||
prismarine-biome: 1.3.0(minecraft-data@3.98.0)(prismarine-registry@1.11.0)
|
prismarine-biome: 1.3.0(minecraft-data@3.92.0)(prismarine-registry@1.11.0)
|
||||||
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
||||||
prismarine-nbt: 2.7.0
|
prismarine-nbt: 2.7.0
|
||||||
prismarine-registry: 1.11.0
|
prismarine-registry: 1.11.0
|
||||||
|
|
@ -18210,11 +18207,11 @@ snapshots:
|
||||||
prismarine-entity@2.5.0:
|
prismarine-entity@2.5.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
prismarine-chat: 1.11.0
|
prismarine-chat: 1.11.0
|
||||||
prismarine-item: 1.17.0
|
prismarine-item: 1.16.0
|
||||||
prismarine-registry: 1.11.0
|
prismarine-registry: 1.11.0
|
||||||
vec3: 0.1.10
|
vec3: 0.1.10
|
||||||
|
|
||||||
prismarine-item@1.17.0:
|
prismarine-item@1.16.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
prismarine-nbt: 2.7.0
|
prismarine-nbt: 2.7.0
|
||||||
prismarine-registry: 1.11.0
|
prismarine-registry: 1.11.0
|
||||||
|
|
@ -18225,14 +18222,14 @@ snapshots:
|
||||||
|
|
||||||
prismarine-physics@https://codeload.github.com/zardoy/prismarine-physics/tar.gz/353e25b800149393f40539ec381218be44cbb03b:
|
prismarine-physics@https://codeload.github.com/zardoy/prismarine-physics/tar.gz/353e25b800149393f40539ec381218be44cbb03b:
|
||||||
dependencies:
|
dependencies:
|
||||||
minecraft-data: 3.98.0
|
minecraft-data: 3.92.0
|
||||||
prismarine-nbt: 2.7.0
|
prismarine-nbt: 2.7.0
|
||||||
vec3: 0.1.10
|
vec3: 0.1.10
|
||||||
|
|
||||||
prismarine-provider-anvil@https://codeload.github.com/zardoy/prismarine-provider-anvil/tar.gz/1d548fac63fe977c8281f0a9a522b37e4d92d0b7(minecraft-data@3.98.0):
|
prismarine-provider-anvil@https://codeload.github.com/zardoy/prismarine-provider-anvil/tar.gz/1d548fac63fe977c8281f0a9a522b37e4d92d0b7(minecraft-data@3.92.0):
|
||||||
dependencies:
|
dependencies:
|
||||||
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
||||||
prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.98.0)
|
prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/c5feac83b61d95feb4d4f22c063dacfb8c192a9f(minecraft-data@3.92.0)
|
||||||
prismarine-nbt: 2.7.0
|
prismarine-nbt: 2.7.0
|
||||||
prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c
|
prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c
|
||||||
uint4: 0.1.2
|
uint4: 0.1.2
|
||||||
|
|
@ -18254,13 +18251,13 @@ snapshots:
|
||||||
|
|
||||||
prismarine-registry@1.11.0:
|
prismarine-registry@1.11.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
minecraft-data: 3.98.0
|
minecraft-data: 3.92.0
|
||||||
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
||||||
prismarine-nbt: 2.7.0
|
prismarine-nbt: 2.7.0
|
||||||
|
|
||||||
prismarine-schematic@1.2.3:
|
prismarine-schematic@1.2.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
minecraft-data: 3.98.0
|
minecraft-data: 3.92.0
|
||||||
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9
|
||||||
prismarine-nbt: 2.7.0
|
prismarine-nbt: 2.7.0
|
||||||
prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c
|
prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c
|
||||||
|
|
@ -18268,7 +18265,7 @@ snapshots:
|
||||||
|
|
||||||
prismarine-windows@2.9.0:
|
prismarine-windows@2.9.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
prismarine-item: 1.17.0
|
prismarine-item: 1.16.0
|
||||||
prismarine-registry: 1.11.0
|
prismarine-registry: 1.11.0
|
||||||
typed-emitter: 2.1.0
|
typed-emitter: 2.1.0
|
||||||
|
|
||||||
|
|
@ -18459,7 +18456,7 @@ snapshots:
|
||||||
puppeteer-core@2.1.1:
|
puppeteer-core@2.1.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/mime-types': 2.1.4
|
'@types/mime-types': 2.1.4
|
||||||
debug: 4.4.1
|
debug: 4.4.0(supports-color@8.1.1)
|
||||||
extract-zip: 1.7.0
|
extract-zip: 1.7.0
|
||||||
https-proxy-agent: 4.0.0
|
https-proxy-agent: 4.0.0
|
||||||
mime: 2.6.0
|
mime: 2.6.0
|
||||||
|
|
@ -19561,8 +19558,6 @@ snapshots:
|
||||||
stack-generator: 2.0.10
|
stack-generator: 2.0.10
|
||||||
stacktrace-gps: 3.1.2
|
stacktrace-gps: 3.1.2
|
||||||
|
|
||||||
state-local@1.0.7: {}
|
|
||||||
|
|
||||||
static-extend@0.1.2:
|
static-extend@0.1.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
define-property: 0.2.5
|
define-property: 0.2.5
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ function getAllMethods (obj) {
|
||||||
return [...methods] as string[]
|
return [...methods] as string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const delayedIterator = async <T> (arr: T[], delay: number, exec: (item: T, index: number) => Promise<void>, chunkSize = 1) => {
|
export const delayedIterator = async <T> (arr: T[], delay: number, exec: (item: T, index: number) => void, chunkSize = 1) => {
|
||||||
// if delay is 0 then don't use setTimeout
|
// if delay is 0 then don't use setTimeout
|
||||||
for (let i = 0; i < arr.length; i += chunkSize) {
|
for (let i = 0; i < arr.length; i += chunkSize) {
|
||||||
if (delay) {
|
if (delay) {
|
||||||
|
|
@ -74,6 +74,6 @@ export const delayedIterator = async <T> (arr: T[], delay: number, exec: (item:
|
||||||
setTimeout(resolve, delay)
|
setTimeout(resolve, delay)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
await exec(arr[i], i)
|
exec(arr[i], i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,12 +73,12 @@ export const appAndRendererSharedConfig = () => defineConfig({
|
||||||
})
|
})
|
||||||
|
|
||||||
export const rspackViewerConfig = (config, { appendPlugins, addRules, rspack }: ModifyRspackConfigUtils) => {
|
export const rspackViewerConfig = (config, { appendPlugins, addRules, rspack }: ModifyRspackConfigUtils) => {
|
||||||
appendPlugins(new rspack.NormalModuleReplacementPlugin(/data|prismarine-physics/, (resource) => {
|
appendPlugins(new rspack.NormalModuleReplacementPlugin(/data/, (resource) => {
|
||||||
let absolute: string
|
let absolute: string
|
||||||
const request = resource.request.replaceAll('\\', '/')
|
const request = resource.request.replaceAll('\\', '/')
|
||||||
absolute = path.join(resource.context, request).replaceAll('\\', '/')
|
absolute = path.join(resource.context, request).replaceAll('\\', '/')
|
||||||
if (request.includes('minecraft-data/data/pc/1.') || request.includes('prismarine-physics')) {
|
if (request.includes('minecraft-data/data/pc/1.')) {
|
||||||
console.log('Error: incompatible resource', request, 'from', resource.contextInfo.issuer)
|
console.log('Error: incompatible resource', request, resource.contextInfo.issuer)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
// throw new Error(`${resource.request} was requested by ${resource.contextInfo.issuer}`)
|
// throw new Error(`${resource.request} was requested by ${resource.contextInfo.issuer}`)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import { proxy } from 'valtio'
|
|
||||||
import { NonReactiveState, RendererReactiveState } from '../../src/appViewer'
|
import { NonReactiveState, RendererReactiveState } from '../../src/appViewer'
|
||||||
|
|
||||||
export const getDefaultRendererState = (): {
|
export const getDefaultRendererState = (): {
|
||||||
|
|
@ -6,7 +5,7 @@ export const getDefaultRendererState = (): {
|
||||||
nonReactive: NonReactiveState
|
nonReactive: NonReactiveState
|
||||||
} => {
|
} => {
|
||||||
return {
|
return {
|
||||||
reactive: proxy({
|
reactive: {
|
||||||
world: {
|
world: {
|
||||||
chunksLoaded: new Set(),
|
chunksLoaded: new Set(),
|
||||||
heightmaps: new Map(),
|
heightmaps: new Map(),
|
||||||
|
|
@ -16,7 +15,7 @@ export const getDefaultRendererState = (): {
|
||||||
},
|
},
|
||||||
renderer: '',
|
renderer: '',
|
||||||
preventEscapeMenu: false
|
preventEscapeMenu: false
|
||||||
}),
|
},
|
||||||
nonReactive: {
|
nonReactive: {
|
||||||
world: {
|
world: {
|
||||||
chunksLoaded: new Set(),
|
chunksLoaded: new Set(),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { ItemSelector } from 'mc-assets/dist/itemDefinitions'
|
import { ItemSelector } from 'mc-assets/dist/itemDefinitions'
|
||||||
import { GameMode, Team } from 'mineflayer'
|
import { GameMode } from 'mineflayer'
|
||||||
import { proxy } from 'valtio'
|
import { proxy } from 'valtio'
|
||||||
import type { HandItemBlock } from '../three/holdingBlock'
|
import type { HandItemBlock } from '../three/holdingBlock'
|
||||||
|
|
||||||
|
|
@ -48,11 +48,8 @@ export const getInitialPlayerState = () => proxy({
|
||||||
heldItemMain: undefined as HandItemBlock | undefined,
|
heldItemMain: undefined as HandItemBlock | undefined,
|
||||||
heldItemOff: undefined as HandItemBlock | undefined,
|
heldItemOff: undefined as HandItemBlock | undefined,
|
||||||
perspective: 'first_person' as CameraPerspective,
|
perspective: 'first_person' as CameraPerspective,
|
||||||
onFire: false,
|
|
||||||
|
|
||||||
cameraSpectatingEntity: undefined as number | undefined,
|
cameraSpectatingEntity: undefined as number | undefined,
|
||||||
|
|
||||||
team: undefined as Team | undefined,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getPlayerStateUtils = (reactive: PlayerStateReactive) => ({
|
export const getPlayerStateUtils = (reactive: PlayerStateReactive) => ({
|
||||||
|
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
import { PlayerObject, PlayerAnimation } from 'skinview3d'
|
|
||||||
import * as THREE from 'three'
|
|
||||||
import { WalkingGeneralSwing } from '../three/entity/animations'
|
|
||||||
import { loadSkinImage, stevePngUrl } from './utils/skins'
|
|
||||||
|
|
||||||
export type PlayerObjectType = PlayerObject & {
|
|
||||||
animation?: PlayerAnimation
|
|
||||||
realPlayerUuid: string
|
|
||||||
realUsername: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createPlayerObject (options: {
|
|
||||||
username?: string
|
|
||||||
uuid?: string
|
|
||||||
scale?: number
|
|
||||||
}): {
|
|
||||||
playerObject: PlayerObjectType
|
|
||||||
wrapper: THREE.Group
|
|
||||||
} {
|
|
||||||
const wrapper = new THREE.Group()
|
|
||||||
const playerObject = new PlayerObject() as PlayerObjectType
|
|
||||||
|
|
||||||
playerObject.realPlayerUuid = options.uuid ?? ''
|
|
||||||
playerObject.realUsername = options.username ?? ''
|
|
||||||
playerObject.position.set(0, 16, 0)
|
|
||||||
|
|
||||||
// fix issues with starfield
|
|
||||||
playerObject.traverse((obj) => {
|
|
||||||
if (obj instanceof THREE.Mesh && obj.material instanceof THREE.MeshStandardMaterial) {
|
|
||||||
obj.material.transparent = true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
wrapper.add(playerObject as any)
|
|
||||||
const scale = options.scale ?? (1 / 16)
|
|
||||||
wrapper.scale.set(scale, scale, scale)
|
|
||||||
wrapper.rotation.set(0, Math.PI, 0)
|
|
||||||
|
|
||||||
// Set up animation
|
|
||||||
playerObject.animation = new WalkingGeneralSwing()
|
|
||||||
;(playerObject.animation as WalkingGeneralSwing).isMoving = false
|
|
||||||
playerObject.animation.update(playerObject, 0)
|
|
||||||
|
|
||||||
return { playerObject, wrapper }
|
|
||||||
}
|
|
||||||
|
|
||||||
export const applySkinToPlayerObject = async (playerObject: PlayerObjectType, skinUrl: string) => {
|
|
||||||
return loadSkinImage(skinUrl || stevePngUrl).then(({ canvas }) => {
|
|
||||||
const skinTexture = new THREE.CanvasTexture(canvas)
|
|
||||||
skinTexture.magFilter = THREE.NearestFilter
|
|
||||||
skinTexture.minFilter = THREE.NearestFilter
|
|
||||||
skinTexture.needsUpdate = true
|
|
||||||
playerObject.skin.map = skinTexture as any
|
|
||||||
}).catch(console.error)
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import * as THREE from 'three'
|
import * as THREE from 'three'
|
||||||
import { loadSkinFromUsername, loadSkinImage } from '../lib/utils/skins'
|
import { loadSkinToCanvas } from 'skinview-utils'
|
||||||
import { steveTexture } from './entities'
|
import { loadSkinFromUsername, loadSkinImage, steveTexture } from './utils/skins'
|
||||||
|
|
||||||
|
|
||||||
export const getMyHand = async (image?: string, userName?: string) => {
|
export const getMyHand = async (image?: string, userName?: string) => {
|
||||||
let newMap: THREE.Texture
|
let newMap: THREE.Texture
|
||||||
|
|
@ -542,6 +542,7 @@ export function getSectionGeometry (sx: number, sy: number, sz: number, world: W
|
||||||
heads: {},
|
heads: {},
|
||||||
signs: {},
|
signs: {},
|
||||||
// isFull: true,
|
// isFull: true,
|
||||||
|
highestBlocks: new Map(),
|
||||||
hadErrors: false,
|
hadErrors: false,
|
||||||
blocksCount: 0
|
blocksCount: 0
|
||||||
}
|
}
|
||||||
|
|
@ -551,6 +552,12 @@ export function getSectionGeometry (sx: number, sy: number, sz: number, world: W
|
||||||
for (cursor.z = sz; cursor.z < sz + 16; cursor.z++) {
|
for (cursor.z = sz; cursor.z < sz + 16; cursor.z++) {
|
||||||
for (cursor.x = sx; cursor.x < sx + 16; cursor.x++) {
|
for (cursor.x = sx; cursor.x < sx + 16; cursor.x++) {
|
||||||
let block = world.getBlock(cursor, blockProvider, attr)!
|
let block = world.getBlock(cursor, blockProvider, attr)!
|
||||||
|
if (!INVISIBLE_BLOCKS.has(block.name)) {
|
||||||
|
const highest = attr.highestBlocks.get(`${cursor.x},${cursor.z}`)
|
||||||
|
if (!highest || highest.y < cursor.y) {
|
||||||
|
attr.highestBlocks.set(`${cursor.x},${cursor.z}`, { y: cursor.y, stateId: block.stateId, biomeId: block.biome.id })
|
||||||
|
}
|
||||||
|
}
|
||||||
if (INVISIBLE_BLOCKS.has(block.name)) continue
|
if (INVISIBLE_BLOCKS.has(block.name)) continue
|
||||||
if ((block.name.includes('_sign') || block.name === 'sign') && !world.config.disableSignsMapsSupport) {
|
if ((block.name.includes('_sign') || block.name === 'sign') && !world.config.disableSignsMapsSupport) {
|
||||||
const key = `${cursor.x},${cursor.y},${cursor.z}`
|
const key = `${cursor.x},${cursor.y},${cursor.z}`
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ export type MesherGeometryOutput = {
|
||||||
heads: Record<string, any>,
|
heads: Record<string, any>,
|
||||||
signs: Record<string, any>,
|
signs: Record<string, any>,
|
||||||
// isFull: boolean
|
// isFull: boolean
|
||||||
|
highestBlocks: Map<string, HighestBlockInfo>
|
||||||
hadErrors: boolean
|
hadErrors: boolean
|
||||||
blocksCount: number
|
blocksCount: number
|
||||||
customBlockModels?: CustomBlockModels
|
customBlockModels?: CustomBlockModels
|
||||||
|
|
|
||||||
11
renderer/viewer/lib/renderUtils.js
Normal file
11
renderer/viewer/lib/renderUtils.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { fromFormattedString } from '@xmcl/text-component'
|
||||||
|
|
||||||
|
export const formattedStringToSimpleString = (str) => {
|
||||||
|
const result = fromFormattedString(str)
|
||||||
|
str = result.text
|
||||||
|
// todo recursive
|
||||||
|
for (const extra of result.extra) {
|
||||||
|
str += extra.text
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,30 @@
|
||||||
|
import * as THREE from 'three'
|
||||||
|
import { loadThreeJsTextureFromUrl, loadThreeJsTextureFromUrlSync } from './utils/skins'
|
||||||
|
|
||||||
|
let textureCache: Record<string, THREE.Texture> = {}
|
||||||
|
let imagesPromises: Record<string, Promise<THREE.Texture>> = {}
|
||||||
|
|
||||||
|
export async function loadTexture (texture: string, cb: (texture: THREE.Texture) => void, onLoad?: () => void): Promise<void> {
|
||||||
|
const cached = textureCache[texture]
|
||||||
|
if (!cached) {
|
||||||
|
const { promise, resolve } = Promise.withResolvers<THREE.Texture>()
|
||||||
|
const t = loadThreeJsTextureFromUrlSync(texture)
|
||||||
|
textureCache[texture] = t.texture
|
||||||
|
void t.promise.then(resolve)
|
||||||
|
imagesPromises[texture] = promise
|
||||||
|
}
|
||||||
|
|
||||||
|
cb(textureCache[texture])
|
||||||
|
void imagesPromises[texture].then(() => {
|
||||||
|
onLoad?.()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const clearTextureCache = () => {
|
||||||
|
textureCache = {}
|
||||||
|
imagesPromises = {}
|
||||||
|
}
|
||||||
|
|
||||||
export const loadScript = async function (scriptSrc: string, highPriority = true): Promise<HTMLScriptElement> {
|
export const loadScript = async function (scriptSrc: string, highPriority = true): Promise<HTMLScriptElement> {
|
||||||
const existingScript = document.querySelector<HTMLScriptElement>(`script[src="${scriptSrc}"]`)
|
const existingScript = document.querySelector<HTMLScriptElement>(`script[src="${scriptSrc}"]`)
|
||||||
if (existingScript) {
|
if (existingScript) {
|
||||||
|
|
@ -25,33 +52,3 @@ export const loadScript = async function (scriptSrc: string, highPriority = true
|
||||||
document.head.appendChild(scriptElement)
|
document.head.appendChild(scriptElement)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const detectFullOffscreenCanvasSupport = () => {
|
|
||||||
if (typeof OffscreenCanvas === 'undefined') return false
|
|
||||||
try {
|
|
||||||
const canvas = new OffscreenCanvas(1, 1)
|
|
||||||
// Try to get a WebGL context - this will fail on iOS where only 2D is supported (iOS 16)
|
|
||||||
const gl = canvas.getContext('webgl2') || canvas.getContext('webgl')
|
|
||||||
return gl !== null
|
|
||||||
} catch (e) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const hasFullOffscreenCanvasSupport = detectFullOffscreenCanvasSupport()
|
|
||||||
|
|
||||||
export const createCanvas = (width: number, height: number): OffscreenCanvas => {
|
|
||||||
if (hasFullOffscreenCanvasSupport) {
|
|
||||||
return new OffscreenCanvas(width, height)
|
|
||||||
}
|
|
||||||
const canvas = document.createElement('canvas')
|
|
||||||
canvas.width = width
|
|
||||||
canvas.height = height
|
|
||||||
return canvas as unknown as OffscreenCanvas // todo-low
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function loadImageFromUrl (imageUrl: string): Promise<ImageBitmap> {
|
|
||||||
const response = await fetch(imageUrl)
|
|
||||||
const blob = await response.blob()
|
|
||||||
return createImageBitmap(blob)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,68 @@
|
||||||
import { loadSkinToCanvas } from 'skinview-utils'
|
import { loadSkinToCanvas } from 'skinview-utils'
|
||||||
import { createCanvas, loadImageFromUrl } from '../utils'
|
import * as THREE from 'three'
|
||||||
|
import stevePng from 'mc-assets/dist/other-textures/latest/entity/player/wide/steve.png'
|
||||||
|
import { getLoadedImage } from 'mc-assets/dist/utils'
|
||||||
|
|
||||||
export { default as stevePngUrl } from 'mc-assets/dist/other-textures/latest/entity/player/wide/steve.png'
|
const detectFullOffscreenCanvasSupport = () => {
|
||||||
|
if (typeof OffscreenCanvas === 'undefined') return false
|
||||||
|
try {
|
||||||
|
const canvas = new OffscreenCanvas(1, 1)
|
||||||
|
// Try to get a WebGL context - this will fail on iOS where only 2D is supported (iOS 16)
|
||||||
|
const gl = canvas.getContext('webgl2') || canvas.getContext('webgl')
|
||||||
|
return gl !== null
|
||||||
|
} catch (e) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasFullOffscreenCanvasSupport = detectFullOffscreenCanvasSupport()
|
||||||
|
|
||||||
|
export const loadThreeJsTextureFromUrlSync = (imageUrl: string) => {
|
||||||
|
const texture = new THREE.Texture()
|
||||||
|
const promise = getLoadedImage(imageUrl).then(image => {
|
||||||
|
texture.image = image
|
||||||
|
texture.needsUpdate = true
|
||||||
|
return texture
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
texture,
|
||||||
|
promise
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const createCanvas = (width: number, height: number): OffscreenCanvas => {
|
||||||
|
if (hasFullOffscreenCanvasSupport) {
|
||||||
|
return new OffscreenCanvas(width, height)
|
||||||
|
}
|
||||||
|
const canvas = document.createElement('canvas')
|
||||||
|
canvas.width = width
|
||||||
|
canvas.height = height
|
||||||
|
return canvas as unknown as OffscreenCanvas // todo-low
|
||||||
|
}
|
||||||
|
|
||||||
|
export const loadThreeJsTextureFromUrl = async (imageUrl: string) => {
|
||||||
|
const loaded = new THREE.TextureLoader().loadAsync(imageUrl)
|
||||||
|
return loaded
|
||||||
|
}
|
||||||
|
export const loadThreeJsTextureFromBitmap = (image: ImageBitmap) => {
|
||||||
|
const canvas = createCanvas(image.width, image.height)
|
||||||
|
const ctx = canvas.getContext('2d')!
|
||||||
|
ctx.drawImage(image, 0, 0)
|
||||||
|
const texture = new THREE.Texture(canvas)
|
||||||
|
texture.magFilter = THREE.NearestFilter
|
||||||
|
texture.minFilter = THREE.NearestFilter
|
||||||
|
return texture
|
||||||
|
}
|
||||||
|
|
||||||
|
export const stevePngUrl = stevePng
|
||||||
|
export const steveTexture = loadThreeJsTextureFromUrl(stevePngUrl)
|
||||||
|
|
||||||
|
|
||||||
|
export async function loadImageFromUrl (imageUrl: string): Promise<ImageBitmap> {
|
||||||
|
const response = await fetch(imageUrl)
|
||||||
|
const blob = await response.blob()
|
||||||
|
return createImageBitmap(blob)
|
||||||
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
apiEnabled: true,
|
apiEnabled: true,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import { Vec3 } from 'vec3'
|
||||||
import { BotEvents } from 'mineflayer'
|
import { BotEvents } from 'mineflayer'
|
||||||
import { proxy } from 'valtio'
|
import { proxy } from 'valtio'
|
||||||
import TypedEmitter from 'typed-emitter'
|
import TypedEmitter from 'typed-emitter'
|
||||||
import { Biome } from 'minecraft-data'
|
|
||||||
import { delayedIterator } from '../../playground/shared'
|
import { delayedIterator } from '../../playground/shared'
|
||||||
import { chunkPos } from './simpleUtils'
|
import { chunkPos } from './simpleUtils'
|
||||||
|
|
||||||
|
|
@ -29,8 +28,6 @@ export type WorldDataEmitterEvents = {
|
||||||
updateLight: (data: { pos: Vec3 }) => void
|
updateLight: (data: { pos: Vec3 }) => void
|
||||||
onWorldSwitch: () => void
|
onWorldSwitch: () => void
|
||||||
end: () => void
|
end: () => void
|
||||||
biomeUpdate: (data: { biome: Biome }) => void
|
|
||||||
biomeReset: () => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WorldDataEmitterWorker extends (EventEmitter as new () => TypedEmitter<WorldDataEmitterEvents>) {
|
export class WorldDataEmitterWorker extends (EventEmitter as new () => TypedEmitter<WorldDataEmitterEvents>) {
|
||||||
|
|
@ -38,15 +35,7 @@ export class WorldDataEmitterWorker extends (EventEmitter as new () => TypedEmit
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WorldDataEmitter extends (EventEmitter as new () => TypedEmitter<WorldDataEmitterEvents>) {
|
export class WorldDataEmitter extends (EventEmitter as new () => TypedEmitter<WorldDataEmitterEvents>) {
|
||||||
spiralNumber = 0
|
|
||||||
gotPanicLastTime = false
|
|
||||||
panicChunksReload = () => {}
|
|
||||||
loadedChunks: Record<ChunkPosKey, boolean>
|
loadedChunks: Record<ChunkPosKey, boolean>
|
||||||
private inLoading = false
|
|
||||||
private chunkReceiveTimes: number[] = []
|
|
||||||
private lastChunkReceiveTime = 0
|
|
||||||
public lastChunkReceiveTimeAvg = 0
|
|
||||||
private panicTimeout?: NodeJS.Timeout
|
|
||||||
readonly lastPos: Vec3
|
readonly lastPos: Vec3
|
||||||
private eventListeners: Record<string, any> = {}
|
private eventListeners: Record<string, any> = {}
|
||||||
private readonly emitter: WorldDataEmitter
|
private readonly emitter: WorldDataEmitter
|
||||||
|
|
@ -115,7 +104,6 @@ export class WorldDataEmitter extends (EventEmitter as new () => TypedEmitter<Wo
|
||||||
...e,
|
...e,
|
||||||
pos: e.position,
|
pos: e.position,
|
||||||
username: e.username,
|
username: e.username,
|
||||||
team: bot.teamMap[e.username] || bot.teamMap[e.uuid],
|
|
||||||
// set debugTree (obj) {
|
// set debugTree (obj) {
|
||||||
// e.debugTree = obj
|
// e.debugTree = obj
|
||||||
// }
|
// }
|
||||||
|
|
@ -144,19 +132,12 @@ export class WorldDataEmitter extends (EventEmitter as new () => TypedEmitter<Wo
|
||||||
this.emitter.emit('entity', { id: e.id, delete: true })
|
this.emitter.emit('entity', { id: e.id, delete: true })
|
||||||
},
|
},
|
||||||
chunkColumnLoad: (pos: Vec3) => {
|
chunkColumnLoad: (pos: Vec3) => {
|
||||||
const now = performance.now()
|
|
||||||
if (this.lastChunkReceiveTime) {
|
|
||||||
this.chunkReceiveTimes.push(now - this.lastChunkReceiveTime)
|
|
||||||
}
|
|
||||||
this.lastChunkReceiveTime = now
|
|
||||||
|
|
||||||
if (this.waitingSpiralChunksLoad[`${pos.x},${pos.z}`]) {
|
if (this.waitingSpiralChunksLoad[`${pos.x},${pos.z}`]) {
|
||||||
this.waitingSpiralChunksLoad[`${pos.x},${pos.z}`](true)
|
this.waitingSpiralChunksLoad[`${pos.x},${pos.z}`](true)
|
||||||
delete this.waitingSpiralChunksLoad[`${pos.x},${pos.z}`]
|
delete this.waitingSpiralChunksLoad[`${pos.x},${pos.z}`]
|
||||||
} else if (this.loadedChunks[`${pos.x},${pos.z}`]) {
|
} else if (this.loadedChunks[`${pos.x},${pos.z}`]) {
|
||||||
void this.loadChunk(pos, false, 'Received another chunkColumnLoad event while already loaded')
|
void this.loadChunk(pos, false, 'Received another chunkColumnLoad event while already loaded')
|
||||||
}
|
}
|
||||||
this.chunkProgress()
|
|
||||||
},
|
},
|
||||||
chunkColumnUnload: (pos: Vec3) => {
|
chunkColumnUnload: (pos: Vec3) => {
|
||||||
this.unloadChunk(pos)
|
this.unloadChunk(pos)
|
||||||
|
|
@ -228,7 +209,7 @@ export class WorldDataEmitter extends (EventEmitter as new () => TypedEmitter<Wo
|
||||||
if (bot?.time?.timeOfDay) {
|
if (bot?.time?.timeOfDay) {
|
||||||
this.emitter.emit('time', bot.time.timeOfDay)
|
this.emitter.emit('time', bot.time.timeOfDay)
|
||||||
}
|
}
|
||||||
if (bot?.entity) {
|
if (bot.entity) {
|
||||||
this.emitter.emit('playerEntity', bot.entity)
|
this.emitter.emit('playerEntity', bot.entity)
|
||||||
}
|
}
|
||||||
this.emitterGotConnected()
|
this.emitterGotConnected()
|
||||||
|
|
@ -237,59 +218,33 @@ export class WorldDataEmitter extends (EventEmitter as new () => TypedEmitter<Wo
|
||||||
const positions = generateSpiralMatrix(this.viewDistance).map(([x, z]) => new Vec3((botX + x) * 16, 0, (botZ + z) * 16))
|
const positions = generateSpiralMatrix(this.viewDistance).map(([x, z]) => new Vec3((botX + x) * 16, 0, (botZ + z) * 16))
|
||||||
|
|
||||||
this.lastPos.update(pos)
|
this.lastPos.update(pos)
|
||||||
await this._loadChunks(positions, pos)
|
await this._loadChunks(positions)
|
||||||
}
|
}
|
||||||
|
|
||||||
chunkProgress () {
|
async _loadChunks (positions: Vec3[], sliceSize = 5) {
|
||||||
if (this.panicTimeout) clearTimeout(this.panicTimeout)
|
|
||||||
if (this.chunkReceiveTimes.length >= 5) {
|
|
||||||
const avgReceiveTime = this.chunkReceiveTimes.reduce((a, b) => a + b, 0) / this.chunkReceiveTimes.length
|
|
||||||
this.lastChunkReceiveTimeAvg = avgReceiveTime
|
|
||||||
const timeoutDelay = avgReceiveTime * 2 + 1000 // 2x average + 1 second
|
|
||||||
|
|
||||||
// Clear any existing timeout
|
|
||||||
if (this.panicTimeout) clearTimeout(this.panicTimeout)
|
|
||||||
|
|
||||||
// Set new timeout for panic reload
|
|
||||||
this.panicTimeout = setTimeout(() => {
|
|
||||||
if (!this.gotPanicLastTime && this.inLoading) {
|
|
||||||
console.warn('Chunk loading seems stuck, triggering panic reload')
|
|
||||||
this.gotPanicLastTime = true
|
|
||||||
this.panicChunksReload()
|
|
||||||
}
|
|
||||||
}, timeoutDelay)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async _loadChunks (positions: Vec3[], centerPos: Vec3) {
|
|
||||||
this.spiralNumber++
|
|
||||||
const { spiralNumber } = this
|
|
||||||
// stop loading previous chunks
|
// stop loading previous chunks
|
||||||
for (const pos of Object.keys(this.waitingSpiralChunksLoad)) {
|
for (const pos of Object.keys(this.waitingSpiralChunksLoad)) {
|
||||||
this.waitingSpiralChunksLoad[pos](false)
|
this.waitingSpiralChunksLoad[pos](false)
|
||||||
delete this.waitingSpiralChunksLoad[pos]
|
delete this.waitingSpiralChunksLoad[pos]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const promises = [] as Array<Promise<void>>
|
||||||
let continueLoading = true
|
let continueLoading = true
|
||||||
this.inLoading = true
|
|
||||||
await delayedIterator(positions, this.addWaitTime, async (pos) => {
|
await delayedIterator(positions, this.addWaitTime, async (pos) => {
|
||||||
|
const promise = (async () => {
|
||||||
if (!continueLoading || this.loadedChunks[`${pos.x},${pos.z}`]) return
|
if (!continueLoading || this.loadedChunks[`${pos.x},${pos.z}`]) return
|
||||||
|
|
||||||
// Wait for chunk to be available from server
|
|
||||||
if (!this.world.getColumnAt(pos)) {
|
if (!this.world.getColumnAt(pos)) {
|
||||||
continueLoading = await new Promise<boolean>(resolve => {
|
continueLoading = await new Promise<boolean>(resolve => {
|
||||||
this.waitingSpiralChunksLoad[`${pos.x},${pos.z}`] = resolve
|
this.waitingSpiralChunksLoad[`${pos.x},${pos.z}`] = resolve
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (!continueLoading) return
|
if (!continueLoading) return
|
||||||
await this.loadChunk(pos, undefined, `spiral ${spiralNumber} from ${centerPos.x},${centerPos.z}`)
|
await this.loadChunk(pos)
|
||||||
this.chunkProgress()
|
})()
|
||||||
|
promises.push(promise)
|
||||||
})
|
})
|
||||||
if (this.panicTimeout) clearTimeout(this.panicTimeout)
|
await Promise.all(promises)
|
||||||
this.inLoading = false
|
|
||||||
this.gotPanicLastTime = false
|
|
||||||
this.chunkReceiveTimes = []
|
|
||||||
this.lastChunkReceiveTime = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readdDebug () {
|
readdDebug () {
|
||||||
|
|
@ -363,37 +318,8 @@ export class WorldDataEmitter extends (EventEmitter as new () => TypedEmitter<Wo
|
||||||
delete this.debugChunksInfo[`${pos.x},${pos.z}`]
|
delete this.debugChunksInfo[`${pos.x},${pos.z}`]
|
||||||
}
|
}
|
||||||
|
|
||||||
lastBiomeId: number | null = null
|
|
||||||
|
|
||||||
udpateBiome (pos: Vec3) {
|
|
||||||
try {
|
|
||||||
const biomeId = this.world.getBiome(pos)
|
|
||||||
if (biomeId !== this.lastBiomeId) {
|
|
||||||
this.lastBiomeId = biomeId
|
|
||||||
const biomeData = loadedData.biomes[biomeId]
|
|
||||||
if (biomeData) {
|
|
||||||
this.emitter.emit('biomeUpdate', {
|
|
||||||
biome: biomeData
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// unknown biome
|
|
||||||
this.emitter.emit('biomeReset')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('error updating biome', e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastPosCheck: Vec3 | null = null
|
|
||||||
async updatePosition (pos: Vec3, force = false) {
|
async updatePosition (pos: Vec3, force = false) {
|
||||||
if (!this.allowPositionUpdate) return
|
if (!this.allowPositionUpdate) return
|
||||||
const posFloored = pos.floored()
|
|
||||||
if (!force && this.lastPosCheck && this.lastPosCheck.equals(posFloored)) return
|
|
||||||
this.lastPosCheck = posFloored
|
|
||||||
|
|
||||||
this.udpateBiome(pos)
|
|
||||||
|
|
||||||
const [lastX, lastZ] = chunkPos(this.lastPos)
|
const [lastX, lastZ] = chunkPos(this.lastPos)
|
||||||
const [botX, botZ] = chunkPos(pos)
|
const [botX, botZ] = chunkPos(pos)
|
||||||
if (lastX !== botX || lastZ !== botZ || force) {
|
if (lastX !== botX || lastZ !== botZ || force) {
|
||||||
|
|
@ -411,6 +337,7 @@ export class WorldDataEmitter extends (EventEmitter as new () => TypedEmitter<Wo
|
||||||
chunksToUnload.push(p)
|
chunksToUnload.push(p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('unloading', chunksToUnload.length, 'total now', Object.keys(this.loadedChunks).length)
|
||||||
for (const p of chunksToUnload) {
|
for (const p of chunksToUnload) {
|
||||||
this.unloadChunk(p)
|
this.unloadChunk(p)
|
||||||
}
|
}
|
||||||
|
|
@ -422,7 +349,7 @@ export class WorldDataEmitter extends (EventEmitter as new () => TypedEmitter<Wo
|
||||||
return undefined!
|
return undefined!
|
||||||
}).filter(a => !!a)
|
}).filter(a => !!a)
|
||||||
this.lastPos.update(pos)
|
this.lastPos.update(pos)
|
||||||
void this._loadChunks(positions, pos)
|
void this._loadChunks(positions)
|
||||||
} else {
|
} else {
|
||||||
this.emitter.emit('chunkPosUpdate', { pos }) // todo-low
|
this.emitter.emit('chunkPosUpdate', { pos }) // todo-low
|
||||||
this.lastPos.update(pos)
|
this.lastPos.update(pos)
|
||||||
|
|
|
||||||
|
|
@ -32,45 +32,31 @@ const toMajorVersion = version => {
|
||||||
export const worldCleanup = buildCleanupDecorator('resetWorld')
|
export const worldCleanup = buildCleanupDecorator('resetWorld')
|
||||||
|
|
||||||
export const defaultWorldRendererConfig = {
|
export const defaultWorldRendererConfig = {
|
||||||
// Debug settings
|
|
||||||
showChunkBorders: false,
|
showChunkBorders: false,
|
||||||
enableDebugOverlay: false,
|
|
||||||
|
|
||||||
// Performance settings
|
|
||||||
mesherWorkers: 4,
|
mesherWorkers: 4,
|
||||||
addChunksBatchWaitTime: 200,
|
isPlayground: false,
|
||||||
_experimentalSmoothChunkLoading: true,
|
renderEars: true,
|
||||||
_renderByChunks: false,
|
skinTexturesProxy: undefined as string | undefined,
|
||||||
|
// game renderer setting actually
|
||||||
// Rendering engine settings
|
showHand: false,
|
||||||
dayCycle: true,
|
viewBobbing: false,
|
||||||
|
extraBlockRenderers: true,
|
||||||
|
clipWorldBelowY: undefined as number | undefined,
|
||||||
smoothLighting: true,
|
smoothLighting: true,
|
||||||
enableLighting: true,
|
enableLighting: true,
|
||||||
starfield: true,
|
starfield: true,
|
||||||
defaultSkybox: true,
|
addChunksBatchWaitTime: 200,
|
||||||
renderEntities: true,
|
|
||||||
extraBlockRenderers: true,
|
|
||||||
foreground: true,
|
|
||||||
fov: 75,
|
|
||||||
volume: 1,
|
|
||||||
|
|
||||||
// Camera visual related settings
|
|
||||||
showHand: false,
|
|
||||||
viewBobbing: false,
|
|
||||||
renderEars: true,
|
|
||||||
highlightBlockColor: 'blue',
|
|
||||||
|
|
||||||
// Player models
|
|
||||||
fetchPlayerSkins: true,
|
|
||||||
skinTexturesProxy: undefined as string | undefined,
|
|
||||||
|
|
||||||
// VR settings
|
|
||||||
vrSupport: true,
|
vrSupport: true,
|
||||||
vrPageGameRendering: true,
|
vrPageGameRendering: true,
|
||||||
|
renderEntities: true,
|
||||||
// World settings
|
fov: 75,
|
||||||
clipWorldBelowY: undefined as number | undefined,
|
fetchPlayerSkins: true,
|
||||||
isPlayground: false
|
highlightBlockColor: 'blue',
|
||||||
|
foreground: true,
|
||||||
|
enableDebugOverlay: false,
|
||||||
|
_experimentalSmoothChunkLoading: true,
|
||||||
|
_renderByChunks: false,
|
||||||
|
volume: 1
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WorldRendererConfig = typeof defaultWorldRendererConfig
|
export type WorldRendererConfig = typeof defaultWorldRendererConfig
|
||||||
|
|
@ -137,6 +123,7 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
||||||
|
|
||||||
handleResize = () => { }
|
handleResize = () => { }
|
||||||
highestBlocksByChunks = new Map<string, { [chunkKey: string]: HighestBlockInfo }>()
|
highestBlocksByChunks = new Map<string, { [chunkKey: string]: HighestBlockInfo }>()
|
||||||
|
highestBlocksBySections = new Map<string, { [sectionKey: string]: HighestBlockInfo }>()
|
||||||
blockEntities = {}
|
blockEntities = {}
|
||||||
|
|
||||||
workersProcessAverageTime = 0
|
workersProcessAverageTime = 0
|
||||||
|
|
@ -402,6 +389,8 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
||||||
this.logWorkerWork(() => `-> ${data.workerIndex} geometry ${data.key} ${JSON.stringify({ dataSize: JSON.stringify(data).length })}`)
|
this.logWorkerWork(() => `-> ${data.workerIndex} geometry ${data.key} ${JSON.stringify({ dataSize: JSON.stringify(data).length })}`)
|
||||||
this.geometryReceiveCount[data.workerIndex] ??= 0
|
this.geometryReceiveCount[data.workerIndex] ??= 0
|
||||||
this.geometryReceiveCount[data.workerIndex]++
|
this.geometryReceiveCount[data.workerIndex]++
|
||||||
|
const { geometry } = data
|
||||||
|
this.highestBlocksBySections[data.key] = geometry.highestBlocks
|
||||||
const chunkCoords = data.key.split(',').map(Number)
|
const chunkCoords = data.key.split(',').map(Number)
|
||||||
this.lastChunkDistance = Math.max(...this.getDistance(new Vec3(chunkCoords[0], 0, chunkCoords[2])))
|
this.lastChunkDistance = Math.max(...this.getDistance(new Vec3(chunkCoords[0], 0, chunkCoords[2])))
|
||||||
}
|
}
|
||||||
|
|
@ -510,10 +499,6 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
||||||
|
|
||||||
timeUpdated? (newTime: number): void
|
timeUpdated? (newTime: number): void
|
||||||
|
|
||||||
biomeUpdated? (biome: any): void
|
|
||||||
|
|
||||||
biomeReset? (): void
|
|
||||||
|
|
||||||
updateViewerPosition (pos: Vec3) {
|
updateViewerPosition (pos: Vec3) {
|
||||||
this.viewerChunkPosition = pos
|
this.viewerChunkPosition = pos
|
||||||
for (const [key, value] of Object.entries(this.loadedChunks)) {
|
for (const [key, value] of Object.entries(this.loadedChunks)) {
|
||||||
|
|
@ -703,6 +688,7 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
||||||
for (let y = this.worldSizeParams.minY; y < this.worldSizeParams.worldHeight; y += 16) {
|
for (let y = this.worldSizeParams.minY; y < this.worldSizeParams.worldHeight; y += 16) {
|
||||||
this.setSectionDirty(new Vec3(x, y, z), false)
|
this.setSectionDirty(new Vec3(x, y, z), false)
|
||||||
delete this.finishedSections[`${x},${y},${z}`]
|
delete this.finishedSections[`${x},${y},${z}`]
|
||||||
|
this.highestBlocksBySections.delete(`${x},${y},${z}`)
|
||||||
}
|
}
|
||||||
this.highestBlocksByChunks.delete(`${x},${z}`)
|
this.highestBlocksByChunks.delete(`${x},${z}`)
|
||||||
|
|
||||||
|
|
@ -835,9 +821,12 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
||||||
})
|
})
|
||||||
|
|
||||||
worldEmitter.on('time', (timeOfDay) => {
|
worldEmitter.on('time', (timeOfDay) => {
|
||||||
if (!this.worldRendererConfig.dayCycle) return
|
|
||||||
this.timeUpdated?.(timeOfDay)
|
this.timeUpdated?.(timeOfDay)
|
||||||
|
|
||||||
|
if (timeOfDay < 0 || timeOfDay > 24_000) {
|
||||||
|
throw new Error('Invalid time of day. It should be between 0 and 24000.')
|
||||||
|
}
|
||||||
|
|
||||||
this.timeOfTheDay = timeOfDay
|
this.timeOfTheDay = timeOfDay
|
||||||
|
|
||||||
// if (this.worldRendererConfig.skyLight === skyLight) return
|
// if (this.worldRendererConfig.skyLight === skyLight) return
|
||||||
|
|
@ -846,14 +835,6 @@ export abstract class WorldRendererCommon<WorkerSend = any, WorkerReceive = any>
|
||||||
// (this).rerenderAllChunks?.()
|
// (this).rerenderAllChunks?.()
|
||||||
// }
|
// }
|
||||||
})
|
})
|
||||||
|
|
||||||
worldEmitter.on('biomeUpdate', ({ biome }) => {
|
|
||||||
this.biomeUpdated?.(biome)
|
|
||||||
})
|
|
||||||
|
|
||||||
worldEmitter.on('biomeReset', () => {
|
|
||||||
this.biomeReset?.()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setBlockStateIdInner (pos: Vec3, stateId: number | undefined, needAoRecalculation = true) {
|
setBlockStateIdInner (pos: Vec3, stateId: number | undefined, needAoRecalculation = true) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
|
import { fromFormattedString, render, RenderNode, TextComponent } from '@xmcl/text-component'
|
||||||
import type { ChatMessage } from 'prismarine-chat'
|
import type { ChatMessage } from 'prismarine-chat'
|
||||||
import { createCanvas } from '../lib/utils'
|
|
||||||
|
|
||||||
type SignBlockEntity = {
|
type SignBlockEntity = {
|
||||||
Color?: string
|
Color?: string
|
||||||
|
|
@ -32,40 +32,29 @@ const parseSafe = (text: string, task: string) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const LEGACY_COLORS = {
|
export const renderSign = (blockEntity: SignBlockEntity, PrismarineChat: typeof ChatMessage, ctxHook = (ctx) => { }) => {
|
||||||
black: '#000000',
|
|
||||||
dark_blue: '#0000AA',
|
|
||||||
dark_green: '#00AA00',
|
|
||||||
dark_aqua: '#00AAAA',
|
|
||||||
dark_red: '#AA0000',
|
|
||||||
dark_purple: '#AA00AA',
|
|
||||||
gold: '#FFAA00',
|
|
||||||
gray: '#AAAAAA',
|
|
||||||
dark_gray: '#555555',
|
|
||||||
blue: '#5555FF',
|
|
||||||
green: '#55FF55',
|
|
||||||
aqua: '#55FFFF',
|
|
||||||
red: '#FF5555',
|
|
||||||
light_purple: '#FF55FF',
|
|
||||||
yellow: '#FFFF55',
|
|
||||||
white: '#FFFFFF',
|
|
||||||
}
|
|
||||||
|
|
||||||
export const renderSign = (
|
|
||||||
blockEntity: SignBlockEntity,
|
|
||||||
isHanging: boolean,
|
|
||||||
PrismarineChat: typeof ChatMessage,
|
|
||||||
ctxHook = (ctx) => { },
|
|
||||||
canvasCreator = (width, height): OffscreenCanvas => { return createCanvas(width, height) }
|
|
||||||
) => {
|
|
||||||
// todo don't use texture rendering, investigate the font rendering when possible
|
// todo don't use texture rendering, investigate the font rendering when possible
|
||||||
// or increase factor when needed
|
// or increase factor when needed
|
||||||
const factor = 40
|
const factor = 40
|
||||||
const fontSize = 1.6 * factor
|
|
||||||
const signboardY = [16, 9]
|
const signboardY = [16, 9]
|
||||||
const heightOffset = signboardY[0] - signboardY[1]
|
const heightOffset = signboardY[0] - signboardY[1]
|
||||||
const heightScalar = heightOffset / 16
|
const heightScalar = heightOffset / 16
|
||||||
// todo the text should be clipped based on it's render width (needs investigate)
|
|
||||||
|
let canvas: HTMLCanvasElement | undefined
|
||||||
|
let _ctx: CanvasRenderingContext2D | null = null
|
||||||
|
const getCtx = () => {
|
||||||
|
if (_ctx) return _ctx
|
||||||
|
canvas = document.createElement('canvas')
|
||||||
|
|
||||||
|
canvas.width = 16 * factor
|
||||||
|
canvas.height = heightOffset * factor
|
||||||
|
|
||||||
|
_ctx = canvas.getContext('2d')!
|
||||||
|
_ctx.imageSmoothingEnabled = false
|
||||||
|
|
||||||
|
ctxHook(_ctx)
|
||||||
|
return _ctx
|
||||||
|
}
|
||||||
|
|
||||||
const texts = 'front_text' in blockEntity ? /* > 1.20 */ blockEntity.front_text.messages : [
|
const texts = 'front_text' in blockEntity ? /* > 1.20 */ blockEntity.front_text.messages : [
|
||||||
blockEntity.Text1,
|
blockEntity.Text1,
|
||||||
|
|
@ -73,144 +62,78 @@ export const renderSign = (
|
||||||
blockEntity.Text3,
|
blockEntity.Text3,
|
||||||
blockEntity.Text4
|
blockEntity.Text4
|
||||||
]
|
]
|
||||||
|
|
||||||
if (!texts.some((text) => text !== 'null')) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
const canvas = canvasCreator(16 * factor, heightOffset * factor)
|
|
||||||
|
|
||||||
const _ctx = canvas.getContext('2d')!
|
|
||||||
|
|
||||||
ctxHook(_ctx)
|
|
||||||
const defaultColor = ('front_text' in blockEntity ? blockEntity.front_text.color : blockEntity.Color) || 'black'
|
const defaultColor = ('front_text' in blockEntity ? blockEntity.front_text.color : blockEntity.Color) || 'black'
|
||||||
for (const [lineNum, text] of texts.slice(0, 4).entries()) {
|
for (const [lineNum, text] of texts.slice(0, 4).entries()) {
|
||||||
if (text === 'null') continue
|
|
||||||
renderComponent(text, PrismarineChat, canvas, fontSize, defaultColor, fontSize * (lineNum + 1) + (isHanging ? 0 : -8))
|
|
||||||
}
|
|
||||||
return canvas
|
|
||||||
}
|
|
||||||
|
|
||||||
export const renderComponent = (
|
|
||||||
text: JsonEncodedType | string | undefined,
|
|
||||||
PrismarineChat: typeof ChatMessage,
|
|
||||||
canvas: OffscreenCanvas,
|
|
||||||
fontSize: number,
|
|
||||||
defaultColor: string,
|
|
||||||
offset = 0
|
|
||||||
) => {
|
|
||||||
// todo: in pre flatenning it seems the format was not json
|
// todo: in pre flatenning it seems the format was not json
|
||||||
const parsed = typeof text === 'string' && (text?.startsWith('{') || text?.startsWith('"')) ? parseSafe(text ?? '""', 'sign text') : text
|
if (text === 'null') continue
|
||||||
if (!parsed || (typeof parsed !== 'object' && typeof parsed !== 'string')) return
|
const parsed = text?.startsWith('{') || text?.startsWith('"') ? parseSafe(text ?? '""', 'sign text') : text
|
||||||
|
if (!parsed || (typeof parsed !== 'object' && typeof parsed !== 'string')) continue
|
||||||
// todo fix type
|
// todo fix type
|
||||||
|
const message = typeof parsed === 'string' ? fromFormattedString(parsed) : new PrismarineChat(parsed) as never
|
||||||
const ctx = canvas.getContext('2d')!
|
const patchExtra = ({ extra }: TextComponent) => {
|
||||||
if (!ctx) throw new Error('Could not get 2d context')
|
if (!extra) return
|
||||||
ctx.imageSmoothingEnabled = false
|
for (const child of extra) {
|
||||||
ctx.font = `${fontSize}px mojangles`
|
if (child.color) {
|
||||||
|
child.color = child.color === 'dark_green' ? child.color.toUpperCase() : child.color.toLowerCase()
|
||||||
type Formatting = {
|
|
||||||
color: string | undefined
|
|
||||||
underlined: boolean | undefined
|
|
||||||
strikethrough: boolean | undefined
|
|
||||||
bold: boolean | undefined
|
|
||||||
italic: boolean | undefined
|
|
||||||
}
|
}
|
||||||
|
patchExtra(child)
|
||||||
type Message = ChatMessage & Formatting & { text: string }
|
}
|
||||||
|
}
|
||||||
const message = new PrismarineChat(parsed) as Message
|
patchExtra(message)
|
||||||
|
const rendered = render(message)
|
||||||
|
|
||||||
const toRenderCanvas: Array<{
|
const toRenderCanvas: Array<{
|
||||||
fontStyle: string
|
fontStyle: string
|
||||||
fillStyle: string
|
fillStyle: string
|
||||||
underlineStyle: boolean
|
underlineStyle: boolean
|
||||||
strikeStyle: boolean
|
strikeStyle: boolean
|
||||||
offset: number
|
|
||||||
text: string
|
text: string
|
||||||
}> = []
|
}> = []
|
||||||
let visibleFormatting = false
|
|
||||||
let plainText = ''
|
let plainText = ''
|
||||||
let textOffset = offset
|
// todo the text should be clipped based on it's render width (needs investigate)
|
||||||
const textWidths: number[] = []
|
const MAX_LENGTH = 50 // avoid abusing the signboard
|
||||||
|
const renderText = (node: RenderNode) => {
|
||||||
const renderText = (component: Message, parentFormatting?: Formatting | undefined) => {
|
const { component } = node
|
||||||
const { text } = component
|
let { text } = component
|
||||||
const formatting = {
|
if (plainText.length + text.length > MAX_LENGTH) {
|
||||||
color: component.color ?? parentFormatting?.color,
|
text = text.slice(0, MAX_LENGTH - plainText.length)
|
||||||
underlined: component.underlined ?? parentFormatting?.underlined,
|
if (!text) return false
|
||||||
strikethrough: component.strikethrough ?? parentFormatting?.strikethrough,
|
|
||||||
bold: component.bold ?? parentFormatting?.bold,
|
|
||||||
italic: component.italic ?? parentFormatting?.italic
|
|
||||||
}
|
}
|
||||||
visibleFormatting = visibleFormatting || formatting.underlined || formatting.strikethrough || false
|
|
||||||
if (text?.includes('\n')) {
|
|
||||||
for (const line of text.split('\n')) {
|
|
||||||
addTextPart(line, formatting)
|
|
||||||
textOffset += fontSize
|
|
||||||
plainText = ''
|
|
||||||
}
|
|
||||||
} else if (text) {
|
|
||||||
addTextPart(text, formatting)
|
|
||||||
}
|
|
||||||
if (component.extra) {
|
|
||||||
for (const child of component.extra) {
|
|
||||||
renderText(child as Message, formatting)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const addTextPart = (text: string, formatting: Formatting) => {
|
|
||||||
plainText += text
|
plainText += text
|
||||||
textWidths[textOffset] = ctx.measureText(plainText).width
|
|
||||||
let color = formatting.color ?? defaultColor
|
|
||||||
if (!color.startsWith('#')) {
|
|
||||||
color = LEGACY_COLORS[color.toLowerCase()] || color
|
|
||||||
}
|
|
||||||
toRenderCanvas.push({
|
toRenderCanvas.push({
|
||||||
fontStyle: `${formatting.bold ? 'bold' : ''} ${formatting.italic ? 'italic' : ''}`,
|
fontStyle: `${component.bold ? 'bold' : ''} ${component.italic ? 'italic' : ''}`,
|
||||||
fillStyle: color,
|
fillStyle: node.style['color'] || defaultColor,
|
||||||
underlineStyle: formatting.underlined ?? false,
|
underlineStyle: component.underlined ?? false,
|
||||||
strikeStyle: formatting.strikethrough ?? false,
|
strikeStyle: component.strikethrough ?? false,
|
||||||
offset: textOffset,
|
|
||||||
text
|
text
|
||||||
})
|
})
|
||||||
|
for (const child of node.children) {
|
||||||
|
const stop = renderText(child) === false
|
||||||
|
if (stop) return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderText(message)
|
renderText(rendered)
|
||||||
|
|
||||||
// skip rendering empty lines
|
// skip rendering empty lines (and possible signs)
|
||||||
if (!visibleFormatting && !message.toString().trim()) return
|
if (!plainText.trim()) continue
|
||||||
|
|
||||||
|
const ctx = getCtx()
|
||||||
|
const fontSize = 1.6 * factor
|
||||||
|
ctx.font = `${fontSize}px mojangles`
|
||||||
|
const textWidth = ctx.measureText(plainText).width
|
||||||
|
|
||||||
let renderedWidth = 0
|
let renderedWidth = 0
|
||||||
let previousOffsetY = 0
|
for (const { fillStyle, fontStyle, strikeStyle, text, underlineStyle } of toRenderCanvas) {
|
||||||
for (const { fillStyle, fontStyle, underlineStyle, strikeStyle, offset: offsetY, text } of toRenderCanvas) {
|
// todo strikeStyle, underlineStyle
|
||||||
if (previousOffsetY !== offsetY) {
|
|
||||||
renderedWidth = 0
|
|
||||||
}
|
|
||||||
previousOffsetY = offsetY
|
|
||||||
ctx.fillStyle = fillStyle
|
ctx.fillStyle = fillStyle
|
||||||
ctx.textRendering = 'optimizeLegibility'
|
|
||||||
ctx.font = `${fontStyle} ${fontSize}px mojangles`
|
ctx.font = `${fontStyle} ${fontSize}px mojangles`
|
||||||
const textWidth = textWidths[offsetY] ?? ctx.measureText(text).width
|
ctx.fillText(text, (canvas!.width - textWidth) / 2 + renderedWidth, fontSize * (lineNum + 1))
|
||||||
const offsetX = (canvas.width - textWidth) / 2 + renderedWidth
|
renderedWidth += ctx.measureText(text).width // todo isn't the font is monospace?
|
||||||
ctx.fillText(text, offsetX, offsetY)
|
|
||||||
if (strikeStyle) {
|
|
||||||
ctx.lineWidth = fontSize / 8
|
|
||||||
ctx.strokeStyle = fillStyle
|
|
||||||
ctx.beginPath()
|
|
||||||
ctx.moveTo(offsetX, offsetY - ctx.lineWidth * 2.5)
|
|
||||||
ctx.lineTo(offsetX + ctx.measureText(text).width, offsetY - ctx.lineWidth * 2.5)
|
|
||||||
ctx.stroke()
|
|
||||||
}
|
|
||||||
if (underlineStyle) {
|
|
||||||
ctx.lineWidth = fontSize / 8
|
|
||||||
ctx.strokeStyle = fillStyle
|
|
||||||
ctx.beginPath()
|
|
||||||
ctx.moveTo(offsetX, offsetY + ctx.lineWidth)
|
|
||||||
ctx.lineTo(offsetX + ctx.measureText(text).width, offsetY + ctx.lineWidth)
|
|
||||||
ctx.stroke()
|
|
||||||
}
|
|
||||||
renderedWidth += ctx.measureText(text).width
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ctx.fillStyle = 'red'
|
||||||
|
// ctx.fillRect(0, 0, canvas.width, canvas.height)
|
||||||
|
|
||||||
|
return canvas
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,9 @@ const blockEntity = {
|
||||||
|
|
||||||
await document.fonts.load('1em mojangles')
|
await document.fonts.load('1em mojangles')
|
||||||
|
|
||||||
const canvas = renderSign(blockEntity, false, PrismarineChat, (ctx) => {
|
const canvas = renderSign(blockEntity, PrismarineChat, (ctx) => {
|
||||||
ctx.drawImage(img, 0, 0, ctx.canvas.width, ctx.canvas.height)
|
ctx.drawImage(img, 0, 0, ctx.canvas.width, ctx.canvas.height)
|
||||||
}, (width, height) => {
|
})
|
||||||
const canvas = document.createElement('canvas')
|
|
||||||
canvas.width = width
|
|
||||||
canvas.height = height
|
|
||||||
return canvas as unknown as OffscreenCanvas
|
|
||||||
}) as unknown as HTMLCanvasElement
|
|
||||||
|
|
||||||
if (canvas) {
|
if (canvas) {
|
||||||
canvas.style.imageRendering = 'pixelated'
|
canvas.style.imageRendering = 'pixelated'
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ global.document = {
|
||||||
|
|
||||||
const render = (entity) => {
|
const render = (entity) => {
|
||||||
ctxTexts = []
|
ctxTexts = []
|
||||||
renderSign(entity, true, PrismarineChat)
|
renderSign(entity, PrismarineChat)
|
||||||
return ctxTexts.map(({ text, y }) => [y / 64, text])
|
return ctxTexts.map(({ text, y }) => [y / 64, text])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,6 +37,10 @@ test('sign renderer', () => {
|
||||||
} as any
|
} as any
|
||||||
expect(render(blockEntity)).toMatchInlineSnapshot(`
|
expect(render(blockEntity)).toMatchInlineSnapshot(`
|
||||||
[
|
[
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
"",
|
||||||
|
],
|
||||||
[
|
[
|
||||||
1,
|
1,
|
||||||
"Minecraft ",
|
"Minecraft ",
|
||||||
|
|
|
||||||
|
|
@ -80,12 +80,8 @@ export class CameraShake {
|
||||||
camera.setRotationFromQuaternion(yawQuat)
|
camera.setRotationFromQuaternion(yawQuat)
|
||||||
} else {
|
} else {
|
||||||
// For regular camera, apply all rotations
|
// For regular camera, apply all rotations
|
||||||
// Add tiny offsets to prevent z-fighting at ideal angles (90, 180, 270 degrees)
|
const pitchQuat = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1, 0, 0), this.basePitch)
|
||||||
const pitchOffset = this.addAntiZfightingOffset(this.basePitch)
|
const yawQuat = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), this.baseYaw)
|
||||||
const yawOffset = this.addAntiZfightingOffset(this.baseYaw)
|
|
||||||
|
|
||||||
const pitchQuat = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1, 0, 0), pitchOffset)
|
|
||||||
const yawQuat = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), yawOffset)
|
|
||||||
const rollQuat = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 0, 1), THREE.MathUtils.degToRad(this.rollAngle))
|
const rollQuat = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 0, 1), THREE.MathUtils.degToRad(this.rollAngle))
|
||||||
// Combine rotations in the correct order: pitch -> yaw -> roll
|
// Combine rotations in the correct order: pitch -> yaw -> roll
|
||||||
const finalQuat = yawQuat.multiply(pitchQuat).multiply(rollQuat)
|
const finalQuat = yawQuat.multiply(pitchQuat).multiply(rollQuat)
|
||||||
|
|
@ -100,21 +96,4 @@ export class CameraShake {
|
||||||
private easeInOut (t: number): number {
|
private easeInOut (t: number): number {
|
||||||
return t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2
|
return t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
private addAntiZfightingOffset (angle: number): number {
|
|
||||||
const offset = 0.001 // Very small offset in radians (about 0.057 degrees)
|
|
||||||
|
|
||||||
// Check if the angle is close to ideal angles (0, π/2, π, 3π/2)
|
|
||||||
const normalizedAngle = ((angle % (Math.PI * 2)) + Math.PI * 2) % (Math.PI * 2)
|
|
||||||
const tolerance = 0.01 // Tolerance for considering an angle "ideal"
|
|
||||||
|
|
||||||
if (Math.abs(normalizedAngle) < tolerance ||
|
|
||||||
Math.abs(normalizedAngle - Math.PI / 2) < tolerance ||
|
|
||||||
Math.abs(normalizedAngle - Math.PI) < tolerance ||
|
|
||||||
Math.abs(normalizedAngle - 3 * Math.PI / 2) < tolerance) {
|
|
||||||
return angle + offset
|
|
||||||
}
|
|
||||||
|
|
||||||
return angle
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,8 @@ export class DocumentRenderer {
|
||||||
this.previousCanvasWidth = this.canvas.width
|
this.previousCanvasWidth = this.canvas.width
|
||||||
this.previousCanvasHeight = this.canvas.height
|
this.previousCanvasHeight = this.canvas.height
|
||||||
|
|
||||||
const supportsWebGL2 = 'WebGL2RenderingContext' in window
|
|
||||||
// Only initialize stats and DOM-related features in main thread
|
// Only initialize stats and DOM-related features in main thread
|
||||||
if (!externalCanvas && supportsWebGL2) {
|
if (!externalCanvas) {
|
||||||
this.stats = new TopRightStats(this.canvas as HTMLCanvasElement, this.config.statsVisible)
|
this.stats = new TopRightStats(this.canvas as HTMLCanvasElement, this.config.statsVisible)
|
||||||
this.setupFpsTracking()
|
this.setupFpsTracking()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
//@ts-check
|
//@ts-check
|
||||||
|
import EventEmitter from 'events'
|
||||||
import { UnionToIntersection } from 'type-fest'
|
import { UnionToIntersection } from 'type-fest'
|
||||||
import nbt from 'prismarine-nbt'
|
import nbt from 'prismarine-nbt'
|
||||||
import * as TWEEN from '@tweenjs/tween.js'
|
import * as TWEEN from '@tweenjs/tween.js'
|
||||||
import * as THREE from 'three'
|
import * as THREE from 'three'
|
||||||
import { PlayerAnimation, PlayerObject } from 'skinview3d'
|
import { PlayerObject, PlayerAnimation } from 'skinview3d'
|
||||||
import { inferModelType, loadCapeToCanvas, loadEarsToCanvasFromSkin } from 'skinview-utils'
|
import { loadSkinToCanvas, loadEarsToCanvasFromSkin, inferModelType, loadCapeToCanvas, loadImage } from 'skinview-utils'
|
||||||
// todo replace with url
|
// todo replace with url
|
||||||
import { degreesToRadians } from '@nxg-org/mineflayer-tracker/lib/mathUtils'
|
import { degreesToRadians } from '@nxg-org/mineflayer-tracker/lib/mathUtils'
|
||||||
import { NameTagObject } from 'skinview3d/libs/nametag'
|
import { NameTagObject } from 'skinview3d/libs/nametag'
|
||||||
|
|
@ -12,28 +13,29 @@ import { flat, fromFormattedString } from '@xmcl/text-component'
|
||||||
import mojangson from 'mojangson'
|
import mojangson from 'mojangson'
|
||||||
import { snakeCase } from 'change-case'
|
import { snakeCase } from 'change-case'
|
||||||
import { Item } from 'prismarine-item'
|
import { Item } from 'prismarine-item'
|
||||||
|
import { BlockModel } from 'mc-assets'
|
||||||
import { isEntityAttackable } from 'mineflayer-mouse/dist/attackableEntity'
|
import { isEntityAttackable } from 'mineflayer-mouse/dist/attackableEntity'
|
||||||
import { Team } from 'mineflayer'
|
import { Vec3 } from 'vec3'
|
||||||
import PrismarineChatLoader from 'prismarine-chat'
|
|
||||||
import { EntityMetadataVersions } from '../../../src/mcDataTypes'
|
import { EntityMetadataVersions } from '../../../src/mcDataTypes'
|
||||||
import { ItemSpecificContextProperties } from '../lib/basePlayerState'
|
import { ItemSpecificContextProperties } from '../lib/basePlayerState'
|
||||||
import { loadSkinFromUsername, loadSkinImage, stevePngUrl } from '../lib/utils/skins'
|
import { loadSkinImage, loadSkinFromUsername, stevePngUrl, steveTexture, createCanvas } from '../lib/utils/skins'
|
||||||
import { renderComponent } from '../sign-renderer'
|
import { loadTexture } from '../lib/utils'
|
||||||
import { createCanvas } from '../lib/utils'
|
|
||||||
import { PlayerObjectType } from '../lib/createPlayerObject'
|
|
||||||
import { getBlockMeshFromModel } from './holdingBlock'
|
import { getBlockMeshFromModel } from './holdingBlock'
|
||||||
import { createItemMesh } from './itemMesh'
|
|
||||||
import * as Entity from './entity/EntityMesh'
|
import * as Entity from './entity/EntityMesh'
|
||||||
import { getMesh } from './entity/EntityMesh'
|
import { getMesh } from './entity/EntityMesh'
|
||||||
import { WalkingGeneralSwing } from './entity/animations'
|
import { WalkingGeneralSwing } from './entity/animations'
|
||||||
import { disposeObject, loadTexture, loadThreeJsTextureFromUrl } from './threeJsUtils'
|
import { disposeObject } from './threeJsUtils'
|
||||||
import { armorModel, armorTextures, elytraTexture } from './entity/armorModels'
|
import { armorModel, elytraTexture, armorTextures } from './entity/armorModels'
|
||||||
import { WorldRendererThree } from './worldrendererThree'
|
import { WorldRendererThree } from './worldrendererThree'
|
||||||
|
|
||||||
export const steveTexture = loadThreeJsTextureFromUrl(stevePngUrl)
|
|
||||||
|
|
||||||
export const TWEEN_DURATION = 120
|
export const TWEEN_DURATION = 120
|
||||||
|
|
||||||
|
type PlayerObjectType = PlayerObject & {
|
||||||
|
animation?: PlayerAnimation
|
||||||
|
realPlayerUuid: string
|
||||||
|
realUsername: string
|
||||||
|
}
|
||||||
|
|
||||||
function convert2sComplementToHex (complement: number) {
|
function convert2sComplementToHex (complement: number) {
|
||||||
if (complement < 0) {
|
if (complement < 0) {
|
||||||
complement = (0xFF_FF_FF_FF + complement + 1) >>> 0
|
complement = (0xFF_FF_FF_FF + complement + 1) >>> 0
|
||||||
|
|
@ -93,11 +95,8 @@ function getUsernameTexture ({
|
||||||
username,
|
username,
|
||||||
nameTagBackgroundColor = 'rgba(0, 0, 0, 0.3)',
|
nameTagBackgroundColor = 'rgba(0, 0, 0, 0.3)',
|
||||||
nameTagTextOpacity = 255
|
nameTagTextOpacity = 255
|
||||||
}: any, { fontFamily = 'mojangles' }: any, version: string) {
|
}: any, { fontFamily = 'sans-serif' }: any) {
|
||||||
const canvas = createCanvas(64, 64)
|
const canvas = createCanvas(64, 64)
|
||||||
|
|
||||||
const PrismarineChat = PrismarineChatLoader(version)
|
|
||||||
|
|
||||||
const ctx = canvas.getContext('2d')
|
const ctx = canvas.getContext('2d')
|
||||||
if (!ctx) throw new Error('Could not get 2d context')
|
if (!ctx) throw new Error('Could not get 2d context')
|
||||||
|
|
||||||
|
|
@ -105,39 +104,38 @@ function getUsernameTexture ({
|
||||||
const padding = 5
|
const padding = 5
|
||||||
ctx.font = `${fontSize}px ${fontFamily}`
|
ctx.font = `${fontSize}px ${fontFamily}`
|
||||||
|
|
||||||
const plainLines = String(typeof username === 'string' ? username : new PrismarineChat(username).toString()).split('\n')
|
const lines = String(username).split('\n')
|
||||||
|
|
||||||
let textWidth = 0
|
let textWidth = 0
|
||||||
for (const line of plainLines) {
|
for (const line of lines) {
|
||||||
const width = ctx.measureText(line).width + padding * 2
|
const width = ctx.measureText(line).width + padding * 2
|
||||||
if (width > textWidth) textWidth = width
|
if (width > textWidth) textWidth = width
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.width = textWidth
|
canvas.width = textWidth
|
||||||
canvas.height = (fontSize + padding) * plainLines.length
|
canvas.height = (fontSize + padding) * lines.length
|
||||||
|
|
||||||
ctx.fillStyle = nameTagBackgroundColor
|
ctx.fillStyle = nameTagBackgroundColor
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height)
|
ctx.fillRect(0, 0, canvas.width, canvas.height)
|
||||||
|
|
||||||
ctx.globalAlpha = nameTagTextOpacity / 255
|
ctx.font = `${fontSize}px ${fontFamily}`
|
||||||
|
ctx.fillStyle = `rgba(255, 255, 255, ${nameTagTextOpacity / 255})`
|
||||||
renderComponent(username, PrismarineChat, canvas, fontSize, 'white', -padding + fontSize)
|
let i = 0
|
||||||
|
for (const line of lines) {
|
||||||
ctx.globalAlpha = 1
|
i++
|
||||||
|
ctx.fillText(line, (textWidth - ctx.measureText(line).width) / 2, -padding + fontSize * i)
|
||||||
|
}
|
||||||
|
|
||||||
return canvas
|
return canvas
|
||||||
}
|
}
|
||||||
|
|
||||||
const addNametag = (entity, options: { fontFamily: string }, mesh, version: string) => {
|
const addNametag = (entity, options, mesh) => {
|
||||||
for (const c of mesh.children) {
|
|
||||||
if (c.name === 'nametag') {
|
|
||||||
c.removeFromParent()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (entity.username !== undefined) {
|
if (entity.username !== undefined) {
|
||||||
const canvas = getUsernameTexture(entity, options, version)
|
if (mesh.children.some(c => c.name === 'nametag')) return // todo update
|
||||||
|
const canvas = getUsernameTexture(entity, options)
|
||||||
const tex = new THREE.Texture(canvas)
|
const tex = new THREE.Texture(canvas)
|
||||||
tex.needsUpdate = true
|
tex.needsUpdate = true
|
||||||
let nameTag: THREE.Object3D
|
let nameTag
|
||||||
if (entity.nameTagFixed) {
|
if (entity.nameTagFixed) {
|
||||||
const geometry = new THREE.PlaneGeometry()
|
const geometry = new THREE.PlaneGeometry()
|
||||||
const material = new THREE.MeshBasicMaterial({ map: tex })
|
const material = new THREE.MeshBasicMaterial({ map: tex })
|
||||||
|
|
@ -167,7 +165,6 @@ const addNametag = (entity, options: { fontFamily: string }, mesh, version: stri
|
||||||
nameTag.name = 'nametag'
|
nameTag.name = 'nametag'
|
||||||
|
|
||||||
mesh.add(nameTag)
|
mesh.add(nameTag)
|
||||||
return nameTag
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,7 +173,7 @@ const nametags = {}
|
||||||
|
|
||||||
const isFirstUpperCase = (str) => str.charAt(0) === str.charAt(0).toUpperCase()
|
const isFirstUpperCase = (str) => str.charAt(0) === str.charAt(0).toUpperCase()
|
||||||
|
|
||||||
function getEntityMesh (entity: import('prismarine-entity').Entity & { delete?: any; pos?: any; name?: any }, world: WorldRendererThree, options: { fontFamily: string }, overrides) {
|
function getEntityMesh (entity: import('prismarine-entity').Entity & { delete?: any; pos?: any; name?: any }, world: WorldRendererThree | undefined, options: { fontFamily: string }, overrides) {
|
||||||
if (entity.name) {
|
if (entity.name) {
|
||||||
try {
|
try {
|
||||||
// https://github.com/PrismarineJS/prismarine-viewer/pull/410
|
// https://github.com/PrismarineJS/prismarine-viewer/pull/410
|
||||||
|
|
@ -184,7 +181,7 @@ function getEntityMesh (entity: import('prismarine-entity').Entity & { delete?:
|
||||||
const e = new Entity.EntityMesh('1.16.4', entityName, world, overrides)
|
const e = new Entity.EntityMesh('1.16.4', entityName, world, overrides)
|
||||||
|
|
||||||
if (e.mesh) {
|
if (e.mesh) {
|
||||||
addNametag(entity, options, e.mesh, world.version)
|
addNametag(entity, options, e.mesh)
|
||||||
return e.mesh
|
return e.mesh
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -202,7 +199,7 @@ function getEntityMesh (entity: import('prismarine-entity').Entity & { delete?:
|
||||||
addNametag({
|
addNametag({
|
||||||
username: entity.name,
|
username: entity.name,
|
||||||
height: entity.height,
|
height: entity.height,
|
||||||
}, options, cube, world.version)
|
}, options, cube)
|
||||||
}
|
}
|
||||||
return cube
|
return cube
|
||||||
}
|
}
|
||||||
|
|
@ -212,7 +209,7 @@ export type SceneEntity = THREE.Object3D & {
|
||||||
username?: string
|
username?: string
|
||||||
uuid?: string
|
uuid?: string
|
||||||
additionalCleanup?: () => void
|
additionalCleanup?: () => void
|
||||||
originalEntity: import('prismarine-entity').Entity & { delete?; pos?, name, team?: Team }
|
originalEntity: import('prismarine-entity').Entity & { delete?; pos?, name }
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Entities {
|
export class Entities {
|
||||||
|
|
@ -488,13 +485,8 @@ export class Entities {
|
||||||
.some(channel => channel !== 0)
|
.some(channel => channel !== 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo true/undefined doesnt reset the skin to the default one
|
|
||||||
// eslint-disable-next-line max-params
|
// eslint-disable-next-line max-params
|
||||||
async updatePlayerSkin (entityId: string | number, username: string | undefined, uuidCache: string | undefined, skinUrl: string | true, capeUrl: string | true | undefined = undefined) {
|
async updatePlayerSkin (entityId: string | number, username: string | undefined, uuidCache: string | undefined, skinUrl: string | true, capeUrl: string | true | undefined = undefined) {
|
||||||
const isCustomSkin = skinUrl !== stevePngUrl
|
|
||||||
if (isCustomSkin) {
|
|
||||||
this.loadedSkinEntityIds.add(String(entityId))
|
|
||||||
}
|
|
||||||
if (uuidCache) {
|
if (uuidCache) {
|
||||||
if (typeof skinUrl === 'string' || typeof capeUrl === 'string') this.uuidPerSkinUrlsCache[uuidCache] = {}
|
if (typeof skinUrl === 'string' || typeof capeUrl === 'string') this.uuidPerSkinUrlsCache[uuidCache] = {}
|
||||||
if (typeof skinUrl === 'string') this.uuidPerSkinUrlsCache[uuidCache].skinUrl = skinUrl
|
if (typeof skinUrl === 'string') this.uuidPerSkinUrlsCache[uuidCache].skinUrl = skinUrl
|
||||||
|
|
@ -718,7 +710,7 @@ export class Entities {
|
||||||
return typeof component === 'string' ? component : component.text ?? ''
|
return typeof component === 'string' ? component : component.text ?? ''
|
||||||
}
|
}
|
||||||
|
|
||||||
getItemMesh (item, specificProps: ItemSpecificContextProperties, faceCamera = false, previousModel?: string) {
|
getItemMesh (item, specificProps: ItemSpecificContextProperties, previousModel?: string) {
|
||||||
if (!item.nbt && item.nbtData) item.nbt = item.nbtData
|
if (!item.nbt && item.nbtData) item.nbt = item.nbtData
|
||||||
const textureUv = this.worldRenderer.getItemRenderData(item, specificProps)
|
const textureUv = this.worldRenderer.getItemRenderData(item, specificProps)
|
||||||
if (previousModel && previousModel === textureUv?.modelName) return undefined
|
if (previousModel && previousModel === textureUv?.modelName) return undefined
|
||||||
|
|
@ -737,41 +729,60 @@ export class Entities {
|
||||||
return {
|
return {
|
||||||
mesh: outerGroup,
|
mesh: outerGroup,
|
||||||
isBlock: true,
|
isBlock: true,
|
||||||
|
itemsTexture: null,
|
||||||
|
itemsTextureFlipped: null,
|
||||||
modelName: textureUv.modelName,
|
modelName: textureUv.modelName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render proper 3D model for items
|
// TODO: Render proper model (especially for blocks) instead of flat texture
|
||||||
if (textureUv) {
|
if (textureUv) {
|
||||||
const textureThree = textureUv.renderInfo?.texture === 'blocks' ? this.worldRenderer.material.map! : this.worldRenderer.itemsTexture
|
const textureThree = textureUv.renderInfo?.texture === 'blocks' ? this.worldRenderer.material.map! : this.worldRenderer.itemsTexture
|
||||||
|
// todo use geometry buffer uv instead!
|
||||||
const { u, v, su, sv } = textureUv
|
const { u, v, su, sv } = textureUv
|
||||||
const sizeX = su ?? 1 // su is actually width
|
const size = undefined
|
||||||
const sizeY = sv ?? 1 // sv is actually height
|
const itemsTexture = textureThree.clone()
|
||||||
|
itemsTexture.flipY = true
|
||||||
// Use the new unified item mesh function
|
const sizeY = (sv ?? size)!
|
||||||
const result = createItemMesh(textureThree, {
|
const sizeX = (su ?? size)!
|
||||||
u,
|
itemsTexture.offset.set(u, 1 - v - sizeY)
|
||||||
v,
|
itemsTexture.repeat.set(sizeX, sizeY)
|
||||||
sizeX,
|
itemsTexture.needsUpdate = true
|
||||||
sizeY
|
itemsTexture.magFilter = THREE.NearestFilter
|
||||||
}, {
|
itemsTexture.minFilter = THREE.NearestFilter
|
||||||
faceCamera,
|
const itemsTextureFlipped = itemsTexture.clone()
|
||||||
use3D: !faceCamera, // Only use 3D for non-camera-facing items
|
itemsTextureFlipped.repeat.x *= -1
|
||||||
|
itemsTextureFlipped.needsUpdate = true
|
||||||
|
itemsTextureFlipped.offset.set(u + (sizeX), 1 - v - sizeY)
|
||||||
|
const material = new THREE.MeshStandardMaterial({
|
||||||
|
map: itemsTexture,
|
||||||
|
transparent: true,
|
||||||
|
alphaTest: 0.1,
|
||||||
})
|
})
|
||||||
|
const materialFlipped = new THREE.MeshStandardMaterial({
|
||||||
|
map: itemsTextureFlipped,
|
||||||
|
transparent: true,
|
||||||
|
alphaTest: 0.1,
|
||||||
|
})
|
||||||
|
const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 0), [
|
||||||
|
// top left and right bottom are black box materials others are transparent
|
||||||
|
new THREE.MeshBasicMaterial({ color: 0x00_00_00 }), new THREE.MeshBasicMaterial({ color: 0x00_00_00 }),
|
||||||
|
new THREE.MeshBasicMaterial({ color: 0x00_00_00 }), new THREE.MeshBasicMaterial({ color: 0x00_00_00 }),
|
||||||
|
material, materialFlipped,
|
||||||
|
])
|
||||||
let SCALE = 1
|
let SCALE = 1
|
||||||
if (specificProps['minecraft:display_context'] === 'ground') {
|
if (specificProps['minecraft:display_context'] === 'ground') {
|
||||||
SCALE = 0.5
|
SCALE = 0.5
|
||||||
} else if (specificProps['minecraft:display_context'] === 'thirdperson') {
|
} else if (specificProps['minecraft:display_context'] === 'thirdperson') {
|
||||||
SCALE = 6
|
SCALE = 6
|
||||||
}
|
}
|
||||||
result.mesh.scale.set(SCALE, SCALE, SCALE)
|
mesh.scale.set(SCALE, SCALE, SCALE)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mesh: result.mesh,
|
mesh,
|
||||||
isBlock: false,
|
isBlock: false,
|
||||||
|
itemsTexture,
|
||||||
|
itemsTextureFlipped,
|
||||||
modelName: textureUv.modelName,
|
modelName: textureUv.modelName,
|
||||||
cleanup: result.cleanup
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -787,6 +798,8 @@ export class Entities {
|
||||||
}
|
}
|
||||||
|
|
||||||
update (entity: SceneEntity['originalEntity'], overrides) {
|
update (entity: SceneEntity['originalEntity'], overrides) {
|
||||||
|
const justAdded = !this.entities[entity.id]
|
||||||
|
|
||||||
const isPlayerModel = entity.name === 'player'
|
const isPlayerModel = entity.name === 'player'
|
||||||
if (entity.name === 'zombie_villager' || entity.name === 'husk') {
|
if (entity.name === 'zombie_villager' || entity.name === 'husk') {
|
||||||
overrides.texture = `textures/1.16.4/entity/${entity.name === 'zombie_villager' ? 'zombie_villager/zombie_villager.png' : `zombie/${entity.name}.png`}`
|
overrides.texture = `textures/1.16.4/entity/${entity.name === 'zombie_villager' ? 'zombie_villager/zombie_villager.png' : `zombie/${entity.name}.png`}`
|
||||||
|
|
@ -797,7 +810,6 @@ export class Entities {
|
||||||
}
|
}
|
||||||
// this can be undefined in case where packet entity_destroy was sent twice (so it was already deleted)
|
// this can be undefined in case where packet entity_destroy was sent twice (so it was already deleted)
|
||||||
let e = this.entities[entity.id]
|
let e = this.entities[entity.id]
|
||||||
const justAdded = !e
|
|
||||||
|
|
||||||
if (entity.delete) {
|
if (entity.delete) {
|
||||||
if (!e) return
|
if (!e) return
|
||||||
|
|
@ -817,23 +829,21 @@ export class Entities {
|
||||||
if (e === undefined) {
|
if (e === undefined) {
|
||||||
const group = new THREE.Group() as unknown as SceneEntity
|
const group = new THREE.Group() as unknown as SceneEntity
|
||||||
group.originalEntity = entity
|
group.originalEntity = entity
|
||||||
if (entity.name === 'item' || entity.name === 'tnt' || entity.name === 'falling_block' || entity.name === 'snowball'
|
if (entity.name === 'item' || entity.name === 'tnt' || entity.name === 'falling_block') {
|
||||||
|| entity.name === 'egg' || entity.name === 'ender_pearl' || entity.name === 'experience_bottle'
|
const item = entity.name === 'tnt'
|
||||||
|| entity.name === 'splash_potion' || entity.name === 'lingering_potion') {
|
? { name: 'tnt' }
|
||||||
const item = entity.name === 'tnt' || entity.type === 'projectile'
|
|
||||||
? { name: entity.name }
|
|
||||||
: entity.name === 'falling_block'
|
: entity.name === 'falling_block'
|
||||||
? { blockState: entity['objectData'] }
|
? { blockState: entity['objectData'] }
|
||||||
: entity.metadata?.find((m: any) => typeof m === 'object' && m?.itemCount)
|
: entity.metadata?.find((m: any) => typeof m === 'object' && m?.itemCount)
|
||||||
if (item) {
|
if (item) {
|
||||||
const object = this.getItemMesh(item, {
|
const object = this.getItemMesh(item, {
|
||||||
'minecraft:display_context': 'ground',
|
'minecraft:display_context': 'ground',
|
||||||
}, entity.type === 'projectile')
|
})
|
||||||
if (object) {
|
if (object) {
|
||||||
mesh = object.mesh
|
mesh = object.mesh
|
||||||
if (entity.name === 'item' || entity.type === 'projectile') {
|
if (entity.name === 'item') {
|
||||||
mesh.scale.set(0.5, 0.5, 0.5)
|
mesh.scale.set(0.5, 0.5, 0.5)
|
||||||
mesh.position.set(0, entity.name === 'item' ? 0.2 : 0.1, 0)
|
mesh.position.set(0, 0.2, 0)
|
||||||
} else {
|
} else {
|
||||||
mesh.scale.set(2, 2, 2)
|
mesh.scale.set(2, 2, 2)
|
||||||
mesh.position.set(0, 0.5, 0)
|
mesh.position.set(0, 0.5, 0)
|
||||||
|
|
@ -841,8 +851,8 @@ export class Entities {
|
||||||
// set faces
|
// set faces
|
||||||
// mesh.position.set(targetPos.x + 0.5 + 2, targetPos.y + 0.5, targetPos.z + 0.5)
|
// mesh.position.set(targetPos.x + 0.5 + 2, targetPos.y + 0.5, targetPos.z + 0.5)
|
||||||
// viewer.scene.add(mesh)
|
// viewer.scene.add(mesh)
|
||||||
if (entity.name === 'item') {
|
|
||||||
const clock = new THREE.Clock()
|
const clock = new THREE.Clock()
|
||||||
|
if (entity.name === 'item') {
|
||||||
mesh.onBeforeRender = () => {
|
mesh.onBeforeRender = () => {
|
||||||
const delta = clock.getDelta()
|
const delta = clock.getDelta()
|
||||||
mesh!.rotation.y += delta
|
mesh!.rotation.y += delta
|
||||||
|
|
@ -871,9 +881,8 @@ export class Entities {
|
||||||
|
|
||||||
group.additionalCleanup = () => {
|
group.additionalCleanup = () => {
|
||||||
// important: avoid texture memory leak and gpu slowdown
|
// important: avoid texture memory leak and gpu slowdown
|
||||||
if (object.cleanup) {
|
object.itemsTexture?.dispose()
|
||||||
object.cleanup()
|
object.itemsTextureFlipped?.dispose()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -884,14 +893,18 @@ export class Entities {
|
||||||
mesh = wrapper
|
mesh = wrapper
|
||||||
|
|
||||||
if (entity.username) {
|
if (entity.username) {
|
||||||
const nametag = addNametag(entity, { fontFamily: 'mojangles' }, wrapper, this.worldRenderer.version)
|
// todo proper colors
|
||||||
if (nametag) {
|
const nameTag = new NameTagObject(fromFormattedString(entity.username).text, {
|
||||||
nametag.position.y = playerObject.position.y + playerObject.scale.y * 16 + 3
|
font: `48px ${this.entitiesOptions.fontFamily}`,
|
||||||
nametag.scale.multiplyScalar(12)
|
})
|
||||||
}
|
nameTag.position.y = playerObject.position.y + playerObject.scale.y * 16 + 3
|
||||||
|
nameTag.renderOrder = 1000
|
||||||
|
|
||||||
|
//@ts-expect-error
|
||||||
|
wrapper.add(nameTag)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mesh = getEntityMesh(entity, this.worldRenderer, this.entitiesOptions, { ...overrides, customModel: entity['customModel'] })
|
mesh = getEntityMesh(entity, this.worldRenderer, this.entitiesOptions, overrides)
|
||||||
}
|
}
|
||||||
if (!mesh) return
|
if (!mesh) return
|
||||||
mesh.name = 'mesh'
|
mesh.name = 'mesh'
|
||||||
|
|
@ -950,22 +963,21 @@ export class Entities {
|
||||||
// entity specific meta
|
// entity specific meta
|
||||||
const textDisplayMeta = getSpecificEntityMetadata('text_display', entity)
|
const textDisplayMeta = getSpecificEntityMetadata('text_display', entity)
|
||||||
const displayTextRaw = textDisplayMeta?.text || meta.custom_name_visible && meta.custom_name
|
const displayTextRaw = textDisplayMeta?.text || meta.custom_name_visible && meta.custom_name
|
||||||
if (entity.name !== 'player' && displayTextRaw) {
|
const displayText = this.parseEntityLabel(displayTextRaw)
|
||||||
|
if (entity.name !== 'player' && displayText) {
|
||||||
const nameTagFixed = textDisplayMeta && (textDisplayMeta.billboard_render_constraints === 'fixed' || !textDisplayMeta.billboard_render_constraints)
|
const nameTagFixed = textDisplayMeta && (textDisplayMeta.billboard_render_constraints === 'fixed' || !textDisplayMeta.billboard_render_constraints)
|
||||||
const nameTagBackgroundColor = (textDisplayMeta && (parseInt(textDisplayMeta.style_flags, 10) & 0x04) === 0) ? toRgba(textDisplayMeta.background_color) : undefined
|
const nameTagBackgroundColor = textDisplayMeta && toRgba(textDisplayMeta.background_color)
|
||||||
let nameTagTextOpacity: any
|
let nameTagTextOpacity: any
|
||||||
if (textDisplayMeta?.text_opacity) {
|
if (textDisplayMeta?.text_opacity) {
|
||||||
const rawOpacity = parseInt(textDisplayMeta?.text_opacity, 10)
|
const rawOpacity = parseInt(textDisplayMeta?.text_opacity, 10)
|
||||||
nameTagTextOpacity = rawOpacity > 0 ? rawOpacity : 256 - rawOpacity
|
nameTagTextOpacity = rawOpacity > 0 ? rawOpacity : 256 - rawOpacity
|
||||||
}
|
}
|
||||||
addNametag(
|
addNametag(
|
||||||
{ ...entity, username: typeof displayTextRaw === 'string' ? mojangson.simplify(mojangson.parse(displayTextRaw)) : nbt.simplify(displayTextRaw),
|
{ ...entity, username: displayText, nameTagBackgroundColor, nameTagTextOpacity, nameTagFixed,
|
||||||
nameTagBackgroundColor, nameTagTextOpacity, nameTagFixed,
|
|
||||||
nameTagScale: textDisplayMeta?.scale, nameTagTranslation: textDisplayMeta && (textDisplayMeta.translation || new THREE.Vector3(0, 0, 0)),
|
nameTagScale: textDisplayMeta?.scale, nameTagTranslation: textDisplayMeta && (textDisplayMeta.translation || new THREE.Vector3(0, 0, 0)),
|
||||||
nameTagRotationLeft: toQuaternion(textDisplayMeta?.left_rotation), nameTagRotationRight: toQuaternion(textDisplayMeta?.right_rotation) },
|
nameTagRotationLeft: toQuaternion(textDisplayMeta?.left_rotation), nameTagRotationRight: toQuaternion(textDisplayMeta?.right_rotation) },
|
||||||
this.entitiesOptions,
|
this.entitiesOptions,
|
||||||
mesh,
|
mesh
|
||||||
this.worldRenderer.version
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1099,12 +1111,10 @@ export class Entities {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity.username !== undefined) {
|
if (entity.username) {
|
||||||
e.username = entity.username
|
e.username = entity.username
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateNameTagVisibility(e)
|
|
||||||
|
|
||||||
this.updateEntityPosition(entity, justAdded, overrides)
|
this.updateEntityPosition(entity, justAdded, overrides)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1147,7 +1157,8 @@ export class Entities {
|
||||||
const cameraPos = this.worldRenderer.cameraObject.position
|
const cameraPos = this.worldRenderer.cameraObject.position
|
||||||
const distance = mesh.position.distanceTo(cameraPos)
|
const distance = mesh.position.distanceTo(cameraPos)
|
||||||
if (distance < MAX_DISTANCE_SKIN_LOAD && distance < (this.worldRenderer.viewDistance * 16)) {
|
if (distance < MAX_DISTANCE_SKIN_LOAD && distance < (this.worldRenderer.viewDistance * 16)) {
|
||||||
if (this.loadedSkinEntityIds.has(String(entityId))) return
|
if (this.loadedSkinEntityIds.has(entityId)) return
|
||||||
|
this.loadedSkinEntityIds.add(entityId)
|
||||||
void this.updatePlayerSkin(entityId, mesh.playerObject.realUsername, mesh.playerObject.realPlayerUuid, true, true)
|
void this.updatePlayerSkin(entityId, mesh.playerObject.realUsername, mesh.playerObject.realPlayerUuid, true, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1172,20 +1183,6 @@ export class Entities {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateNameTagVisibility (entity: SceneEntity) {
|
|
||||||
const playerTeam = this.worldRenderer.playerStateReactive.team
|
|
||||||
const entityTeam = entity.originalEntity.team
|
|
||||||
const nameTagVisibility = entityTeam?.nameTagVisibility || 'always'
|
|
||||||
const showNameTag = nameTagVisibility === 'always' ||
|
|
||||||
(nameTagVisibility === 'hideForOwnTeam' && entityTeam?.team !== playerTeam?.team) ||
|
|
||||||
(nameTagVisibility === 'hideForOtherTeams' && (entityTeam?.team === playerTeam?.team || playerTeam === undefined))
|
|
||||||
entity.traverse(c => {
|
|
||||||
if (c.name === 'nametag') {
|
|
||||||
c.visible = showNameTag
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
addMapModel (entityMesh: THREE.Object3D, mapNumber: number, rotation: number) {
|
addMapModel (entityMesh: THREE.Object3D, mapNumber: number, rotation: number) {
|
||||||
const imageData = this.cachedMapsImages?.[mapNumber]
|
const imageData = this.cachedMapsImages?.[mapNumber]
|
||||||
let texture: THREE.Texture | null = null
|
let texture: THREE.Texture | null = null
|
||||||
|
|
@ -1262,9 +1259,8 @@ export class Entities {
|
||||||
const group = new THREE.Object3D()
|
const group = new THREE.Object3D()
|
||||||
group['additionalCleanup'] = () => {
|
group['additionalCleanup'] = () => {
|
||||||
// important: avoid texture memory leak and gpu slowdown
|
// important: avoid texture memory leak and gpu slowdown
|
||||||
if (itemObject.cleanup) {
|
itemObject.itemsTexture?.dispose()
|
||||||
itemObject.cleanup()
|
itemObject.itemsTextureFlipped?.dispose()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const itemMesh = itemObject.mesh
|
const itemMesh = itemObject.mesh
|
||||||
group.rotation.z = -Math.PI / 16
|
group.rotation.z = -Math.PI / 16
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import ocelotPng from '../../../../node_modules/mc-assets/dist/other-textures/la
|
||||||
import arrowTexture from '../../../../node_modules/mc-assets/dist/other-textures/1.21.2/entity/projectiles/arrow.png'
|
import arrowTexture from '../../../../node_modules/mc-assets/dist/other-textures/1.21.2/entity/projectiles/arrow.png'
|
||||||
import spectralArrowTexture from '../../../../node_modules/mc-assets/dist/other-textures/1.21.2/entity/projectiles/spectral_arrow.png'
|
import spectralArrowTexture from '../../../../node_modules/mc-assets/dist/other-textures/1.21.2/entity/projectiles/spectral_arrow.png'
|
||||||
import tippedArrowTexture from '../../../../node_modules/mc-assets/dist/other-textures/1.21.2/entity/projectiles/tipped_arrow.png'
|
import tippedArrowTexture from '../../../../node_modules/mc-assets/dist/other-textures/1.21.2/entity/projectiles/tipped_arrow.png'
|
||||||
import { loadTexture } from '../threeJsUtils'
|
import { loadTexture } from '../../lib/utils'
|
||||||
import { WorldRendererThree } from '../worldrendererThree'
|
import { WorldRendererThree } from '../worldrendererThree'
|
||||||
import entities from './entities.json'
|
import entities from './entities.json'
|
||||||
import { externalModels } from './objModels'
|
import { externalModels } from './objModels'
|
||||||
|
|
|
||||||
|
|
@ -44,12 +44,6 @@ const getBackendMethods = (worldRenderer: WorldRendererThree) => {
|
||||||
shakeFromDamage: worldRenderer.cameraShake.shakeFromDamage.bind(worldRenderer.cameraShake),
|
shakeFromDamage: worldRenderer.cameraShake.shakeFromDamage.bind(worldRenderer.cameraShake),
|
||||||
onPageInteraction: worldRenderer.media.onPageInteraction.bind(worldRenderer.media),
|
onPageInteraction: worldRenderer.media.onPageInteraction.bind(worldRenderer.media),
|
||||||
downloadMesherLog: worldRenderer.downloadMesherLog.bind(worldRenderer),
|
downloadMesherLog: worldRenderer.downloadMesherLog.bind(worldRenderer),
|
||||||
|
|
||||||
addWaypoint: worldRenderer.waypoints.addWaypoint.bind(worldRenderer.waypoints),
|
|
||||||
removeWaypoint: worldRenderer.waypoints.removeWaypoint.bind(worldRenderer.waypoints),
|
|
||||||
|
|
||||||
// New method for updating skybox
|
|
||||||
setSkyboxImage: worldRenderer.skyboxRenderer.setSkyboxImage.bind(worldRenderer.skyboxRenderer)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ import PrismarineItem from 'prismarine-item'
|
||||||
import worldBlockProvider, { WorldBlockProvider } from 'mc-assets/dist/worldBlockProvider'
|
import worldBlockProvider, { WorldBlockProvider } from 'mc-assets/dist/worldBlockProvider'
|
||||||
import { BlockModel } from 'mc-assets'
|
import { BlockModel } from 'mc-assets'
|
||||||
import { getThreeBlockModelGroup, renderBlockThree, setBlockPosition } from '../lib/mesher/standaloneRenderer'
|
import { getThreeBlockModelGroup, renderBlockThree, setBlockPosition } from '../lib/mesher/standaloneRenderer'
|
||||||
|
import { getMyHand } from '../lib/hand'
|
||||||
import { MovementState, PlayerStateRenderer } from '../lib/basePlayerState'
|
import { MovementState, PlayerStateRenderer } from '../lib/basePlayerState'
|
||||||
import { DebugGui } from '../lib/DebugGui'
|
import { DebugGui } from '../lib/DebugGui'
|
||||||
import { SmoothSwitcher } from '../lib/smoothSwitcher'
|
import { SmoothSwitcher } from '../lib/smoothSwitcher'
|
||||||
import { watchProperty } from '../lib/utils/proxy'
|
import { watchProperty } from '../lib/utils/proxy'
|
||||||
import { WorldRendererConfig } from '../lib/worldrendererCommon'
|
import { WorldRendererConfig } from '../lib/worldrendererCommon'
|
||||||
import { getMyHand } from './hand'
|
|
||||||
import { WorldRendererThree } from './worldrendererThree'
|
import { WorldRendererThree } from './worldrendererThree'
|
||||||
import { disposeObject } from './threeJsUtils'
|
import { disposeObject } from './threeJsUtils'
|
||||||
|
|
||||||
|
|
@ -357,7 +357,7 @@ export default class HoldingBlock {
|
||||||
'minecraft:display_context': 'firstperson',
|
'minecraft:display_context': 'firstperson',
|
||||||
'minecraft:use_duration': this.worldRenderer.playerStateReactive.itemUsageTicks,
|
'minecraft:use_duration': this.worldRenderer.playerStateReactive.itemUsageTicks,
|
||||||
'minecraft:using_item': !!this.worldRenderer.playerStateReactive.itemUsageTicks,
|
'minecraft:using_item': !!this.worldRenderer.playerStateReactive.itemUsageTicks,
|
||||||
}, false, this.lastItemModelName)
|
}, this.lastItemModelName)
|
||||||
if (result) {
|
if (result) {
|
||||||
const { mesh: itemMesh, isBlock, modelName } = result
|
const { mesh: itemMesh, isBlock, modelName } = result
|
||||||
if (isBlock) {
|
if (isBlock) {
|
||||||
|
|
|
||||||
|
|
@ -1,427 +0,0 @@
|
||||||
import * as THREE from 'three'
|
|
||||||
|
|
||||||
export interface Create3DItemMeshOptions {
|
|
||||||
depth: number
|
|
||||||
pixelSize?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Create3DItemMeshResult {
|
|
||||||
geometry: THREE.BufferGeometry
|
|
||||||
totalVertices: number
|
|
||||||
totalTriangles: number
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a 3D item geometry with front/back faces and connecting edges
|
|
||||||
* from a canvas containing the item texture
|
|
||||||
*/
|
|
||||||
export function create3DItemMesh (
|
|
||||||
canvas: HTMLCanvasElement,
|
|
||||||
options: Create3DItemMeshOptions
|
|
||||||
): Create3DItemMeshResult {
|
|
||||||
const { depth, pixelSize } = options
|
|
||||||
|
|
||||||
// Validate canvas dimensions
|
|
||||||
if (canvas.width <= 0 || canvas.height <= 0) {
|
|
||||||
throw new Error(`Invalid canvas dimensions: ${canvas.width}x${canvas.height}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const ctx = canvas.getContext('2d')!
|
|
||||||
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height)
|
|
||||||
const { data } = imageData
|
|
||||||
|
|
||||||
const w = canvas.width
|
|
||||||
const h = canvas.height
|
|
||||||
const halfDepth = depth / 2
|
|
||||||
const actualPixelSize = pixelSize ?? (1 / Math.max(w, h))
|
|
||||||
|
|
||||||
// Find opaque pixels
|
|
||||||
const isOpaque = (x: number, y: number) => {
|
|
||||||
if (x < 0 || y < 0 || x >= w || y >= h) return false
|
|
||||||
const i = (y * w + x) * 4
|
|
||||||
return data[i + 3] > 128 // alpha > 128
|
|
||||||
}
|
|
||||||
|
|
||||||
const vertices: number[] = []
|
|
||||||
const indices: number[] = []
|
|
||||||
const uvs: number[] = []
|
|
||||||
const normals: number[] = []
|
|
||||||
|
|
||||||
let vertexIndex = 0
|
|
||||||
|
|
||||||
// Helper to add a vertex
|
|
||||||
const addVertex = (x: number, y: number, z: number, u: number, v: number, nx: number, ny: number, nz: number) => {
|
|
||||||
vertices.push(x, y, z)
|
|
||||||
uvs.push(u, v)
|
|
||||||
normals.push(nx, ny, nz)
|
|
||||||
return vertexIndex++
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper to add a quad (two triangles)
|
|
||||||
const addQuad = (v0: number, v1: number, v2: number, v3: number) => {
|
|
||||||
indices.push(v0, v1, v2, v0, v2, v3)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert pixel coordinates to world coordinates
|
|
||||||
const pixelToWorld = (px: number, py: number) => {
|
|
||||||
const x = (px / w - 0.5) * actualPixelSize * w
|
|
||||||
const y = -(py / h - 0.5) * actualPixelSize * h
|
|
||||||
return { x, y }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a grid of vertices for front and back faces
|
|
||||||
const frontVertices: Array<Array<number | null>> = Array.from({ length: h + 1 }, () => Array.from({ length: w + 1 }, () => null))
|
|
||||||
const backVertices: Array<Array<number | null>> = Array.from({ length: h + 1 }, () => Array.from({ length: w + 1 }, () => null))
|
|
||||||
|
|
||||||
// Create vertices at pixel corners
|
|
||||||
for (let py = 0; py <= h; py++) {
|
|
||||||
for (let px = 0; px <= w; px++) {
|
|
||||||
const { x, y } = pixelToWorld(px - 0.5, py - 0.5)
|
|
||||||
|
|
||||||
// UV coordinates should map to the texture space of the extracted tile
|
|
||||||
const u = px / w
|
|
||||||
const v = py / h
|
|
||||||
|
|
||||||
// Check if this vertex is needed for any face or edge
|
|
||||||
let needVertex = false
|
|
||||||
|
|
||||||
// Check all 4 adjacent pixels to see if any are opaque
|
|
||||||
const adjacentPixels = [
|
|
||||||
[px - 1, py - 1], // top-left pixel
|
|
||||||
[px, py - 1], // top-right pixel
|
|
||||||
[px - 1, py], // bottom-left pixel
|
|
||||||
[px, py] // bottom-right pixel
|
|
||||||
]
|
|
||||||
|
|
||||||
for (const [adjX, adjY] of adjacentPixels) {
|
|
||||||
if (isOpaque(adjX, adjY)) {
|
|
||||||
needVertex = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (needVertex) {
|
|
||||||
frontVertices[py][px] = addVertex(x, y, halfDepth, u, v, 0, 0, 1)
|
|
||||||
backVertices[py][px] = addVertex(x, y, -halfDepth, u, v, 0, 0, -1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create front and back faces
|
|
||||||
for (let py = 0; py < h; py++) {
|
|
||||||
for (let px = 0; px < w; px++) {
|
|
||||||
if (!isOpaque(px, py)) continue
|
|
||||||
|
|
||||||
const v00 = frontVertices[py][px]
|
|
||||||
const v10 = frontVertices[py][px + 1]
|
|
||||||
const v11 = frontVertices[py + 1][px + 1]
|
|
||||||
const v01 = frontVertices[py + 1][px]
|
|
||||||
|
|
||||||
const b00 = backVertices[py][px]
|
|
||||||
const b10 = backVertices[py][px + 1]
|
|
||||||
const b11 = backVertices[py + 1][px + 1]
|
|
||||||
const b01 = backVertices[py + 1][px]
|
|
||||||
|
|
||||||
if (v00 !== null && v10 !== null && v11 !== null && v01 !== null) {
|
|
||||||
// Front face
|
|
||||||
addQuad(v00, v10, v11, v01)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b00 !== null && b10 !== null && b11 !== null && b01 !== null) {
|
|
||||||
// Back face (reversed winding)
|
|
||||||
addQuad(b10, b00, b01, b11)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create edge faces for each side of the pixel with proper UVs
|
|
||||||
for (let py = 0; py < h; py++) {
|
|
||||||
for (let px = 0; px < w; px++) {
|
|
||||||
if (!isOpaque(px, py)) continue
|
|
||||||
|
|
||||||
const pixelU = (px + 0.5) / w // Center of current pixel
|
|
||||||
const pixelV = (py + 0.5) / h
|
|
||||||
|
|
||||||
// Left edge (x = px)
|
|
||||||
if (!isOpaque(px - 1, py)) {
|
|
||||||
const f0 = frontVertices[py][px]
|
|
||||||
const f1 = frontVertices[py + 1][px]
|
|
||||||
const b0 = backVertices[py][px]
|
|
||||||
const b1 = backVertices[py + 1][px]
|
|
||||||
|
|
||||||
if (f0 !== null && f1 !== null && b0 !== null && b1 !== null) {
|
|
||||||
// Create new vertices for edge with current pixel's UV
|
|
||||||
const ef0 = addVertex(vertices[f0 * 3], vertices[f0 * 3 + 1], vertices[f0 * 3 + 2], pixelU, pixelV, -1, 0, 0)
|
|
||||||
const ef1 = addVertex(vertices[f1 * 3], vertices[f1 * 3 + 1], vertices[f1 * 3 + 2], pixelU, pixelV, -1, 0, 0)
|
|
||||||
const eb1 = addVertex(vertices[b1 * 3], vertices[b1 * 3 + 1], vertices[b1 * 3 + 2], pixelU, pixelV, -1, 0, 0)
|
|
||||||
const eb0 = addVertex(vertices[b0 * 3], vertices[b0 * 3 + 1], vertices[b0 * 3 + 2], pixelU, pixelV, -1, 0, 0)
|
|
||||||
addQuad(ef0, ef1, eb1, eb0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Right edge (x = px + 1)
|
|
||||||
if (!isOpaque(px + 1, py)) {
|
|
||||||
const f0 = frontVertices[py + 1][px + 1]
|
|
||||||
const f1 = frontVertices[py][px + 1]
|
|
||||||
const b0 = backVertices[py + 1][px + 1]
|
|
||||||
const b1 = backVertices[py][px + 1]
|
|
||||||
|
|
||||||
if (f0 !== null && f1 !== null && b0 !== null && b1 !== null) {
|
|
||||||
const ef0 = addVertex(vertices[f0 * 3], vertices[f0 * 3 + 1], vertices[f0 * 3 + 2], pixelU, pixelV, 1, 0, 0)
|
|
||||||
const ef1 = addVertex(vertices[f1 * 3], vertices[f1 * 3 + 1], vertices[f1 * 3 + 2], pixelU, pixelV, 1, 0, 0)
|
|
||||||
const eb1 = addVertex(vertices[b1 * 3], vertices[b1 * 3 + 1], vertices[b1 * 3 + 2], pixelU, pixelV, 1, 0, 0)
|
|
||||||
const eb0 = addVertex(vertices[b0 * 3], vertices[b0 * 3 + 1], vertices[b0 * 3 + 2], pixelU, pixelV, 1, 0, 0)
|
|
||||||
addQuad(ef0, ef1, eb1, eb0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Top edge (y = py)
|
|
||||||
if (!isOpaque(px, py - 1)) {
|
|
||||||
const f0 = frontVertices[py][px]
|
|
||||||
const f1 = frontVertices[py][px + 1]
|
|
||||||
const b0 = backVertices[py][px]
|
|
||||||
const b1 = backVertices[py][px + 1]
|
|
||||||
|
|
||||||
if (f0 !== null && f1 !== null && b0 !== null && b1 !== null) {
|
|
||||||
const ef0 = addVertex(vertices[f0 * 3], vertices[f0 * 3 + 1], vertices[f0 * 3 + 2], pixelU, pixelV, 0, -1, 0)
|
|
||||||
const ef1 = addVertex(vertices[f1 * 3], vertices[f1 * 3 + 1], vertices[f1 * 3 + 2], pixelU, pixelV, 0, -1, 0)
|
|
||||||
const eb1 = addVertex(vertices[b1 * 3], vertices[b1 * 3 + 1], vertices[b1 * 3 + 2], pixelU, pixelV, 0, -1, 0)
|
|
||||||
const eb0 = addVertex(vertices[b0 * 3], vertices[b0 * 3 + 1], vertices[b0 * 3 + 2], pixelU, pixelV, 0, -1, 0)
|
|
||||||
addQuad(ef0, ef1, eb1, eb0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bottom edge (y = py + 1)
|
|
||||||
if (!isOpaque(px, py + 1)) {
|
|
||||||
const f0 = frontVertices[py + 1][px + 1]
|
|
||||||
const f1 = frontVertices[py + 1][px]
|
|
||||||
const b0 = backVertices[py + 1][px + 1]
|
|
||||||
const b1 = backVertices[py + 1][px]
|
|
||||||
|
|
||||||
if (f0 !== null && f1 !== null && b0 !== null && b1 !== null) {
|
|
||||||
const ef0 = addVertex(vertices[f0 * 3], vertices[f0 * 3 + 1], vertices[f0 * 3 + 2], pixelU, pixelV, 0, 1, 0)
|
|
||||||
const ef1 = addVertex(vertices[f1 * 3], vertices[f1 * 3 + 1], vertices[f1 * 3 + 2], pixelU, pixelV, 0, 1, 0)
|
|
||||||
const eb1 = addVertex(vertices[b1 * 3], vertices[b1 * 3 + 1], vertices[b1 * 3 + 2], pixelU, pixelV, 0, 1, 0)
|
|
||||||
const eb0 = addVertex(vertices[b0 * 3], vertices[b0 * 3 + 1], vertices[b0 * 3 + 2], pixelU, pixelV, 0, 1, 0)
|
|
||||||
addQuad(ef0, ef1, eb1, eb0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const geometry = new THREE.BufferGeometry()
|
|
||||||
geometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3))
|
|
||||||
geometry.setAttribute('uv', new THREE.Float32BufferAttribute(uvs, 2))
|
|
||||||
geometry.setAttribute('normal', new THREE.Float32BufferAttribute(normals, 3))
|
|
||||||
geometry.setIndex(indices)
|
|
||||||
|
|
||||||
// Compute normals properly
|
|
||||||
geometry.computeVertexNormals()
|
|
||||||
|
|
||||||
return {
|
|
||||||
geometry,
|
|
||||||
totalVertices: vertexIndex,
|
|
||||||
totalTriangles: indices.length / 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ItemTextureInfo {
|
|
||||||
u: number
|
|
||||||
v: number
|
|
||||||
sizeX: number
|
|
||||||
sizeY: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ItemMeshResult {
|
|
||||||
mesh: THREE.Object3D
|
|
||||||
itemsTexture?: THREE.Texture
|
|
||||||
itemsTextureFlipped?: THREE.Texture
|
|
||||||
cleanup?: () => void
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extracts item texture region to a canvas
|
|
||||||
*/
|
|
||||||
export function extractItemTextureToCanvas (
|
|
||||||
sourceTexture: THREE.Texture,
|
|
||||||
textureInfo: ItemTextureInfo
|
|
||||||
): HTMLCanvasElement {
|
|
||||||
const { u, v, sizeX, sizeY } = textureInfo
|
|
||||||
|
|
||||||
// Calculate canvas size - fix the calculation
|
|
||||||
const canvasWidth = Math.max(1, Math.floor(sizeX * sourceTexture.image.width))
|
|
||||||
const canvasHeight = Math.max(1, Math.floor(sizeY * sourceTexture.image.height))
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas')
|
|
||||||
canvas.width = canvasWidth
|
|
||||||
canvas.height = canvasHeight
|
|
||||||
|
|
||||||
const ctx = canvas.getContext('2d')!
|
|
||||||
ctx.imageSmoothingEnabled = false
|
|
||||||
|
|
||||||
// Draw the item texture region to canvas
|
|
||||||
ctx.drawImage(
|
|
||||||
sourceTexture.image,
|
|
||||||
u * sourceTexture.image.width,
|
|
||||||
v * sourceTexture.image.height,
|
|
||||||
sizeX * sourceTexture.image.width,
|
|
||||||
sizeY * sourceTexture.image.height,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
canvas.width,
|
|
||||||
canvas.height
|
|
||||||
)
|
|
||||||
|
|
||||||
return canvas
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates either a 2D or 3D item mesh based on parameters
|
|
||||||
*/
|
|
||||||
export function createItemMesh (
|
|
||||||
sourceTexture: THREE.Texture,
|
|
||||||
textureInfo: ItemTextureInfo,
|
|
||||||
options: {
|
|
||||||
faceCamera?: boolean
|
|
||||||
use3D?: boolean
|
|
||||||
depth?: number
|
|
||||||
} = {}
|
|
||||||
): ItemMeshResult {
|
|
||||||
const { faceCamera = false, use3D = true, depth = 0.04 } = options
|
|
||||||
const { u, v, sizeX, sizeY } = textureInfo
|
|
||||||
|
|
||||||
if (faceCamera) {
|
|
||||||
// Create sprite for camera-facing items
|
|
||||||
const itemsTexture = sourceTexture.clone()
|
|
||||||
itemsTexture.flipY = true
|
|
||||||
itemsTexture.offset.set(u, 1 - v - sizeY)
|
|
||||||
itemsTexture.repeat.set(sizeX, sizeY)
|
|
||||||
itemsTexture.needsUpdate = true
|
|
||||||
itemsTexture.magFilter = THREE.NearestFilter
|
|
||||||
itemsTexture.minFilter = THREE.NearestFilter
|
|
||||||
|
|
||||||
const spriteMat = new THREE.SpriteMaterial({
|
|
||||||
map: itemsTexture,
|
|
||||||
transparent: true,
|
|
||||||
alphaTest: 0.1,
|
|
||||||
})
|
|
||||||
const mesh = new THREE.Sprite(spriteMat)
|
|
||||||
|
|
||||||
return {
|
|
||||||
mesh,
|
|
||||||
itemsTexture,
|
|
||||||
cleanup () {
|
|
||||||
itemsTexture.dispose()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (use3D) {
|
|
||||||
// Try to create 3D mesh
|
|
||||||
try {
|
|
||||||
const canvas = extractItemTextureToCanvas(sourceTexture, textureInfo)
|
|
||||||
const { geometry } = create3DItemMesh(canvas, { depth })
|
|
||||||
|
|
||||||
// Create texture from canvas for the 3D mesh
|
|
||||||
const itemsTexture = new THREE.CanvasTexture(canvas)
|
|
||||||
itemsTexture.magFilter = THREE.NearestFilter
|
|
||||||
itemsTexture.minFilter = THREE.NearestFilter
|
|
||||||
itemsTexture.wrapS = itemsTexture.wrapT = THREE.ClampToEdgeWrapping
|
|
||||||
itemsTexture.flipY = false
|
|
||||||
itemsTexture.needsUpdate = true
|
|
||||||
|
|
||||||
const material = new THREE.MeshStandardMaterial({
|
|
||||||
map: itemsTexture,
|
|
||||||
side: THREE.DoubleSide,
|
|
||||||
transparent: true,
|
|
||||||
alphaTest: 0.1,
|
|
||||||
})
|
|
||||||
|
|
||||||
const mesh = new THREE.Mesh(geometry, material)
|
|
||||||
|
|
||||||
return {
|
|
||||||
mesh,
|
|
||||||
itemsTexture,
|
|
||||||
cleanup () {
|
|
||||||
itemsTexture.dispose()
|
|
||||||
geometry.dispose()
|
|
||||||
if (material.map) material.map.dispose()
|
|
||||||
material.dispose()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.warn('Failed to create 3D item mesh, falling back to 2D:', error)
|
|
||||||
// Fall through to 2D rendering
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to 2D flat rendering
|
|
||||||
const itemsTexture = sourceTexture.clone()
|
|
||||||
itemsTexture.flipY = true
|
|
||||||
itemsTexture.offset.set(u, 1 - v - sizeY)
|
|
||||||
itemsTexture.repeat.set(sizeX, sizeY)
|
|
||||||
itemsTexture.needsUpdate = true
|
|
||||||
itemsTexture.magFilter = THREE.NearestFilter
|
|
||||||
itemsTexture.minFilter = THREE.NearestFilter
|
|
||||||
|
|
||||||
const itemsTextureFlipped = itemsTexture.clone()
|
|
||||||
itemsTextureFlipped.repeat.x *= -1
|
|
||||||
itemsTextureFlipped.needsUpdate = true
|
|
||||||
itemsTextureFlipped.offset.set(u + sizeX, 1 - v - sizeY)
|
|
||||||
|
|
||||||
const material = new THREE.MeshStandardMaterial({
|
|
||||||
map: itemsTexture,
|
|
||||||
transparent: true,
|
|
||||||
alphaTest: 0.1,
|
|
||||||
})
|
|
||||||
const materialFlipped = new THREE.MeshStandardMaterial({
|
|
||||||
map: itemsTextureFlipped,
|
|
||||||
transparent: true,
|
|
||||||
alphaTest: 0.1,
|
|
||||||
})
|
|
||||||
const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 0), [
|
|
||||||
new THREE.MeshBasicMaterial({ color: 0x00_00_00 }), new THREE.MeshBasicMaterial({ color: 0x00_00_00 }),
|
|
||||||
new THREE.MeshBasicMaterial({ color: 0x00_00_00 }), new THREE.MeshBasicMaterial({ color: 0x00_00_00 }),
|
|
||||||
material, materialFlipped,
|
|
||||||
])
|
|
||||||
|
|
||||||
return {
|
|
||||||
mesh,
|
|
||||||
itemsTexture,
|
|
||||||
itemsTextureFlipped,
|
|
||||||
cleanup () {
|
|
||||||
itemsTexture.dispose()
|
|
||||||
itemsTextureFlipped.dispose()
|
|
||||||
material.dispose()
|
|
||||||
materialFlipped.dispose()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a complete 3D item mesh from a canvas texture
|
|
||||||
*/
|
|
||||||
export function createItemMeshFromCanvas (
|
|
||||||
canvas: HTMLCanvasElement,
|
|
||||||
options: Create3DItemMeshOptions
|
|
||||||
): THREE.Mesh {
|
|
||||||
const { geometry } = create3DItemMesh(canvas, options)
|
|
||||||
|
|
||||||
// Base color texture for the item
|
|
||||||
const colorTexture = new THREE.CanvasTexture(canvas)
|
|
||||||
colorTexture.magFilter = THREE.NearestFilter
|
|
||||||
colorTexture.minFilter = THREE.NearestFilter
|
|
||||||
colorTexture.wrapS = colorTexture.wrapT = THREE.ClampToEdgeWrapping
|
|
||||||
colorTexture.flipY = false // Important for canvas textures
|
|
||||||
colorTexture.needsUpdate = true
|
|
||||||
|
|
||||||
// Material - no transparency, no alpha test needed for edges
|
|
||||||
const material = new THREE.MeshBasicMaterial({
|
|
||||||
map: colorTexture,
|
|
||||||
side: THREE.DoubleSide,
|
|
||||||
transparent: true,
|
|
||||||
alphaTest: 0.1
|
|
||||||
})
|
|
||||||
|
|
||||||
return new THREE.Mesh(geometry, material)
|
|
||||||
}
|
|
||||||
|
|
@ -7,13 +7,12 @@ import type { GraphicsInitOptions } from '../../../src/appViewer'
|
||||||
import { WorldDataEmitter } from '../lib/worldDataEmitter'
|
import { WorldDataEmitter } from '../lib/worldDataEmitter'
|
||||||
import { defaultWorldRendererConfig, WorldRendererCommon } from '../lib/worldrendererCommon'
|
import { defaultWorldRendererConfig, WorldRendererCommon } from '../lib/worldrendererCommon'
|
||||||
import { getDefaultRendererState } from '../baseGraphicsBackend'
|
import { getDefaultRendererState } from '../baseGraphicsBackend'
|
||||||
|
import { loadThreeJsTextureFromUrl, loadThreeJsTextureFromUrlSync } from '../lib/utils/skins'
|
||||||
import { ResourcesManager } from '../../../src/resourcesManager'
|
import { ResourcesManager } from '../../../src/resourcesManager'
|
||||||
import { getInitialPlayerStateRenderer } from '../lib/basePlayerState'
|
import { getInitialPlayerStateRenderer } from '../lib/basePlayerState'
|
||||||
import { loadThreeJsTextureFromUrl, loadThreeJsTextureFromUrlSync } from './threeJsUtils'
|
|
||||||
import { WorldRendererThree } from './worldrendererThree'
|
import { WorldRendererThree } from './worldrendererThree'
|
||||||
import { EntityMesh } from './entity/EntityMesh'
|
import { EntityMesh } from './entity/EntityMesh'
|
||||||
import { DocumentRenderer } from './documentRenderer'
|
import { DocumentRenderer } from './documentRenderer'
|
||||||
import { PANORAMA_VERSION } from './panoramaShared'
|
|
||||||
|
|
||||||
const panoramaFiles = [
|
const panoramaFiles = [
|
||||||
'panorama_3.png', // right (+x)
|
'panorama_3.png', // right (+x)
|
||||||
|
|
@ -157,7 +156,7 @@ export class PanoramaRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
async worldBlocksPanorama () {
|
async worldBlocksPanorama () {
|
||||||
const version = PANORAMA_VERSION
|
const version = '1.21.4'
|
||||||
const fullResourceManager = this.options.resourcesManager as ResourcesManager
|
const fullResourceManager = this.options.resourcesManager as ResourcesManager
|
||||||
fullResourceManager.currentConfig = { version, noInventoryGui: true, }
|
fullResourceManager.currentConfig = { version, noInventoryGui: true, }
|
||||||
await fullResourceManager.updateAssetsData({ })
|
await fullResourceManager.updateAssetsData({ })
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
export const PANORAMA_VERSION = '1.21.4'
|
|
||||||
|
|
@ -10,11 +10,11 @@ export type ResolvedItemModelRender = {
|
||||||
|
|
||||||
export const renderSlot = (model: ResolvedItemModelRender, resourcesManager: ResourcesManagerCommon, debugIsQuickbar = false, fullBlockModelSupport = false): {
|
export const renderSlot = (model: ResolvedItemModelRender, resourcesManager: ResourcesManagerCommon, debugIsQuickbar = false, fullBlockModelSupport = false): {
|
||||||
texture: string,
|
texture: string,
|
||||||
blockData: Record<string, { slice, path }> & { resolvedModel: BlockModel } | null,
|
blockData?: Record<string, { slice, path }> & { resolvedModel: BlockModel },
|
||||||
scale: number | null,
|
scale?: number,
|
||||||
slice: number[] | null,
|
slice?: number[],
|
||||||
modelName: string | null,
|
modelName?: string,
|
||||||
} => {
|
} | undefined => {
|
||||||
let itemModelName = model.modelName
|
let itemModelName = model.modelName
|
||||||
const isItem = loadedData.itemsByName[itemModelName]
|
const isItem = loadedData.itemsByName[itemModelName]
|
||||||
|
|
||||||
|
|
@ -37,8 +37,6 @@ export const renderSlot = (model: ResolvedItemModelRender, resourcesManager: Res
|
||||||
texture: 'gui',
|
texture: 'gui',
|
||||||
slice: [x, y, atlas.tileSize, atlas.tileSize],
|
slice: [x, y, atlas.tileSize, atlas.tileSize],
|
||||||
scale: 0.25,
|
scale: 0.25,
|
||||||
blockData: null,
|
|
||||||
modelName: null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -65,18 +63,14 @@ export const renderSlot = (model: ResolvedItemModelRender, resourcesManager: Res
|
||||||
return {
|
return {
|
||||||
texture: itemTexture.type,
|
texture: itemTexture.type,
|
||||||
slice: itemTexture.slice,
|
slice: itemTexture.slice,
|
||||||
modelName: itemModelName,
|
modelName: itemModelName
|
||||||
blockData: null,
|
|
||||||
scale: null
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// is block
|
// is block
|
||||||
return {
|
return {
|
||||||
texture: 'blocks',
|
texture: 'blocks',
|
||||||
blockData: itemTexture,
|
blockData: itemTexture,
|
||||||
modelName: itemModelName,
|
modelName: itemModelName
|
||||||
slice: null,
|
|
||||||
scale: null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,406 +0,0 @@
|
||||||
import * as THREE from 'three'
|
|
||||||
import { DebugGui } from '../lib/DebugGui'
|
|
||||||
|
|
||||||
export const DEFAULT_TEMPERATURE = 0.75
|
|
||||||
|
|
||||||
export class SkyboxRenderer {
|
|
||||||
private texture: THREE.Texture | null = null
|
|
||||||
private mesh: THREE.Mesh<THREE.SphereGeometry, THREE.MeshBasicMaterial> | null = null
|
|
||||||
private skyMesh: THREE.Mesh | null = null
|
|
||||||
private voidMesh: THREE.Mesh | null = null
|
|
||||||
|
|
||||||
// World state
|
|
||||||
private worldTime = 0
|
|
||||||
private partialTicks = 0
|
|
||||||
private viewDistance = 4
|
|
||||||
private temperature = DEFAULT_TEMPERATURE
|
|
||||||
private inWater = false
|
|
||||||
private waterBreathing = false
|
|
||||||
private fogBrightness = 0
|
|
||||||
private prevFogBrightness = 0
|
|
||||||
private readonly fogOrangeness = 0 // Debug property to control sky color orangeness
|
|
||||||
private readonly distanceFactor = 2.7
|
|
||||||
|
|
||||||
private readonly brightnessAtPosition = 1
|
|
||||||
debugGui: DebugGui
|
|
||||||
|
|
||||||
constructor (private readonly scene: THREE.Scene, public defaultSkybox: boolean, public initialImage: string | null) {
|
|
||||||
this.debugGui = new DebugGui('skybox_renderer', this, [
|
|
||||||
'temperature',
|
|
||||||
'worldTime',
|
|
||||||
'inWater',
|
|
||||||
'waterBreathing',
|
|
||||||
'fogOrangeness',
|
|
||||||
'brightnessAtPosition',
|
|
||||||
'distanceFactor'
|
|
||||||
], {
|
|
||||||
brightnessAtPosition: { min: 0, max: 1, step: 0.01 },
|
|
||||||
temperature: { min: 0, max: 1, step: 0.01 },
|
|
||||||
worldTime: { min: 0, max: 24_000, step: 1 },
|
|
||||||
fogOrangeness: { min: -1, max: 1, step: 0.01 },
|
|
||||||
distanceFactor: { min: 0, max: 5, step: 0.01 },
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!initialImage) {
|
|
||||||
this.createGradientSky()
|
|
||||||
}
|
|
||||||
// this.debugGui.activate()
|
|
||||||
}
|
|
||||||
|
|
||||||
async init () {
|
|
||||||
if (this.initialImage) {
|
|
||||||
await this.setSkyboxImage(this.initialImage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async setSkyboxImage (imageUrl: string) {
|
|
||||||
// Dispose old textures if they exist
|
|
||||||
if (this.texture) {
|
|
||||||
this.texture.dispose()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the equirectangular texture
|
|
||||||
const textureLoader = new THREE.TextureLoader()
|
|
||||||
this.texture = await new Promise((resolve) => {
|
|
||||||
textureLoader.load(
|
|
||||||
imageUrl,
|
|
||||||
(texture) => {
|
|
||||||
texture.mapping = THREE.EquirectangularReflectionMapping
|
|
||||||
texture.encoding = THREE.sRGBEncoding
|
|
||||||
// Keep pixelated look
|
|
||||||
texture.minFilter = THREE.NearestFilter
|
|
||||||
texture.magFilter = THREE.NearestFilter
|
|
||||||
texture.needsUpdate = true
|
|
||||||
resolve(texture)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Create or update the skybox
|
|
||||||
if (this.mesh) {
|
|
||||||
// Just update the texture on the existing material
|
|
||||||
this.mesh.material.map = this.texture
|
|
||||||
this.mesh.material.needsUpdate = true
|
|
||||||
} else {
|
|
||||||
// Create a large sphere geometry for the skybox
|
|
||||||
const geometry = new THREE.SphereGeometry(500, 60, 40)
|
|
||||||
// Flip the geometry inside out
|
|
||||||
geometry.scale(-1, 1, 1)
|
|
||||||
|
|
||||||
// Create material using the loaded texture
|
|
||||||
const material = new THREE.MeshBasicMaterial({
|
|
||||||
map: this.texture,
|
|
||||||
side: THREE.FrontSide // Changed to FrontSide since we're flipping the geometry
|
|
||||||
})
|
|
||||||
|
|
||||||
// Create and add the skybox mesh
|
|
||||||
this.mesh = new THREE.Mesh(geometry, material)
|
|
||||||
this.scene.add(this.mesh)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
update (cameraPosition: THREE.Vector3, newViewDistance: number) {
|
|
||||||
if (newViewDistance !== this.viewDistance) {
|
|
||||||
this.viewDistance = newViewDistance
|
|
||||||
this.updateSkyColors()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.mesh) {
|
|
||||||
// Update skybox position
|
|
||||||
this.mesh.position.copy(cameraPosition)
|
|
||||||
} else if (this.skyMesh) {
|
|
||||||
// Update gradient sky position
|
|
||||||
this.skyMesh.position.copy(cameraPosition)
|
|
||||||
this.voidMesh?.position.copy(cameraPosition)
|
|
||||||
this.updateSkyColors() // Update colors based on time of day
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update world time
|
|
||||||
updateTime (timeOfDay: number, partialTicks = 0) {
|
|
||||||
if (this.debugGui.visible) return
|
|
||||||
this.worldTime = timeOfDay
|
|
||||||
this.partialTicks = partialTicks
|
|
||||||
this.updateSkyColors()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update view distance
|
|
||||||
updateViewDistance (viewDistance: number) {
|
|
||||||
this.viewDistance = viewDistance
|
|
||||||
this.updateSkyColors()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update temperature (for biome support)
|
|
||||||
updateTemperature (temperature: number) {
|
|
||||||
if (this.debugGui.visible) return
|
|
||||||
this.temperature = temperature
|
|
||||||
this.updateSkyColors()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update water state
|
|
||||||
updateWaterState (inWater: boolean, waterBreathing: boolean) {
|
|
||||||
if (this.debugGui.visible) return
|
|
||||||
this.inWater = inWater
|
|
||||||
this.waterBreathing = waterBreathing
|
|
||||||
this.updateSkyColors()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update default skybox setting
|
|
||||||
updateDefaultSkybox (defaultSkybox: boolean) {
|
|
||||||
if (this.debugGui.visible) return
|
|
||||||
this.defaultSkybox = defaultSkybox
|
|
||||||
this.updateSkyColors()
|
|
||||||
}
|
|
||||||
|
|
||||||
private createGradientSky () {
|
|
||||||
const size = 64
|
|
||||||
const scale = 256 / size + 2
|
|
||||||
|
|
||||||
{
|
|
||||||
const geometry = new THREE.PlaneGeometry(size * scale * 2, size * scale * 2)
|
|
||||||
geometry.rotateX(-Math.PI / 2)
|
|
||||||
geometry.translate(0, 16, 0)
|
|
||||||
|
|
||||||
const material = new THREE.MeshBasicMaterial({
|
|
||||||
color: 0xff_ff_ff,
|
|
||||||
side: THREE.DoubleSide,
|
|
||||||
depthTest: false
|
|
||||||
})
|
|
||||||
|
|
||||||
this.skyMesh = new THREE.Mesh(geometry, material)
|
|
||||||
this.scene.add(this.skyMesh)
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const geometry = new THREE.PlaneGeometry(size * scale * 2, size * scale * 2)
|
|
||||||
geometry.rotateX(-Math.PI / 2)
|
|
||||||
geometry.translate(0, -16, 0)
|
|
||||||
|
|
||||||
const material = new THREE.MeshBasicMaterial({
|
|
||||||
color: 0xff_ff_ff,
|
|
||||||
side: THREE.DoubleSide,
|
|
||||||
depthTest: false
|
|
||||||
})
|
|
||||||
|
|
||||||
this.voidMesh = new THREE.Mesh(geometry, material)
|
|
||||||
this.scene.add(this.voidMesh)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateSkyColors()
|
|
||||||
}
|
|
||||||
|
|
||||||
private getFogColor (partialTicks = 0): THREE.Vector3 {
|
|
||||||
const angle = this.getCelestialAngle(partialTicks)
|
|
||||||
let rotation = Math.cos(angle * Math.PI * 2) * 2 + 0.5
|
|
||||||
rotation = Math.max(0, Math.min(1, rotation))
|
|
||||||
|
|
||||||
let x = 0.752_941_2
|
|
||||||
let y = 0.847_058_83
|
|
||||||
let z = 1
|
|
||||||
|
|
||||||
x *= (rotation * 0.94 + 0.06)
|
|
||||||
y *= (rotation * 0.94 + 0.06)
|
|
||||||
z *= (rotation * 0.91 + 0.09)
|
|
||||||
|
|
||||||
return new THREE.Vector3(x, y, z)
|
|
||||||
}
|
|
||||||
|
|
||||||
private getSkyColor (x = 0, z = 0, partialTicks = 0): THREE.Vector3 {
|
|
||||||
const angle = this.getCelestialAngle(partialTicks)
|
|
||||||
let brightness = Math.cos(angle * 3.141_593 * 2) * 2 + 0.5
|
|
||||||
|
|
||||||
if (brightness < 0) brightness = 0
|
|
||||||
if (brightness > 1) brightness = 1
|
|
||||||
|
|
||||||
const temperature = this.getTemperature(x, z)
|
|
||||||
const rgb = this.getSkyColorByTemp(temperature)
|
|
||||||
|
|
||||||
const red = ((rgb >> 16) & 0xff) / 255
|
|
||||||
const green = ((rgb >> 8) & 0xff) / 255
|
|
||||||
const blue = (rgb & 0xff) / 255
|
|
||||||
|
|
||||||
return new THREE.Vector3(
|
|
||||||
red * brightness,
|
|
||||||
green * brightness,
|
|
||||||
blue * brightness
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private calculateCelestialAngle (time: number, partialTicks: number): number {
|
|
||||||
const modTime = (time % 24_000)
|
|
||||||
let angle = (modTime + partialTicks) / 24_000 - 0.25
|
|
||||||
|
|
||||||
if (angle < 0) {
|
|
||||||
angle++
|
|
||||||
}
|
|
||||||
if (angle > 1) {
|
|
||||||
angle--
|
|
||||||
}
|
|
||||||
|
|
||||||
angle = 1 - ((Math.cos(angle * Math.PI) + 1) / 2)
|
|
||||||
angle += (angle - angle) / 3
|
|
||||||
|
|
||||||
return angle
|
|
||||||
}
|
|
||||||
|
|
||||||
private getCelestialAngle (partialTicks: number): number {
|
|
||||||
return this.calculateCelestialAngle(this.worldTime, partialTicks)
|
|
||||||
}
|
|
||||||
|
|
||||||
private getTemperature (x: number, z: number): number {
|
|
||||||
return this.temperature
|
|
||||||
}
|
|
||||||
|
|
||||||
private getSkyColorByTemp (temperature: number): number {
|
|
||||||
temperature /= 3
|
|
||||||
if (temperature < -1) temperature = -1
|
|
||||||
if (temperature > 1) temperature = 1
|
|
||||||
|
|
||||||
// Apply debug fog orangeness to hue - positive values make it more orange, negative make it less orange
|
|
||||||
const baseHue = 0.622_222_2 - temperature * 0.05
|
|
||||||
// Orange is around hue 0.08-0.15, so we need to shift from blue-purple (0.62) toward orange
|
|
||||||
// Use a more dramatic shift and also increase saturation for more noticeable effect
|
|
||||||
const orangeHue = 0.12 // Orange hue value
|
|
||||||
const hue = this.fogOrangeness > 0
|
|
||||||
? baseHue + (orangeHue - baseHue) * this.fogOrangeness * 0.8 // Blend toward orange
|
|
||||||
: baseHue + this.fogOrangeness * 0.1 // Subtle shift for negative values
|
|
||||||
const saturation = 0.5 + temperature * 0.1 + Math.abs(this.fogOrangeness) * 0.3 // Increase saturation with orangeness
|
|
||||||
const brightness = 1
|
|
||||||
|
|
||||||
return this.hsbToRgb(hue, saturation, brightness)
|
|
||||||
}
|
|
||||||
|
|
||||||
private hsbToRgb (hue: number, saturation: number, brightness: number): number {
|
|
||||||
let r = 0; let g = 0; let b = 0
|
|
||||||
if (saturation === 0) {
|
|
||||||
r = g = b = Math.floor(brightness * 255 + 0.5)
|
|
||||||
} else {
|
|
||||||
const h = (hue - Math.floor(hue)) * 6
|
|
||||||
const f = h - Math.floor(h)
|
|
||||||
const p = brightness * (1 - saturation)
|
|
||||||
const q = brightness * (1 - saturation * f)
|
|
||||||
const t = brightness * (1 - (saturation * (1 - f)))
|
|
||||||
switch (Math.floor(h)) {
|
|
||||||
case 0:
|
|
||||||
r = Math.floor(brightness * 255 + 0.5)
|
|
||||||
g = Math.floor(t * 255 + 0.5)
|
|
||||||
b = Math.floor(p * 255 + 0.5)
|
|
||||||
break
|
|
||||||
case 1:
|
|
||||||
r = Math.floor(q * 255 + 0.5)
|
|
||||||
g = Math.floor(brightness * 255 + 0.5)
|
|
||||||
b = Math.floor(p * 255 + 0.5)
|
|
||||||
break
|
|
||||||
case 2:
|
|
||||||
r = Math.floor(p * 255 + 0.5)
|
|
||||||
g = Math.floor(brightness * 255 + 0.5)
|
|
||||||
b = Math.floor(t * 255 + 0.5)
|
|
||||||
break
|
|
||||||
case 3:
|
|
||||||
r = Math.floor(p * 255 + 0.5)
|
|
||||||
g = Math.floor(q * 255 + 0.5)
|
|
||||||
b = Math.floor(brightness * 255 + 0.5)
|
|
||||||
break
|
|
||||||
case 4:
|
|
||||||
r = Math.floor(t * 255 + 0.5)
|
|
||||||
g = Math.floor(p * 255 + 0.5)
|
|
||||||
b = Math.floor(brightness * 255 + 0.5)
|
|
||||||
break
|
|
||||||
case 5:
|
|
||||||
r = Math.floor(brightness * 255 + 0.5)
|
|
||||||
g = Math.floor(p * 255 + 0.5)
|
|
||||||
b = Math.floor(q * 255 + 0.5)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0xff_00_00_00 | (r << 16) | (g << 8) | (Math.trunc(b))
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateSkyColors () {
|
|
||||||
if (!this.skyMesh || !this.voidMesh) return
|
|
||||||
|
|
||||||
// If default skybox is disabled, hide the skybox meshes
|
|
||||||
if (!this.defaultSkybox) {
|
|
||||||
this.skyMesh.visible = false
|
|
||||||
this.voidMesh.visible = false
|
|
||||||
if (this.mesh) {
|
|
||||||
this.mesh.visible = false
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show skybox meshes when default skybox is enabled
|
|
||||||
this.skyMesh.visible = true
|
|
||||||
this.voidMesh.visible = true
|
|
||||||
if (this.mesh) {
|
|
||||||
this.mesh.visible = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update fog brightness with smooth transition
|
|
||||||
this.prevFogBrightness = this.fogBrightness
|
|
||||||
const renderDistance = this.viewDistance / 32
|
|
||||||
const targetBrightness = this.brightnessAtPosition * (1 - renderDistance) + renderDistance
|
|
||||||
this.fogBrightness += (targetBrightness - this.fogBrightness) * 0.1
|
|
||||||
|
|
||||||
// Handle water fog
|
|
||||||
if (this.inWater) {
|
|
||||||
const waterViewDistance = this.waterBreathing ? 100 : 5
|
|
||||||
this.scene.fog = new THREE.Fog(new THREE.Color(0, 0, 1), 0.0025, waterViewDistance)
|
|
||||||
this.scene.background = new THREE.Color(0, 0, 1)
|
|
||||||
|
|
||||||
// Update sky and void colors for underwater effect
|
|
||||||
;(this.skyMesh.material as THREE.MeshBasicMaterial).color.set(new THREE.Color(0, 0, 1))
|
|
||||||
;(this.voidMesh.material as THREE.MeshBasicMaterial).color.set(new THREE.Color(0, 0, 0.6))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Normal sky colors
|
|
||||||
const viewDistance = this.viewDistance * 16
|
|
||||||
const viewFactor = 1 - (0.25 + 0.75 * this.viewDistance / 32) ** 0.25
|
|
||||||
|
|
||||||
const angle = this.getCelestialAngle(this.partialTicks)
|
|
||||||
const skyColor = this.getSkyColor(0, 0, this.partialTicks)
|
|
||||||
const fogColor = this.getFogColor(this.partialTicks)
|
|
||||||
|
|
||||||
const brightness = Math.cos(angle * Math.PI * 2) * 2 + 0.5
|
|
||||||
const clampedBrightness = Math.max(0, Math.min(1, brightness))
|
|
||||||
|
|
||||||
// Interpolate fog brightness
|
|
||||||
const interpolatedBrightness = this.prevFogBrightness + (this.fogBrightness - this.prevFogBrightness) * this.partialTicks
|
|
||||||
|
|
||||||
const red = (fogColor.x + (skyColor.x - fogColor.x) * viewFactor) * clampedBrightness * interpolatedBrightness
|
|
||||||
const green = (fogColor.y + (skyColor.y - fogColor.y) * viewFactor) * clampedBrightness * interpolatedBrightness
|
|
||||||
const blue = (fogColor.z + (skyColor.z - fogColor.z) * viewFactor) * clampedBrightness * interpolatedBrightness
|
|
||||||
|
|
||||||
this.scene.background = new THREE.Color(red, green, blue)
|
|
||||||
this.scene.fog = new THREE.Fog(new THREE.Color(red, green, blue), 0.0025, viewDistance * this.distanceFactor)
|
|
||||||
|
|
||||||
;(this.skyMesh.material as THREE.MeshBasicMaterial).color.set(new THREE.Color(skyColor.x, skyColor.y, skyColor.z))
|
|
||||||
;(this.voidMesh.material as THREE.MeshBasicMaterial).color.set(new THREE.Color(
|
|
||||||
skyColor.x * 0.2 + 0.04,
|
|
||||||
skyColor.y * 0.2 + 0.04,
|
|
||||||
skyColor.z * 0.6 + 0.1
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
dispose () {
|
|
||||||
if (this.texture) {
|
|
||||||
this.texture.dispose()
|
|
||||||
}
|
|
||||||
if (this.mesh) {
|
|
||||||
this.mesh.geometry.dispose()
|
|
||||||
;(this.mesh.material as THREE.Material).dispose()
|
|
||||||
this.scene.remove(this.mesh)
|
|
||||||
}
|
|
||||||
if (this.skyMesh) {
|
|
||||||
this.skyMesh.geometry.dispose()
|
|
||||||
;(this.skyMesh.material as THREE.Material).dispose()
|
|
||||||
this.scene.remove(this.skyMesh)
|
|
||||||
}
|
|
||||||
if (this.voidMesh) {
|
|
||||||
this.voidMesh.geometry.dispose()
|
|
||||||
;(this.voidMesh.material as THREE.Material).dispose()
|
|
||||||
this.scene.remove(this.voidMesh)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,7 @@ import * as THREE from 'three'
|
||||||
import { WorldRendererThree } from './worldrendererThree'
|
import { WorldRendererThree } from './worldrendererThree'
|
||||||
|
|
||||||
export interface SoundSystem {
|
export interface SoundSystem {
|
||||||
playSound: (position: { x: number, y: number, z: number }, path: string, volume?: number, pitch?: number, timeout?: number) => void
|
playSound: (position: { x: number, y: number, z: number }, path: string, volume?: number, pitch?: number) => void
|
||||||
destroy: () => void
|
destroy: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -10,17 +10,7 @@ export class ThreeJsSound implements SoundSystem {
|
||||||
audioListener: THREE.AudioListener | undefined
|
audioListener: THREE.AudioListener | undefined
|
||||||
private readonly activeSounds = new Set<THREE.PositionalAudio>()
|
private readonly activeSounds = new Set<THREE.PositionalAudio>()
|
||||||
private readonly audioContext: AudioContext | undefined
|
private readonly audioContext: AudioContext | undefined
|
||||||
private readonly soundVolumes = new Map<THREE.PositionalAudio, number>()
|
|
||||||
baseVolume = 1
|
|
||||||
|
|
||||||
constructor (public worldRenderer: WorldRendererThree) {
|
constructor (public worldRenderer: WorldRendererThree) {
|
||||||
worldRenderer.onWorldSwitched.push(() => {
|
|
||||||
this.stopAll()
|
|
||||||
})
|
|
||||||
|
|
||||||
worldRenderer.onReactiveConfigUpdated('volume', (volume) => {
|
|
||||||
this.changeVolume(volume)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initAudioListener () {
|
initAudioListener () {
|
||||||
|
|
@ -29,24 +19,20 @@ export class ThreeJsSound implements SoundSystem {
|
||||||
this.worldRenderer.camera.add(this.audioListener)
|
this.worldRenderer.camera.add(this.audioListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
playSound (position: { x: number, y: number, z: number }, path: string, volume = 1, pitch = 1, timeout = 500) {
|
playSound (position: { x: number, y: number, z: number }, path: string, volume = 1, pitch = 1) {
|
||||||
this.initAudioListener()
|
this.initAudioListener()
|
||||||
|
|
||||||
const sound = new THREE.PositionalAudio(this.audioListener!)
|
const sound = new THREE.PositionalAudio(this.audioListener!)
|
||||||
this.activeSounds.add(sound)
|
this.activeSounds.add(sound)
|
||||||
this.soundVolumes.set(sound, volume)
|
|
||||||
|
|
||||||
const audioLoader = new THREE.AudioLoader()
|
const audioLoader = new THREE.AudioLoader()
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
void audioLoader.loadAsync(path).then((buffer) => {
|
void audioLoader.loadAsync(path).then((buffer) => {
|
||||||
if (Date.now() - start > timeout) {
|
if (Date.now() - start > 500) return
|
||||||
console.warn('Ignored playing sound', path, 'due to timeout:', timeout, 'ms <', Date.now() - start, 'ms')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// play
|
// play
|
||||||
sound.setBuffer(buffer)
|
sound.setBuffer(buffer)
|
||||||
sound.setRefDistance(20)
|
sound.setRefDistance(20)
|
||||||
sound.setVolume(volume * this.baseVolume)
|
sound.setVolume(volume)
|
||||||
sound.setPlaybackRate(pitch) // set the pitch
|
sound.setPlaybackRate(pitch) // set the pitch
|
||||||
this.worldRenderer.scene.add(sound)
|
this.worldRenderer.scene.add(sound)
|
||||||
// set sound position
|
// set sound position
|
||||||
|
|
@ -57,35 +43,21 @@ export class ThreeJsSound implements SoundSystem {
|
||||||
sound.disconnect()
|
sound.disconnect()
|
||||||
}
|
}
|
||||||
this.activeSounds.delete(sound)
|
this.activeSounds.delete(sound)
|
||||||
this.soundVolumes.delete(sound)
|
|
||||||
audioLoader.manager.itemEnd(path)
|
audioLoader.manager.itemEnd(path)
|
||||||
}
|
}
|
||||||
sound.play()
|
sound.play()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
stopAll () {
|
destroy () {
|
||||||
|
// Stop and clean up all active sounds
|
||||||
for (const sound of this.activeSounds) {
|
for (const sound of this.activeSounds) {
|
||||||
if (!sound) continue
|
|
||||||
sound.stop()
|
sound.stop()
|
||||||
if (sound.source) {
|
if (sound.source) {
|
||||||
sound.disconnect()
|
sound.disconnect()
|
||||||
}
|
}
|
||||||
this.worldRenderer.scene.remove(sound)
|
|
||||||
}
|
|
||||||
this.activeSounds.clear()
|
|
||||||
this.soundVolumes.clear()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
changeVolume (volume: number) {
|
|
||||||
this.baseVolume = volume
|
|
||||||
for (const [sound, individualVolume] of this.soundVolumes) {
|
|
||||||
sound.setVolume(individualVolume * this.baseVolume)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
destroy () {
|
|
||||||
this.stopAll()
|
|
||||||
// Remove and cleanup audio listener
|
// Remove and cleanup audio listener
|
||||||
if (this.audioListener) {
|
if (this.audioListener) {
|
||||||
this.audioListener.removeFromParent()
|
this.audioListener.removeFromParent()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
import * as THREE from 'three'
|
import * as THREE from 'three'
|
||||||
import { getLoadedImage } from 'mc-assets/dist/utils'
|
|
||||||
import { createCanvas } from '../lib/utils'
|
|
||||||
|
|
||||||
export const disposeObject = (obj: THREE.Object3D, cleanTextures = false) => {
|
export const disposeObject = (obj: THREE.Object3D, cleanTextures = false) => {
|
||||||
// not cleaning texture there as it might be used by other objects, but would be good to also do that
|
// not cleaning texture there as it might be used by other objects, but would be good to also do that
|
||||||
|
|
@ -18,56 +16,3 @@ export const disposeObject = (obj: THREE.Object3D, cleanTextures = false) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let textureCache: Record<string, THREE.Texture> = {}
|
|
||||||
let imagesPromises: Record<string, Promise<THREE.Texture>> = {}
|
|
||||||
|
|
||||||
export const loadThreeJsTextureFromUrlSync = (imageUrl: string) => {
|
|
||||||
const texture = new THREE.Texture()
|
|
||||||
const promise = getLoadedImage(imageUrl).then(image => {
|
|
||||||
texture.image = image
|
|
||||||
texture.needsUpdate = true
|
|
||||||
return texture
|
|
||||||
})
|
|
||||||
return {
|
|
||||||
texture,
|
|
||||||
promise
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const loadThreeJsTextureFromUrl = async (imageUrl: string) => {
|
|
||||||
const loaded = new THREE.TextureLoader().loadAsync(imageUrl)
|
|
||||||
return loaded
|
|
||||||
}
|
|
||||||
|
|
||||||
export const loadThreeJsTextureFromBitmap = (image: ImageBitmap) => {
|
|
||||||
const canvas = createCanvas(image.width, image.height)
|
|
||||||
const ctx = canvas.getContext('2d')!
|
|
||||||
ctx.drawImage(image, 0, 0)
|
|
||||||
const texture = new THREE.Texture(canvas)
|
|
||||||
texture.magFilter = THREE.NearestFilter
|
|
||||||
texture.minFilter = THREE.NearestFilter
|
|
||||||
return texture
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function loadTexture (texture: string, cb: (texture: THREE.Texture) => void, onLoad?: () => void): Promise<void> {
|
|
||||||
const cached = textureCache[texture]
|
|
||||||
if (!cached) {
|
|
||||||
const { promise, resolve } = Promise.withResolvers<THREE.Texture>()
|
|
||||||
const t = loadThreeJsTextureFromUrlSync(texture)
|
|
||||||
textureCache[texture] = t.texture
|
|
||||||
void t.promise.then(resolve)
|
|
||||||
imagesPromises[texture] = promise
|
|
||||||
}
|
|
||||||
|
|
||||||
cb(textureCache[texture])
|
|
||||||
void imagesPromises[texture].then(() => {
|
|
||||||
onLoad?.()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export const clearTextureCache = () => {
|
|
||||||
textureCache = {}
|
|
||||||
imagesPromises = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,418 +0,0 @@
|
||||||
import * as THREE from 'three'
|
|
||||||
|
|
||||||
// Centralized visual configuration (in screen pixels)
|
|
||||||
export const WAYPOINT_CONFIG = {
|
|
||||||
// Target size in screen pixels (this controls the final sprite size)
|
|
||||||
TARGET_SCREEN_PX: 150,
|
|
||||||
// Canvas size for internal rendering (keep power of 2 for textures)
|
|
||||||
CANVAS_SIZE: 256,
|
|
||||||
// Relative positions in canvas (0-1)
|
|
||||||
LAYOUT: {
|
|
||||||
DOT_Y: 0.3,
|
|
||||||
NAME_Y: 0.45,
|
|
||||||
DISTANCE_Y: 0.55,
|
|
||||||
},
|
|
||||||
// Multiplier for canvas internal resolution to keep text crisp
|
|
||||||
CANVAS_SCALE: 2,
|
|
||||||
ARROW: {
|
|
||||||
enabledDefault: false,
|
|
||||||
pixelSize: 50,
|
|
||||||
paddingPx: 50,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
export type WaypointSprite = {
|
|
||||||
group: THREE.Group
|
|
||||||
sprite: THREE.Sprite
|
|
||||||
// Offscreen arrow controls
|
|
||||||
enableOffscreenArrow: (enabled: boolean) => void
|
|
||||||
setArrowParent: (parent: THREE.Object3D | null) => void
|
|
||||||
// Convenience combined updater
|
|
||||||
updateForCamera: (
|
|
||||||
cameraPosition: THREE.Vector3,
|
|
||||||
camera: THREE.PerspectiveCamera,
|
|
||||||
viewportWidthPx: number,
|
|
||||||
viewportHeightPx: number
|
|
||||||
) => boolean
|
|
||||||
// Utilities
|
|
||||||
setColor: (color: number) => void
|
|
||||||
setLabel: (label?: string) => void
|
|
||||||
updateDistanceText: (label: string, distanceText: string) => void
|
|
||||||
setVisible: (visible: boolean) => void
|
|
||||||
setPosition: (x: number, y: number, z: number) => void
|
|
||||||
dispose: () => void
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createWaypointSprite (options: {
|
|
||||||
position: THREE.Vector3 | { x: number, y: number, z: number },
|
|
||||||
color?: number,
|
|
||||||
label?: string,
|
|
||||||
depthTest?: boolean,
|
|
||||||
// Y offset in world units used by updateScaleWorld only (screen-pixel API ignores this)
|
|
||||||
labelYOffset?: number,
|
|
||||||
metadata?: any,
|
|
||||||
}): WaypointSprite {
|
|
||||||
const color = options.color ?? 0xFF_00_00
|
|
||||||
const depthTest = options.depthTest ?? false
|
|
||||||
const labelYOffset = options.labelYOffset ?? 1.5
|
|
||||||
|
|
||||||
// Build combined sprite
|
|
||||||
const sprite = createCombinedSprite(color, options.label ?? '', '0m', depthTest)
|
|
||||||
sprite.renderOrder = 10
|
|
||||||
let currentLabel = options.label ?? ''
|
|
||||||
|
|
||||||
// Offscreen arrow (detached by default)
|
|
||||||
let arrowSprite: THREE.Sprite | undefined
|
|
||||||
let arrowParent: THREE.Object3D | null = null
|
|
||||||
let arrowEnabled = WAYPOINT_CONFIG.ARROW.enabledDefault
|
|
||||||
|
|
||||||
// Group for easy add/remove
|
|
||||||
const group = new THREE.Group()
|
|
||||||
group.add(sprite)
|
|
||||||
|
|
||||||
// Initial position
|
|
||||||
const { x, y, z } = options.position
|
|
||||||
group.position.set(x, y, z)
|
|
||||||
|
|
||||||
function setColor (newColor: number) {
|
|
||||||
const canvas = drawCombinedCanvas(newColor, currentLabel, '0m')
|
|
||||||
const texture = new THREE.CanvasTexture(canvas)
|
|
||||||
const mat = sprite.material
|
|
||||||
mat.map?.dispose()
|
|
||||||
mat.map = texture
|
|
||||||
mat.needsUpdate = true
|
|
||||||
}
|
|
||||||
|
|
||||||
function setLabel (newLabel?: string) {
|
|
||||||
currentLabel = newLabel ?? ''
|
|
||||||
const canvas = drawCombinedCanvas(color, currentLabel, '0m')
|
|
||||||
const texture = new THREE.CanvasTexture(canvas)
|
|
||||||
const mat = sprite.material
|
|
||||||
mat.map?.dispose()
|
|
||||||
mat.map = texture
|
|
||||||
mat.needsUpdate = true
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateDistanceText (label: string, distanceText: string) {
|
|
||||||
const canvas = drawCombinedCanvas(color, label, distanceText)
|
|
||||||
const texture = new THREE.CanvasTexture(canvas)
|
|
||||||
const mat = sprite.material
|
|
||||||
mat.map?.dispose()
|
|
||||||
mat.map = texture
|
|
||||||
mat.needsUpdate = true
|
|
||||||
}
|
|
||||||
|
|
||||||
function setVisible (visible: boolean) {
|
|
||||||
sprite.visible = visible
|
|
||||||
}
|
|
||||||
|
|
||||||
function setPosition (nx: number, ny: number, nz: number) {
|
|
||||||
group.position.set(nx, ny, nz)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keep constant pixel size on screen using global config
|
|
||||||
function updateScaleScreenPixels (
|
|
||||||
cameraPosition: THREE.Vector3,
|
|
||||||
cameraFov: number,
|
|
||||||
distance: number,
|
|
||||||
viewportHeightPx: number
|
|
||||||
) {
|
|
||||||
const vFovRad = cameraFov * Math.PI / 180
|
|
||||||
const worldUnitsPerScreenHeightAtDist = Math.tan(vFovRad / 2) * 2 * distance
|
|
||||||
// Use configured target screen size
|
|
||||||
const scale = worldUnitsPerScreenHeightAtDist * (WAYPOINT_CONFIG.TARGET_SCREEN_PX / viewportHeightPx)
|
|
||||||
sprite.scale.set(scale, scale, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
function ensureArrow () {
|
|
||||||
if (arrowSprite) return
|
|
||||||
const size = 128
|
|
||||||
const canvas = document.createElement('canvas')
|
|
||||||
canvas.width = size
|
|
||||||
canvas.height = size
|
|
||||||
const ctx = canvas.getContext('2d')!
|
|
||||||
ctx.clearRect(0, 0, size, size)
|
|
||||||
|
|
||||||
// Draw arrow shape
|
|
||||||
ctx.beginPath()
|
|
||||||
ctx.moveTo(size * 0.15, size * 0.5)
|
|
||||||
ctx.lineTo(size * 0.85, size * 0.5)
|
|
||||||
ctx.lineTo(size * 0.5, size * 0.15)
|
|
||||||
ctx.closePath()
|
|
||||||
|
|
||||||
// Use waypoint color for arrow
|
|
||||||
const colorHex = `#${color.toString(16).padStart(6, '0')}`
|
|
||||||
ctx.lineWidth = 6
|
|
||||||
ctx.strokeStyle = 'black'
|
|
||||||
ctx.stroke()
|
|
||||||
ctx.fillStyle = colorHex
|
|
||||||
ctx.fill()
|
|
||||||
|
|
||||||
const texture = new THREE.CanvasTexture(canvas)
|
|
||||||
const material = new THREE.SpriteMaterial({ map: texture, transparent: true, depthTest: false, depthWrite: false })
|
|
||||||
arrowSprite = new THREE.Sprite(material)
|
|
||||||
arrowSprite.renderOrder = 12
|
|
||||||
arrowSprite.visible = false
|
|
||||||
if (arrowParent) arrowParent.add(arrowSprite)
|
|
||||||
}
|
|
||||||
|
|
||||||
function enableOffscreenArrow (enabled: boolean) {
|
|
||||||
arrowEnabled = enabled
|
|
||||||
if (!enabled && arrowSprite) arrowSprite.visible = false
|
|
||||||
}
|
|
||||||
|
|
||||||
function setArrowParent (parent: THREE.Object3D | null) {
|
|
||||||
if (arrowSprite?.parent) arrowSprite.parent.remove(arrowSprite)
|
|
||||||
arrowParent = parent
|
|
||||||
if (arrowSprite && parent) parent.add(arrowSprite)
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateOffscreenArrow (
|
|
||||||
camera: THREE.PerspectiveCamera,
|
|
||||||
viewportWidthPx: number,
|
|
||||||
viewportHeightPx: number
|
|
||||||
): boolean {
|
|
||||||
if (!arrowEnabled) return true
|
|
||||||
ensureArrow()
|
|
||||||
if (!arrowSprite) return true
|
|
||||||
|
|
||||||
// Check if onlyLeftRight is enabled in metadata
|
|
||||||
const onlyLeftRight = options.metadata?.onlyLeftRight === true
|
|
||||||
|
|
||||||
// Build camera basis using camera.up to respect custom orientations
|
|
||||||
const forward = new THREE.Vector3()
|
|
||||||
camera.getWorldDirection(forward) // camera look direction
|
|
||||||
const upWorld = camera.up.clone().normalize()
|
|
||||||
const right = new THREE.Vector3().copy(forward).cross(upWorld).normalize()
|
|
||||||
const upCam = new THREE.Vector3().copy(right).cross(forward).normalize()
|
|
||||||
|
|
||||||
// Vector from camera to waypoint
|
|
||||||
const camPos = new THREE.Vector3().setFromMatrixPosition(camera.matrixWorld)
|
|
||||||
const toWp = new THREE.Vector3(group.position.x, group.position.y, group.position.z).sub(camPos)
|
|
||||||
|
|
||||||
// Components in camera basis
|
|
||||||
const z = toWp.dot(forward)
|
|
||||||
const x = toWp.dot(right)
|
|
||||||
const y = toWp.dot(upCam)
|
|
||||||
|
|
||||||
const aspect = viewportWidthPx / viewportHeightPx
|
|
||||||
const vFovRad = camera.fov * Math.PI / 180
|
|
||||||
const hFovRad = 2 * Math.atan(Math.tan(vFovRad / 2) * aspect)
|
|
||||||
|
|
||||||
// Determine if waypoint is inside view frustum using angular checks
|
|
||||||
const thetaX = Math.atan2(x, z)
|
|
||||||
const thetaY = Math.atan2(y, z)
|
|
||||||
const visible = z > 0 && Math.abs(thetaX) <= hFovRad / 2 && Math.abs(thetaY) <= vFovRad / 2
|
|
||||||
if (visible) {
|
|
||||||
arrowSprite.visible = false
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Direction on screen in normalized frustum units
|
|
||||||
let rx = thetaX / (hFovRad / 2)
|
|
||||||
let ry = thetaY / (vFovRad / 2)
|
|
||||||
|
|
||||||
// If behind the camera, snap to dominant axis to avoid confusing directions
|
|
||||||
if (z <= 0) {
|
|
||||||
if (Math.abs(rx) > Math.abs(ry)) {
|
|
||||||
rx = Math.sign(rx)
|
|
||||||
ry = 0
|
|
||||||
} else {
|
|
||||||
rx = 0
|
|
||||||
ry = Math.sign(ry)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply onlyLeftRight logic - restrict arrows to left/right edges only
|
|
||||||
if (onlyLeftRight) {
|
|
||||||
// Force the arrow to appear only on left or right edges
|
|
||||||
if (Math.abs(rx) > Math.abs(ry)) {
|
|
||||||
// Horizontal direction is dominant, keep it
|
|
||||||
ry = 0
|
|
||||||
} else {
|
|
||||||
// Vertical direction is dominant, but we want only left/right
|
|
||||||
// So choose left or right based on the sign of rx
|
|
||||||
rx = rx >= 0 ? 1 : -1
|
|
||||||
ry = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Place on the rectangle border [-1,1]x[-1,1]
|
|
||||||
const s = Math.max(Math.abs(rx), Math.abs(ry)) || 1
|
|
||||||
let ndcX = rx / s
|
|
||||||
let ndcY = ry / s
|
|
||||||
|
|
||||||
// Apply padding in pixel space by clamping
|
|
||||||
const padding = WAYPOINT_CONFIG.ARROW.paddingPx
|
|
||||||
const pxX = ((ndcX + 1) * 0.5) * viewportWidthPx
|
|
||||||
const pxY = ((1 - ndcY) * 0.5) * viewportHeightPx
|
|
||||||
const clampedPxX = Math.min(Math.max(pxX, padding), viewportWidthPx - padding)
|
|
||||||
const clampedPxY = Math.min(Math.max(pxY, padding), viewportHeightPx - padding)
|
|
||||||
ndcX = (clampedPxX / viewportWidthPx) * 2 - 1
|
|
||||||
ndcY = -(clampedPxY / viewportHeightPx) * 2 + 1
|
|
||||||
|
|
||||||
// Compute world position at a fixed distance in front of the camera using camera basis
|
|
||||||
const placeDist = Math.max(2, camera.near * 4)
|
|
||||||
const halfPlaneHeight = Math.tan(vFovRad / 2) * placeDist
|
|
||||||
const halfPlaneWidth = halfPlaneHeight * aspect
|
|
||||||
const pos = camPos.clone()
|
|
||||||
.add(forward.clone().multiplyScalar(placeDist))
|
|
||||||
.add(right.clone().multiplyScalar(ndcX * halfPlaneWidth))
|
|
||||||
.add(upCam.clone().multiplyScalar(ndcY * halfPlaneHeight))
|
|
||||||
|
|
||||||
// Update arrow sprite
|
|
||||||
arrowSprite.visible = true
|
|
||||||
arrowSprite.position.copy(pos)
|
|
||||||
|
|
||||||
// Angle for rotation relative to screen right/up (derived from camera up vector)
|
|
||||||
const angle = Math.atan2(ry, rx)
|
|
||||||
arrowSprite.material.rotation = angle - Math.PI / 2
|
|
||||||
|
|
||||||
// Constant pixel size for arrow (use fixed placement distance)
|
|
||||||
const worldUnitsPerScreenHeightAtDist = Math.tan(vFovRad / 2) * 2 * placeDist
|
|
||||||
const sPx = worldUnitsPerScreenHeightAtDist * (WAYPOINT_CONFIG.ARROW.pixelSize / viewportHeightPx)
|
|
||||||
arrowSprite.scale.set(sPx, sPx, 1)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
function computeDistance (cameraPosition: THREE.Vector3): number {
|
|
||||||
return cameraPosition.distanceTo(group.position)
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateForCamera (
|
|
||||||
cameraPosition: THREE.Vector3,
|
|
||||||
camera: THREE.PerspectiveCamera,
|
|
||||||
viewportWidthPx: number,
|
|
||||||
viewportHeightPx: number
|
|
||||||
): boolean {
|
|
||||||
const distance = computeDistance(cameraPosition)
|
|
||||||
// Keep constant pixel size
|
|
||||||
updateScaleScreenPixels(cameraPosition, camera.fov, distance, viewportHeightPx)
|
|
||||||
// Update text
|
|
||||||
updateDistanceText(currentLabel, `${Math.round(distance)}m`)
|
|
||||||
// Update arrow and visibility
|
|
||||||
const onScreen = updateOffscreenArrow(camera, viewportWidthPx, viewportHeightPx)
|
|
||||||
setVisible(onScreen)
|
|
||||||
return onScreen
|
|
||||||
}
|
|
||||||
|
|
||||||
function dispose () {
|
|
||||||
const mat = sprite.material
|
|
||||||
mat.map?.dispose()
|
|
||||||
mat.dispose()
|
|
||||||
if (arrowSprite) {
|
|
||||||
const am = arrowSprite.material
|
|
||||||
am.map?.dispose()
|
|
||||||
am.dispose()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
group,
|
|
||||||
sprite,
|
|
||||||
enableOffscreenArrow,
|
|
||||||
setArrowParent,
|
|
||||||
updateForCamera,
|
|
||||||
setColor,
|
|
||||||
setLabel,
|
|
||||||
updateDistanceText,
|
|
||||||
setVisible,
|
|
||||||
setPosition,
|
|
||||||
dispose,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Internal helpers
|
|
||||||
function drawCombinedCanvas (color: number, id: string, distance: string): HTMLCanvasElement {
|
|
||||||
const scale = WAYPOINT_CONFIG.CANVAS_SCALE * (globalThis.devicePixelRatio || 1)
|
|
||||||
const size = WAYPOINT_CONFIG.CANVAS_SIZE * scale
|
|
||||||
const canvas = document.createElement('canvas')
|
|
||||||
canvas.width = size
|
|
||||||
canvas.height = size
|
|
||||||
const ctx = canvas.getContext('2d')!
|
|
||||||
|
|
||||||
// Clear canvas
|
|
||||||
ctx.clearRect(0, 0, size, size)
|
|
||||||
|
|
||||||
// Draw dot
|
|
||||||
const centerX = size / 2
|
|
||||||
const dotY = Math.round(size * WAYPOINT_CONFIG.LAYOUT.DOT_Y)
|
|
||||||
const radius = Math.round(size * 0.05) // Dot takes up ~12% of canvas height
|
|
||||||
const borderWidth = Math.max(2, Math.round(4 * scale))
|
|
||||||
|
|
||||||
// Outer border (black)
|
|
||||||
ctx.beginPath()
|
|
||||||
ctx.arc(centerX, dotY, radius + borderWidth, 0, Math.PI * 2)
|
|
||||||
ctx.fillStyle = 'black'
|
|
||||||
ctx.fill()
|
|
||||||
|
|
||||||
// Inner circle (colored)
|
|
||||||
ctx.beginPath()
|
|
||||||
ctx.arc(centerX, dotY, radius, 0, Math.PI * 2)
|
|
||||||
ctx.fillStyle = `#${color.toString(16).padStart(6, '0')}`
|
|
||||||
ctx.fill()
|
|
||||||
|
|
||||||
// Text properties
|
|
||||||
ctx.textAlign = 'center'
|
|
||||||
ctx.textBaseline = 'middle'
|
|
||||||
|
|
||||||
// Title
|
|
||||||
const nameFontPx = Math.round(size * 0.08) // ~8% of canvas height
|
|
||||||
const distanceFontPx = Math.round(size * 0.06) // ~6% of canvas height
|
|
||||||
ctx.font = `bold ${nameFontPx}px mojangles`
|
|
||||||
ctx.lineWidth = Math.max(2, Math.round(3 * scale))
|
|
||||||
const nameY = Math.round(size * WAYPOINT_CONFIG.LAYOUT.NAME_Y)
|
|
||||||
|
|
||||||
ctx.strokeStyle = 'black'
|
|
||||||
ctx.strokeText(id, centerX, nameY)
|
|
||||||
ctx.fillStyle = 'white'
|
|
||||||
ctx.fillText(id, centerX, nameY)
|
|
||||||
|
|
||||||
// Distance
|
|
||||||
ctx.font = `bold ${distanceFontPx}px mojangles`
|
|
||||||
ctx.lineWidth = Math.max(2, Math.round(2 * scale))
|
|
||||||
const distanceY = Math.round(size * WAYPOINT_CONFIG.LAYOUT.DISTANCE_Y)
|
|
||||||
|
|
||||||
ctx.strokeStyle = 'black'
|
|
||||||
ctx.strokeText(distance, centerX, distanceY)
|
|
||||||
ctx.fillStyle = '#CCCCCC'
|
|
||||||
ctx.fillText(distance, centerX, distanceY)
|
|
||||||
|
|
||||||
return canvas
|
|
||||||
}
|
|
||||||
|
|
||||||
function createCombinedSprite (color: number, id: string, distance: string, depthTest: boolean): THREE.Sprite {
|
|
||||||
const canvas = drawCombinedCanvas(color, id, distance)
|
|
||||||
const texture = new THREE.CanvasTexture(canvas)
|
|
||||||
texture.anisotropy = 1
|
|
||||||
texture.magFilter = THREE.LinearFilter
|
|
||||||
texture.minFilter = THREE.LinearFilter
|
|
||||||
const material = new THREE.SpriteMaterial({
|
|
||||||
map: texture,
|
|
||||||
transparent: true,
|
|
||||||
opacity: 1,
|
|
||||||
depthTest,
|
|
||||||
depthWrite: false,
|
|
||||||
})
|
|
||||||
const sprite = new THREE.Sprite(material)
|
|
||||||
sprite.position.set(0, 0, 0)
|
|
||||||
return sprite
|
|
||||||
}
|
|
||||||
|
|
||||||
export const WaypointHelpers = {
|
|
||||||
// World-scale constant size helper
|
|
||||||
computeWorldScale (distance: number, fixedReference = 10) {
|
|
||||||
return Math.max(0.0001, distance / fixedReference)
|
|
||||||
},
|
|
||||||
// Screen-pixel constant size helper
|
|
||||||
computeScreenPixelScale (
|
|
||||||
camera: THREE.PerspectiveCamera,
|
|
||||||
distance: number,
|
|
||||||
pixelSize: number,
|
|
||||||
viewportHeightPx: number
|
|
||||||
) {
|
|
||||||
const vFovRad = camera.fov * Math.PI / 180
|
|
||||||
const worldUnitsPerScreenHeightAtDist = Math.tan(vFovRad / 2) * 2 * distance
|
|
||||||
return worldUnitsPerScreenHeightAtDist * (pixelSize / viewportHeightPx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,140 +0,0 @@
|
||||||
import * as THREE from 'three'
|
|
||||||
import { WorldRendererThree } from './worldrendererThree'
|
|
||||||
import { createWaypointSprite, type WaypointSprite } from './waypointSprite'
|
|
||||||
|
|
||||||
interface Waypoint {
|
|
||||||
id: string
|
|
||||||
x: number
|
|
||||||
y: number
|
|
||||||
z: number
|
|
||||||
minDistance: number
|
|
||||||
color: number
|
|
||||||
label?: string
|
|
||||||
sprite: WaypointSprite
|
|
||||||
}
|
|
||||||
|
|
||||||
interface WaypointOptions {
|
|
||||||
color?: number
|
|
||||||
label?: string
|
|
||||||
minDistance?: number
|
|
||||||
metadata?: any
|
|
||||||
}
|
|
||||||
|
|
||||||
export class WaypointsRenderer {
|
|
||||||
private readonly waypoints = new Map<string, Waypoint>()
|
|
||||||
private readonly waypointScene = new THREE.Scene()
|
|
||||||
|
|
||||||
constructor (
|
|
||||||
private readonly worldRenderer: WorldRendererThree
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateWaypoints () {
|
|
||||||
const playerPos = this.worldRenderer.cameraObject.position
|
|
||||||
const sizeVec = this.worldRenderer.renderer.getSize(new THREE.Vector2())
|
|
||||||
|
|
||||||
for (const waypoint of this.waypoints.values()) {
|
|
||||||
const waypointPos = new THREE.Vector3(waypoint.x, waypoint.y, waypoint.z)
|
|
||||||
const distance = playerPos.distanceTo(waypointPos)
|
|
||||||
const visible = !waypoint.minDistance || distance >= waypoint.minDistance
|
|
||||||
|
|
||||||
waypoint.sprite.setVisible(visible)
|
|
||||||
|
|
||||||
if (visible) {
|
|
||||||
// Update position
|
|
||||||
waypoint.sprite.setPosition(waypoint.x, waypoint.y, waypoint.z)
|
|
||||||
// Ensure camera-based update each frame
|
|
||||||
waypoint.sprite.updateForCamera(this.worldRenderer.getCameraPosition(), this.worldRenderer.camera, sizeVec.width, sizeVec.height)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render () {
|
|
||||||
if (this.waypoints.size === 0) return
|
|
||||||
|
|
||||||
// Update waypoint scaling
|
|
||||||
this.updateWaypoints()
|
|
||||||
|
|
||||||
// Render waypoints scene with the world camera
|
|
||||||
this.worldRenderer.renderer.render(this.waypointScene, this.worldRenderer.camera)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removed sprite/label texture creation. Use utils/waypointSprite.ts
|
|
||||||
|
|
||||||
addWaypoint (
|
|
||||||
id: string,
|
|
||||||
x: number,
|
|
||||||
y: number,
|
|
||||||
z: number,
|
|
||||||
options: WaypointOptions = {}
|
|
||||||
) {
|
|
||||||
// Remove existing waypoint if it exists
|
|
||||||
this.removeWaypoint(id)
|
|
||||||
|
|
||||||
const color = options.color ?? 0xFF_00_00
|
|
||||||
const { label, metadata } = options
|
|
||||||
const minDistance = options.minDistance ?? 0
|
|
||||||
|
|
||||||
const sprite = createWaypointSprite({
|
|
||||||
position: new THREE.Vector3(x, y, z),
|
|
||||||
color,
|
|
||||||
label: (label || id),
|
|
||||||
metadata,
|
|
||||||
})
|
|
||||||
sprite.enableOffscreenArrow(true)
|
|
||||||
sprite.setArrowParent(this.waypointScene)
|
|
||||||
|
|
||||||
this.waypointScene.add(sprite.group)
|
|
||||||
|
|
||||||
this.waypoints.set(id, {
|
|
||||||
id, x: x + 0.5, y: y + 0.5, z: z + 0.5, minDistance,
|
|
||||||
color, label,
|
|
||||||
sprite,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
removeWaypoint (id: string) {
|
|
||||||
const waypoint = this.waypoints.get(id)
|
|
||||||
if (waypoint) {
|
|
||||||
this.waypointScene.remove(waypoint.sprite.group)
|
|
||||||
waypoint.sprite.dispose()
|
|
||||||
this.waypoints.delete(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
clear () {
|
|
||||||
for (const id of this.waypoints.keys()) {
|
|
||||||
this.removeWaypoint(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
testWaypoint () {
|
|
||||||
this.addWaypoint('Test Point', 0, 70, 0, { color: 0x00_FF_00, label: 'Test Point' })
|
|
||||||
this.addWaypoint('Spawn', 0, 64, 0, { color: 0xFF_FF_00, label: 'Spawn' })
|
|
||||||
this.addWaypoint('Far Point', 100, 70, 100, { color: 0x00_00_FF, label: 'Far Point' })
|
|
||||||
}
|
|
||||||
|
|
||||||
getWaypoint (id: string): Waypoint | undefined {
|
|
||||||
return this.waypoints.get(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
getAllWaypoints (): Waypoint[] {
|
|
||||||
return [...this.waypoints.values()]
|
|
||||||
}
|
|
||||||
|
|
||||||
setWaypointColor (id: string, color: number) {
|
|
||||||
const waypoint = this.waypoints.get(id)
|
|
||||||
if (waypoint) {
|
|
||||||
waypoint.sprite.setColor(color)
|
|
||||||
waypoint.color = color
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setWaypointLabel (id: string, label?: string) {
|
|
||||||
const waypoint = this.waypoints.get(id)
|
|
||||||
if (waypoint) {
|
|
||||||
waypoint.label = label
|
|
||||||
waypoint.sprite.setLabel(label)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import * as THREE from 'three'
|
import * as THREE from 'three'
|
||||||
import { LineMaterial, LineSegmentsGeometry, Wireframe } from 'three-stdlib'
|
import { LineMaterial, LineSegmentsGeometry, Wireframe } from 'three-stdlib'
|
||||||
import { Vec3 } from 'vec3'
|
import { Vec3 } from 'vec3'
|
||||||
|
import { subscribeKey } from 'valtio/utils'
|
||||||
|
import { Block } from 'prismarine-block'
|
||||||
import { BlockShape, BlocksShapes } from 'renderer/viewer/lib/basePlayerState'
|
import { BlockShape, BlocksShapes } from 'renderer/viewer/lib/basePlayerState'
|
||||||
import { WorldRendererThree } from '../worldrendererThree'
|
import { WorldRendererThree } from '../worldrendererThree'
|
||||||
import { loadThreeJsTextureFromUrl } from '../threeJsUtils'
|
|
||||||
import destroyStage0 from '../../../../assets/destroy_stage_0.png'
|
import destroyStage0 from '../../../../assets/destroy_stage_0.png'
|
||||||
import destroyStage1 from '../../../../assets/destroy_stage_1.png'
|
import destroyStage1 from '../../../../assets/destroy_stage_1.png'
|
||||||
import destroyStage2 from '../../../../assets/destroy_stage_2.png'
|
import destroyStage2 from '../../../../assets/destroy_stage_2.png'
|
||||||
|
|
@ -14,6 +15,7 @@ import destroyStage6 from '../../../../assets/destroy_stage_6.png'
|
||||||
import destroyStage7 from '../../../../assets/destroy_stage_7.png'
|
import destroyStage7 from '../../../../assets/destroy_stage_7.png'
|
||||||
import destroyStage8 from '../../../../assets/destroy_stage_8.png'
|
import destroyStage8 from '../../../../assets/destroy_stage_8.png'
|
||||||
import destroyStage9 from '../../../../assets/destroy_stage_9.png'
|
import destroyStage9 from '../../../../assets/destroy_stage_9.png'
|
||||||
|
import { loadThreeJsTextureFromUrl } from '../../lib/utils/skins'
|
||||||
|
|
||||||
export class CursorBlock {
|
export class CursorBlock {
|
||||||
_cursorLinesHidden = false
|
_cursorLinesHidden = false
|
||||||
|
|
@ -28,7 +30,7 @@ export class CursorBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
cursorLineMaterial: LineMaterial
|
cursorLineMaterial: LineMaterial
|
||||||
interactionLines: null | { blockPos: Vec3, mesh: THREE.Group, shapePositions: BlocksShapes | undefined } = null
|
interactionLines: null | { blockPos: Vec3, mesh: THREE.Group } = null
|
||||||
prevColor: string | undefined
|
prevColor: string | undefined
|
||||||
blockBreakMesh: THREE.Mesh
|
blockBreakMesh: THREE.Mesh
|
||||||
breakTextures: THREE.Texture[] = []
|
breakTextures: THREE.Texture[] = []
|
||||||
|
|
@ -62,13 +64,6 @@ export class CursorBlock {
|
||||||
this.worldRenderer.onReactivePlayerStateUpdated('gameMode', () => {
|
this.worldRenderer.onReactivePlayerStateUpdated('gameMode', () => {
|
||||||
this.updateLineMaterial()
|
this.updateLineMaterial()
|
||||||
})
|
})
|
||||||
// todo figure out why otherwise fog from skybox breaks it
|
|
||||||
setTimeout(() => {
|
|
||||||
this.updateLineMaterial()
|
|
||||||
if (this.interactionLines) {
|
|
||||||
this.setHighlightCursorBlock(this.interactionLines.blockPos, this.interactionLines.shapePositions, true)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update functions
|
// Update functions
|
||||||
|
|
@ -76,9 +71,6 @@ export class CursorBlock {
|
||||||
const inCreative = this.worldRenderer.playerStateReactive.gameMode === 'creative'
|
const inCreative = this.worldRenderer.playerStateReactive.gameMode === 'creative'
|
||||||
const pixelRatio = this.worldRenderer.renderer.getPixelRatio()
|
const pixelRatio = this.worldRenderer.renderer.getPixelRatio()
|
||||||
|
|
||||||
if (this.cursorLineMaterial) {
|
|
||||||
this.cursorLineMaterial.dispose()
|
|
||||||
}
|
|
||||||
this.cursorLineMaterial = new LineMaterial({
|
this.cursorLineMaterial = new LineMaterial({
|
||||||
color: (() => {
|
color: (() => {
|
||||||
switch (this.worldRenderer.worldRendererConfig.highlightBlockColor) {
|
switch (this.worldRenderer.worldRendererConfig.highlightBlockColor) {
|
||||||
|
|
@ -125,8 +117,8 @@ export class CursorBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setHighlightCursorBlock (blockPos: Vec3 | null, shapePositions?: BlocksShapes, force = false): void {
|
setHighlightCursorBlock (blockPos: Vec3 | null, shapePositions?: BlocksShapes): void {
|
||||||
if (blockPos && this.interactionLines && blockPos.equals(this.interactionLines.blockPos) && !force) {
|
if (blockPos && this.interactionLines && blockPos.equals(this.interactionLines.blockPos)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (this.interactionLines !== null) {
|
if (this.interactionLines !== null) {
|
||||||
|
|
@ -150,7 +142,7 @@ export class CursorBlock {
|
||||||
}
|
}
|
||||||
this.worldRenderer.scene.add(group)
|
this.worldRenderer.scene.add(group)
|
||||||
group.visible = !this.cursorLinesHidden
|
group.visible = !this.cursorLinesHidden
|
||||||
this.interactionLines = { blockPos, mesh: group, shapePositions }
|
this.interactionLines = { blockPos, mesh: group }
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { Vec3 } from 'vec3'
|
||||||
import nbt from 'prismarine-nbt'
|
import nbt from 'prismarine-nbt'
|
||||||
import PrismarineChatLoader from 'prismarine-chat'
|
import PrismarineChatLoader from 'prismarine-chat'
|
||||||
import * as tweenJs from '@tweenjs/tween.js'
|
import * as tweenJs from '@tweenjs/tween.js'
|
||||||
import { Biome } from 'minecraft-data'
|
|
||||||
import { renderSign } from '../sign-renderer'
|
import { renderSign } from '../sign-renderer'
|
||||||
import { DisplayWorldOptions, GraphicsInitOptions } from '../../../src/appViewer'
|
import { DisplayWorldOptions, GraphicsInitOptions } from '../../../src/appViewer'
|
||||||
import { chunkPos, sectionPos } from '../lib/simpleUtils'
|
import { chunkPos, sectionPos } from '../lib/simpleUtils'
|
||||||
|
|
@ -11,12 +10,13 @@ import { WorldRendererCommon } from '../lib/worldrendererCommon'
|
||||||
import { addNewStat } from '../lib/ui/newStats'
|
import { addNewStat } from '../lib/ui/newStats'
|
||||||
import { MesherGeometryOutput } from '../lib/mesher/shared'
|
import { MesherGeometryOutput } from '../lib/mesher/shared'
|
||||||
import { ItemSpecificContextProperties } from '../lib/basePlayerState'
|
import { ItemSpecificContextProperties } from '../lib/basePlayerState'
|
||||||
|
import { getMyHand } from '../lib/hand'
|
||||||
import { setBlockPosition } from '../lib/mesher/standaloneRenderer'
|
import { setBlockPosition } from '../lib/mesher/standaloneRenderer'
|
||||||
import { getMyHand } from './hand'
|
import { loadThreeJsTextureFromBitmap } from '../lib/utils/skins'
|
||||||
import HoldingBlock from './holdingBlock'
|
import HoldingBlock from './holdingBlock'
|
||||||
import { getMesh } from './entity/EntityMesh'
|
import { getMesh } from './entity/EntityMesh'
|
||||||
import { armorModel } from './entity/armorModels'
|
import { armorModel } from './entity/armorModels'
|
||||||
import { disposeObject, loadThreeJsTextureFromBitmap } from './threeJsUtils'
|
import { disposeObject } from './threeJsUtils'
|
||||||
import { CursorBlock } from './world/cursorBlock'
|
import { CursorBlock } from './world/cursorBlock'
|
||||||
import { getItemUv } from './appShared'
|
import { getItemUv } from './appShared'
|
||||||
import { Entities } from './entities'
|
import { Entities } from './entities'
|
||||||
|
|
@ -24,8 +24,6 @@ import { ThreeJsSound } from './threeJsSound'
|
||||||
import { CameraShake } from './cameraShake'
|
import { CameraShake } from './cameraShake'
|
||||||
import { ThreeJsMedia } from './threeJsMedia'
|
import { ThreeJsMedia } from './threeJsMedia'
|
||||||
import { Fountain } from './threeJsParticles'
|
import { Fountain } from './threeJsParticles'
|
||||||
import { WaypointsRenderer } from './waypoints'
|
|
||||||
import { DEFAULT_TEMPERATURE, SkyboxRenderer } from './skyboxRenderer'
|
|
||||||
|
|
||||||
type SectionKey = string
|
type SectionKey = string
|
||||||
|
|
||||||
|
|
@ -51,7 +49,6 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
cameraContainer: THREE.Object3D
|
cameraContainer: THREE.Object3D
|
||||||
media: ThreeJsMedia
|
media: ThreeJsMedia
|
||||||
waitingChunksToDisplay = {} as { [chunkKey: string]: SectionKey[] }
|
waitingChunksToDisplay = {} as { [chunkKey: string]: SectionKey[] }
|
||||||
waypoints: WaypointsRenderer
|
|
||||||
camera: THREE.PerspectiveCamera
|
camera: THREE.PerspectiveCamera
|
||||||
renderTimeAvg = 0
|
renderTimeAvg = 0
|
||||||
sectionsOffsetsAnimations = {} as {
|
sectionsOffsetsAnimations = {} as {
|
||||||
|
|
@ -73,7 +70,6 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
}
|
}
|
||||||
fountains: Fountain[] = []
|
fountains: Fountain[] = []
|
||||||
DEBUG_RAYCAST = false
|
DEBUG_RAYCAST = false
|
||||||
skyboxRenderer: SkyboxRenderer
|
|
||||||
|
|
||||||
private currentPosTween?: tweenJs.Tween<THREE.Vector3>
|
private currentPosTween?: tweenJs.Tween<THREE.Vector3>
|
||||||
private currentRotTween?: tweenJs.Tween<{ pitch: number, yaw: number }>
|
private currentRotTween?: tweenJs.Tween<{ pitch: number, yaw: number }>
|
||||||
|
|
@ -97,10 +93,6 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
this.holdingBlock = new HoldingBlock(this)
|
this.holdingBlock = new HoldingBlock(this)
|
||||||
this.holdingBlockLeft = new HoldingBlock(this, true)
|
this.holdingBlockLeft = new HoldingBlock(this, true)
|
||||||
|
|
||||||
// Initialize skybox renderer
|
|
||||||
this.skyboxRenderer = new SkyboxRenderer(this.scene, this.worldRendererConfig.defaultSkybox, null)
|
|
||||||
void this.skyboxRenderer.init()
|
|
||||||
|
|
||||||
this.addDebugOverlay()
|
this.addDebugOverlay()
|
||||||
this.resetScene()
|
this.resetScene()
|
||||||
void this.init()
|
void this.init()
|
||||||
|
|
@ -108,8 +100,6 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
this.soundSystem = new ThreeJsSound(this)
|
this.soundSystem = new ThreeJsSound(this)
|
||||||
this.cameraShake = new CameraShake(this, this.onRender)
|
this.cameraShake = new CameraShake(this, this.onRender)
|
||||||
this.media = new ThreeJsMedia(this)
|
this.media = new ThreeJsMedia(this)
|
||||||
this.waypoints = new WaypointsRenderer(this)
|
|
||||||
|
|
||||||
// this.fountain = new Fountain(this.scene, this.scene, {
|
// this.fountain = new Fountain(this.scene, this.scene, {
|
||||||
// position: new THREE.Vector3(0, 10, 0),
|
// position: new THREE.Vector3(0, 10, 0),
|
||||||
// })
|
// })
|
||||||
|
|
@ -130,8 +120,6 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
this.protocolCustomBlocks.clear()
|
this.protocolCustomBlocks.clear()
|
||||||
// Reset section animations
|
// Reset section animations
|
||||||
this.sectionsOffsetsAnimations = {}
|
this.sectionsOffsetsAnimations = {}
|
||||||
// Clear waypoints
|
|
||||||
this.waypoints.clear()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -174,10 +162,7 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
override watchReactivePlayerState () {
|
override watchReactivePlayerState () {
|
||||||
super.watchReactivePlayerState()
|
super.watchReactivePlayerState()
|
||||||
this.onReactivePlayerStateUpdated('inWater', (value) => {
|
this.onReactivePlayerStateUpdated('inWater', (value) => {
|
||||||
this.skyboxRenderer.updateWaterState(value, this.playerStateReactive.waterBreathing)
|
this.scene.fog = value ? new THREE.Fog(0x00_00_ff, 0.1, this.playerStateReactive.waterBreathing ? 100 : 20) : null
|
||||||
})
|
|
||||||
this.onReactivePlayerStateUpdated('waterBreathing', (value) => {
|
|
||||||
this.skyboxRenderer.updateWaterState(this.playerStateReactive.inWater, value)
|
|
||||||
})
|
})
|
||||||
this.onReactivePlayerStateUpdated('ambientLight', (value) => {
|
this.onReactivePlayerStateUpdated('ambientLight', (value) => {
|
||||||
if (!value) return
|
if (!value) return
|
||||||
|
|
@ -206,9 +191,6 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
this.onReactiveConfigUpdated('showChunkBorders', (value) => {
|
this.onReactiveConfigUpdated('showChunkBorders', (value) => {
|
||||||
this.updateShowChunksBorder(value)
|
this.updateShowChunksBorder(value)
|
||||||
})
|
})
|
||||||
this.onReactiveConfigUpdated('defaultSkybox', (value) => {
|
|
||||||
this.skyboxRenderer.updateDefaultSkybox(value)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
changeHandSwingingState (isAnimationPlaying: boolean, isLeft = false) {
|
changeHandSwingingState (isAnimationPlaying: boolean, isLeft = false) {
|
||||||
|
|
@ -271,19 +253,6 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
} else {
|
} else {
|
||||||
this.starField.remove()
|
this.starField.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.skyboxRenderer.updateTime(newTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
biomeUpdated (biome: Biome): void {
|
|
||||||
if (biome?.temperature !== undefined) {
|
|
||||||
this.skyboxRenderer.updateTemperature(biome.temperature)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
biomeReset (): void {
|
|
||||||
// Reset to default temperature when biome is unknown
|
|
||||||
this.skyboxRenderer.updateTemperature(DEFAULT_TEMPERATURE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getItemRenderData (item: Record<string, any>, specificProps: ItemSpecificContextProperties) {
|
getItemRenderData (item: Record<string, any>, specificProps: ItemSpecificContextProperties) {
|
||||||
|
|
@ -457,7 +426,7 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
this.scene.add(object)
|
this.scene.add(object)
|
||||||
}
|
}
|
||||||
|
|
||||||
getSignTexture (position: Vec3, blockEntity, isHanging, backSide = false) {
|
getSignTexture (position: Vec3, blockEntity, backSide = false) {
|
||||||
const chunk = chunkPos(position)
|
const chunk = chunkPos(position)
|
||||||
let textures = this.chunkTextures.get(`${chunk[0]},${chunk[1]}`)
|
let textures = this.chunkTextures.get(`${chunk[0]},${chunk[1]}`)
|
||||||
if (!textures) {
|
if (!textures) {
|
||||||
|
|
@ -469,7 +438,7 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
if (textures[texturekey]) return textures[texturekey]
|
if (textures[texturekey]) return textures[texturekey]
|
||||||
|
|
||||||
const PrismarineChat = PrismarineChatLoader(this.version)
|
const PrismarineChat = PrismarineChatLoader(this.version)
|
||||||
const canvas = renderSign(blockEntity, isHanging, PrismarineChat)
|
const canvas = renderSign(blockEntity, PrismarineChat)
|
||||||
if (!canvas) return
|
if (!canvas) return
|
||||||
const tex = new THREE.Texture(canvas)
|
const tex = new THREE.Texture(canvas)
|
||||||
tex.magFilter = THREE.NearestFilter
|
tex.magFilter = THREE.NearestFilter
|
||||||
|
|
@ -485,7 +454,7 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
return worldPos
|
return worldPos
|
||||||
}
|
}
|
||||||
|
|
||||||
getSectionCameraPosition () {
|
getWorldCameraPosition () {
|
||||||
const pos = this.getCameraPosition()
|
const pos = this.getCameraPosition()
|
||||||
return new Vec3(
|
return new Vec3(
|
||||||
Math.floor(pos.x / 16),
|
Math.floor(pos.x / 16),
|
||||||
|
|
@ -495,7 +464,7 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCameraSectionPos () {
|
updateCameraSectionPos () {
|
||||||
const newSectionPos = this.getSectionCameraPosition()
|
const newSectionPos = this.getWorldCameraPosition()
|
||||||
if (!this.cameraSectionPos.equals(newSectionPos)) {
|
if (!this.cameraSectionPos.equals(newSectionPos)) {
|
||||||
this.cameraSectionPos = newSectionPos
|
this.cameraSectionPos = newSectionPos
|
||||||
this.cameraSectionPositionUpdate()
|
this.cameraSectionPositionUpdate()
|
||||||
|
|
@ -734,10 +703,6 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
this.cursorBlock.render()
|
this.cursorBlock.render()
|
||||||
this.updateSectionOffsets()
|
this.updateSectionOffsets()
|
||||||
|
|
||||||
// Update skybox position to follow camera
|
|
||||||
const cameraPos = this.getCameraPosition()
|
|
||||||
this.skyboxRenderer.update(cameraPos, this.viewDistance)
|
|
||||||
|
|
||||||
const sizeOrFovChanged = sizeChanged || this.displayOptions.inWorldRenderingConfig.fov !== this.camera.fov
|
const sizeOrFovChanged = sizeChanged || this.displayOptions.inWorldRenderingConfig.fov !== this.camera.fov
|
||||||
if (sizeOrFovChanged) {
|
if (sizeOrFovChanged) {
|
||||||
const size = this.renderer.getSize(new THREE.Vector2())
|
const size = this.renderer.getSize(new THREE.Vector2())
|
||||||
|
|
@ -773,8 +738,6 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
fountain.render()
|
fountain.render()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.waypoints.render()
|
|
||||||
|
|
||||||
for (const onRender of this.onRender) {
|
for (const onRender of this.onRender) {
|
||||||
onRender()
|
onRender()
|
||||||
}
|
}
|
||||||
|
|
@ -787,17 +750,12 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
}
|
}
|
||||||
|
|
||||||
renderHead (position: Vec3, rotation: number, isWall: boolean, blockEntity) {
|
renderHead (position: Vec3, rotation: number, isWall: boolean, blockEntity) {
|
||||||
let textureData: string
|
const textures = blockEntity.SkullOwner?.Properties?.textures[0]
|
||||||
if (blockEntity.SkullOwner) {
|
if (!textures) return
|
||||||
textureData = blockEntity.SkullOwner.Properties?.textures?.[0]?.Value
|
|
||||||
} else {
|
|
||||||
textureData = blockEntity.profile?.properties?.find(p => p.name === 'textures')?.value
|
|
||||||
}
|
|
||||||
if (!textureData) return
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const decodedData = JSON.parse(Buffer.from(textureData, 'base64').toString())
|
const textureData = JSON.parse(Buffer.from(textures.Value, 'base64').toString())
|
||||||
let skinUrl = decodedData.textures?.SKIN?.url
|
let skinUrl = textureData.textures?.SKIN?.url
|
||||||
const { skinTexturesProxy } = this.worldRendererConfig
|
const { skinTexturesProxy } = this.worldRendererConfig
|
||||||
if (skinTexturesProxy) {
|
if (skinTexturesProxy) {
|
||||||
skinUrl = skinUrl?.replace('http://textures.minecraft.net/', skinTexturesProxy)
|
skinUrl = skinUrl?.replace('http://textures.minecraft.net/', skinTexturesProxy)
|
||||||
|
|
@ -826,7 +784,7 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
}
|
}
|
||||||
|
|
||||||
renderSign (position: Vec3, rotation: number, isWall: boolean, isHanging: boolean, blockEntity) {
|
renderSign (position: Vec3, rotation: number, isWall: boolean, isHanging: boolean, blockEntity) {
|
||||||
const tex = this.getSignTexture(position, blockEntity, isHanging)
|
const tex = this.getSignTexture(position, blockEntity)
|
||||||
|
|
||||||
if (!tex) return
|
if (!tex) return
|
||||||
|
|
||||||
|
|
@ -982,7 +940,6 @@ export class WorldRendererThree extends WorldRendererCommon {
|
||||||
|
|
||||||
destroy (): void {
|
destroy (): void {
|
||||||
super.destroy()
|
super.destroy()
|
||||||
this.skyboxRenderer.dispose()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldObjectVisible (object: THREE.Object3D) {
|
shouldObjectVisible (object: THREE.Object3D) {
|
||||||
|
|
@ -1066,13 +1023,6 @@ class StarField {
|
||||||
constructor (
|
constructor (
|
||||||
private readonly worldRenderer: WorldRendererThree
|
private readonly worldRenderer: WorldRendererThree
|
||||||
) {
|
) {
|
||||||
const clock = new THREE.Clock()
|
|
||||||
const speed = 0.2
|
|
||||||
this.worldRenderer.onRender.push(() => {
|
|
||||||
if (!this.points) return
|
|
||||||
this.points.position.copy(this.worldRenderer.getCameraPosition());
|
|
||||||
(this.points.material as StarfieldMaterial).uniforms.time.value = clock.getElapsedTime() * speed
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addToScene () {
|
addToScene () {
|
||||||
|
|
@ -1083,6 +1033,7 @@ class StarField {
|
||||||
const count = 7000
|
const count = 7000
|
||||||
const factor = 7
|
const factor = 7
|
||||||
const saturation = 10
|
const saturation = 10
|
||||||
|
const speed = 0.2
|
||||||
|
|
||||||
const geometry = new THREE.BufferGeometry()
|
const geometry = new THREE.BufferGeometry()
|
||||||
|
|
||||||
|
|
@ -1115,6 +1066,11 @@ class StarField {
|
||||||
this.points = new THREE.Points(geometry, material)
|
this.points = new THREE.Points(geometry, material)
|
||||||
this.worldRenderer.scene.add(this.points)
|
this.worldRenderer.scene.add(this.points)
|
||||||
|
|
||||||
|
const clock = new THREE.Clock()
|
||||||
|
this.points.onBeforeRender = (renderer, scene, camera) => {
|
||||||
|
this.points?.position.copy?.(this.worldRenderer.getCameraPosition())
|
||||||
|
material.uniforms.time.value = clock.getElapsedTime() * speed
|
||||||
|
}
|
||||||
this.points.renderOrder = -1
|
this.points.renderOrder = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import { appAndRendererSharedConfig } from './renderer/rsbuildSharedConfig'
|
||||||
import { genLargeDataAliases } from './scripts/genLargeDataAliases'
|
import { genLargeDataAliases } from './scripts/genLargeDataAliases'
|
||||||
import sharp from 'sharp'
|
import sharp from 'sharp'
|
||||||
import supportedVersions from './src/supportedVersions.mjs'
|
import supportedVersions from './src/supportedVersions.mjs'
|
||||||
import { startWsServer } from './scripts/wsServer'
|
|
||||||
|
|
||||||
const SINGLE_FILE_BUILD = process.env.SINGLE_FILE_BUILD === 'true'
|
const SINGLE_FILE_BUILD = process.env.SINGLE_FILE_BUILD === 'true'
|
||||||
|
|
||||||
|
|
@ -60,8 +59,6 @@ const configSource = (SINGLE_FILE_BUILD ? 'BUNDLED' : (process.env.CONFIG_JSON_S
|
||||||
|
|
||||||
const faviconPath = 'favicon.png'
|
const faviconPath = 'favicon.png'
|
||||||
|
|
||||||
const enableMetrics = process.env.ENABLE_METRICS === 'true'
|
|
||||||
|
|
||||||
// base options are in ./renderer/rsbuildSharedConfig.ts
|
// base options are in ./renderer/rsbuildSharedConfig.ts
|
||||||
const appConfig = defineConfig({
|
const appConfig = defineConfig({
|
||||||
html: {
|
html: {
|
||||||
|
|
@ -139,13 +136,6 @@ const appConfig = defineConfig({
|
||||||
// 50kb limit for data uri
|
// 50kb limit for data uri
|
||||||
dataUriLimit: SINGLE_FILE_BUILD ? 1 * 1024 * 1024 * 1024 : 50 * 1024
|
dataUriLimit: SINGLE_FILE_BUILD ? 1 * 1024 * 1024 * 1024 : 50 * 1024
|
||||||
},
|
},
|
||||||
performance: {
|
|
||||||
// prefetch: {
|
|
||||||
// include(filename) {
|
|
||||||
// return filename.includes('mc-data') || filename.includes('mc-assets')
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
},
|
|
||||||
source: {
|
source: {
|
||||||
entry: {
|
entry: {
|
||||||
index: './src/index.ts',
|
index: './src/index.ts',
|
||||||
|
|
@ -161,7 +151,7 @@ const appConfig = defineConfig({
|
||||||
'process.platform': '"browser"',
|
'process.platform': '"browser"',
|
||||||
'process.env.GITHUB_URL':
|
'process.env.GITHUB_URL':
|
||||||
JSON.stringify(`https://github.com/${process.env.GITHUB_REPOSITORY || `${process.env.VERCEL_GIT_REPO_OWNER}/${process.env.VERCEL_GIT_REPO_SLUG}` || githubRepositoryFallback}`),
|
JSON.stringify(`https://github.com/${process.env.GITHUB_REPOSITORY || `${process.env.VERCEL_GIT_REPO_OWNER}/${process.env.VERCEL_GIT_REPO_SLUG}` || githubRepositoryFallback}`),
|
||||||
'process.env.ALWAYS_MINIMAL_SERVER_UI': JSON.stringify(process.env.ALWAYS_MINIMAL_SERVER_UI),
|
'process.env.DEPS_VERSIONS': JSON.stringify({}),
|
||||||
'process.env.RELEASE_TAG': JSON.stringify(releaseTag),
|
'process.env.RELEASE_TAG': JSON.stringify(releaseTag),
|
||||||
'process.env.RELEASE_LINK': JSON.stringify(releaseLink),
|
'process.env.RELEASE_LINK': JSON.stringify(releaseLink),
|
||||||
'process.env.RELEASE_CHANGELOG': JSON.stringify(releaseChangelog),
|
'process.env.RELEASE_CHANGELOG': JSON.stringify(releaseChangelog),
|
||||||
|
|
@ -169,7 +159,6 @@ const appConfig = defineConfig({
|
||||||
'process.env.INLINED_APP_CONFIG': JSON.stringify(configSource === 'BUNDLED' ? configJson : null),
|
'process.env.INLINED_APP_CONFIG': JSON.stringify(configSource === 'BUNDLED' ? configJson : null),
|
||||||
'process.env.ENABLE_COOKIE_STORAGE': JSON.stringify(process.env.ENABLE_COOKIE_STORAGE || true),
|
'process.env.ENABLE_COOKIE_STORAGE': JSON.stringify(process.env.ENABLE_COOKIE_STORAGE || true),
|
||||||
'process.env.COOKIE_STORAGE_PREFIX': JSON.stringify(process.env.COOKIE_STORAGE_PREFIX || ''),
|
'process.env.COOKIE_STORAGE_PREFIX': JSON.stringify(process.env.COOKIE_STORAGE_PREFIX || ''),
|
||||||
'process.env.WS_PORT': JSON.stringify(enableMetrics ? 8081 : false),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
|
|
@ -197,14 +186,13 @@ const appConfig = defineConfig({
|
||||||
childProcess.execSync('tsx ./scripts/optimizeBlockCollisions.ts', { stdio: 'inherit' })
|
childProcess.execSync('tsx ./scripts/optimizeBlockCollisions.ts', { stdio: 'inherit' })
|
||||||
}
|
}
|
||||||
// childProcess.execSync(['tsx', './scripts/genLargeDataAliases.ts', ...(SINGLE_FILE_BUILD ? ['--compressed'] : [])].join(' '), { stdio: 'inherit' })
|
// childProcess.execSync(['tsx', './scripts/genLargeDataAliases.ts', ...(SINGLE_FILE_BUILD ? ['--compressed'] : [])].join(' '), { stdio: 'inherit' })
|
||||||
genLargeDataAliases(SINGLE_FILE_BUILD || process.env.ALWAYS_COMPRESS_LARGE_DATA === 'true')
|
genLargeDataAliases(SINGLE_FILE_BUILD)
|
||||||
fsExtra.copySync('./node_modules/mc-assets/dist/other-textures/latest/entity', './dist/textures/entity')
|
fsExtra.copySync('./node_modules/mc-assets/dist/other-textures/latest/entity', './dist/textures/entity')
|
||||||
fsExtra.copySync('./assets/background', './dist/background')
|
fsExtra.copySync('./assets/background', './dist/background')
|
||||||
fs.copyFileSync('./assets/favicon.png', './dist/favicon.png')
|
fs.copyFileSync('./assets/favicon.png', './dist/favicon.png')
|
||||||
fs.copyFileSync('./assets/playground.html', './dist/playground.html')
|
fs.copyFileSync('./assets/playground.html', './dist/playground.html')
|
||||||
fs.copyFileSync('./assets/manifest.json', './dist/manifest.json')
|
fs.copyFileSync('./assets/manifest.json', './dist/manifest.json')
|
||||||
fs.copyFileSync('./assets/config.html', './dist/config.html')
|
fs.copyFileSync('./assets/config.html', './dist/config.html')
|
||||||
fs.copyFileSync('./assets/debug-inputs.html', './dist/debug-inputs.html')
|
|
||||||
fs.copyFileSync('./assets/loading-bg.jpg', './dist/loading-bg.jpg')
|
fs.copyFileSync('./assets/loading-bg.jpg', './dist/loading-bg.jpg')
|
||||||
if (fs.existsSync('./assets/release.json')) {
|
if (fs.existsSync('./assets/release.json')) {
|
||||||
fs.copyFileSync('./assets/release.json', './dist/release.json')
|
fs.copyFileSync('./assets/release.json', './dist/release.json')
|
||||||
|
|
@ -227,12 +215,6 @@ const appConfig = defineConfig({
|
||||||
await execAsync('pnpm run build-mesher')
|
await execAsync('pnpm run build-mesher')
|
||||||
}
|
}
|
||||||
fs.writeFileSync('./dist/version.txt', buildingVersion, 'utf-8')
|
fs.writeFileSync('./dist/version.txt', buildingVersion, 'utf-8')
|
||||||
|
|
||||||
// Start WebSocket server in development
|
|
||||||
if (dev && enableMetrics) {
|
|
||||||
await startWsServer(8081, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
console.timeEnd('total-prep')
|
console.timeEnd('total-prep')
|
||||||
}
|
}
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
|
|
@ -240,10 +222,6 @@ const appConfig = defineConfig({
|
||||||
prep()
|
prep()
|
||||||
})
|
})
|
||||||
build.onAfterBuild(async () => {
|
build.onAfterBuild(async () => {
|
||||||
if (fs.readdirSync('./assets/customTextures').length > 0) {
|
|
||||||
childProcess.execSync('tsx ./scripts/patchAssets.ts', { stdio: 'inherit' })
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SINGLE_FILE_BUILD) {
|
if (SINGLE_FILE_BUILD) {
|
||||||
// check that only index.html is in the dist/single folder
|
// check that only index.html is in the dist/single folder
|
||||||
const singleBuildFiles = fs.readdirSync('./dist/single')
|
const singleBuildFiles = fs.readdirSync('./dist/single')
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,7 @@ export const genLargeDataAliases = async (isCompressed: boolean) => {
|
||||||
|
|
||||||
let str = `${decoderCode}\nexport const importLargeData = async (mod: ${Object.keys(modules).map(x => `'${x}'`).join(' | ')}) => {\n`
|
let str = `${decoderCode}\nexport const importLargeData = async (mod: ${Object.keys(modules).map(x => `'${x}'`).join(' | ')}) => {\n`
|
||||||
for (const [module, { compressed, raw }] of Object.entries(modules)) {
|
for (const [module, { compressed, raw }] of Object.entries(modules)) {
|
||||||
const chunkName = module === 'mcData' ? 'mc-data' : 'mc-assets';
|
let importCode = `(await import('${isCompressed ? compressed : raw}')).default`;
|
||||||
let importCode = `(await import(/* webpackChunkName: "${chunkName}" */ '${isCompressed ? compressed : raw}')).default`;
|
|
||||||
if (isCompressed) {
|
if (isCompressed) {
|
||||||
importCode = `JSON.parse(decompressFromBase64(${importCode}))`
|
importCode = `JSON.parse(decompressFromBase64(${importCode}))`
|
||||||
}
|
}
|
||||||
|
|
@ -31,8 +30,6 @@ export const genLargeDataAliases = async (isCompressed: boolean) => {
|
||||||
const decoderCode = /* ts */ `
|
const decoderCode = /* ts */ `
|
||||||
import pako from 'pako';
|
import pako from 'pako';
|
||||||
|
|
||||||
globalThis.pako = { inflate: pako.inflate.bind(pako) }
|
|
||||||
|
|
||||||
function decompressFromBase64(input) {
|
function decompressFromBase64(input) {
|
||||||
console.time('decompressFromBase64')
|
console.time('decompressFromBase64')
|
||||||
// Decode the Base64 string
|
// Decode the Base64 string
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import supportedVersions from '../src/supportedVersions.mjs'
|
||||||
import { gzipSizeFromFileSync } from 'gzip-size'
|
import { gzipSizeFromFileSync } from 'gzip-size'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import {default as _JsonOptimizer} from '../src/optimizeJson'
|
import {default as _JsonOptimizer} from '../src/optimizeJson'
|
||||||
import { gzipSync } from 'zlib'
|
import { gzipSync } from 'zlib';
|
||||||
import MinecraftData from 'minecraft-data'
|
import MinecraftData from 'minecraft-data'
|
||||||
import MCProtocol from 'minecraft-protocol'
|
import MCProtocol from 'minecraft-protocol'
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ function toMajor(version) {
|
||||||
return `${a}.${b}`
|
return `${a}.${b}`
|
||||||
}
|
}
|
||||||
|
|
||||||
let versions = {}
|
const versions = {}
|
||||||
const dataTypes = new Set()
|
const dataTypes = new Set()
|
||||||
|
|
||||||
for (const [version, dataSet] of Object.entries(dataPaths.pc)) {
|
for (const [version, dataSet] of Object.entries(dataPaths.pc)) {
|
||||||
|
|
@ -42,31 +42,6 @@ const versionToNumber = (ver) => {
|
||||||
return +`${x.padStart(2, '0')}${y.padStart(2, '0')}${z.padStart(2, '0')}`
|
return +`${x.padStart(2, '0')}${y.padStart(2, '0')}${z.padStart(2, '0')}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version clipping support
|
|
||||||
const minVersion = process.env.MIN_MC_VERSION
|
|
||||||
const maxVersion = process.env.MAX_MC_VERSION
|
|
||||||
|
|
||||||
// Filter versions based on MIN_VERSION and MAX_VERSION if provided
|
|
||||||
if (minVersion || maxVersion) {
|
|
||||||
const filteredVersions = {}
|
|
||||||
const minVersionNum = minVersion ? versionToNumber(minVersion) : 0
|
|
||||||
const maxVersionNum = maxVersion ? versionToNumber(maxVersion) : Infinity
|
|
||||||
|
|
||||||
for (const [version, dataSet] of Object.entries(versions)) {
|
|
||||||
const versionNum = versionToNumber(version)
|
|
||||||
if (versionNum >= minVersionNum && versionNum <= maxVersionNum) {
|
|
||||||
filteredVersions[version] = dataSet
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
versions = filteredVersions
|
|
||||||
|
|
||||||
console.log(`Version clipping applied: ${minVersion || 'none'} to ${maxVersion || 'none'}`)
|
|
||||||
console.log(`Processing ${Object.keys(versions).length} versions:`, Object.keys(versions).sort((a, b) => versionToNumber(a) - versionToNumber(b)))
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Bundling version range:', Object.keys(versions)[0], 'to', Object.keys(versions).at(-1))
|
|
||||||
|
|
||||||
// if not included here (even as {}) will not be bundled & accessible!
|
// if not included here (even as {}) will not be bundled & accessible!
|
||||||
// const compressedOutput = !!process.env.SINGLE_FILE_BUILD
|
// const compressedOutput = !!process.env.SINGLE_FILE_BUILD
|
||||||
const compressedOutput = true
|
const compressedOutput = true
|
||||||
|
|
@ -82,27 +57,22 @@ const dataTypeBundling2 = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const dataTypeBundling = {
|
const dataTypeBundling = {
|
||||||
language: process.env.SKIP_MC_DATA_LANGUAGE === 'true' ? {
|
language: {
|
||||||
raw: {}
|
|
||||||
} : {
|
|
||||||
ignoreRemoved: true,
|
ignoreRemoved: true,
|
||||||
ignoreChanges: true
|
ignoreChanges: true
|
||||||
},
|
},
|
||||||
blocks: {
|
blocks: {
|
||||||
arrKey: 'name',
|
arrKey: 'name',
|
||||||
processData(current, prev, _, version) {
|
processData (current, prev) {
|
||||||
for (const block of current) {
|
for (const block of current) {
|
||||||
const prevBlock = prev?.find(x => x.name === block.name)
|
|
||||||
if (block.transparent) {
|
if (block.transparent) {
|
||||||
const forceOpaque = block.name.includes('shulker_box') || block.name.match(/^double_.+_slab\d?$/) || ['melon_block', 'lit_pumpkin', 'lit_redstone_ore', 'lit_furnace'].includes(block.name)
|
const forceOpaque = block.name.includes('shulker_box') || block.name.match(/^double_.+_slab\d?$/) || ['melon_block', 'lit_pumpkin', 'lit_redstone_ore', 'lit_furnace'].includes(block.name)
|
||||||
|
|
||||||
|
const prevBlock = prev?.find(x => x.name === block.name);
|
||||||
if (forceOpaque || (prevBlock && !prevBlock.transparent)) {
|
if (forceOpaque || (prevBlock && !prevBlock.transparent)) {
|
||||||
block.transparent = false
|
block.transparent = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (block.hardness === 0 && prevBlock && prevBlock.hardness > 0) {
|
|
||||||
block.hardness = prevBlock.hardness
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ignoreRemoved: true,
|
// ignoreRemoved: true,
|
||||||
|
|
@ -166,9 +136,7 @@ const dataTypeBundling = {
|
||||||
blockLoot: {
|
blockLoot: {
|
||||||
arrKey: 'block'
|
arrKey: 'block'
|
||||||
},
|
},
|
||||||
recipes: process.env.SKIP_MC_DATA_RECIPES === 'true' ? {
|
recipes: {
|
||||||
raw: {}
|
|
||||||
} : {
|
|
||||||
raw: true
|
raw: true
|
||||||
// processData: processRecipes
|
// processData: processRecipes
|
||||||
},
|
},
|
||||||
|
|
@ -274,39 +242,30 @@ for (const [i, [version, dataSet]] of versionsArr.reverse().entries()) {
|
||||||
for (const [dataType, dataPath] of Object.entries(dataSet)) {
|
for (const [dataType, dataPath] of Object.entries(dataSet)) {
|
||||||
const config = dataTypeBundling[dataType]
|
const config = dataTypeBundling[dataType]
|
||||||
if (!config) continue
|
if (!config) continue
|
||||||
const ignoreCollisionShapes = dataType === 'blockCollisionShapes' && versionToNumber(version) >= versionToNumber('1.13')
|
if (dataType === 'blockCollisionShapes' && versionToNumber(version) >= versionToNumber('1.13')) {
|
||||||
|
// contents += ` get ${dataType} () { return window.globalGetCollisionShapes?.("${version}") },\n`
|
||||||
|
continue
|
||||||
|
}
|
||||||
let injectCode = ''
|
let injectCode = ''
|
||||||
const getRealData = (type) => {
|
const getData = (type) => {
|
||||||
const loc = `minecraft-data/data/${dataSet[type]}/`
|
const loc = `minecraft-data/data/${dataSet[type]}/`
|
||||||
const dataPathAbsolute = require.resolve(`minecraft-data/${loc}${type}`)
|
const dataPathAbsolute = require.resolve(`minecraft-data/${loc}${type}`)
|
||||||
// const data = fs.readFileSync(dataPathAbsolute, 'utf8')
|
// const data = fs.readFileSync(dataPathAbsolute, 'utf8')
|
||||||
const dataRaw = require(dataPathAbsolute)
|
const dataRaw = require(dataPathAbsolute)
|
||||||
return dataRaw
|
return dataRaw
|
||||||
}
|
}
|
||||||
const dataRaw = getRealData(dataType)
|
const dataRaw = getData(dataType)
|
||||||
let rawData = dataRaw
|
let rawData = dataRaw
|
||||||
if (config.raw) {
|
if (config.raw) {
|
||||||
rawDataVersions[dataType] ??= {}
|
rawDataVersions[dataType] ??= {}
|
||||||
rawDataVersions[dataType][version] = rawData
|
rawDataVersions[dataType][version] = rawData
|
||||||
if (config.raw === true) {
|
|
||||||
rawData = dataRaw
|
rawData = dataRaw
|
||||||
} else {
|
|
||||||
rawData = config.raw
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ignoreCollisionShapes && dataType === 'blockCollisionShapes') {
|
|
||||||
rawData = {
|
|
||||||
blocks: {},
|
|
||||||
shapes: {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!diffSources[dataType]) {
|
if (!diffSources[dataType]) {
|
||||||
diffSources[dataType] = new JsonOptimizer(config.arrKey, config.ignoreChanges, config.ignoreRemoved)
|
diffSources[dataType] = new JsonOptimizer(config.arrKey, config.ignoreChanges, config.ignoreRemoved)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
config.processData?.(dataRaw, previousData[dataType], getRealData, version)
|
config.processData?.(dataRaw, previousData[dataType], getData, version)
|
||||||
diffSources[dataType].recordDiff(version, dataRaw)
|
diffSources[dataType].recordDiff(version, dataRaw)
|
||||||
injectCode = `restoreDiff(sources, ${JSON.stringify(dataType)}, ${JSON.stringify(version)})`
|
injectCode = `restoreDiff(sources, ${JSON.stringify(dataType)}, ${JSON.stringify(version)})`
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -338,16 +297,16 @@ console.log('total size (mb)', totalSize / 1024 / 1024)
|
||||||
console.log(
|
console.log(
|
||||||
'size per data type (mb, %)',
|
'size per data type (mb, %)',
|
||||||
Object.fromEntries(Object.entries(sizePerDataType).map(([dataType, size]) => {
|
Object.fromEntries(Object.entries(sizePerDataType).map(([dataType, size]) => {
|
||||||
return [dataType, [size / 1024 / 1024, Math.round(size / totalSize * 100)]]
|
return [dataType, [size / 1024 / 1024, Math.round(size / totalSize * 100)]];
|
||||||
}).sort((a, b) => {
|
}).sort((a, b) => {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
return b[1][1] - a[1][1]
|
return b[1][1] - a[1][1];
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
|
|
||||||
function compressToBase64(input) {
|
function compressToBase64(input) {
|
||||||
const buffer = gzipSync(input)
|
const buffer = gzipSync(input);
|
||||||
return buffer.toString('base64')
|
return buffer.toString('base64');
|
||||||
}
|
}
|
||||||
|
|
||||||
const filePath = './generated/minecraft-data-optimized.json'
|
const filePath = './generated/minecraft-data-optimized.json'
|
||||||
|
|
@ -371,7 +330,6 @@ console.log('size', fs.lstatSync(filePath).size / 1000 / 1000, gzipSizeFromFileS
|
||||||
|
|
||||||
const { defaultVersion } = MCProtocol
|
const { defaultVersion } = MCProtocol
|
||||||
const data = MinecraftData(defaultVersion)
|
const data = MinecraftData(defaultVersion)
|
||||||
console.log('defaultVersion', defaultVersion, !!data)
|
|
||||||
const initialMcData = {
|
const initialMcData = {
|
||||||
[defaultVersion]: {
|
[defaultVersion]: {
|
||||||
version: data.version,
|
version: data.version,
|
||||||
|
|
|
||||||
|
|
@ -1,137 +0,0 @@
|
||||||
import blocksAtlas from 'mc-assets/dist/blocksAtlases.json'
|
|
||||||
import itemsAtlas from 'mc-assets/dist/itemsAtlases.json'
|
|
||||||
import * as fs from 'fs'
|
|
||||||
import * as path from 'path'
|
|
||||||
import sharp from 'sharp'
|
|
||||||
|
|
||||||
interface AtlasFile {
|
|
||||||
latest: {
|
|
||||||
suSv: number
|
|
||||||
tileSize: number
|
|
||||||
width: number
|
|
||||||
height: number
|
|
||||||
textures: {
|
|
||||||
[key: string]: {
|
|
||||||
u: number
|
|
||||||
v: number
|
|
||||||
su: number
|
|
||||||
sv: number
|
|
||||||
tileIndex: number
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function patchTextureAtlas(
|
|
||||||
atlasType: 'blocks' | 'items',
|
|
||||||
atlasData: AtlasFile,
|
|
||||||
customTexturesDir: string,
|
|
||||||
distDir: string
|
|
||||||
) {
|
|
||||||
// Check if custom textures directory exists and has files
|
|
||||||
if (!fs.existsSync(customTexturesDir) || fs.readdirSync(customTexturesDir).length === 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the latest atlas file
|
|
||||||
const atlasFiles = fs.readdirSync(distDir)
|
|
||||||
.filter(file => file.startsWith(`${atlasType}AtlasLatest`) && file.endsWith('.png'))
|
|
||||||
.sort()
|
|
||||||
|
|
||||||
if (atlasFiles.length === 0) {
|
|
||||||
console.log(`No ${atlasType}AtlasLatest.png found in ${distDir}`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const latestAtlasFile = atlasFiles[atlasFiles.length - 1]
|
|
||||||
const atlasPath = path.join(distDir, latestAtlasFile)
|
|
||||||
console.log(`Patching ${atlasPath}`)
|
|
||||||
|
|
||||||
// Get atlas dimensions
|
|
||||||
const atlasMetadata = await sharp(atlasPath).metadata()
|
|
||||||
if (!atlasMetadata.width || !atlasMetadata.height) {
|
|
||||||
throw new Error(`Failed to get atlas dimensions for ${atlasPath}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process each custom texture
|
|
||||||
const customTextureFiles = fs.readdirSync(customTexturesDir)
|
|
||||||
.filter(file => file.endsWith('.png'))
|
|
||||||
|
|
||||||
if (customTextureFiles.length === 0) return
|
|
||||||
|
|
||||||
// Prepare composite operations
|
|
||||||
const composites: sharp.OverlayOptions[] = []
|
|
||||||
|
|
||||||
for (const textureFile of customTextureFiles) {
|
|
||||||
const textureName = path.basename(textureFile, '.png')
|
|
||||||
|
|
||||||
if (atlasData.latest.textures[textureName]) {
|
|
||||||
const textureData = atlasData.latest.textures[textureName]
|
|
||||||
const customTexturePath = path.join(customTexturesDir, textureFile)
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Convert UV coordinates to pixel coordinates
|
|
||||||
const x = Math.round(textureData.u * atlasMetadata.width)
|
|
||||||
const y = Math.round(textureData.v * atlasMetadata.height)
|
|
||||||
const width = Math.round((textureData.su ?? atlasData.latest.suSv) * atlasMetadata.width)
|
|
||||||
const height = Math.round((textureData.sv ?? atlasData.latest.suSv) * atlasMetadata.height)
|
|
||||||
|
|
||||||
// Resize custom texture to match atlas dimensions and add to composite operations
|
|
||||||
const resizedTextureBuffer = await sharp(customTexturePath)
|
|
||||||
.resize(width, height, {
|
|
||||||
fit: 'fill',
|
|
||||||
kernel: 'nearest' // Preserve pixel art quality
|
|
||||||
})
|
|
||||||
.png()
|
|
||||||
.toBuffer()
|
|
||||||
|
|
||||||
composites.push({
|
|
||||||
input: resizedTextureBuffer,
|
|
||||||
left: x,
|
|
||||||
top: y,
|
|
||||||
blend: 'over'
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log(`Prepared ${textureName} at (${x}, ${y}) with size (${width}, ${height})`)
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Failed to prepare ${textureName}:`, error)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.warn(`Texture ${textureName} not found in ${atlasType} atlas`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (composites.length > 0) {
|
|
||||||
// Apply all patches at once using Sharp's composite
|
|
||||||
await sharp(atlasPath)
|
|
||||||
.composite(composites)
|
|
||||||
.png()
|
|
||||||
.toFile(atlasPath + '.tmp')
|
|
||||||
|
|
||||||
// Replace original with patched version
|
|
||||||
fs.renameSync(atlasPath + '.tmp', atlasPath)
|
|
||||||
console.log(`Saved patched ${atlasType} atlas to ${atlasPath}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const customBlocksDir = './assets/customTextures/blocks'
|
|
||||||
const customItemsDir = './assets/customTextures/items'
|
|
||||||
const distDir = './dist/static/image'
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Patch blocks atlas
|
|
||||||
await patchTextureAtlas('blocks', blocksAtlas as unknown as AtlasFile, customBlocksDir, distDir)
|
|
||||||
|
|
||||||
// Patch items atlas
|
|
||||||
await patchTextureAtlas('items', itemsAtlas as unknown as AtlasFile, customItemsDir, distDir)
|
|
||||||
|
|
||||||
console.log('Texture atlas patching completed!')
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to patch texture atlases:', error)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run the script
|
|
||||||
main()
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
import WebSocket from 'ws'
|
|
||||||
|
|
||||||
function formatBytes(bytes: number) {
|
|
||||||
return `${(bytes).toFixed(2)} MB`
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTime(ms: number) {
|
|
||||||
return `${(ms / 1000).toFixed(2)}s`
|
|
||||||
}
|
|
||||||
|
|
||||||
const ws = new WebSocket('ws://localhost:8081')
|
|
||||||
|
|
||||||
ws.on('open', () => {
|
|
||||||
console.log('Connected to metrics server, waiting for metrics...')
|
|
||||||
})
|
|
||||||
|
|
||||||
ws.on('message', (data) => {
|
|
||||||
try {
|
|
||||||
const metrics = JSON.parse(data.toString())
|
|
||||||
console.log('\nPerformance Metrics:')
|
|
||||||
console.log('------------------')
|
|
||||||
console.log(`Load Time: ${formatTime(metrics.loadTime)}`)
|
|
||||||
console.log(`Memory Usage: ${formatBytes(metrics.memoryUsage)}`)
|
|
||||||
console.log(`Timestamp: ${new Date(metrics.timestamp).toLocaleString()}`)
|
|
||||||
if (!process.argv.includes('-f')) { // follow mode
|
|
||||||
process.exit(0)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error parsing metrics:', error)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
ws.on('error', (error) => {
|
|
||||||
console.error('WebSocket error:', error)
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Exit if no metrics received after 5 seconds
|
|
||||||
setTimeout(() => {
|
|
||||||
console.error('Timeout waiting for metrics')
|
|
||||||
process.exit(1)
|
|
||||||
}, 5000)
|
|
||||||
|
|
@ -149,8 +149,8 @@ async function main() {
|
||||||
}
|
}
|
||||||
fs.writeFileSync(lockfilePath, newLockfileContent)
|
fs.writeFileSync(lockfilePath, newLockfileContent)
|
||||||
console.log('\nUpdated pnpm-lock.yaml with new commit hashes')
|
console.log('\nUpdated pnpm-lock.yaml with new commit hashes')
|
||||||
// console.log('Running pnpm install to apply changes...')
|
console.log('Running pnpm install to apply changes...')
|
||||||
// execSync('pnpm install', { stdio: 'inherit' })
|
execSync('pnpm install', { stdio: 'inherit' })
|
||||||
console.log('Done!')
|
console.log('Done!')
|
||||||
} else {
|
} else {
|
||||||
console.log('\nNo changes were made.')
|
console.log('\nNo changes were made.')
|
||||||
|
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
import {WebSocketServer} from 'ws'
|
|
||||||
|
|
||||||
export function startWsServer(port: number = 8081, tryOtherPort: boolean = true): Promise<number> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const tryPort = (currentPort: number) => {
|
|
||||||
const wss = new WebSocketServer({ port: currentPort })
|
|
||||||
.on('listening', () => {
|
|
||||||
console.log(`WebSocket server started on port ${currentPort}`)
|
|
||||||
resolve(currentPort)
|
|
||||||
})
|
|
||||||
.on('error', (err: any) => {
|
|
||||||
if (err.code === 'EADDRINUSE' && tryOtherPort) {
|
|
||||||
console.log(`Port ${currentPort} in use, trying ${currentPort + 1}`)
|
|
||||||
wss.close()
|
|
||||||
tryPort(currentPort + 1)
|
|
||||||
} else {
|
|
||||||
reject(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
wss.on('connection', (ws) => {
|
|
||||||
console.log('Client connected')
|
|
||||||
|
|
||||||
ws.on('message', (message) => {
|
|
||||||
try {
|
|
||||||
// Simply relay the message to all connected clients except sender
|
|
||||||
wss.clients.forEach(client => {
|
|
||||||
if (client !== ws && client.readyState === WebSocket.OPEN) {
|
|
||||||
client.send(message.toString())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error processing message:', error)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
ws.on('close', () => {
|
|
||||||
console.log('Client disconnected')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
tryPort(port)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
@ -24,7 +24,6 @@ export type MobileButtonConfig = {
|
||||||
readonly icon?: string
|
readonly icon?: string
|
||||||
readonly action?: ActionType
|
readonly action?: ActionType
|
||||||
readonly actionHold?: ActionType | ActionHoldConfig
|
readonly actionHold?: ActionType | ActionHoldConfig
|
||||||
readonly iconStyle?: React.CSSProperties
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AppConfig = {
|
export type AppConfig = {
|
||||||
|
|
@ -35,7 +34,7 @@ export type AppConfig = {
|
||||||
// defaultVersion?: string
|
// defaultVersion?: string
|
||||||
peerJsServer?: string
|
peerJsServer?: string
|
||||||
peerJsServerFallback?: string
|
peerJsServerFallback?: string
|
||||||
promoteServers?: Array<{ ip, description, name?, version?, }>
|
promoteServers?: Array<{ ip, description, version? }>
|
||||||
mapsProvider?: string
|
mapsProvider?: string
|
||||||
|
|
||||||
appParams?: Record<string, any> // query string params
|
appParams?: Record<string, any> // query string params
|
||||||
|
|
@ -57,12 +56,9 @@ export type AppConfig = {
|
||||||
defaultUsername?: string
|
defaultUsername?: string
|
||||||
skinTexturesProxy?: string
|
skinTexturesProxy?: string
|
||||||
alwaysReconnectButton?: boolean
|
alwaysReconnectButton?: boolean
|
||||||
reportBugButtonWithReconnect?: boolean
|
|
||||||
disabledCommands?: string[] // Array of command IDs to disable (e.g. ['general.jump', 'general.chat'])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadAppConfig = (appConfig: AppConfig) => {
|
export const loadAppConfig = (appConfig: AppConfig) => {
|
||||||
|
|
||||||
if (miscUiState.appConfig) {
|
if (miscUiState.appConfig) {
|
||||||
Object.assign(miscUiState.appConfig, appConfig)
|
Object.assign(miscUiState.appConfig, appConfig)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -74,7 +70,7 @@ export const loadAppConfig = (appConfig: AppConfig) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
disabledSettings.value.add(key)
|
disabledSettings.value.add(key)
|
||||||
// since the setting is forced, we need to set it to that value
|
// since the setting is forced, we need to set it to that value
|
||||||
if (appConfig.defaultSettings && key in appConfig.defaultSettings && !qsOptions[key]) {
|
if (appConfig.defaultSettings?.[key] && !qsOptions[key]) {
|
||||||
options[key] = appConfig.defaultSettings[key]
|
options[key] = appConfig.defaultSettings[key]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -82,7 +78,6 @@ export const loadAppConfig = (appConfig: AppConfig) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// todo apply defaultSettings to defaults even if not forced in case of remote config
|
|
||||||
|
|
||||||
if (appConfig.keybindings) {
|
if (appConfig.keybindings) {
|
||||||
Object.assign(customKeymaps, defaultsDeep(appConfig.keybindings, customKeymaps))
|
Object.assign(customKeymaps, defaultsDeep(appConfig.keybindings, customKeymaps))
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ export type AppQsParams = {
|
||||||
username?: string
|
username?: string
|
||||||
lockConnect?: string
|
lockConnect?: string
|
||||||
autoConnect?: string
|
autoConnect?: string
|
||||||
alwaysReconnect?: string
|
|
||||||
// googledrive.ts params
|
// googledrive.ts params
|
||||||
state?: string
|
state?: string
|
||||||
// ServersListProvider.tsx params
|
// ServersListProvider.tsx params
|
||||||
|
|
@ -47,7 +46,6 @@ export type AppQsParams = {
|
||||||
connectText?: string
|
connectText?: string
|
||||||
freezeSettings?: string
|
freezeSettings?: string
|
||||||
testIosCrash?: string
|
testIosCrash?: string
|
||||||
addPing?: string
|
|
||||||
|
|
||||||
// Replay params
|
// Replay params
|
||||||
replayFilter?: string
|
replayFilter?: string
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import { proxy, subscribe } from 'valtio'
|
||||||
import { getDefaultRendererState } from 'renderer/viewer/baseGraphicsBackend'
|
import { getDefaultRendererState } from 'renderer/viewer/baseGraphicsBackend'
|
||||||
import { getSyncWorld } from 'renderer/playground/shared'
|
import { getSyncWorld } from 'renderer/playground/shared'
|
||||||
import { MaybePromise } from 'contro-max/build/types/store'
|
import { MaybePromise } from 'contro-max/build/types/store'
|
||||||
import { PANORAMA_VERSION } from 'renderer/viewer/three/panoramaShared'
|
|
||||||
import { playerState } from './mineflayer/playerState'
|
import { playerState } from './mineflayer/playerState'
|
||||||
import { createNotificationProgressReporter, ProgressReporter } from './core/progressReporter'
|
import { createNotificationProgressReporter, ProgressReporter } from './core/progressReporter'
|
||||||
import { setLoadingScreenStatus } from './appStatus'
|
import { setLoadingScreenStatus } from './appStatus'
|
||||||
|
|
@ -16,9 +15,6 @@ import { activeModalStack, miscUiState } from './globalState'
|
||||||
import { options } from './optionsStorage'
|
import { options } from './optionsStorage'
|
||||||
import { ResourcesManager, ResourcesManagerTransferred } from './resourcesManager'
|
import { ResourcesManager, ResourcesManagerTransferred } from './resourcesManager'
|
||||||
import { watchOptionsAfterWorldViewInit } from './watchOptions'
|
import { watchOptionsAfterWorldViewInit } from './watchOptions'
|
||||||
import { loadMinecraftData } from './connect'
|
|
||||||
import { reloadChunks } from './utils'
|
|
||||||
import { displayClientChat } from './botUtils'
|
|
||||||
|
|
||||||
export interface RendererReactiveState {
|
export interface RendererReactiveState {
|
||||||
world: {
|
world: {
|
||||||
|
|
@ -116,7 +112,7 @@ export class AppViewer {
|
||||||
inWorldRenderingConfig: WorldRendererConfig = proxy(defaultWorldRendererConfig)
|
inWorldRenderingConfig: WorldRendererConfig = proxy(defaultWorldRendererConfig)
|
||||||
lastCamUpdate = 0
|
lastCamUpdate = 0
|
||||||
playerState = playerState
|
playerState = playerState
|
||||||
rendererState = getDefaultRendererState().reactive
|
rendererState = proxy(getDefaultRendererState().reactive)
|
||||||
nonReactiveState: NonReactiveState = getDefaultRendererState().nonReactive
|
nonReactiveState: NonReactiveState = getDefaultRendererState().nonReactive
|
||||||
worldReady: Promise<void>
|
worldReady: Promise<void>
|
||||||
private resolveWorldReady: () => void
|
private resolveWorldReady: () => void
|
||||||
|
|
@ -166,9 +162,6 @@ export class AppViewer {
|
||||||
|
|
||||||
// Execute queued action if exists
|
// Execute queued action if exists
|
||||||
if (this.currentState) {
|
if (this.currentState) {
|
||||||
if (this.currentState.method === 'startPanorama') {
|
|
||||||
this.startPanorama()
|
|
||||||
} else {
|
|
||||||
const { method, args } = this.currentState
|
const { method, args } = this.currentState
|
||||||
this.backend[method](...args)
|
this.backend[method](...args)
|
||||||
if (method === 'startWorld') {
|
if (method === 'startWorld') {
|
||||||
|
|
@ -176,7 +169,6 @@ export class AppViewer {
|
||||||
// void this.worldView!.init(args[0].playerState.getPosition())
|
// void this.worldView!.init(args[0].playerState.getPosition())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
modalStackUpdateChecks()
|
modalStackUpdateChecks()
|
||||||
|
|
@ -199,13 +191,6 @@ export class AppViewer {
|
||||||
this.currentDisplay = 'world'
|
this.currentDisplay = 'world'
|
||||||
const startPosition = bot.entity?.position ?? new Vec3(0, 64, 0)
|
const startPosition = bot.entity?.position ?? new Vec3(0, 64, 0)
|
||||||
this.worldView = new WorldDataEmitter(world, renderDistance, startPosition)
|
this.worldView = new WorldDataEmitter(world, renderDistance, startPosition)
|
||||||
this.worldView.panicChunksReload = () => {
|
|
||||||
if (!options.experimentalClientSelfReload) return
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
|
||||||
displayClientChat(`[client] client panicked due to too long loading time. Soft reloading chunks...`)
|
|
||||||
}
|
|
||||||
void reloadChunks()
|
|
||||||
}
|
|
||||||
window.worldView = this.worldView
|
window.worldView = this.worldView
|
||||||
watchOptionsAfterWorldViewInit(this.worldView)
|
watchOptionsAfterWorldViewInit(this.worldView)
|
||||||
this.appConfigUdpate()
|
this.appConfigUdpate()
|
||||||
|
|
@ -240,17 +225,11 @@ export class AppViewer {
|
||||||
|
|
||||||
startPanorama () {
|
startPanorama () {
|
||||||
if (this.currentDisplay === 'menu') return
|
if (this.currentDisplay === 'menu') return
|
||||||
if (options.disableAssets) return
|
|
||||||
if (this.backend && !hasAppStatus()) {
|
|
||||||
this.currentDisplay = 'menu'
|
this.currentDisplay = 'menu'
|
||||||
if (process.env.SINGLE_FILE_BUILD_MODE) {
|
if (options.disableAssets) return
|
||||||
void loadMinecraftData(PANORAMA_VERSION).then(() => {
|
if (this.backend) {
|
||||||
this.backend?.startPanorama()
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this.backend.startPanorama()
|
this.backend.startPanorama()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this.currentState = { method: 'startPanorama', args: [] }
|
this.currentState = { method: 'startPanorama', args: [] }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -337,16 +316,15 @@ const initialMenuStart = async () => {
|
||||||
}
|
}
|
||||||
window.initialMenuStart = initialMenuStart
|
window.initialMenuStart = initialMenuStart
|
||||||
|
|
||||||
const hasAppStatus = () => activeModalStack.some(m => m.reactType === 'app-status')
|
|
||||||
|
|
||||||
const modalStackUpdateChecks = () => {
|
const modalStackUpdateChecks = () => {
|
||||||
// maybe start panorama
|
// maybe start panorama
|
||||||
if (!miscUiState.gameLoaded && !hasAppStatus()) {
|
if (!miscUiState.gameLoaded) {
|
||||||
void initialMenuStart()
|
void initialMenuStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appViewer.backend) {
|
if (appViewer.backend) {
|
||||||
appViewer.backend.setRendering(!hasAppStatus())
|
const hasAppStatus = activeModalStack.some(m => m.reactType === 'app-status')
|
||||||
|
appViewer.backend.setRendering(!hasAppStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
appViewer.inWorldRenderingConfig.foreground = activeModalStack.length === 0
|
appViewer.inWorldRenderingConfig.foreground = activeModalStack.length === 0
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,7 @@ let audioContext: AudioContext
|
||||||
const sounds: Record<string, any> = {}
|
const sounds: Record<string, any> = {}
|
||||||
|
|
||||||
// Track currently playing sounds and their gain nodes
|
// Track currently playing sounds and their gain nodes
|
||||||
const activeSounds: Array<{
|
const activeSounds: Array<{ source: AudioBufferSourceNode; gainNode: GainNode; volumeMultiplier: number }> = []
|
||||||
source: AudioBufferSourceNode;
|
|
||||||
gainNode: GainNode;
|
|
||||||
volumeMultiplier: number;
|
|
||||||
isMusic: boolean;
|
|
||||||
}> = []
|
|
||||||
window.activeSounds = activeSounds
|
window.activeSounds = activeSounds
|
||||||
|
|
||||||
// load as many resources on page load as possible instead on demand as user can disable internet connection after he thinks the page is loaded
|
// load as many resources on page load as possible instead on demand as user can disable internet connection after he thinks the page is loaded
|
||||||
|
|
@ -48,7 +43,7 @@ export async function loadSound (path: string, contents = path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loadOrPlaySound = async (url, soundVolume = 1, loadTimeout = options.remoteSoundsLoadTimeout, loop = false, isMusic = false) => {
|
export const loadOrPlaySound = async (url, soundVolume = 1, loadTimeout = 500) => {
|
||||||
const soundBuffer = sounds[url]
|
const soundBuffer = sounds[url]
|
||||||
if (!soundBuffer) {
|
if (!soundBuffer) {
|
||||||
const start = Date.now()
|
const start = Date.now()
|
||||||
|
|
@ -56,11 +51,11 @@ export const loadOrPlaySound = async (url, soundVolume = 1, loadTimeout = option
|
||||||
if (cancelled || Date.now() - start > loadTimeout) return
|
if (cancelled || Date.now() - start > loadTimeout) return
|
||||||
}
|
}
|
||||||
|
|
||||||
return playSound(url, soundVolume, loop, isMusic)
|
return playSound(url, soundVolume)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function playSound (url, soundVolume = 1, loop = false, isMusic = false) {
|
export async function playSound (url, soundVolume = 1) {
|
||||||
const volume = soundVolume * (options.volume / 100) * (isMusic ? options.musicVolume / 100 : 1)
|
const volume = soundVolume * (options.volume / 100)
|
||||||
|
|
||||||
if (!volume) return
|
if (!volume) return
|
||||||
|
|
||||||
|
|
@ -80,14 +75,13 @@ export async function playSound (url, soundVolume = 1, loop = false, isMusic = f
|
||||||
const gainNode = audioContext.createGain()
|
const gainNode = audioContext.createGain()
|
||||||
const source = audioContext.createBufferSource()
|
const source = audioContext.createBufferSource()
|
||||||
source.buffer = soundBuffer
|
source.buffer = soundBuffer
|
||||||
source.loop = loop
|
|
||||||
source.connect(gainNode)
|
source.connect(gainNode)
|
||||||
gainNode.connect(audioContext.destination)
|
gainNode.connect(audioContext.destination)
|
||||||
gainNode.gain.value = volume
|
gainNode.gain.value = volume
|
||||||
source.start(0)
|
source.start(0)
|
||||||
|
|
||||||
// Add to active sounds
|
// Add to active sounds
|
||||||
activeSounds.push({ source, gainNode, volumeMultiplier: soundVolume, isMusic })
|
activeSounds.push({ source, gainNode, volumeMultiplier: soundVolume })
|
||||||
|
|
||||||
const callbacks = [] as Array<() => void>
|
const callbacks = [] as Array<() => void>
|
||||||
source.onended = () => {
|
source.onended = () => {
|
||||||
|
|
@ -105,17 +99,6 @@ export async function playSound (url, soundVolume = 1, loop = false, isMusic = f
|
||||||
onEnded (callback: () => void) {
|
onEnded (callback: () => void) {
|
||||||
callbacks.push(callback)
|
callbacks.push(callback)
|
||||||
},
|
},
|
||||||
stop () {
|
|
||||||
try {
|
|
||||||
source.stop()
|
|
||||||
// Remove from active sounds
|
|
||||||
const index = activeSounds.findIndex(s => s.source === source)
|
|
||||||
if (index !== -1) activeSounds.splice(index, 1)
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('Failed to stop sound:', err)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
gainNode,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,24 +113,11 @@ export function stopAllSounds () {
|
||||||
activeSounds.length = 0
|
activeSounds.length = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stopSound (url: string) {
|
export function changeVolumeOfCurrentlyPlayingSounds (newVolume: number) {
|
||||||
const soundIndex = activeSounds.findIndex(s => s.source.buffer === sounds[url])
|
|
||||||
if (soundIndex !== -1) {
|
|
||||||
const { source } = activeSounds[soundIndex]
|
|
||||||
try {
|
|
||||||
source.stop()
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('Failed to stop sound:', err)
|
|
||||||
}
|
|
||||||
activeSounds.splice(soundIndex, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function changeVolumeOfCurrentlyPlayingSounds (newVolume: number, newMusicVolume: number) {
|
|
||||||
const normalizedVolume = newVolume / 100
|
const normalizedVolume = newVolume / 100
|
||||||
for (const { gainNode, volumeMultiplier, isMusic } of activeSounds) {
|
for (const { gainNode, volumeMultiplier } of activeSounds) {
|
||||||
try {
|
try {
|
||||||
gainNode.gain.value = normalizedVolume * volumeMultiplier * (isMusic ? newMusicVolume / 100 : 1)
|
gainNode.gain.value = normalizedVolume * volumeMultiplier
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('Failed to change sound volume:', err)
|
console.warn('Failed to change sound volume:', err)
|
||||||
}
|
}
|
||||||
|
|
@ -155,9 +125,5 @@ export function changeVolumeOfCurrentlyPlayingSounds (newVolume: number, newMusi
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeKey(options, 'volume', () => {
|
subscribeKey(options, 'volume', () => {
|
||||||
changeVolumeOfCurrentlyPlayingSounds(options.volume, options.musicVolume)
|
changeVolumeOfCurrentlyPlayingSounds(options.volume)
|
||||||
})
|
|
||||||
|
|
||||||
subscribeKey(options, 'musicVolume', () => {
|
|
||||||
changeVolumeOfCurrentlyPlayingSounds(options.volume, options.musicVolume)
|
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -118,14 +118,6 @@ export const formatMessage = (message: MessageInput, mcData: IndexedData = globa
|
||||||
return msglist
|
return msglist
|
||||||
}
|
}
|
||||||
|
|
||||||
export const messageToString = (message: MessageInput | string) => {
|
|
||||||
if (typeof message === 'string') {
|
|
||||||
return message
|
|
||||||
}
|
|
||||||
const msglist = formatMessage(message)
|
|
||||||
return msglist.map(msg => msg.text).join('')
|
|
||||||
}
|
|
||||||
|
|
||||||
const blockToItemRemaps = {
|
const blockToItemRemaps = {
|
||||||
water: 'water_bucket',
|
water: 'water_bucket',
|
||||||
lava: 'lava_bucket',
|
lava: 'lava_bucket',
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
import MinecraftData from 'minecraft-data'
|
import MinecraftData from 'minecraft-data'
|
||||||
import PrismarineBlock from 'prismarine-block'
|
import PrismarineBlock from 'prismarine-block'
|
||||||
import PrismarineItem from 'prismarine-item'
|
import PrismarineItem from 'prismarine-item'
|
||||||
|
import pathfinder from 'mineflayer-pathfinder'
|
||||||
import { miscUiState } from './globalState'
|
import { miscUiState } from './globalState'
|
||||||
import supportedVersions from './supportedVersions.mjs'
|
import supportedVersions from './supportedVersions.mjs'
|
||||||
import { options } from './optionsStorage'
|
import { options } from './optionsStorage'
|
||||||
|
|
@ -64,6 +65,7 @@ export const loadMinecraftData = async (version: string) => {
|
||||||
window.PrismarineItem = PrismarineItem(mcData.version.minecraftVersion!)
|
window.PrismarineItem = PrismarineItem(mcData.version.minecraftVersion!)
|
||||||
window.loadedData = mcData
|
window.loadedData = mcData
|
||||||
window.mcData = mcData
|
window.mcData = mcData
|
||||||
|
window.pathfinder = pathfinder
|
||||||
miscUiState.loadedDataVersion = version
|
miscUiState.loadedDataVersion = version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,10 +116,6 @@ export const contro = new ControMax({
|
||||||
window.controMax = contro
|
window.controMax = contro
|
||||||
export type Command = CommandEventArgument<typeof contro['_commandsRaw']>['command']
|
export type Command = CommandEventArgument<typeof contro['_commandsRaw']>['command']
|
||||||
|
|
||||||
export const isCommandDisabled = (command: Command) => {
|
|
||||||
return miscUiState.appConfig?.disabledCommands?.includes(command)
|
|
||||||
}
|
|
||||||
|
|
||||||
onControInit()
|
onControInit()
|
||||||
|
|
||||||
updateBinds(customKeymaps)
|
updateBinds(customKeymaps)
|
||||||
|
|
@ -548,8 +544,6 @@ const customCommandsHandler = ({ command }) => {
|
||||||
contro.on('trigger', customCommandsHandler)
|
contro.on('trigger', customCommandsHandler)
|
||||||
|
|
||||||
contro.on('trigger', ({ command }) => {
|
contro.on('trigger', ({ command }) => {
|
||||||
if (isCommandDisabled(command)) return
|
|
||||||
|
|
||||||
const willContinue = !isGameActive(true)
|
const willContinue = !isGameActive(true)
|
||||||
alwaysPressedHandledCommand(command)
|
alwaysPressedHandledCommand(command)
|
||||||
if (willContinue) return
|
if (willContinue) return
|
||||||
|
|
@ -683,8 +677,6 @@ contro.on('trigger', ({ command }) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
contro.on('release', ({ command }) => {
|
contro.on('release', ({ command }) => {
|
||||||
if (isCommandDisabled(command)) return
|
|
||||||
|
|
||||||
inModalCommand(command, false)
|
inModalCommand(command, false)
|
||||||
onTriggerOrReleased(command, false)
|
onTriggerOrReleased(command, false)
|
||||||
})
|
})
|
||||||
|
|
@ -818,11 +810,6 @@ export const f3Keybinds: Array<{
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
export const reloadChunksAction = () => {
|
|
||||||
const action = f3Keybinds.find(f3Keybind => f3Keybind.key === 'KeyA')
|
|
||||||
void action!.action()
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
if (!isGameActive(false)) return
|
if (!isGameActive(false)) return
|
||||||
if (contro.pressedKeys.has('F3')) {
|
if (contro.pressedKeys.has('F3')) {
|
||||||
|
|
@ -992,17 +979,14 @@ export function updateBinds (commands: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onF3LongPress = async () => {
|
export const onF3LongPress = async () => {
|
||||||
const actions = f3Keybinds.filter(f3Keybind => {
|
const select = await showOptionsModal('', f3Keybinds.filter(f3Keybind => {
|
||||||
return f3Keybind.mobileTitle && (f3Keybind.enabled?.() ?? true)
|
return f3Keybind.mobileTitle && (f3Keybind.enabled?.() ?? true)
|
||||||
})
|
}).map(f3Keybind => {
|
||||||
const actionNames = actions.map(f3Keybind => {
|
|
||||||
return `${f3Keybind.mobileTitle}${f3Keybind.key ? ` (F3+${f3Keybind.key})` : ''}`
|
return `${f3Keybind.mobileTitle}${f3Keybind.key ? ` (F3+${f3Keybind.key})` : ''}`
|
||||||
})
|
}))
|
||||||
const select = await showOptionsModal('', actionNames)
|
|
||||||
if (!select) return
|
if (!select) return
|
||||||
const actionIndex = actionNames.indexOf(select)
|
const f3Keybind = f3Keybinds.find(f3Keybind => f3Keybind.mobileTitle === select)
|
||||||
const f3Keybind = actions[actionIndex]!
|
if (f3Keybind) void f3Keybind.action()
|
||||||
void f3Keybind.action()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handleMobileButtonCustomAction = (action: CustomAction) => {
|
export const handleMobileButtonCustomAction = (action: CustomAction) => {
|
||||||
|
|
@ -1012,16 +996,9 @@ export const handleMobileButtonCustomAction = (action: CustomAction) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const triggerCommand = (command: Command, isDown: boolean) => {
|
|
||||||
handleMobileButtonActionCommand(command, isDown)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const handleMobileButtonActionCommand = (command: ActionType | ActionHoldConfig, isDown: boolean) => {
|
export const handleMobileButtonActionCommand = (command: ActionType | ActionHoldConfig, isDown: boolean) => {
|
||||||
const commandValue = typeof command === 'string' ? command : 'command' in command ? command.command : command
|
const commandValue = typeof command === 'string' ? command : 'command' in command ? command.command : command
|
||||||
|
|
||||||
// Check if command is disabled before proceeding
|
|
||||||
if (typeof commandValue === 'string' && isCommandDisabled(commandValue as Command)) return
|
|
||||||
|
|
||||||
if (typeof commandValue === 'string' && !stringStartsWith(commandValue, 'custom')) {
|
if (typeof commandValue === 'string' && !stringStartsWith(commandValue, 'custom')) {
|
||||||
const event: CommandEventArgument<typeof contro['_commandsRaw']> = {
|
const event: CommandEventArgument<typeof contro['_commandsRaw']> = {
|
||||||
command: commandValue as Command,
|
command: commandValue as Command,
|
||||||
|
|
|
||||||
|
|
@ -1,106 +0,0 @@
|
||||||
import { proxy } from 'valtio'
|
|
||||||
|
|
||||||
export const ideState = proxy({
|
|
||||||
id: '',
|
|
||||||
contents: '',
|
|
||||||
line: 0,
|
|
||||||
column: 0,
|
|
||||||
language: 'typescript',
|
|
||||||
title: '',
|
|
||||||
})
|
|
||||||
globalThis.ideState = ideState
|
|
||||||
|
|
||||||
export const registerIdeChannels = () => {
|
|
||||||
registerIdeOpenChannel()
|
|
||||||
registerIdeSaveChannel()
|
|
||||||
}
|
|
||||||
|
|
||||||
const registerIdeOpenChannel = () => {
|
|
||||||
const CHANNEL_NAME = 'minecraft-web-client:ide-open'
|
|
||||||
|
|
||||||
const packetStructure = [
|
|
||||||
'container',
|
|
||||||
[
|
|
||||||
{
|
|
||||||
name: 'id',
|
|
||||||
type: ['pstring', { countType: 'i16' }]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'language',
|
|
||||||
type: ['pstring', { countType: 'i16' }]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'contents',
|
|
||||||
type: ['pstring', { countType: 'i16' }]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'line',
|
|
||||||
type: 'i32'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'column',
|
|
||||||
type: 'i32'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'title',
|
|
||||||
type: ['pstring', { countType: 'i16' }]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
bot._client.registerChannel(CHANNEL_NAME, packetStructure, true)
|
|
||||||
|
|
||||||
bot._client.on(CHANNEL_NAME as any, (data) => {
|
|
||||||
const { id, language, contents, line, column, title } = data
|
|
||||||
|
|
||||||
ideState.contents = contents
|
|
||||||
ideState.line = line
|
|
||||||
ideState.column = column
|
|
||||||
ideState.id = id
|
|
||||||
ideState.language = language || 'typescript'
|
|
||||||
ideState.title = title
|
|
||||||
})
|
|
||||||
|
|
||||||
console.debug(`registered custom channel ${CHANNEL_NAME} channel`)
|
|
||||||
}
|
|
||||||
const IDE_SAVE_CHANNEL_NAME = 'minecraft-web-client:ide-save'
|
|
||||||
const registerIdeSaveChannel = () => {
|
|
||||||
|
|
||||||
const packetStructure = [
|
|
||||||
'container',
|
|
||||||
[
|
|
||||||
{
|
|
||||||
name: 'id',
|
|
||||||
type: ['pstring', { countType: 'i16' }]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'contents',
|
|
||||||
type: ['pstring', { countType: 'i16' }]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'language',
|
|
||||||
type: ['pstring', { countType: 'i16' }]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'line',
|
|
||||||
type: 'i32'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'column',
|
|
||||||
type: 'i32'
|
|
||||||
},
|
|
||||||
]
|
|
||||||
]
|
|
||||||
bot._client.registerChannel(IDE_SAVE_CHANNEL_NAME, packetStructure, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const saveIde = () => {
|
|
||||||
bot._client.writeChannel(IDE_SAVE_CHANNEL_NAME, {
|
|
||||||
id: ideState.id,
|
|
||||||
contents: ideState.contents,
|
|
||||||
language: ideState.language,
|
|
||||||
// todo: reflect updated
|
|
||||||
line: ideState.line,
|
|
||||||
column: ideState.column,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
@ -2,20 +2,19 @@ import PItem from 'prismarine-item'
|
||||||
import { getThreeJsRendererMethods } from 'renderer/viewer/three/threeJsMethods'
|
import { getThreeJsRendererMethods } from 'renderer/viewer/three/threeJsMethods'
|
||||||
import { options } from './optionsStorage'
|
import { options } from './optionsStorage'
|
||||||
import { jeiCustomCategories } from './inventoryWindows'
|
import { jeiCustomCategories } from './inventoryWindows'
|
||||||
import { registerIdeChannels } from './core/ideChannels'
|
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
customEvents.on('mineflayerBotCreated', async () => {
|
customEvents.on('mineflayerBotCreated', async () => {
|
||||||
if (!options.customChannels) return
|
if (!options.customChannels) return
|
||||||
|
await new Promise(resolve => {
|
||||||
bot.once('login', () => {
|
bot.once('login', () => {
|
||||||
|
resolve(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
registerBlockModelsChannel()
|
registerBlockModelsChannel()
|
||||||
registerMediaChannels()
|
registerMediaChannels()
|
||||||
registerSectionAnimationChannels()
|
registerSectionAnimationChannels()
|
||||||
registeredJeiChannel()
|
registeredJeiChannel()
|
||||||
registerBlockInteractionsCustomizationChannel()
|
|
||||||
registerWaypointChannels()
|
|
||||||
registerIdeChannels()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,95 +32,6 @@ const registerChannel = (channelName: string, packetStructure: any[], handler: (
|
||||||
console.debug(`registered custom channel ${channelName} channel`)
|
console.debug(`registered custom channel ${channelName} channel`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const registerBlockInteractionsCustomizationChannel = () => {
|
|
||||||
const CHANNEL_NAME = 'minecraft-web-client:block-interactions-customization'
|
|
||||||
const packetStructure = [
|
|
||||||
'container',
|
|
||||||
[
|
|
||||||
{
|
|
||||||
name: 'newConfiguration',
|
|
||||||
type: ['pstring', { countType: 'i16' }]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
registerChannel(CHANNEL_NAME, packetStructure, (data) => {
|
|
||||||
const config = JSON.parse(data.newConfiguration)
|
|
||||||
bot.mouse.setConfigFromPacket(config)
|
|
||||||
}, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
const registerWaypointChannels = () => {
|
|
||||||
const packetStructure = [
|
|
||||||
'container',
|
|
||||||
[
|
|
||||||
{
|
|
||||||
name: 'id',
|
|
||||||
type: ['pstring', { countType: 'i16' }]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'x',
|
|
||||||
type: 'f32'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'y',
|
|
||||||
type: 'f32'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'z',
|
|
||||||
type: 'f32'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'minDistance',
|
|
||||||
type: 'i32'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'label',
|
|
||||||
type: ['pstring', { countType: 'i16' }]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'color',
|
|
||||||
type: 'i32'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'metadataJson',
|
|
||||||
type: ['pstring', { countType: 'i16' }]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
registerChannel('minecraft-web-client:waypoint-add', packetStructure, (data) => {
|
|
||||||
// Parse metadata if provided
|
|
||||||
let metadata: any = {}
|
|
||||||
if (data.metadataJson && data.metadataJson.trim() !== '') {
|
|
||||||
try {
|
|
||||||
metadata = JSON.parse(data.metadataJson)
|
|
||||||
} catch (error) {
|
|
||||||
console.warn('Failed to parse waypoint metadataJson:', error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getThreeJsRendererMethods()?.addWaypoint(data.id, data.x, data.y, data.z, {
|
|
||||||
minDistance: data.minDistance,
|
|
||||||
label: data.label || undefined,
|
|
||||||
color: data.color || undefined,
|
|
||||||
metadata
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
registerChannel('minecraft-web-client:waypoint-delete', [
|
|
||||||
'container',
|
|
||||||
[
|
|
||||||
{
|
|
||||||
name: 'id',
|
|
||||||
type: ['pstring', { countType: 'i16' }]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
], (data) => {
|
|
||||||
getThreeJsRendererMethods()?.removeWaypoint(data.id)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const registerBlockModelsChannel = () => {
|
const registerBlockModelsChannel = () => {
|
||||||
const CHANNEL_NAME = 'minecraft-web-client:blockmodels'
|
const CHANNEL_NAME = 'minecraft-web-client:blockmodels'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
//@ts-check
|
|
||||||
import * as nbt from 'prismarine-nbt'
|
|
||||||
import { options } from './optionsStorage'
|
import { options } from './optionsStorage'
|
||||||
|
|
||||||
|
//@ts-check
|
||||||
const { EventEmitter } = require('events')
|
const { EventEmitter } = require('events')
|
||||||
const debug = require('debug')('minecraft-protocol')
|
const debug = require('debug')('minecraft-protocol')
|
||||||
const states = require('minecraft-protocol/src/states')
|
const states = require('minecraft-protocol/src/states')
|
||||||
|
|
@ -52,20 +51,8 @@ class CustomChannelClient extends EventEmitter {
|
||||||
this.emit('state', newProperty, oldProperty)
|
this.emit('state', newProperty, oldProperty)
|
||||||
}
|
}
|
||||||
|
|
||||||
end(endReason, fullReason) {
|
end(reason) {
|
||||||
// eslint-disable-next-line unicorn/no-this-assignment
|
this._endReason = reason
|
||||||
const client = this
|
|
||||||
if (client.state === states.PLAY) {
|
|
||||||
fullReason ||= loadedData.supportFeature('chatPacketsUseNbtComponents')
|
|
||||||
? nbt.comp({ text: nbt.string(endReason) })
|
|
||||||
: JSON.stringify({ text: endReason })
|
|
||||||
client.write('kick_disconnect', { reason: fullReason })
|
|
||||||
} else if (client.state === states.LOGIN) {
|
|
||||||
fullReason ||= JSON.stringify({ text: endReason })
|
|
||||||
client.write('disconnect', { reason: fullReason })
|
|
||||||
}
|
|
||||||
|
|
||||||
this._endReason = endReason
|
|
||||||
this.emit('end', this._endReason) // still emits on server side only, doesn't send anything to our client
|
this.emit('end', this._endReason) // still emits on server side only, doesn't send anything to our client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
46
src/dayCycle.ts
Normal file
46
src/dayCycle.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
import { options } from './optionsStorage'
|
||||||
|
import { assertDefined } from './utils'
|
||||||
|
import { updateBackground } from './water'
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const timeUpdated = () => {
|
||||||
|
// 0 morning
|
||||||
|
const dayTotal = 24_000
|
||||||
|
const evening = 11_500
|
||||||
|
const night = 13_500
|
||||||
|
const morningStart = 23_000
|
||||||
|
const morningEnd = 23_961
|
||||||
|
const timeProgress = options.dayCycleAndLighting ? bot.time.timeOfDay : 0
|
||||||
|
|
||||||
|
// todo check actual colors
|
||||||
|
const dayColorRainy = { r: 111 / 255, g: 156 / 255, b: 236 / 255 }
|
||||||
|
// todo yes, we should make animations (and rain)
|
||||||
|
// eslint-disable-next-line unicorn/numeric-separators-style
|
||||||
|
const dayColor = bot.isRaining ? dayColorRainy : { r: 0.6784313725490196, g: 0.8470588235294118, b: 0.9019607843137255 } // lightblue
|
||||||
|
// let newColor = dayColor
|
||||||
|
let int = 1
|
||||||
|
if (timeProgress < evening) {
|
||||||
|
// stay dayily
|
||||||
|
} else if (timeProgress < night) {
|
||||||
|
const progressNorm = timeProgress - evening
|
||||||
|
const progressMax = night - evening
|
||||||
|
int = 1 - progressNorm / progressMax
|
||||||
|
} else if (timeProgress < morningStart) {
|
||||||
|
int = 0
|
||||||
|
} else if (timeProgress < morningEnd) {
|
||||||
|
const progressNorm = timeProgress - morningStart
|
||||||
|
const progressMax = night - morningEnd
|
||||||
|
int = progressNorm / progressMax
|
||||||
|
}
|
||||||
|
// todo need to think wisely how to set these values & also move directional light around!
|
||||||
|
const colorInt = Math.max(int, 0.1)
|
||||||
|
updateBackground({ r: dayColor.r * colorInt, g: dayColor.g * colorInt, b: dayColor.b * colorInt })
|
||||||
|
if (!options.newVersionsLighting && bot.supportFeature('blockStateId')) {
|
||||||
|
appViewer.playerState.reactive.ambientLight = Math.max(int, 0.25)
|
||||||
|
appViewer.playerState.reactive.directionalLight = Math.min(int, 0.5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bot.on('time', timeUpdated)
|
||||||
|
timeUpdated()
|
||||||
|
}
|
||||||
|
|
@ -16,11 +16,9 @@ export const defaultOptions = {
|
||||||
chatOpacityOpened: 100,
|
chatOpacityOpened: 100,
|
||||||
messagesLimit: 200,
|
messagesLimit: 200,
|
||||||
volume: 50,
|
volume: 50,
|
||||||
enableMusic: true,
|
enableMusic: false,
|
||||||
musicVolume: 50,
|
|
||||||
// fov: 70,
|
// fov: 70,
|
||||||
fov: 75,
|
fov: 75,
|
||||||
defaultPerspective: 'first_person' as 'first_person' | 'third_person_back' | 'third_person_front',
|
|
||||||
guiScale: 3,
|
guiScale: 3,
|
||||||
autoRequestCompletions: true,
|
autoRequestCompletions: true,
|
||||||
touchButtonsSize: 40,
|
touchButtonsSize: 40,
|
||||||
|
|
@ -42,7 +40,6 @@ export const defaultOptions = {
|
||||||
renderEars: true,
|
renderEars: true,
|
||||||
lowMemoryMode: false,
|
lowMemoryMode: false,
|
||||||
starfieldRendering: true,
|
starfieldRendering: true,
|
||||||
defaultSkybox: true,
|
|
||||||
enabledResourcepack: null as string | null,
|
enabledResourcepack: null as string | null,
|
||||||
useVersionsTextures: 'latest',
|
useVersionsTextures: 'latest',
|
||||||
serverResourcePacks: 'prompt' as 'prompt' | 'always' | 'never',
|
serverResourcePacks: 'prompt' as 'prompt' | 'always' | 'never',
|
||||||
|
|
@ -79,17 +76,13 @@ export const defaultOptions = {
|
||||||
frameLimit: false as number | false,
|
frameLimit: false as number | false,
|
||||||
alwaysBackupWorldBeforeLoading: undefined as boolean | undefined | null,
|
alwaysBackupWorldBeforeLoading: undefined as boolean | undefined | null,
|
||||||
alwaysShowMobileControls: false,
|
alwaysShowMobileControls: false,
|
||||||
excludeCommunicationDebugEvents: [] as string[],
|
excludeCommunicationDebugEvents: [],
|
||||||
preventDevReloadWhilePlaying: false,
|
preventDevReloadWhilePlaying: false,
|
||||||
numWorkers: 4,
|
numWorkers: 4,
|
||||||
localServerOptions: {
|
localServerOptions: {
|
||||||
gameMode: 1
|
gameMode: 1
|
||||||
} as any,
|
} as any,
|
||||||
saveLoginPassword: 'prompt' as 'prompt' | 'never' | 'always',
|
|
||||||
preferLoadReadonly: false,
|
preferLoadReadonly: false,
|
||||||
experimentalClientSelfReload: false,
|
|
||||||
remoteSoundsSupport: false,
|
|
||||||
remoteSoundsLoadTimeout: 500,
|
|
||||||
disableLoadPrompts: false,
|
disableLoadPrompts: false,
|
||||||
guestUsername: 'guest',
|
guestUsername: 'guest',
|
||||||
askGuestName: true,
|
askGuestName: true,
|
||||||
|
|
|
||||||
113
src/devtools.ts
113
src/devtools.ts
|
|
@ -5,17 +5,6 @@ import { WorldRendererThree } from 'renderer/viewer/three/worldrendererThree'
|
||||||
import { enable, disable, enabled } from 'debug'
|
import { enable, disable, enabled } from 'debug'
|
||||||
import { Vec3 } from 'vec3'
|
import { Vec3 } from 'vec3'
|
||||||
|
|
||||||
customEvents.on('mineflayerBotCreated', () => {
|
|
||||||
window.debugServerPacketNames = Object.fromEntries(Object.keys(loadedData.protocol.play.toClient.types).map(name => {
|
|
||||||
name = name.replace('packet_', '')
|
|
||||||
return [name, name]
|
|
||||||
}))
|
|
||||||
window.debugClientPacketNames = Object.fromEntries(Object.keys(loadedData.protocol.play.toServer.types).map(name => {
|
|
||||||
name = name.replace('packet_', '')
|
|
||||||
return [name, name]
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
|
|
||||||
window.Vec3 = Vec3
|
window.Vec3 = Vec3
|
||||||
window.cursorBlockRel = (x = 0, y = 0, z = 0) => {
|
window.cursorBlockRel = (x = 0, y = 0, z = 0) => {
|
||||||
const newPos = bot.blockAtCursor(5)?.position.offset(x, y, z)
|
const newPos = bot.blockAtCursor(5)?.position.offset(x, y, z)
|
||||||
|
|
@ -220,105 +209,3 @@ setInterval(() => {
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
// Add type declaration for performance.memory
|
|
||||||
declare global {
|
|
||||||
interface Performance {
|
|
||||||
memory?: {
|
|
||||||
usedJSHeapSize: number
|
|
||||||
totalJSHeapSize: number
|
|
||||||
jsHeapSizeLimit: number
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Performance metrics WebSocket client
|
|
||||||
let ws: WebSocket | null = null
|
|
||||||
let wsReconnectTimeout: NodeJS.Timeout | null = null
|
|
||||||
let metricsInterval: NodeJS.Timeout | null = null
|
|
||||||
|
|
||||||
// Start collecting metrics immediately
|
|
||||||
const startTime = performance.now()
|
|
||||||
|
|
||||||
function collectAndSendMetrics () {
|
|
||||||
if (!ws || ws.readyState !== WebSocket.OPEN) return
|
|
||||||
|
|
||||||
const metrics = {
|
|
||||||
loadTime: performance.now() - startTime,
|
|
||||||
memoryUsage: (performance.memory?.usedJSHeapSize ?? 0) / 1024 / 1024,
|
|
||||||
timestamp: Date.now()
|
|
||||||
}
|
|
||||||
|
|
||||||
ws.send(JSON.stringify(metrics))
|
|
||||||
}
|
|
||||||
|
|
||||||
function getWebSocketUrl () {
|
|
||||||
const wsPort = process.env.WS_PORT
|
|
||||||
if (!wsPort) return null
|
|
||||||
|
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
||||||
const { hostname } = window.location
|
|
||||||
return `${protocol}//${hostname}:${wsPort}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function connectWebSocket () {
|
|
||||||
if (ws) return
|
|
||||||
|
|
||||||
const wsUrl = getWebSocketUrl()
|
|
||||||
if (!wsUrl) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ws = new WebSocket(wsUrl)
|
|
||||||
|
|
||||||
ws.onopen = () => {
|
|
||||||
console.log('Connected to metrics server')
|
|
||||||
if (wsReconnectTimeout) {
|
|
||||||
clearTimeout(wsReconnectTimeout)
|
|
||||||
wsReconnectTimeout = null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start sending metrics immediately after connection
|
|
||||||
collectAndSendMetrics()
|
|
||||||
|
|
||||||
// Clear existing interval if any
|
|
||||||
if (metricsInterval) {
|
|
||||||
clearInterval(metricsInterval)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set new interval
|
|
||||||
metricsInterval = setInterval(collectAndSendMetrics, 500)
|
|
||||||
}
|
|
||||||
|
|
||||||
ws.onclose = () => {
|
|
||||||
console.log('Disconnected from metrics server')
|
|
||||||
ws = null
|
|
||||||
|
|
||||||
// Clear metrics interval
|
|
||||||
if (metricsInterval) {
|
|
||||||
clearInterval(metricsInterval)
|
|
||||||
metricsInterval = null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to reconnect after 3 seconds
|
|
||||||
wsReconnectTimeout = setTimeout(connectWebSocket, 3000)
|
|
||||||
}
|
|
||||||
|
|
||||||
ws.onerror = (error) => {
|
|
||||||
console.error('WebSocket error:', error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect immediately
|
|
||||||
connectWebSocket()
|
|
||||||
|
|
||||||
// Add command to request current metrics
|
|
||||||
window.requestMetrics = () => {
|
|
||||||
const metrics = {
|
|
||||||
loadTime: performance.now() - startTime,
|
|
||||||
memoryUsage: (performance.memory?.usedJSHeapSize ?? 0) / 1024 / 1024,
|
|
||||||
timestamp: Date.now()
|
|
||||||
}
|
|
||||||
console.log('Current metrics:', metrics)
|
|
||||||
return metrics
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,6 @@ export const getFixedFilesize = (bytes: number) => {
|
||||||
return prettyBytes(bytes, { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
return prettyBytes(bytes, { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isInterestedInDownload = () => {
|
|
||||||
const { map, texturepack, replayFileUrl } = appQueryParams
|
|
||||||
const { mapDir } = appQueryParamsArray
|
|
||||||
return !!map || !!texturepack || !!replayFileUrl || !!mapDir
|
|
||||||
}
|
|
||||||
|
|
||||||
const inner = async () => {
|
const inner = async () => {
|
||||||
const { map, texturepack, replayFileUrl } = appQueryParams
|
const { map, texturepack, replayFileUrl } = appQueryParams
|
||||||
const { mapDir } = appQueryParamsArray
|
const { mapDir } = appQueryParamsArray
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import fs from 'fs'
|
||||||
import * as nbt from 'prismarine-nbt'
|
import * as nbt from 'prismarine-nbt'
|
||||||
import RegionFile from 'prismarine-provider-anvil/src/region'
|
import RegionFile from 'prismarine-provider-anvil/src/region'
|
||||||
import { versions } from 'minecraft-data'
|
import { versions } from 'minecraft-data'
|
||||||
import { getThreeJsRendererMethods } from 'renderer/viewer/three/threeJsMethods'
|
|
||||||
import { openWorldDirectory, openWorldZip } from './browserfs'
|
import { openWorldDirectory, openWorldZip } from './browserfs'
|
||||||
import { isGameActive } from './globalState'
|
import { isGameActive } from './globalState'
|
||||||
import { showNotification } from './react/NotificationProvider'
|
import { showNotification } from './react/NotificationProvider'
|
||||||
|
|
@ -13,9 +12,6 @@ const parseNbt = promisify(nbt.parse)
|
||||||
const simplifyNbt = nbt.simplify
|
const simplifyNbt = nbt.simplify
|
||||||
window.nbt = nbt
|
window.nbt = nbt
|
||||||
|
|
||||||
// Supported image types for skybox
|
|
||||||
const VALID_IMAGE_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.webp']
|
|
||||||
|
|
||||||
// todo display drop zone
|
// todo display drop zone
|
||||||
for (const event of ['drag', 'dragstart', 'dragend', 'dragover', 'dragenter', 'dragleave', 'drop']) {
|
for (const event of ['drag', 'dragstart', 'dragend', 'dragover', 'dragenter', 'dragleave', 'drop']) {
|
||||||
window.addEventListener(event, (e: any) => {
|
window.addEventListener(event, (e: any) => {
|
||||||
|
|
@ -49,34 +45,6 @@ window.addEventListener('drop', async e => {
|
||||||
})
|
})
|
||||||
|
|
||||||
async function handleDroppedFile (file: File) {
|
async function handleDroppedFile (file: File) {
|
||||||
// Check for image files first when game is active
|
|
||||||
if (isGameActive(false) && VALID_IMAGE_EXTENSIONS.some(ext => file.name.toLowerCase().endsWith(ext))) {
|
|
||||||
try {
|
|
||||||
// Convert image to base64
|
|
||||||
const reader = new FileReader()
|
|
||||||
const base64Promise = new Promise<string>((resolve, reject) => {
|
|
||||||
reader.onload = () => resolve(reader.result as string)
|
|
||||||
reader.onerror = reject
|
|
||||||
})
|
|
||||||
reader.readAsDataURL(file)
|
|
||||||
const base64Image = await base64Promise
|
|
||||||
|
|
||||||
// Get ThreeJS backend methods and update skybox
|
|
||||||
const setSkyboxImage = getThreeJsRendererMethods()?.setSkyboxImage
|
|
||||||
if (setSkyboxImage) {
|
|
||||||
await setSkyboxImage(base64Image)
|
|
||||||
showNotification('Skybox updated successfully')
|
|
||||||
} else {
|
|
||||||
showNotification('Cannot update skybox - renderer does not support it')
|
|
||||||
}
|
|
||||||
return
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to update skybox:', err)
|
|
||||||
showNotification('Failed to update skybox', 'error')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file.name.endsWith('.zip')) {
|
if (file.name.endsWith('.zip')) {
|
||||||
void openWorldZip(file)
|
void openWorldZip(file)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
162
src/entities.ts
162
src/entities.ts
|
|
@ -4,7 +4,6 @@ import tracker from '@nxg-org/mineflayer-tracker'
|
||||||
import { loader as autoJumpPlugin } from '@nxg-org/mineflayer-auto-jump'
|
import { loader as autoJumpPlugin } from '@nxg-org/mineflayer-auto-jump'
|
||||||
import { subscribeKey } from 'valtio/utils'
|
import { subscribeKey } from 'valtio/utils'
|
||||||
import { getThreeJsRendererMethods } from 'renderer/viewer/three/threeJsMethods'
|
import { getThreeJsRendererMethods } from 'renderer/viewer/three/threeJsMethods'
|
||||||
import { Team } from 'mineflayer'
|
|
||||||
import { options, watchValue } from './optionsStorage'
|
import { options, watchValue } from './optionsStorage'
|
||||||
import { gameAdditionalState, miscUiState } from './globalState'
|
import { gameAdditionalState, miscUiState } from './globalState'
|
||||||
import { EntityStatus } from './mineflayer/entityStatus'
|
import { EntityStatus } from './mineflayer/entityStatus'
|
||||||
|
|
@ -126,28 +125,6 @@ customEvents.on('gameLoaded', () => {
|
||||||
if (entityStatus === EntityStatus.HURT) {
|
if (entityStatus === EntityStatus.HURT) {
|
||||||
getThreeJsRendererMethods()?.damageEntity(entityId, entityStatus)
|
getThreeJsRendererMethods()?.damageEntity(entityId, entityStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entityStatus === EntityStatus.BURNED) {
|
|
||||||
updateEntityStates(entityId, true, true)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// on fire events
|
|
||||||
bot._client.on('entity_metadata', (data) => {
|
|
||||||
if (data.entityId !== bot.entity.id) return
|
|
||||||
handleEntityMetadata(data)
|
|
||||||
})
|
|
||||||
|
|
||||||
bot.on('end', () => {
|
|
||||||
if (onFireTimeout) {
|
|
||||||
clearTimeout(onFireTimeout)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
bot.on('respawn', () => {
|
|
||||||
if (onFireTimeout) {
|
|
||||||
clearTimeout(onFireTimeout)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const updateCamera = (entity: Entity) => {
|
const updateCamera = (entity: Entity) => {
|
||||||
|
|
@ -220,7 +197,9 @@ customEvents.on('gameLoaded', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const applySkinTexturesProxy = (url: string | undefined) => {
|
// Texture override from packet properties
|
||||||
|
bot._client.on('player_info', (packet) => {
|
||||||
|
const applySkinTexturesProxy = (url: string) => {
|
||||||
const { appConfig } = miscUiState
|
const { appConfig } = miscUiState
|
||||||
if (appConfig?.skinTexturesProxy) {
|
if (appConfig?.skinTexturesProxy) {
|
||||||
return url?.replace('http://textures.minecraft.net/', appConfig.skinTexturesProxy)
|
return url?.replace('http://textures.minecraft.net/', appConfig.skinTexturesProxy)
|
||||||
|
|
@ -229,140 +208,33 @@ customEvents.on('gameLoaded', () => {
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
// Texture override from packet properties
|
for (const playerEntry of packet.data) {
|
||||||
const updateSkin = (player: import('mineflayer').Player) => {
|
if (!playerEntry.player && !playerEntry.properties) continue
|
||||||
if (!player.uuid || !player.username || !player.skinData) return
|
let textureProperty = playerEntry.properties?.find(prop => prop?.name === 'textures')
|
||||||
|
if (!textureProperty) {
|
||||||
|
textureProperty = playerEntry.player?.properties?.find(prop => prop?.key === 'textures')
|
||||||
|
}
|
||||||
|
if (textureProperty) {
|
||||||
try {
|
try {
|
||||||
const skinUrl = applySkinTexturesProxy(player.skinData.url)
|
const textureData = JSON.parse(Buffer.from(textureProperty.value, 'base64').toString())
|
||||||
const capeUrl = applySkinTexturesProxy((player.skinData as any).capeUrl)
|
const skinUrl = applySkinTexturesProxy(textureData.textures?.SKIN?.url)
|
||||||
|
const capeUrl = applySkinTexturesProxy(textureData.textures?.CAPE?.url)
|
||||||
|
|
||||||
// Find entity with matching UUID and update skin
|
// Find entity with matching UUID and update skin
|
||||||
let entityId = ''
|
let entityId = ''
|
||||||
for (const [entId, entity] of Object.entries(bot.entities)) {
|
for (const [entId, entity] of Object.entries(bot.entities)) {
|
||||||
if (entity.uuid === player.uuid) {
|
if (entity.uuid === playerEntry.uuid) {
|
||||||
entityId = entId
|
entityId = entId
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// even if not found, still record to cache
|
// even if not found, still record to cache
|
||||||
void getThreeJsRendererMethods()!.updatePlayerSkin(entityId, player.username, player.uuid, skinUrl ?? true, capeUrl)
|
void getThreeJsRendererMethods()?.updatePlayerSkin(entityId, playerEntry.player?.name, playerEntry.uuid, skinUrl, capeUrl)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reportError(new Error('Error applying skin texture:', { cause: err }))
|
console.error('Error decoding player texture:', err)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bot.on('playerJoined', updateSkin)
|
|
||||||
bot.on('playerUpdated', updateSkin)
|
|
||||||
for (const entity of Object.values(bot.players)) {
|
|
||||||
updateSkin(entity)
|
|
||||||
}
|
|
||||||
|
|
||||||
const teamUpdated = (team: Team) => {
|
|
||||||
for (const entity of Object.values(bot.entities)) {
|
|
||||||
if (entity.type === 'player' && entity.username && team.members.includes(entity.username) || entity.uuid && team.members.includes(entity.uuid)) {
|
|
||||||
bot.emit('entityUpdate', entity)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bot.on('teamUpdated', teamUpdated)
|
|
||||||
for (const team of Object.values(bot.teams)) {
|
|
||||||
teamUpdated(team)
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateEntityNameTags = (team: Team) => {
|
|
||||||
for (const entity of Object.values(bot.entities)) {
|
|
||||||
const entityTeam = entity.type === 'player' && entity.username ? bot.teamMap[entity.username] : entity.uuid ? bot.teamMap[entity.uuid] : undefined
|
|
||||||
if ((entityTeam?.nameTagVisibility === 'hideForOwnTeam' && entityTeam.name === team.name)
|
|
||||||
|| (entityTeam?.nameTagVisibility === 'hideForOtherTeams' && entityTeam.name !== team.name)) {
|
|
||||||
bot.emit('entityUpdate', entity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const doEntitiesNeedUpdating = (team: Team) => {
|
|
||||||
return team.nameTagVisibility === 'never'
|
|
||||||
|| (team.nameTagVisibility === 'hideForOtherTeams' && appViewer.playerState.reactive.team?.team !== team.team)
|
|
||||||
|| (team.nameTagVisibility === 'hideForOwnTeam' && appViewer.playerState.reactive.team?.team === team.team)
|
|
||||||
}
|
|
||||||
|
|
||||||
bot.on('teamMemberAdded', (team: Team, members: string[]) => {
|
|
||||||
if (members.includes(bot.username) && appViewer.playerState.reactive.team?.team !== team.team) {
|
|
||||||
appViewer.playerState.reactive.team = team
|
|
||||||
// Player was added to a team, need to check if any entities need updating
|
|
||||||
updateEntityNameTags(team)
|
|
||||||
} else if (doEntitiesNeedUpdating(team)) {
|
|
||||||
// Need to update all entities that were added
|
|
||||||
for (const entity of Object.values(bot.entities)) {
|
|
||||||
if (entity.type === 'player' && entity.username && members.includes(entity.username) || entity.uuid && members.includes(entity.uuid)) {
|
|
||||||
bot.emit('entityUpdate', entity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
bot.on('teamMemberRemoved', (team: Team, members: string[]) => {
|
|
||||||
if (members.includes(bot.username) && appViewer.playerState.reactive.team?.team === team.team) {
|
|
||||||
appViewer.playerState.reactive.team = undefined
|
|
||||||
// Player was removed from a team, need to check if any entities need updating
|
|
||||||
updateEntityNameTags(team)
|
|
||||||
} else if (doEntitiesNeedUpdating(team)) {
|
|
||||||
// Need to update all entities that were removed
|
|
||||||
for (const entity of Object.values(bot.entities)) {
|
|
||||||
if (entity.type === 'player' && entity.username && members.includes(entity.username) || entity.uuid && members.includes(entity.uuid)) {
|
|
||||||
bot.emit('entityUpdate', entity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
bot.on('teamRemoved', (team: Team) => {
|
|
||||||
if (appViewer.playerState.reactive.team?.team === team?.team) {
|
|
||||||
appViewer.playerState.reactive.team = undefined
|
|
||||||
// Player's team was removed, need to update all entities that are in a team
|
|
||||||
updateEntityNameTags(team)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
// Constants
|
|
||||||
const SHARED_FLAGS_KEY = 0
|
|
||||||
const ENTITY_FLAGS = {
|
|
||||||
ON_FIRE: 0x01, // Bit 0
|
|
||||||
SNEAKING: 0x02, // Bit 1
|
|
||||||
SPRINTING: 0x08, // Bit 3
|
|
||||||
SWIMMING: 0x10, // Bit 4
|
|
||||||
INVISIBLE: 0x20, // Bit 5
|
|
||||||
GLOWING: 0x40, // Bit 6
|
|
||||||
FALL_FLYING: 0x80 // Bit 7 (elytra flying)
|
|
||||||
}
|
|
||||||
|
|
||||||
let onFireTimeout: NodeJS.Timeout | undefined
|
|
||||||
const updateEntityStates = (entityId: number, onFire: boolean, timeout?: boolean) => {
|
|
||||||
if (entityId !== bot.entity.id) return
|
|
||||||
appViewer.playerState.reactive.onFire = onFire
|
|
||||||
if (onFireTimeout) {
|
|
||||||
clearTimeout(onFireTimeout)
|
|
||||||
}
|
|
||||||
if (timeout) {
|
|
||||||
onFireTimeout = setTimeout(() => {
|
|
||||||
updateEntityStates(entityId, false, false)
|
|
||||||
}, 5000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process entity metadata packet
|
|
||||||
function handleEntityMetadata (packet: { entityId: number, metadata: Array<{ key: number, type: string, value: number }> }) {
|
|
||||||
const { entityId, metadata } = packet
|
|
||||||
|
|
||||||
// Find shared flags in metadata
|
|
||||||
const flagsData = metadata.find(meta => meta.key === SHARED_FLAGS_KEY &&
|
|
||||||
meta.type === 'byte')
|
|
||||||
|
|
||||||
// Update fire state if flags were found
|
|
||||||
if (flagsData) {
|
|
||||||
const wasOnFire = appViewer.playerState.reactive.onFire
|
|
||||||
appViewer.playerState.reactive.onFire = (flagsData.value & ENTITY_FLAGS.ON_FIRE) !== 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
21
src/env.d.ts
vendored
21
src/env.d.ts
vendored
|
|
@ -2,36 +2,29 @@ declare namespace NodeJS {
|
||||||
interface ProcessEnv {
|
interface ProcessEnv {
|
||||||
// Build configuration
|
// Build configuration
|
||||||
NODE_ENV: 'development' | 'production'
|
NODE_ENV: 'development' | 'production'
|
||||||
MIN_MC_VERSION?: string
|
SINGLE_FILE_BUILD?: string
|
||||||
MAX_MC_VERSION?: string
|
DISABLE_SERVICE_WORKER?: string
|
||||||
ALWAYS_COMPRESS_LARGE_DATA?: 'true' | 'false'
|
|
||||||
SINGLE_FILE_BUILD?: 'true' | 'false'
|
|
||||||
WS_PORT?: string
|
|
||||||
DISABLE_SERVICE_WORKER?: 'true' | 'false'
|
|
||||||
CONFIG_JSON_SOURCE?: 'BUNDLED' | 'REMOTE'
|
CONFIG_JSON_SOURCE?: 'BUNDLED' | 'REMOTE'
|
||||||
LOCAL_CONFIG_FILE?: string
|
LOCAL_CONFIG_FILE?: string
|
||||||
BUILD_VERSION?: string
|
BUILD_VERSION?: string
|
||||||
|
|
||||||
// Build internals
|
// GitHub and Vercel related
|
||||||
GITHUB_REPOSITORY?: string
|
GITHUB_REPOSITORY?: string
|
||||||
VERCEL_GIT_REPO_OWNER?: string
|
VERCEL_GIT_REPO_OWNER?: string
|
||||||
VERCEL_GIT_REPO_SLUG?: string
|
VERCEL_GIT_REPO_SLUG?: string
|
||||||
|
|
||||||
// UI
|
// UI and Features
|
||||||
MAIN_MENU_LINKS?: string
|
MAIN_MENU_LINKS?: string
|
||||||
ALWAYS_MINIMAL_SERVER_UI?: 'true' | 'false'
|
|
||||||
|
|
||||||
// App features
|
|
||||||
ENABLE_COOKIE_STORAGE?: string
|
ENABLE_COOKIE_STORAGE?: string
|
||||||
COOKIE_STORAGE_PREFIX?: string
|
COOKIE_STORAGE_PREFIX?: string
|
||||||
|
|
||||||
// Build info. Release information
|
// Release information
|
||||||
RELEASE_TAG?: string
|
RELEASE_TAG?: string
|
||||||
RELEASE_LINK?: string
|
RELEASE_LINK?: string
|
||||||
RELEASE_CHANGELOG?: string
|
RELEASE_CHANGELOG?: string
|
||||||
|
|
||||||
// Build info
|
// Other configurations
|
||||||
|
DEPS_VERSIONS?: string
|
||||||
INLINED_APP_CONFIG?: string
|
INLINED_APP_CONFIG?: string
|
||||||
GITHUB_URL?: string
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
192
src/index.ts
192
src/index.ts
|
|
@ -29,7 +29,7 @@ import './reactUi'
|
||||||
import { lockUrl, onBotCreate } from './controls'
|
import { lockUrl, onBotCreate } from './controls'
|
||||||
import './dragndrop'
|
import './dragndrop'
|
||||||
import { possiblyCleanHandle } from './browserfs'
|
import { possiblyCleanHandle } from './browserfs'
|
||||||
import downloadAndOpenFile, { isInterestedInDownload } from './downloadAndOpenFile'
|
import downloadAndOpenFile from './downloadAndOpenFile'
|
||||||
|
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import net, { Socket } from 'net'
|
import net, { Socket } from 'net'
|
||||||
|
|
@ -56,12 +56,13 @@ import { isCypress } from './standaloneUtils'
|
||||||
|
|
||||||
import { startLocalServer, unsupportedLocalServerFeatures } from './createLocalServer'
|
import { startLocalServer, unsupportedLocalServerFeatures } from './createLocalServer'
|
||||||
import defaultServerOptions from './defaultLocalServerOptions'
|
import defaultServerOptions from './defaultLocalServerOptions'
|
||||||
|
import dayCycle from './dayCycle'
|
||||||
|
|
||||||
import { onAppLoad, resourcepackReload, resourcePackState } from './resourcePack'
|
import { onAppLoad, resourcepackReload, resourcePackState } from './resourcePack'
|
||||||
import { ConnectPeerOptions, connectToPeer } from './localServerMultiplayer'
|
import { ConnectPeerOptions, connectToPeer } from './localServerMultiplayer'
|
||||||
import CustomChannelClient from './customClient'
|
import CustomChannelClient from './customClient'
|
||||||
import { registerServiceWorker } from './serviceWorker'
|
import { registerServiceWorker } from './serviceWorker'
|
||||||
import { appStatusState, lastConnectOptions, quickDevReconnect } from './react/AppStatusProvider'
|
import { appStatusState, lastConnectOptions } from './react/AppStatusProvider'
|
||||||
|
|
||||||
import { fsState } from './loadSave'
|
import { fsState } from './loadSave'
|
||||||
import { watchFov } from './rendererUtils'
|
import { watchFov } from './rendererUtils'
|
||||||
|
|
@ -96,7 +97,6 @@ import { registerOpenBenchmarkListener } from './benchmark'
|
||||||
import { tryHandleBuiltinCommand } from './builtinCommands'
|
import { tryHandleBuiltinCommand } from './builtinCommands'
|
||||||
import { loadingTimerState } from './react/LoadingTimer'
|
import { loadingTimerState } from './react/LoadingTimer'
|
||||||
import { loadPluginsIntoWorld } from './react/CreateWorldProvider'
|
import { loadPluginsIntoWorld } from './react/CreateWorldProvider'
|
||||||
import { getCurrentProxy, getCurrentUsername } from './react/ServersList'
|
|
||||||
|
|
||||||
window.debug = debug
|
window.debug = debug
|
||||||
window.beforeRenderFrame = []
|
window.beforeRenderFrame = []
|
||||||
|
|
@ -166,7 +166,6 @@ export async function connect (connectOptions: ConnectOptions) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
appStatusState.showReconnect = false
|
|
||||||
loadingTimerState.loading = true
|
loadingTimerState.loading = true
|
||||||
loadingTimerState.start = Date.now()
|
loadingTimerState.start = Date.now()
|
||||||
miscUiState.hasErrors = false
|
miscUiState.hasErrors = false
|
||||||
|
|
@ -214,14 +213,9 @@ export async function connect (connectOptions: ConnectOptions) {
|
||||||
const destroyAll = (wasKicked = false) => {
|
const destroyAll = (wasKicked = false) => {
|
||||||
if (ended) return
|
if (ended) return
|
||||||
loadingTimerState.loading = false
|
loadingTimerState.loading = false
|
||||||
const { alwaysReconnect } = appQueryParams
|
if (!wasKicked && miscUiState.appConfig?.allowAutoConnect && appQueryParams.autoConnect && hadConnected) {
|
||||||
if ((!wasKicked && miscUiState.appConfig?.allowAutoConnect && appQueryParams.autoConnect && hadConnected) || (alwaysReconnect)) {
|
|
||||||
if (alwaysReconnect === 'quick' || alwaysReconnect === 'fast') {
|
|
||||||
quickDevReconnect()
|
|
||||||
} else {
|
|
||||||
location.reload()
|
location.reload()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
errorAbortController.abort()
|
errorAbortController.abort()
|
||||||
ended = true
|
ended = true
|
||||||
progress.end()
|
progress.end()
|
||||||
|
|
@ -235,12 +229,8 @@ export async function connect (connectOptions: ConnectOptions) {
|
||||||
bot.emit('end', '')
|
bot.emit('end', '')
|
||||||
bot.removeAllListeners()
|
bot.removeAllListeners()
|
||||||
bot._client.removeAllListeners()
|
bot._client.removeAllListeners()
|
||||||
bot._client = {
|
//@ts-expect-error TODO?
|
||||||
//@ts-expect-error
|
bot._client = undefined
|
||||||
write (packetName) {
|
|
||||||
console.warn('Tried to write packet', packetName, 'after bot was destroyed')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//@ts-expect-error
|
//@ts-expect-error
|
||||||
window.bot = bot = undefined
|
window.bot = bot = undefined
|
||||||
}
|
}
|
||||||
|
|
@ -286,10 +276,6 @@ export async function connect (connectOptions: ConnectOptions) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (e.reason?.stack?.includes('chrome-extension://')) {
|
|
||||||
// ignore issues caused by chrome extension
|
|
||||||
return
|
|
||||||
}
|
|
||||||
handleError(e.reason)
|
handleError(e.reason)
|
||||||
}, {
|
}, {
|
||||||
signal: errorAbortController.signal
|
signal: errorAbortController.signal
|
||||||
|
|
@ -304,7 +290,7 @@ export async function connect (connectOptions: ConnectOptions) {
|
||||||
|
|
||||||
if (connectOptions.server && !connectOptions.viewerWsConnect && !parsedServer.isWebSocket) {
|
if (connectOptions.server && !connectOptions.viewerWsConnect && !parsedServer.isWebSocket) {
|
||||||
console.log(`using proxy ${proxy.host}:${proxy.port || location.port}`)
|
console.log(`using proxy ${proxy.host}:${proxy.port || location.port}`)
|
||||||
net['setProxy']({ hostname: proxy.host, port: proxy.port, headers: { Authorization: `Bearer ${new URLSearchParams(location.search).get('token') ?? ''}` }, artificialDelay: appQueryParams.addPing ? Number(appQueryParams.addPing) : undefined })
|
net['setProxy']({ hostname: proxy.host, port: proxy.port, headers: { Authorization: `Bearer ${new URLSearchParams(location.search).get('token') ?? ''}` } })
|
||||||
}
|
}
|
||||||
|
|
||||||
const renderDistance = singleplayer ? renderDistanceSingleplayer : multiplayerRenderDistance
|
const renderDistance = singleplayer ? renderDistanceSingleplayer : multiplayerRenderDistance
|
||||||
|
|
@ -793,6 +779,7 @@ export async function connect (connectOptions: ConnectOptions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
initMotionTracking()
|
initMotionTracking()
|
||||||
|
dayCycle()
|
||||||
|
|
||||||
// Bot position callback
|
// Bot position callback
|
||||||
const botPosition = () => {
|
const botPosition = () => {
|
||||||
|
|
@ -893,7 +880,37 @@ export async function connect (connectOptions: ConnectOptions) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const reconnectOptions = sessionStorage.getItem('reconnectOptions') ? JSON.parse(sessionStorage.getItem('reconnectOptions')!) : undefined
|
||||||
|
|
||||||
listenGlobalEvents()
|
listenGlobalEvents()
|
||||||
|
const unsubscribe = subscribe(miscUiState, async () => {
|
||||||
|
if (miscUiState.fsReady && miscUiState.appConfig) {
|
||||||
|
unsubscribe()
|
||||||
|
if (reconnectOptions) {
|
||||||
|
sessionStorage.removeItem('reconnectOptions')
|
||||||
|
if (Date.now() - reconnectOptions.timestamp < 1000 * 60 * 2) {
|
||||||
|
void connect(reconnectOptions.value)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (appQueryParams.singleplayer === '1' || appQueryParams.sp === '1') {
|
||||||
|
loadSingleplayer({}, {
|
||||||
|
worldFolder: undefined,
|
||||||
|
...appQueryParams.version ? { version: appQueryParams.version } : {}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (appQueryParams.loadSave) {
|
||||||
|
const savePath = `/data/worlds/${appQueryParams.loadSave}`
|
||||||
|
try {
|
||||||
|
await fs.promises.stat(savePath)
|
||||||
|
} catch (err) {
|
||||||
|
alert(`Save ${savePath} not found`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await loadInMemorySave(savePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// #region fire click event on touch as we disable default behaviors
|
// #region fire click event on touch as we disable default behaviors
|
||||||
let activeTouch: { touch: Touch, elem: HTMLElement, start: number } | undefined
|
let activeTouch: { touch: Touch, elem: HTMLElement, start: number } | undefined
|
||||||
|
|
@ -929,94 +946,47 @@ document.body.addEventListener('touchstart', (e) => {
|
||||||
}, { passive: false })
|
}, { passive: false })
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
// immediate game enter actions: reconnect or URL QS
|
// qs open actions
|
||||||
const maybeEnterGame = () => {
|
if (!reconnectOptions) {
|
||||||
const waitForConfigFsLoad = (fn: () => void) => {
|
downloadAndOpenFile().then((downloadAction) => {
|
||||||
let unsubscribe: () => void | undefined
|
if (downloadAction) return
|
||||||
const checkDone = () => {
|
if (appQueryParams.reconnect && process.env.NODE_ENV === 'development') {
|
||||||
if (miscUiState.fsReady && miscUiState.appConfig) {
|
|
||||||
fn()
|
|
||||||
unsubscribe?.()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!checkDone()) {
|
|
||||||
const text = miscUiState.appConfig ? 'Loading' : 'Loading config'
|
|
||||||
setLoadingScreenStatus(text)
|
|
||||||
unsubscribe = subscribe(miscUiState, checkDone)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const reconnectOptions = sessionStorage.getItem('reconnectOptions') ? JSON.parse(sessionStorage.getItem('reconnectOptions')!) : undefined
|
|
||||||
|
|
||||||
if (reconnectOptions) {
|
|
||||||
sessionStorage.removeItem('reconnectOptions')
|
|
||||||
if (Date.now() - reconnectOptions.timestamp < 1000 * 60 * 2) {
|
|
||||||
return waitForConfigFsLoad(async () => {
|
|
||||||
void connect(reconnectOptions.value)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (appQueryParams.reconnect && localStorage.lastConnectOptions && process.env.NODE_ENV === 'development') {
|
|
||||||
const lastConnect = JSON.parse(localStorage.lastConnectOptions ?? {})
|
const lastConnect = JSON.parse(localStorage.lastConnectOptions ?? {})
|
||||||
return waitForConfigFsLoad(async () => {
|
|
||||||
void connect({
|
void connect({
|
||||||
botVersion: appQueryParams.version ?? undefined,
|
botVersion: appQueryParams.version ?? undefined,
|
||||||
...lastConnect,
|
...lastConnect,
|
||||||
ip: appQueryParams.ip || undefined
|
ip: appQueryParams.ip || undefined
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (appQueryParams.singleplayer === '1' || appQueryParams.sp === '1') {
|
|
||||||
return waitForConfigFsLoad(async () => {
|
|
||||||
loadSingleplayer({}, {
|
|
||||||
worldFolder: undefined,
|
|
||||||
...appQueryParams.version ? { version: appQueryParams.version } : {}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if (appQueryParams.loadSave) {
|
|
||||||
const enterSave = async () => {
|
|
||||||
const savePath = `/data/worlds/${appQueryParams.loadSave}`
|
|
||||||
try {
|
|
||||||
await fs.promises.stat(savePath)
|
|
||||||
await loadInMemorySave(savePath)
|
|
||||||
} catch (err) {
|
|
||||||
alert(`Save ${savePath} not found`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return waitForConfigFsLoad(enterSave)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (appQueryParams.ip || appQueryParams.proxy) {
|
|
||||||
const openServerAction = () => {
|
|
||||||
if (appQueryParams.autoConnect && miscUiState.appConfig?.allowAutoConnect) {
|
|
||||||
void connect({
|
|
||||||
server: appQueryParams.ip,
|
|
||||||
proxy: getCurrentProxy(),
|
|
||||||
botVersion: appQueryParams.version ?? undefined,
|
|
||||||
username: getCurrentUsername()!,
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (appQueryParams.ip || appQueryParams.proxy) {
|
||||||
setLoadingScreenStatus(undefined)
|
const waitAppConfigLoad = !appQueryParams.proxy
|
||||||
if (appQueryParams.onlyConnect || process.env.ALWAYS_MINIMAL_SERVER_UI === 'true') {
|
const openServerEditor = () => {
|
||||||
|
hideModal()
|
||||||
|
if (appQueryParams.onlyConnect) {
|
||||||
showModal({ reactType: 'only-connect-server' })
|
showModal({ reactType: 'only-connect-server' })
|
||||||
} else {
|
} else {
|
||||||
showModal({ reactType: 'editServer' })
|
showModal({ reactType: 'editServer' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
showModal({ reactType: 'empty' })
|
||||||
// showModal({ reactType: 'empty' })
|
if (waitAppConfigLoad) {
|
||||||
return waitForConfigFsLoad(openServerAction)
|
const unsubscribe = subscribe(miscUiState, checkCanDisplay)
|
||||||
|
checkCanDisplay()
|
||||||
|
// eslint-disable-next-line no-inner-declarations
|
||||||
|
function checkCanDisplay () {
|
||||||
|
if (miscUiState.appConfig) {
|
||||||
|
unsubscribe()
|
||||||
|
openServerEditor()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
openServerEditor()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appQueryParams.connectPeer) {
|
void Promise.resolve().then(() => {
|
||||||
// try to connect to peer
|
// try to connect to peer
|
||||||
const peerId = appQueryParams.connectPeer
|
const peerId = appQueryParams.connectPeer
|
||||||
const peerOptions = {} as ConnectPeerOptions
|
const peerOptions = {} as ConnectPeerOptions
|
||||||
|
|
@ -1024,8 +994,9 @@ const maybeEnterGame = () => {
|
||||||
peerOptions.server = appQueryParams.server
|
peerOptions.server = appQueryParams.server
|
||||||
}
|
}
|
||||||
const version = appQueryParams.peerVersion
|
const version = appQueryParams.peerVersion
|
||||||
|
if (peerId) {
|
||||||
let username: string | null = options.guestUsername
|
let username: string | null = options.guestUsername
|
||||||
if (options.askGuestName) username = prompt('Enter your username to connect to peer', username)
|
if (options.askGuestName) username = prompt('Enter your username', username)
|
||||||
if (!username) return
|
if (!username) return
|
||||||
options.guestUsername = username
|
options.guestUsername = username
|
||||||
void connect({
|
void connect({
|
||||||
|
|
@ -1034,16 +1005,19 @@ const maybeEnterGame = () => {
|
||||||
peerId,
|
peerId,
|
||||||
peerOptions
|
peerOptions
|
||||||
})
|
})
|
||||||
return
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (appQueryParams.serversList && !appQueryParams.ip) {
|
||||||
|
showModal({ reactType: 'serversList' })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appQueryParams.viewerConnect) {
|
const viewerWsConnect = appQueryParams.viewerConnect
|
||||||
|
if (viewerWsConnect) {
|
||||||
void connect({
|
void connect({
|
||||||
username: `viewer-${Math.random().toString(36).slice(2, 10)}`,
|
username: `viewer-${Math.random().toString(36).slice(2, 10)}`,
|
||||||
viewerWsConnect: appQueryParams.viewerConnect,
|
viewerWsConnect,
|
||||||
})
|
})
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appQueryParams.modal) {
|
if (appQueryParams.modal) {
|
||||||
|
|
@ -1051,26 +1025,11 @@ const maybeEnterGame = () => {
|
||||||
for (const modal of modals) {
|
for (const modal of modals) {
|
||||||
showModal({ reactType: modal })
|
showModal({ reactType: modal })
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
}, (err) => {
|
||||||
if (appQueryParams.serversList && !miscUiState.appConfig?.appParams?.serversList) {
|
|
||||||
// open UI only if it's in URL
|
|
||||||
showModal({ reactType: 'serversList' })
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isInterestedInDownload()) {
|
|
||||||
void downloadAndOpenFile()
|
|
||||||
}
|
|
||||||
|
|
||||||
void possiblyHandleStateVariable()
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
maybeEnterGame()
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
console.error(err)
|
||||||
alert(`Something went wrong: ${err}`)
|
alert(`Something went wrong: ${err}`)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||||
|
|
@ -1081,5 +1040,6 @@ if (initialLoader) {
|
||||||
}
|
}
|
||||||
window.pageLoaded = true
|
window.pageLoaded = true
|
||||||
|
|
||||||
|
void possiblyHandleStateVariable()
|
||||||
appViewer.waitBackendLoadPromises.push(appStartup())
|
appViewer.waitBackendLoadPromises.push(appStartup())
|
||||||
registerOpenBenchmarkListener()
|
registerOpenBenchmarkListener()
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,8 @@ import PItem, { Item } from 'prismarine-item'
|
||||||
import { versionToNumber } from 'renderer/viewer/common/utils'
|
import { versionToNumber } from 'renderer/viewer/common/utils'
|
||||||
import { getRenamedData } from 'flying-squid/dist/blockRenames'
|
import { getRenamedData } from 'flying-squid/dist/blockRenames'
|
||||||
import PrismarineChatLoader from 'prismarine-chat'
|
import PrismarineChatLoader from 'prismarine-chat'
|
||||||
import * as nbt from 'prismarine-nbt'
|
|
||||||
import { BlockModel } from 'mc-assets'
|
import { BlockModel } from 'mc-assets'
|
||||||
import { renderSlot } from 'renderer/viewer/three/renderSlot'
|
import { renderSlot } from 'renderer/viewer/three/renderSlot'
|
||||||
import { loadSkinFromUsername } from 'renderer/viewer/lib/utils/skins'
|
|
||||||
import Generic95 from '../assets/generic_95.png'
|
import Generic95 from '../assets/generic_95.png'
|
||||||
import { appReplacableResources } from './generated/resources'
|
import { appReplacableResources } from './generated/resources'
|
||||||
import { activeModalStack, hideCurrentModal, hideModal, miscUiState, showModal } from './globalState'
|
import { activeModalStack, hideCurrentModal, hideModal, miscUiState, showModal } from './globalState'
|
||||||
|
|
@ -24,7 +22,6 @@ import { getItemDescription } from './itemsDescriptions'
|
||||||
import { MessageFormatPart } from './chatUtils'
|
import { MessageFormatPart } from './chatUtils'
|
||||||
import { GeneralInputItem, getItemMetadata, getItemModelName, getItemNameRaw, RenderItem } from './mineflayer/items'
|
import { GeneralInputItem, getItemMetadata, getItemModelName, getItemNameRaw, RenderItem } from './mineflayer/items'
|
||||||
import { playerState } from './mineflayer/playerState'
|
import { playerState } from './mineflayer/playerState'
|
||||||
import { modelViewerState } from './react/OverlayModelViewer'
|
|
||||||
|
|
||||||
const loadedImagesCache = new Map<string, HTMLImageElement | ImageBitmap>()
|
const loadedImagesCache = new Map<string, HTMLImageElement | ImageBitmap>()
|
||||||
const cleanLoadedImagesCache = () => {
|
const cleanLoadedImagesCache = () => {
|
||||||
|
|
@ -42,34 +39,6 @@ export const jeiCustomCategories = proxy({
|
||||||
value: [] as Array<{ id: string, categoryTitle: string, items: any[] }>
|
value: [] as Array<{ id: string, categoryTitle: string, items: any[] }>
|
||||||
})
|
})
|
||||||
|
|
||||||
let remotePlayerSkin: string | undefined | Promise<string>
|
|
||||||
|
|
||||||
export const showInventoryPlayer = () => {
|
|
||||||
modelViewerState.model = {
|
|
||||||
positioning: {
|
|
||||||
windowWidth: 176,
|
|
||||||
windowHeight: 166,
|
|
||||||
x: 25,
|
|
||||||
y: 8,
|
|
||||||
width: 50,
|
|
||||||
height: 70,
|
|
||||||
scaled: true,
|
|
||||||
onlyInitialScale: true,
|
|
||||||
followCursor: true,
|
|
||||||
},
|
|
||||||
// models: ['https://bucket.mcraft.fun/sitarbuckss.glb'],
|
|
||||||
// debug: true,
|
|
||||||
steveModelSkin: appViewer.playerState.reactive.playerSkin ?? (typeof remotePlayerSkin === 'string' ? remotePlayerSkin : ''),
|
|
||||||
}
|
|
||||||
if (remotePlayerSkin === undefined && !appViewer.playerState.reactive.playerSkin) {
|
|
||||||
remotePlayerSkin = loadSkinFromUsername(bot.username, 'skin').then(a => {
|
|
||||||
setTimeout(() => { showInventoryPlayer() }, 0) // todo patch instead and make reactive
|
|
||||||
remotePlayerSkin = a ?? ''
|
|
||||||
return remotePlayerSkin
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const onGameLoad = () => {
|
export const onGameLoad = () => {
|
||||||
version = bot.version
|
version = bot.version
|
||||||
|
|
||||||
|
|
@ -87,23 +56,12 @@ export const onGameLoad = () => {
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|
||||||
const maybeParseNbtJson = (data: any) => {
|
|
||||||
if (typeof data === 'string') {
|
|
||||||
try {
|
|
||||||
data = JSON.parse(data)
|
|
||||||
} catch (err) {
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nbt.simplify(data) ?? data
|
|
||||||
}
|
|
||||||
|
|
||||||
bot.on('windowOpen', (win) => {
|
bot.on('windowOpen', (win) => {
|
||||||
const implementedWindow = implementedContainersGuiMap[mapWindowType(win.type as string, win.inventoryStart)]
|
const implementedWindow = implementedContainersGuiMap[mapWindowType(win.type as string, win.inventoryStart)]
|
||||||
if (implementedWindow) {
|
if (implementedWindow) {
|
||||||
openWindow(implementedWindow, maybeParseNbtJson(win.title))
|
openWindow(implementedWindow)
|
||||||
} else if (options.unimplementedContainers) {
|
} else if (options.unimplementedContainers) {
|
||||||
openWindow('ChestWin', maybeParseNbtJson(win.title))
|
openWindow('ChestWin')
|
||||||
} else {
|
} else {
|
||||||
// todo format
|
// todo format
|
||||||
displayClientChat(`[client error] cannot open unimplemented window ${win.id} (${win.type}). Slots: ${win.slots.map(item => getItemName(item)).filter(Boolean).join(', ')}`)
|
displayClientChat(`[client error] cannot open unimplemented window ${win.id} (${win.type}). Slots: ${win.slots.map(item => getItemName(item)).filter(Boolean).join(', ')}`)
|
||||||
|
|
@ -300,7 +258,6 @@ export const upInventoryItems = (isInventory: boolean, invWindow = lastWindow) =
|
||||||
// inv.pwindow.inv.slots[2].blockData = getBlockData('dirt')
|
// inv.pwindow.inv.slots[2].blockData = getBlockData('dirt')
|
||||||
const customSlots = mapSlots((isInventory ? bot.inventory : bot.currentWindow)!.slots)
|
const customSlots = mapSlots((isInventory ? bot.inventory : bot.currentWindow)!.slots)
|
||||||
invWindow.pwindow.setSlots(customSlots)
|
invWindow.pwindow.setSlots(customSlots)
|
||||||
return customSlots
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onModalClose = (callback: () => any) => {
|
export const onModalClose = (callback: () => any) => {
|
||||||
|
|
@ -397,7 +354,7 @@ const upWindowItemsLocal = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
let skipClosePacketSending = false
|
let skipClosePacketSending = false
|
||||||
const openWindow = (type: string | undefined, title: string | any = undefined) => {
|
const openWindow = (type: string | undefined) => {
|
||||||
// if (activeModalStack.some(x => x.reactType?.includes?.('player_win:'))) {
|
// if (activeModalStack.some(x => x.reactType?.includes?.('player_win:'))) {
|
||||||
if (activeModalStack.length) { // game is not in foreground, don't close current modal
|
if (activeModalStack.length) { // game is not in foreground, don't close current modal
|
||||||
if (type) {
|
if (type) {
|
||||||
|
|
@ -422,16 +379,12 @@ const openWindow = (type: string | undefined, title: string | any = undefined) =
|
||||||
miscUiState.displaySearchInput = false
|
miscUiState.displaySearchInput = false
|
||||||
destroyFn()
|
destroyFn()
|
||||||
skipClosePacketSending = false
|
skipClosePacketSending = false
|
||||||
|
|
||||||
modelViewerState.model = undefined
|
|
||||||
})
|
})
|
||||||
if (type === undefined) {
|
|
||||||
showInventoryPlayer()
|
|
||||||
}
|
|
||||||
cleanLoadedImagesCache()
|
cleanLoadedImagesCache()
|
||||||
const inv = openItemsCanvas(type)
|
const inv = openItemsCanvas(type)
|
||||||
inv.canvasManager.children[0].mobileHelpers = miscUiState.currentTouch
|
inv.canvasManager.children[0].mobileHelpers = miscUiState.currentTouch
|
||||||
window.inventory = inv
|
window.inventory = inv
|
||||||
|
const title = bot.currentWindow?.title
|
||||||
const PrismarineChat = PrismarineChatLoader(bot.version)
|
const PrismarineChat = PrismarineChatLoader(bot.version)
|
||||||
try {
|
try {
|
||||||
inv.canvasManager.children[0].customTitleText = title ?
|
inv.canvasManager.children[0].customTitleText = title ?
|
||||||
|
|
@ -470,7 +423,6 @@ const openWindow = (type: string | undefined, title: string | any = undefined) =
|
||||||
const isRightClick = type === 'rightclick'
|
const isRightClick = type === 'rightclick'
|
||||||
const isLeftClick = type === 'leftclick'
|
const isLeftClick = type === 'leftclick'
|
||||||
if (isLeftClick || isRightClick) {
|
if (isLeftClick || isRightClick) {
|
||||||
modelViewerState.model = undefined
|
|
||||||
inv.canvasManager.children[0].showRecipesOrUsages(isLeftClick, item)
|
inv.canvasManager.children[0].showRecipesOrUsages(isLeftClick, item)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -502,7 +454,6 @@ const openWindow = (type: string | undefined, title: string | any = undefined) =
|
||||||
if (freeSlot === null) return
|
if (freeSlot === null) return
|
||||||
void bot.creative.setInventorySlot(freeSlot, item)
|
void bot.creative.setInventorySlot(freeSlot, item)
|
||||||
} else {
|
} else {
|
||||||
modelViewerState.model = undefined
|
|
||||||
inv.canvasManager.children[0].showRecipesOrUsages(!isRightclick, mapSlots([item], true)[0])
|
inv.canvasManager.children[0].showRecipesOrUsages(!isRightclick, mapSlots([item], true)[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -571,7 +522,7 @@ const getResultingRecipe = (slots: Array<Item | null>, gridRows: number) => {
|
||||||
type Result = RecipeItem | undefined
|
type Result = RecipeItem | undefined
|
||||||
let shapelessResult: Result
|
let shapelessResult: Result
|
||||||
let shapeResult: Result
|
let shapeResult: Result
|
||||||
outer: for (const [id, recipeVariants] of Object.entries(loadedData.recipes ?? {})) {
|
outer: for (const [id, recipeVariants] of Object.entries(loadedData.recipes)) {
|
||||||
for (const recipeVariant of recipeVariants) {
|
for (const recipeVariant of recipeVariants) {
|
||||||
if ('inShape' in recipeVariant && equals(currentShape, recipeVariant.inShape as number[][])) {
|
if ('inShape' in recipeVariant && equals(currentShape, recipeVariant.inShape as number[][])) {
|
||||||
shapeResult = recipeVariant.result!
|
shapeResult = recipeVariant.result!
|
||||||
|
|
@ -599,7 +550,7 @@ const getAllItemRecipes = (itemName: string) => {
|
||||||
const item = loadedData.itemsByName[itemName]
|
const item = loadedData.itemsByName[itemName]
|
||||||
if (!item) return
|
if (!item) return
|
||||||
const itemId = item.id
|
const itemId = item.id
|
||||||
const recipes = loadedData.recipes?.[itemId]
|
const recipes = loadedData.recipes[itemId]
|
||||||
if (!recipes) return
|
if (!recipes) return
|
||||||
const results = [] as Array<{
|
const results = [] as Array<{
|
||||||
result: Item,
|
result: Item,
|
||||||
|
|
@ -644,7 +595,7 @@ const getAllItemUsages = (itemName: string) => {
|
||||||
if (!item) return
|
if (!item) return
|
||||||
const foundRecipeIds = [] as string[]
|
const foundRecipeIds = [] as string[]
|
||||||
|
|
||||||
for (const [id, recipes] of Object.entries(loadedData.recipes ?? {})) {
|
for (const [id, recipes] of Object.entries(loadedData.recipes)) {
|
||||||
for (const recipe of recipes) {
|
for (const recipe of recipes) {
|
||||||
if ('inShape' in recipe) {
|
if ('inShape' in recipe) {
|
||||||
if (recipe.inShape.some(row => row.includes(item.id))) {
|
if (recipe.inShape.some(row => row.includes(item.id))) {
|
||||||
|
|
|
||||||
|
|
@ -58,17 +58,9 @@ export const getItemMetadata = (item: GeneralInputItem, resourcesManager: Resour
|
||||||
}
|
}
|
||||||
if (customModelDataDefinitions) {
|
if (customModelDataDefinitions) {
|
||||||
const customModelDataComponent: any = componentMap.get('custom_model_data')
|
const customModelDataComponent: any = componentMap.get('custom_model_data')
|
||||||
if (customModelDataComponent?.data) {
|
if (customModelDataComponent?.data && typeof customModelDataComponent.data === 'number') {
|
||||||
let customModelData: number | undefined
|
const customModelData = customModelDataComponent.data
|
||||||
if (typeof customModelDataComponent.data === 'number') {
|
if (customModelDataDefinitions[customModelData]) {
|
||||||
customModelData = customModelDataComponent.data
|
|
||||||
} else if (typeof customModelDataComponent.data === 'object'
|
|
||||||
&& 'floats' in customModelDataComponent.data
|
|
||||||
&& Array.isArray(customModelDataComponent.data.floats)
|
|
||||||
&& customModelDataComponent.data.floats.length > 0) {
|
|
||||||
customModelData = customModelDataComponent.data.floats[0]
|
|
||||||
}
|
|
||||||
if (customModelData && customModelDataDefinitions[customModelData]) {
|
|
||||||
customModel = customModelDataDefinitions[customModelData]
|
customModel = customModelDataDefinitions[customModelData]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,13 @@
|
||||||
import net from 'net'
|
|
||||||
import { Client } from 'minecraft-protocol'
|
import { Client } from 'minecraft-protocol'
|
||||||
import { appQueryParams } from '../appParams'
|
import { appQueryParams } from '../appParams'
|
||||||
import { downloadAllMinecraftData, getVersionAutoSelect } from '../connect'
|
import { downloadAllMinecraftData, getVersionAutoSelect } from '../connect'
|
||||||
import { gameAdditionalState } from '../globalState'
|
import { gameAdditionalState } from '../globalState'
|
||||||
import { ProgressReporter } from '../core/progressReporter'
|
import { ProgressReporter } from '../core/progressReporter'
|
||||||
import { parseServerAddress } from '../parseServerAddress'
|
|
||||||
import { getCurrentProxy } from '../react/ServersList'
|
|
||||||
import { pingServerVersion, validatePacket } from './minecraft-protocol-extra'
|
import { pingServerVersion, validatePacket } from './minecraft-protocol-extra'
|
||||||
import { getWebsocketStream } from './websocket-core'
|
import { getWebsocketStream } from './websocket-core'
|
||||||
|
|
||||||
let lastPacketTime = 0
|
let lastPacketTime = 0
|
||||||
customEvents.on('mineflayerBotCreated', () => {
|
customEvents.on('mineflayerBotCreated', () => {
|
||||||
// const oldParsePacketBuffer = bot._client.deserializer.parsePacketBuffer
|
|
||||||
// try {
|
|
||||||
// const parsed = oldParsePacketBuffer(buffer)
|
|
||||||
// } catch (err) {
|
|
||||||
// debugger
|
|
||||||
// reportError(new Error(`Error parsing packet ${buffer.subarray(0, 30).toString('hex')}`, { cause: err }))
|
|
||||||
// throw err
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
class MinecraftProtocolError extends Error {
|
|
||||||
constructor (message: string, cause?: Error, public data?: any) {
|
|
||||||
if (data?.customPayload) {
|
|
||||||
message += ` (Custom payload: ${data.customPayload.channel})`
|
|
||||||
}
|
|
||||||
super(message, { cause })
|
|
||||||
this.name = 'MinecraftProtocolError'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const onClientError = (err, data) => {
|
|
||||||
const error = new MinecraftProtocolError(`Minecraft protocol client error: ${err.message}`, err, data)
|
|
||||||
reportError(error)
|
|
||||||
}
|
|
||||||
if (typeof bot._client['_events'].error === 'function') {
|
|
||||||
// dont report to bot for more explicit error
|
|
||||||
bot._client['_events'].error = onClientError
|
|
||||||
} else {
|
|
||||||
bot._client.on('error' as any, onClientError)
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo move more code here
|
// todo move more code here
|
||||||
if (!appQueryParams.noPacketsValidation) {
|
if (!appQueryParams.noPacketsValidation) {
|
||||||
(bot._client as unknown as Client).on('packet', (data, packetMeta, buffer, fullBuffer) => {
|
(bot._client as unknown as Client).on('packet', (data, packetMeta, buffer, fullBuffer) => {
|
||||||
|
|
@ -68,7 +35,7 @@ setInterval(() => {
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
|
||||||
|
|
||||||
export const getServerInfo = async (ip: string, port?: number, preferredVersion = getVersionAutoSelect(), ping = false, progressReporter?: ProgressReporter, setProxyParams?: ProxyParams) => {
|
export const getServerInfo = async (ip: string, port?: number, preferredVersion = getVersionAutoSelect(), ping = false, progressReporter?: ProgressReporter) => {
|
||||||
await downloadAllMinecraftData()
|
await downloadAllMinecraftData()
|
||||||
const isWebSocket = ip.startsWith('ws://') || ip.startsWith('wss://')
|
const isWebSocket = ip.startsWith('ws://') || ip.startsWith('wss://')
|
||||||
let stream
|
let stream
|
||||||
|
|
@ -76,8 +43,6 @@ export const getServerInfo = async (ip: string, port?: number, preferredVersion
|
||||||
progressReporter?.setMessage('Connecting to WebSocket server')
|
progressReporter?.setMessage('Connecting to WebSocket server')
|
||||||
stream = (await getWebsocketStream(ip)).mineflayerStream
|
stream = (await getWebsocketStream(ip)).mineflayerStream
|
||||||
progressReporter?.setMessage('WebSocket connected. Ping packet sent, waiting for response')
|
progressReporter?.setMessage('WebSocket connected. Ping packet sent, waiting for response')
|
||||||
} else if (setProxyParams) {
|
|
||||||
setProxy(setProxyParams)
|
|
||||||
}
|
}
|
||||||
window.setLoadingMessage = (message?: string) => {
|
window.setLoadingMessage = (message?: string) => {
|
||||||
if (message === undefined) {
|
if (message === undefined) {
|
||||||
|
|
@ -94,46 +59,3 @@ export const getServerInfo = async (ip: string, port?: number, preferredVersion
|
||||||
window.setLoadingMessage = undefined
|
window.setLoadingMessage = undefined
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
globalThis.debugTestPing = async (ip: string) => {
|
|
||||||
const parsed = parseServerAddress(ip, false)
|
|
||||||
const result = await getServerInfo(parsed.host, parsed.port ? Number(parsed.port) : undefined, undefined, true, undefined, { address: getCurrentProxy(), })
|
|
||||||
console.log('result', result)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getDefaultProxyParams = () => {
|
|
||||||
return {
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${new URLSearchParams(location.search).get('token') ?? ''}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ProxyParams = {
|
|
||||||
address?: string
|
|
||||||
headers?: Record<string, string>
|
|
||||||
}
|
|
||||||
|
|
||||||
export const setProxy = (proxyParams: ProxyParams) => {
|
|
||||||
if (proxyParams.address?.startsWith(':')) {
|
|
||||||
proxyParams.address = `${location.protocol}//${location.hostname}${proxyParams.address}`
|
|
||||||
}
|
|
||||||
if (proxyParams.address && location.port !== '80' && location.port !== '443' && !/:\d+$/.test(proxyParams.address)) {
|
|
||||||
const https = proxyParams.address.startsWith('https://') || location.protocol === 'https:'
|
|
||||||
proxyParams.address = `${proxyParams.address}:${https ? 443 : 80}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsedProxy = parseServerAddress(proxyParams.address, false)
|
|
||||||
const proxy = { host: parsedProxy.host, port: parsedProxy.port }
|
|
||||||
proxyParams.headers ??= getDefaultProxyParams().headers
|
|
||||||
net['setProxy']({
|
|
||||||
hostname: proxy.host,
|
|
||||||
port: proxy.port,
|
|
||||||
headers: proxyParams.headers,
|
|
||||||
artificialDelay: appQueryParams.addPing ? Number(appQueryParams.addPing) : undefined
|
|
||||||
})
|
|
||||||
return {
|
|
||||||
proxy
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { getInitialPlayerState, getPlayerStateUtils, PlayerStateReactive, Player
|
||||||
import { subscribe } from 'valtio'
|
import { subscribe } from 'valtio'
|
||||||
import { subscribeKey } from 'valtio/utils'
|
import { subscribeKey } from 'valtio/utils'
|
||||||
import { gameAdditionalState } from '../globalState'
|
import { gameAdditionalState } from '../globalState'
|
||||||
import { options } from '../optionsStorage'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* can be used only in main thread. Mainly for more convenient reactive state updates.
|
* can be used only in main thread. Mainly for more convenient reactive state updates.
|
||||||
|
|
@ -43,7 +42,6 @@ export class PlayerStateControllerMain {
|
||||||
private botCreated () {
|
private botCreated () {
|
||||||
console.log('bot created & plugins injected')
|
console.log('bot created & plugins injected')
|
||||||
this.reactive = getInitialPlayerState()
|
this.reactive = getInitialPlayerState()
|
||||||
this.reactive.perspective = options.defaultPerspective
|
|
||||||
this.utils = getPlayerStateUtils(this.reactive)
|
this.utils = getPlayerStateUtils(this.reactive)
|
||||||
this.onBotCreatedOrGameJoined()
|
this.onBotCreatedOrGameJoined()
|
||||||
|
|
||||||
|
|
@ -101,10 +99,6 @@ export class PlayerStateControllerMain {
|
||||||
})
|
})
|
||||||
this.reactive.gameMode = bot.game?.gameMode
|
this.reactive.gameMode = bot.game?.gameMode
|
||||||
|
|
||||||
customEvents.on('gameLoaded', () => {
|
|
||||||
this.reactive.team = bot.teamMap[bot.username]
|
|
||||||
})
|
|
||||||
|
|
||||||
this.watchReactive()
|
this.watchReactive()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ const domListeners = (bot: Bot) => {
|
||||||
}, { signal: abortController.signal })
|
}, { signal: abortController.signal })
|
||||||
|
|
||||||
bot.mouse.beforeUpdateChecks = () => {
|
bot.mouse.beforeUpdateChecks = () => {
|
||||||
if (!document.hasFocus() || !isGameActive(true)) {
|
if (!document.hasFocus()) {
|
||||||
// deactive all buttons
|
// deactive all buttons
|
||||||
bot.mouse.buttons.fill(false)
|
bot.mouse.buttons.fill(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,9 @@ class CustomDuplex extends Duplex {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getWebsocketStream = async (host: string) => {
|
export const getWebsocketStream = async (host: string) => {
|
||||||
const baseProtocol = host.startsWith('ws://') ? 'ws' : 'wss'
|
const baseProtocol = location.protocol === 'https:' ? 'wss' : host.startsWith('ws://') ? 'ws' : 'wss'
|
||||||
const hostClean = host.replace('ws://', '').replace('wss://', '')
|
const hostClean = host.replace('ws://', '').replace('wss://', '')
|
||||||
const hostURL = new URL(`${baseProtocol}://${hostClean}`)
|
const ws = new WebSocket(`${baseProtocol}://${hostClean}`)
|
||||||
const hostParams = hostURL.searchParams
|
|
||||||
hostParams.append('client_mcraft', '')
|
|
||||||
const ws = new WebSocket(`${baseProtocol}://${hostURL.host}${hostURL.pathname}?${hostParams.toString()}`)
|
|
||||||
const clientDuplex = new CustomDuplex(undefined, data => {
|
const clientDuplex = new CustomDuplex(undefined, data => {
|
||||||
ws.send(data)
|
ws.send(data)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -480,24 +480,6 @@ export const guiOptionsScheme: {
|
||||||
],
|
],
|
||||||
sound: [
|
sound: [
|
||||||
{ volume: {} },
|
{ volume: {} },
|
||||||
{
|
|
||||||
custom () {
|
|
||||||
return <OptionSlider
|
|
||||||
valueOverride={options.enableMusic ? undefined : 0}
|
|
||||||
onChange={(value) => {
|
|
||||||
options.musicVolume = value
|
|
||||||
}}
|
|
||||||
item={{
|
|
||||||
type: 'slider',
|
|
||||||
id: 'musicVolume',
|
|
||||||
text: 'Music Volume',
|
|
||||||
min: 0,
|
|
||||||
max: 100,
|
|
||||||
unit: '%',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
custom () {
|
custom () {
|
||||||
return <Button label='Sound Muffler' onClick={() => showModal({ reactType: 'sound-muffler' })} inScreen />
|
return <Button label='Sound Muffler' onClick={() => showModal({ reactType: 'sound-muffler' })} inScreen />
|
||||||
|
|
@ -565,17 +547,19 @@ export const guiOptionsScheme: {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
custom () {
|
custom () {
|
||||||
return <Category>Server Connection</Category>
|
const { cookieStorage } = useSnapshot(appStorage)
|
||||||
},
|
return <Button
|
||||||
|
label={`Storage: ${cookieStorage ? 'Synced Cookies' : 'Local Storage'}`} onClick={() => {
|
||||||
|
appStorage.cookieStorage = !cookieStorage
|
||||||
|
alert('Reload the page to apply this change')
|
||||||
|
}}
|
||||||
|
inScreen
|
||||||
|
/>
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
saveLoginPassword: {
|
custom () {
|
||||||
tooltip: 'Controls whether to save login passwords for servers in this browser memory.',
|
return <Category>Server Connection</Category>
|
||||||
values: [
|
|
||||||
'prompt',
|
|
||||||
'always',
|
|
||||||
'never'
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,6 @@ export const startLocalReplayServer = (contents: string) => {
|
||||||
const server = createServer({
|
const server = createServer({
|
||||||
Server: LocalServer as any,
|
Server: LocalServer as any,
|
||||||
version: header.minecraftVersion,
|
version: header.minecraftVersion,
|
||||||
keepAlive: false,
|
|
||||||
'online-mode': false
|
'online-mode': false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,10 @@ interface Props {
|
||||||
accounts?: string[]
|
accounts?: string[]
|
||||||
authenticatedAccounts?: number
|
authenticatedAccounts?: number
|
||||||
versions?: string[]
|
versions?: string[]
|
||||||
|
allowAutoConnect?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ({ onBack, onConfirm, title = 'Add a Server', initialData, parseQs, onQsConnect, placeholders, accounts, versions }: Props) => {
|
export default ({ onBack, onConfirm, title = 'Add a Server', initialData, parseQs, onQsConnect, placeholders, accounts, versions, allowAutoConnect }: Props) => {
|
||||||
const isSmallHeight = !usePassesScaledDimensions(null, 350)
|
const isSmallHeight = !usePassesScaledDimensions(null, 350)
|
||||||
const qsParamName = parseQs ? appQueryParams.name : undefined
|
const qsParamName = parseQs ? appQueryParams.name : undefined
|
||||||
const qsParamIp = parseQs ? appQueryParams.ip : undefined
|
const qsParamIp = parseQs ? appQueryParams.ip : undefined
|
||||||
|
|
@ -39,6 +40,7 @@ export default ({ onBack, onConfirm, title = 'Add a Server', initialData, parseQ
|
||||||
const qsParamProxy = parseQs ? appQueryParams.proxy : undefined
|
const qsParamProxy = parseQs ? appQueryParams.proxy : undefined
|
||||||
const qsParamUsername = parseQs ? appQueryParams.username : undefined
|
const qsParamUsername = parseQs ? appQueryParams.username : undefined
|
||||||
const qsParamLockConnect = parseQs ? appQueryParams.lockConnect : undefined
|
const qsParamLockConnect = parseQs ? appQueryParams.lockConnect : undefined
|
||||||
|
const qsParamAutoConnect = parseQs ? appQueryParams.autoConnect : undefined
|
||||||
|
|
||||||
const parsedQsIp = parseServerAddress(qsParamIp)
|
const parsedQsIp = parseServerAddress(qsParamIp)
|
||||||
const parsedInitialIp = parseServerAddress(initialData?.ip)
|
const parsedInitialIp = parseServerAddress(initialData?.ip)
|
||||||
|
|
@ -116,8 +118,14 @@ export default ({ onBack, onConfirm, title = 'Add a Server', initialData, parseQ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (qsParamAutoConnect && qsParamIp && qsParamVersion && allowAutoConnect) {
|
||||||
|
onQsConnect?.(commonUseOptions)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
const displayConnectButton = qsParamIp
|
const displayConnectButton = qsParamIp
|
||||||
const serverExamples = ['example.com:25565', 'play.hypixel.net', 'ws://play.pcm.gg', 'wss://play.webmc.fun']
|
const serverExamples = ['example.com:25565', 'play.hypixel.net', 'ws://play.pcm.gg']
|
||||||
// pick random example
|
// pick random example
|
||||||
const example = serverExamples[Math.floor(Math.random() * serverExamples.length)]
|
const example = serverExamples[Math.floor(Math.random() * serverExamples.length)]
|
||||||
|
|
||||||
|
|
@ -223,7 +231,7 @@ export default ({ onBack, onConfirm, title = 'Add a Server', initialData, parseQ
|
||||||
Cancel
|
Cancel
|
||||||
</ButtonWrapper>
|
</ButtonWrapper>
|
||||||
<ButtonWrapper type='submit'>
|
<ButtonWrapper type='submit'>
|
||||||
{displayConnectButton ? translate('Save') : <strong>{translate('Save')}</strong>}
|
{displayConnectButton ? 'Save' : <strong>Save</strong>}
|
||||||
</ButtonWrapper>
|
</ButtonWrapper>
|
||||||
</>}
|
</>}
|
||||||
{displayConnectButton && (
|
{displayConnectButton && (
|
||||||
|
|
@ -238,7 +246,7 @@ export default ({ onBack, onConfirm, title = 'Add a Server', initialData, parseQ
|
||||||
onQsConnect?.(commonUseOptions)
|
onQsConnect?.(commonUseOptions)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<strong>{translate('Connect')}</strong>
|
<strong>Connect</strong>
|
||||||
</ButtonWrapper>
|
</ButtonWrapper>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -54,17 +54,6 @@ export const reconnectReload = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const quickDevReconnect = () => {
|
|
||||||
if (!lastConnectOptions.value) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
resetAppStatusState()
|
|
||||||
window.dispatchEvent(new window.CustomEvent('connect', {
|
|
||||||
detail: lastConnectOptions.value
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const lastState = useRef(JSON.parse(JSON.stringify(appStatusState)))
|
const lastState = useRef(JSON.parse(JSON.stringify(appStatusState)))
|
||||||
const currentState = useSnapshot(appStatusState)
|
const currentState = useSnapshot(appStatusState)
|
||||||
|
|
@ -116,6 +105,13 @@ export default () => {
|
||||||
}
|
}
|
||||||
}, [isOpen])
|
}, [isOpen])
|
||||||
|
|
||||||
|
const reconnect = () => {
|
||||||
|
resetAppStatusState()
|
||||||
|
window.dispatchEvent(new window.CustomEvent('connect', {
|
||||||
|
detail: lastConnectOptions.value
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
window.addEventListener('keyup', (e) => {
|
window.addEventListener('keyup', (e) => {
|
||||||
|
|
@ -123,7 +119,7 @@ export default () => {
|
||||||
if (activeModalStack.at(-1)?.reactType !== 'app-status') return
|
if (activeModalStack.at(-1)?.reactType !== 'app-status') return
|
||||||
// todo do only if reconnect is possible
|
// todo do only if reconnect is possible
|
||||||
if (e.code !== 'KeyR' || !lastConnectOptions.value) return
|
if (e.code !== 'KeyR' || !lastConnectOptions.value) return
|
||||||
quickDevReconnect()
|
reconnect()
|
||||||
}, {
|
}, {
|
||||||
signal: controller.signal
|
signal: controller.signal
|
||||||
})
|
})
|
||||||
|
|
@ -144,7 +140,7 @@ export default () => {
|
||||||
const account = await showOptionsModal('Choose account to connect with', [...accounts.map(account => account.username), 'Use other account'])
|
const account = await showOptionsModal('Choose account to connect with', [...accounts.map(account => account.username), 'Use other account'])
|
||||||
if (!account) return
|
if (!account) return
|
||||||
lastConnectOptions.value!.authenticatedAccount = accounts.find(acc => acc.username === account) || true
|
lastConnectOptions.value!.authenticatedAccount = accounts.find(acc => acc.username === account) || true
|
||||||
quickDevReconnect()
|
reconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
const lastAutoCapturedPackets = getLastAutoCapturedPackets()
|
const lastAutoCapturedPackets = getLastAutoCapturedPackets()
|
||||||
|
|
@ -188,7 +184,7 @@ export default () => {
|
||||||
actionsSlot={
|
actionsSlot={
|
||||||
<>
|
<>
|
||||||
{displayAuthButton && <Button label='Authenticate' onClick={authReconnectAction} />}
|
{displayAuthButton && <Button label='Authenticate' onClick={authReconnectAction} />}
|
||||||
{displayVpnButton && <PossiblyVpnBypassProxyButton reconnect={quickDevReconnect} />}
|
{displayVpnButton && <PossiblyVpnBypassProxyButton reconnect={reconnect} />}
|
||||||
{replayActive && <Button label={`Download Packets Replay ${replayLogger?.contents.split('\n').length}L`} onClick={downloadPacketsReplay} />}
|
{replayActive && <Button label={`Download Packets Replay ${replayLogger?.contents.split('\n').length}L`} onClick={downloadPacketsReplay} />}
|
||||||
{wasDisconnected && lastAutoCapturedPackets && <Button label={`Inspect Last ${lastAutoCapturedPackets} Packets`} onClick={() => downloadAutoCapturedPackets()} />}
|
{wasDisconnected && lastAutoCapturedPackets && <Button label={`Inspect Last ${lastAutoCapturedPackets} Packets`} onClick={() => downloadAutoCapturedPackets()} />}
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
--offset: calc(-1 * 25px);
|
--offset: calc(-1 * 25px);
|
||||||
--bg-x: calc(-1 * 16px);
|
--bg-x: calc(-1 * 16px);
|
||||||
--bg-y: calc(-1 * 9px);
|
--bg-y: calc(-1 * 9px);
|
||||||
|
pointer-events: none;
|
||||||
image-rendering: pixelated;
|
image-rendering: pixelated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
--offset: calc(-1 * 16px);
|
--offset: calc(-1 * 16px);
|
||||||
--bg-x: calc(-1 * 16px);
|
--bg-x: calc(-1 * 16px);
|
||||||
--bg-y: calc(-1 * 18px);
|
--bg-y: calc(-1 * 18px);
|
||||||
|
pointer-events: none;
|
||||||
image-rendering: pixelated;
|
image-rendering: pixelated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,6 @@ div.chat-wrapper {
|
||||||
/* z-index: 10; */
|
/* z-index: 10; */
|
||||||
padding-left: calc(env(safe-area-inset-left) / 2);
|
padding-left: calc(env(safe-area-inset-left) / 2);
|
||||||
padding-right: calc(env(safe-area-inset-right, 4px) / 2);
|
padding-right: calc(env(safe-area-inset-right, 4px) / 2);
|
||||||
box-sizing: content-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Only apply overflow hidden when not in mobile mode */
|
|
||||||
div.chat-wrapper:not(.display-mobile):not(.input-mobile) {
|
|
||||||
/* overflow: hidden; */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.chat-messages-wrapper {
|
.chat-messages-wrapper {
|
||||||
|
|
@ -17,17 +11,12 @@ div.chat-wrapper:not(.display-mobile):not(.input-mobile) {
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
max-height: var(--chatHeight);
|
max-height: var(--chatHeight);
|
||||||
width: calc(var(--chatWidth) - 5px); /* Custom scrollbar width */
|
width: var(--chatWidth);
|
||||||
transform-origin: bottom left;
|
transform-origin: bottom left;
|
||||||
transform: scale(var(--chatScale));
|
transform: scale(var(--chatScale));
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restore full width when chat is opened */
|
|
||||||
.chat-messages-wrapper.chat-opened {
|
|
||||||
width: var(--chatWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
.chat-input-wrapper {
|
.chat-input-wrapper {
|
||||||
bottom: 1px;
|
bottom: 1px;
|
||||||
width: calc(100% - 3px);
|
width: calc(100% - 3px);
|
||||||
|
|
@ -73,7 +62,7 @@ div.chat-wrapper:not(.display-mobile):not(.input-mobile) {
|
||||||
top: 100%;
|
top: 100%;
|
||||||
padding-left: calc(env(safe-area-inset-left) / 2);
|
padding-left: calc(env(safe-area-inset-left) / 2);
|
||||||
margin-top: 14px;
|
margin-top: 14px;
|
||||||
margin-left: 40px;
|
margin-left: 20px;
|
||||||
/* input height */
|
/* input height */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,11 +109,6 @@ div.chat-wrapper:not(.display-mobile):not(.input-mobile) {
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-mobile .chat-completions-items > div {
|
|
||||||
padding: 4px 0;
|
|
||||||
font-size: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.input-mobile {
|
.input-mobile {
|
||||||
top: 15px;
|
top: 15px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ const MessageLine = ({ message, currentPlayerName, chatOpened }: { message: Mess
|
||||||
const [fadeState, setFadeState] = useState<'visible' | 'fading' | 'faded'>('visible')
|
const [fadeState, setFadeState] = useState<'visible' | 'fading' | 'faded'>('visible')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (window.debugStopChatFade) return
|
|
||||||
// Start fading after 5 seconds
|
// Start fading after 5 seconds
|
||||||
const fadeTimeout = setTimeout(() => {
|
const fadeTimeout = setTimeout(() => {
|
||||||
setFadeState('fading')
|
setFadeState('fading')
|
||||||
|
|
@ -45,7 +44,7 @@ const MessageLine = ({ message, currentPlayerName, chatOpened }: { message: Mess
|
||||||
return <li className={Object.entries(classes).filter(([, val]) => val).map(([name]) => name).join(' ')} data-time={message.timestamp ? new Date(message.timestamp).toLocaleString('en-US', { hour12: false }) : undefined}>
|
return <li className={Object.entries(classes).filter(([, val]) => val).map(([name]) => name).join(' ')} data-time={message.timestamp ? new Date(message.timestamp).toLocaleString('en-US', { hour12: false }) : undefined}>
|
||||||
{message.parts.map((msg, i) => {
|
{message.parts.map((msg, i) => {
|
||||||
// Check if this is a text part that might contain a mention
|
// Check if this is a text part that might contain a mention
|
||||||
if (typeof msg.text === 'string' && currentPlayerName) {
|
if (msg.text && currentPlayerName) {
|
||||||
const parts = msg.text.split(new RegExp(`(@${currentPlayerName})`, 'i'))
|
const parts = msg.text.split(new RegExp(`(@${currentPlayerName})`, 'i'))
|
||||||
if (parts.length > 1) {
|
if (parts.length > 1) {
|
||||||
return parts.map((txtPart, j) => {
|
return parts.map((txtPart, j) => {
|
||||||
|
|
@ -112,9 +111,7 @@ export default ({
|
||||||
|
|
||||||
const sendHistoryRef = useRef(JSON.parse(window.sessionStorage.chatHistory || '[]'))
|
const sendHistoryRef = useRef(JSON.parse(window.sessionStorage.chatHistory || '[]'))
|
||||||
const [isInputFocused, setIsInputFocused] = useState(false)
|
const [isInputFocused, setIsInputFocused] = useState(false)
|
||||||
const [spellCheckEnabled, setSpellCheckEnabled] = useState(false)
|
const spellCheckEnabled = false
|
||||||
const [preservedInputValue, setPreservedInputValue] = useState('')
|
|
||||||
const [inputKey, setInputKey] = useState(0)
|
|
||||||
const pingHistoryRef = useRef(JSON.parse(window.localStorage.pingHistory || '[]'))
|
const pingHistoryRef = useRef(JSON.parse(window.localStorage.pingHistory || '[]'))
|
||||||
|
|
||||||
const [completePadText, setCompletePadText] = useState('')
|
const [completePadText, setCompletePadText] = useState('')
|
||||||
|
|
@ -125,9 +122,7 @@ export default ({
|
||||||
const chatInput = useRef<HTMLInputElement>(null!)
|
const chatInput = useRef<HTMLInputElement>(null!)
|
||||||
const chatMessages = useRef<HTMLDivElement>(null)
|
const chatMessages = useRef<HTMLDivElement>(null)
|
||||||
const chatHistoryPos = useRef(sendHistoryRef.current.length)
|
const chatHistoryPos = useRef(sendHistoryRef.current.length)
|
||||||
const commandHistoryPos = useRef(0)
|
|
||||||
const inputCurrentlyEnteredValue = useRef('')
|
const inputCurrentlyEnteredValue = useRef('')
|
||||||
const commandHistoryRef = useRef(sendHistoryRef.current.filter((msg: string) => msg.startsWith('/')))
|
|
||||||
|
|
||||||
const { scrollToBottom, isAtBottom, wasAtBottom, currentlyAtBottom } = useScrollBehavior(chatMessages, { messages, opened })
|
const { scrollToBottom, isAtBottom, wasAtBottom, currentlyAtBottom } = useScrollBehavior(chatMessages, { messages, opened })
|
||||||
const [rightNowAtBottom, setRightNowAtBottom] = useState(false)
|
const [rightNowAtBottom, setRightNowAtBottom] = useState(false)
|
||||||
|
|
@ -144,9 +139,6 @@ export default ({
|
||||||
sendHistoryRef.current = newHistory
|
sendHistoryRef.current = newHistory
|
||||||
window.sessionStorage.chatHistory = JSON.stringify(newHistory)
|
window.sessionStorage.chatHistory = JSON.stringify(newHistory)
|
||||||
chatHistoryPos.current = newHistory.length
|
chatHistoryPos.current = newHistory.length
|
||||||
// Update command history (only messages starting with /)
|
|
||||||
commandHistoryRef.current = newHistory.filter((msg: string) => msg.startsWith('/'))
|
|
||||||
commandHistoryPos.current = commandHistoryRef.current.length
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const acceptComplete = (item: string) => {
|
const acceptComplete = (item: string) => {
|
||||||
|
|
@ -185,21 +177,6 @@ export default ({
|
||||||
updateInputValue(sendHistoryRef.current[chatHistoryPos.current] || inputCurrentlyEnteredValue.current || '')
|
updateInputValue(sendHistoryRef.current[chatHistoryPos.current] || inputCurrentlyEnteredValue.current || '')
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCommandArrowUp = () => {
|
|
||||||
if (commandHistoryPos.current === 0 || commandHistoryRef.current.length === 0) return
|
|
||||||
if (commandHistoryPos.current === commandHistoryRef.current.length) { // started navigating command history
|
|
||||||
inputCurrentlyEnteredValue.current = chatInput.current.value
|
|
||||||
}
|
|
||||||
commandHistoryPos.current--
|
|
||||||
updateInputValue(commandHistoryRef.current[commandHistoryPos.current] || '')
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCommandArrowDown = () => {
|
|
||||||
if (commandHistoryPos.current === commandHistoryRef.current.length) return
|
|
||||||
commandHistoryPos.current++
|
|
||||||
updateInputValue(commandHistoryRef.current[commandHistoryPos.current] || inputCurrentlyEnteredValue.current || '')
|
|
||||||
}
|
|
||||||
|
|
||||||
const auxInputFocus = (direction: 'up' | 'down') => {
|
const auxInputFocus = (direction: 'up' | 'down') => {
|
||||||
chatInput.current.focus()
|
chatInput.current.focus()
|
||||||
if (direction === 'up') {
|
if (direction === 'up') {
|
||||||
|
|
@ -223,7 +200,6 @@ export default ({
|
||||||
updateInputValue(chatInputValueGlobal.value)
|
updateInputValue(chatInputValueGlobal.value)
|
||||||
chatInputValueGlobal.value = ''
|
chatInputValueGlobal.value = ''
|
||||||
chatHistoryPos.current = sendHistoryRef.current.length
|
chatHistoryPos.current = sendHistoryRef.current.length
|
||||||
commandHistoryPos.current = commandHistoryRef.current.length
|
|
||||||
if (!usingTouch) {
|
if (!usingTouch) {
|
||||||
chatInput.current.focus()
|
chatInput.current.focus()
|
||||||
}
|
}
|
||||||
|
|
@ -260,16 +236,12 @@ export default ({
|
||||||
if (opened) {
|
if (opened) {
|
||||||
completeRequestValue.current = ''
|
completeRequestValue.current = ''
|
||||||
resetCompletionItems()
|
resetCompletionItems()
|
||||||
} else {
|
|
||||||
setPreservedInputValue('')
|
|
||||||
}
|
}
|
||||||
}, [opened])
|
}, [opened])
|
||||||
|
|
||||||
const onMainInputChange = () => {
|
const onMainInputChange = () => {
|
||||||
const lastWord = chatInput.current.value.slice(0, chatInput.current.selectionEnd ?? chatInput.current.value.length).split(' ').at(-1)!
|
const lastWord = chatInput.current.value.slice(0, chatInput.current.selectionEnd ?? chatInput.current.value.length).split(' ').at(-1)!
|
||||||
const isCommand = chatInput.current.value.startsWith('/')
|
if (lastWord.startsWith('@') && getPingComplete) {
|
||||||
|
|
||||||
if (lastWord.startsWith('@') && getPingComplete && !isCommand) {
|
|
||||||
setCompletePadText(lastWord)
|
setCompletePadText(lastWord)
|
||||||
void fetchPingCompletions(true, lastWord.slice(1))
|
void fetchPingCompletions(true, lastWord.slice(1))
|
||||||
return
|
return
|
||||||
|
|
@ -349,33 +321,10 @@ export default ({
|
||||||
return completeValue
|
return completeValue
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSlashCommand = () => {
|
|
||||||
remountInput('/')
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleAcceptFirstCompletion = () => {
|
|
||||||
if (completionItems.length > 0) {
|
|
||||||
acceptComplete(completionItems[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remountInput = (newValue?: string) => {
|
|
||||||
if (newValue !== undefined) {
|
|
||||||
setPreservedInputValue(newValue)
|
|
||||||
}
|
|
||||||
setInputKey(k => k + 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (preservedInputValue && chatInput.current) {
|
|
||||||
chatInput.current.focus()
|
|
||||||
}
|
|
||||||
}, [inputKey]) // Changed from spellCheckEnabled to inputKey
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className={`chat-wrapper chat-messages-wrapper ${usingTouch ? 'display-mobile' : ''} ${opened ? 'chat-opened' : ''}`} style={{
|
className={`chat-wrapper chat-messages-wrapper ${usingTouch ? 'display-mobile' : ''}`} style={{
|
||||||
userSelect: opened && allowSelection ? 'text' : undefined,
|
userSelect: opened && allowSelection ? 'text' : undefined,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
@ -436,53 +385,8 @@ export default ({
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={`chat-wrapper chat-input-wrapper ${usingTouch ? 'input-mobile' : ''}`} hidden={!opened}>
|
<div className={`chat-wrapper chat-input-wrapper ${usingTouch ? 'input-mobile' : ''}`} hidden={!opened}>
|
||||||
{usingTouch && (
|
{/* close button */}
|
||||||
<>
|
{usingTouch && <Button icon={pixelartIcons.close} onClick={() => onClose?.()} />}
|
||||||
<Button
|
|
||||||
icon={pixelartIcons.close}
|
|
||||||
onClick={() => onClose?.()}
|
|
||||||
style={{
|
|
||||||
width: 20,
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{(chatInput.current?.value && !chatInput.current.value.startsWith('/')) ? (
|
|
||||||
// TOGGLE SPELL CHECK
|
|
||||||
<Button
|
|
||||||
style={{
|
|
||||||
width: 20,
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
overlayColor={spellCheckEnabled ? '#00ff00' : '#ff0000'}
|
|
||||||
icon={pixelartIcons['text-wrap']}
|
|
||||||
onClick={() => {
|
|
||||||
setPreservedInputValue(chatInput.current?.value || '')
|
|
||||||
setSpellCheckEnabled(!spellCheckEnabled)
|
|
||||||
remountInput()
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
// SLASH COMMAND
|
|
||||||
<Button
|
|
||||||
style={{
|
|
||||||
width: 20,
|
|
||||||
flexShrink: 0,
|
|
||||||
}}
|
|
||||||
label={chatInput.current?.value ? undefined : '/'}
|
|
||||||
icon={chatInput.current?.value ? pixelartIcons['arrow-right'] : undefined}
|
|
||||||
onClick={() => {
|
|
||||||
const inputValue = chatInput.current.value
|
|
||||||
if (!inputValue) {
|
|
||||||
handleSlashCommand()
|
|
||||||
} else if (completionItems.length > 0) {
|
|
||||||
handleAcceptFirstCompletion()
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<div className="chat-input">
|
<div className="chat-input">
|
||||||
{isInputFocused && completionItems?.length ? (
|
{isInputFocused && completionItems?.length ? (
|
||||||
<div className="chat-completions">
|
<div className="chat-completions">
|
||||||
|
|
@ -526,10 +430,9 @@ export default ({
|
||||||
/>}
|
/>}
|
||||||
<input
|
<input
|
||||||
maxLength={chatVanillaRestrictions ? 256 : undefined}
|
maxLength={chatVanillaRestrictions ? 256 : undefined}
|
||||||
defaultValue={preservedInputValue}
|
defaultValue=''
|
||||||
// ios doesn't support toggling autoCorrect on the fly so we need to re-create the input
|
// ios doesn't support toggling autoCorrect on the fly so we need to re-create the input
|
||||||
key={`${inputKey}`}
|
key={spellCheckEnabled ? 'true' : 'false'}
|
||||||
autoCapitalize={preservedInputValue ? 'off' : 'on'}
|
|
||||||
ref={chatInput}
|
ref={chatInput}
|
||||||
type="text"
|
type="text"
|
||||||
className="chat-input"
|
className="chat-input"
|
||||||
|
|
@ -545,20 +448,10 @@ export default ({
|
||||||
onBlur={() => setIsInputFocused(false)}
|
onBlur={() => setIsInputFocused(false)}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if (e.code === 'ArrowUp') {
|
if (e.code === 'ArrowUp') {
|
||||||
if (e.altKey) {
|
|
||||||
handleCommandArrowUp()
|
|
||||||
e.preventDefault()
|
|
||||||
} else {
|
|
||||||
handleArrowUp()
|
handleArrowUp()
|
||||||
}
|
|
||||||
} else if (e.code === 'ArrowDown') {
|
} else if (e.code === 'ArrowDown') {
|
||||||
if (e.altKey) {
|
|
||||||
handleCommandArrowDown()
|
|
||||||
e.preventDefault()
|
|
||||||
} else {
|
|
||||||
handleArrowDown()
|
handleArrowDown()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (e.code === 'Tab') {
|
if (e.code === 'Tab') {
|
||||||
if (completionItemsSource.length) {
|
if (completionItemsSource.length) {
|
||||||
if (completionItems.length) {
|
if (completionItems.length) {
|
||||||
|
|
|
||||||
|
|
@ -73,28 +73,16 @@ export default () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const builtinHandled = tryHandleBuiltinCommand(message)
|
const builtinHandled = tryHandleBuiltinCommand(message)
|
||||||
if (getServerIndex() !== undefined && (message.startsWith('/login') || message.startsWith('/register')) && options.saveLoginPassword !== 'never') {
|
if (getServerIndex() !== undefined && (message.startsWith('/login') || message.startsWith('/register'))) {
|
||||||
const savePassword = () => {
|
showNotification('Click here to save your password in browser for auto-login', undefined, false, undefined, () => {
|
||||||
let hadPassword = false
|
|
||||||
updateLoadedServerData((server) => {
|
updateLoadedServerData((server) => {
|
||||||
server.autoLogin ??= {}
|
server.autoLogin ??= {}
|
||||||
const password = message.split(' ')[1]
|
const password = message.split(' ')[1]
|
||||||
hadPassword = !!server.autoLogin[bot.username]
|
|
||||||
server.autoLogin[bot.username] = password
|
server.autoLogin[bot.username] = password
|
||||||
return { ...server }
|
return { ...server }
|
||||||
})
|
})
|
||||||
if (options.saveLoginPassword === 'always') {
|
|
||||||
const message = hadPassword ? 'Password updated in browser for auto-login' : 'Password saved in browser for auto-login'
|
|
||||||
showNotification(message, undefined, false, undefined)
|
|
||||||
} else {
|
|
||||||
hideNotification()
|
hideNotification()
|
||||||
}
|
})
|
||||||
}
|
|
||||||
if (options.saveLoginPassword === 'prompt') {
|
|
||||||
showNotification('Click here to save your password in browser for auto-login', undefined, false, undefined, savePassword)
|
|
||||||
} else {
|
|
||||||
savePassword()
|
|
||||||
}
|
|
||||||
notificationProxy.id = 'auto-login'
|
notificationProxy.id = 'auto-login'
|
||||||
const listener = () => {
|
const listener = () => {
|
||||||
hideNotification()
|
hideNotification()
|
||||||
|
|
|
||||||
|
|
@ -98,16 +98,13 @@ export default ({
|
||||||
cursor: chunk ? 'pointer' : 'default',
|
cursor: chunk ? 'pointer' : 'default',
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
width: `${tileSize}px`,
|
width: `${tileSize}px`,
|
||||||
flexDirection: 'column',
|
|
||||||
height: `${tileSize}px`,
|
height: `${tileSize}px`,
|
||||||
padding: 1,
|
|
||||||
// pre-wrap
|
// pre-wrap
|
||||||
whiteSpace: 'pre',
|
whiteSpace: 'pre',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{relX}, {relZ}{'\n'}
|
{relX}, {relZ}{'\n'}
|
||||||
{chunk?.lines[0]}{'\n'}
|
{chunk?.lines.join('\n')}
|
||||||
<span style={{ fontSize: `${fontSize * 0.8}px` }}>{chunk?.lines[1]}</span>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@ import { useEffect, useState } from 'react'
|
||||||
import { useUtilsEffect } from '@zardoy/react-util'
|
import { useUtilsEffect } from '@zardoy/react-util'
|
||||||
import { WorldRendererCommon } from 'renderer/viewer/lib/worldrendererCommon'
|
import { WorldRendererCommon } from 'renderer/viewer/lib/worldrendererCommon'
|
||||||
import { WorldRendererThree } from 'renderer/viewer/three/worldrendererThree'
|
import { WorldRendererThree } from 'renderer/viewer/three/worldrendererThree'
|
||||||
import { Vec3 } from 'vec3'
|
|
||||||
import { generateSpiralMatrix } from 'flying-squid/dist/utils'
|
|
||||||
import Screen from './Screen'
|
import Screen from './Screen'
|
||||||
import ChunksDebug, { ChunkDebug } from './ChunksDebug'
|
import ChunksDebug, { ChunkDebug } from './ChunksDebug'
|
||||||
import { useIsModalActive } from './utilsApp'
|
import { useIsModalActive } from './utilsApp'
|
||||||
|
|
@ -14,10 +12,6 @@ const Inner = () => {
|
||||||
const [update, setUpdate] = useState(0)
|
const [update, setUpdate] = useState(0)
|
||||||
|
|
||||||
useUtilsEffect(({ interval }) => {
|
useUtilsEffect(({ interval }) => {
|
||||||
const up = () => {
|
|
||||||
// setUpdate(u => u + 1)
|
|
||||||
}
|
|
||||||
bot.on('chunkColumnLoad', up)
|
|
||||||
interval(
|
interval(
|
||||||
500,
|
500,
|
||||||
() => {
|
() => {
|
||||||
|
|
@ -26,48 +20,17 @@ const Inner = () => {
|
||||||
setUpdate(u => u + 1)
|
setUpdate(u => u + 1)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return () => {
|
|
||||||
bot.removeListener('chunkColumnLoad', up)
|
|
||||||
}
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Track first load time for all chunks
|
|
||||||
const allLoadTimes = Object.values(worldView!.debugChunksInfo)
|
|
||||||
.map(chunk => chunk?.loads[0]?.time ?? Infinity)
|
|
||||||
.filter(time => time !== Infinity)
|
|
||||||
.sort((a, b) => a - b)
|
|
||||||
|
|
||||||
const allSpiralChunks = Object.fromEntries(generateSpiralMatrix(worldView!.viewDistance).map(pos => [`${pos[0]},${pos[1]}`, pos]))
|
|
||||||
|
|
||||||
const mapChunk = (key: string, state: ChunkDebug['state']): ChunkDebug => {
|
const mapChunk = (key: string, state: ChunkDebug['state']): ChunkDebug => {
|
||||||
const x = Number(key.split(',')[0])
|
|
||||||
const z = Number(key.split(',')[1])
|
|
||||||
const chunkX = Math.floor(x / 16)
|
|
||||||
const chunkZ = Math.floor(z / 16)
|
|
||||||
|
|
||||||
delete allSpiralChunks[`${chunkX},${chunkZ}`]
|
|
||||||
const chunk = worldView!.debugChunksInfo[key]
|
const chunk = worldView!.debugChunksInfo[key]
|
||||||
const firstLoadTime = chunk?.loads[0]?.time
|
|
||||||
const loadIndex = firstLoadTime ? allLoadTimes.indexOf(firstLoadTime) + 1 : 0
|
|
||||||
// const timeSinceFirstLoad = firstLoadTime ? firstLoadTime - allLoadTimes[0] : 0
|
|
||||||
const timeSinceFirstLoad = firstLoadTime ? firstLoadTime - allLoadTimes[0] : 0
|
|
||||||
let line = ''
|
|
||||||
let line2 = ''
|
|
||||||
if (loadIndex) {
|
|
||||||
line = `${loadIndex}`
|
|
||||||
line2 = `${timeSinceFirstLoad}ms`
|
|
||||||
}
|
|
||||||
if (chunk?.loads.length > 1) {
|
|
||||||
line += ` - ${chunk.loads.length}`
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
x,
|
x: Number(key.split(',')[0]),
|
||||||
z,
|
z: Number(key.split(',')[1]),
|
||||||
state,
|
state,
|
||||||
lines: [line, line2],
|
lines: [String(chunk?.loads.length ?? 0)],
|
||||||
sidebarLines: [
|
sidebarLines: [
|
||||||
`loads: ${chunk?.loads?.map(l => `${l.reason} ${l.dataLength} ${l.time}`).join('\n')}`,
|
`loads: ${chunk.loads?.map(l => `${l.reason} ${l.dataLength} ${l.time}`).join('\n')}`,
|
||||||
// `blockUpdates: ${chunk.blockUpdates}`,
|
// `blockUpdates: ${chunk.blockUpdates}`,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
@ -92,22 +55,14 @@ const Inner = () => {
|
||||||
|
|
||||||
const chunksDone = Object.keys(world.finishedChunks).map(key => mapChunk(key, 'done'))
|
const chunksDone = Object.keys(world.finishedChunks).map(key => mapChunk(key, 'done'))
|
||||||
|
|
||||||
|
|
||||||
const chunksWaitingOrder = Object.values(allSpiralChunks).map(([x, z]) => {
|
|
||||||
const pos = new Vec3(x * 16, 0, z * 16)
|
|
||||||
if (bot.world.getColumnAt(pos) === null) return null
|
|
||||||
return mapChunk(`${pos.x},${pos.z}`, 'order-queued')
|
|
||||||
}).filter(a => !!a)
|
|
||||||
|
|
||||||
const allChunks = [
|
const allChunks = [
|
||||||
...chunksWaitingServer,
|
...chunksWaitingServer,
|
||||||
...chunksWaitingClient,
|
...chunksWaitingClient,
|
||||||
...clientProcessingChunks,
|
...clientProcessingChunks,
|
||||||
...chunksDone,
|
...chunksDone,
|
||||||
...chunksDoneEmpty,
|
...chunksDoneEmpty,
|
||||||
...chunksWaitingOrder,
|
|
||||||
]
|
]
|
||||||
return <Screen title={`Chunks Debug (avg: ${worldView!.lastChunkReceiveTimeAvg.toFixed(1)}ms)`}>
|
return <Screen title="Chunks Debug">
|
||||||
<ChunksDebug
|
<ChunksDebug
|
||||||
chunks={allChunks}
|
chunks={allChunks}
|
||||||
playerChunk={{
|
playerChunk={{
|
||||||
|
|
|
||||||
|
|
@ -50,9 +50,7 @@ export default () => {
|
||||||
if (!options.debugContro) return null
|
if (!options.debugContro) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div style={{
|
||||||
className='debug-contro'
|
|
||||||
style={{
|
|
||||||
position: 'fixed',
|
position: 'fixed',
|
||||||
right: 0,
|
right: 0,
|
||||||
top: '50%',
|
top: '50%',
|
||||||
|
|
@ -64,10 +62,8 @@ export default () => {
|
||||||
color: 'white',
|
color: 'white',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
gap: '4px',
|
gap: '4px'
|
||||||
zIndex: 2,
|
}}>
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div>Keys: {[...pressedKeys].join(', ')}</div>
|
<div>Keys: {[...pressedKeys].join(', ')}</div>
|
||||||
<div style={{ color: 'limegreen' }}>Actions: {actions.join(', ')}</div>
|
<div style={{ color: 'limegreen' }}>Actions: {actions.join(', ')}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,153 +0,0 @@
|
||||||
/* eslint-disable no-await-in-loop */
|
|
||||||
import { useSnapshot } from 'valtio'
|
|
||||||
import { useEffect, useState } from 'react'
|
|
||||||
import { getLoadedImage } from 'mc-assets/dist/utils'
|
|
||||||
import { createCanvas } from 'renderer/viewer/lib/utils'
|
|
||||||
|
|
||||||
const TEXTURE_UPDATE_INTERVAL = 100 // 5 times per second
|
|
||||||
|
|
||||||
export default () => {
|
|
||||||
const { onFire, perspective } = useSnapshot(appViewer.playerState.reactive)
|
|
||||||
const [fireTextures, setFireTextures] = useState<string[]>([])
|
|
||||||
const [currentTextureIndex, setCurrentTextureIndex] = useState(0)
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let animationFrameId: number
|
|
||||||
let lastTextureUpdate = 0
|
|
||||||
|
|
||||||
const updateTexture = (timestamp: number) => {
|
|
||||||
if (onFire && fireTextures.length > 0) {
|
|
||||||
if (timestamp - lastTextureUpdate >= TEXTURE_UPDATE_INTERVAL) {
|
|
||||||
setCurrentTextureIndex(prev => (prev + 1) % fireTextures.length)
|
|
||||||
lastTextureUpdate = timestamp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
animationFrameId = requestAnimationFrame(updateTexture)
|
|
||||||
}
|
|
||||||
|
|
||||||
animationFrameId = requestAnimationFrame(updateTexture)
|
|
||||||
return () => cancelAnimationFrame(animationFrameId)
|
|
||||||
}, [onFire, fireTextures])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const loadTextures = async () => {
|
|
||||||
const fireImageUrls: string[] = []
|
|
||||||
|
|
||||||
const { resourcesManager } = appViewer
|
|
||||||
const { blocksAtlasParser } = resourcesManager
|
|
||||||
if (!blocksAtlasParser?.atlas?.latest) {
|
|
||||||
console.warn('FireRenderer: Blocks atlas parser not available')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const keys = Object.keys(blocksAtlasParser.atlas.latest.textures).filter(key => /^fire_\d+$/.exec(key))
|
|
||||||
for (const key of keys) {
|
|
||||||
const textureInfo = blocksAtlasParser.getTextureInfo(key) as { u: number, v: number, width?: number, height?: number }
|
|
||||||
if (textureInfo) {
|
|
||||||
const defaultSize = blocksAtlasParser.atlas.latest.tileSize
|
|
||||||
const imageWidth = blocksAtlasParser.atlas.latest.width
|
|
||||||
const imageHeight = blocksAtlasParser.atlas.latest.height
|
|
||||||
const textureWidth = textureInfo.width ?? defaultSize
|
|
||||||
const textureHeight = textureInfo.height ?? defaultSize
|
|
||||||
|
|
||||||
// Create a temporary canvas for the full texture
|
|
||||||
const tempCanvas = createCanvas(textureWidth, textureHeight)
|
|
||||||
const tempCtx = tempCanvas.getContext('2d')
|
|
||||||
if (tempCtx && blocksAtlasParser.latestImage) {
|
|
||||||
const image = await getLoadedImage(blocksAtlasParser.latestImage)
|
|
||||||
tempCtx.drawImage(
|
|
||||||
image,
|
|
||||||
textureInfo.u * imageWidth,
|
|
||||||
textureInfo.v * imageHeight,
|
|
||||||
textureWidth,
|
|
||||||
textureHeight,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
textureWidth,
|
|
||||||
textureHeight
|
|
||||||
)
|
|
||||||
|
|
||||||
// Create final canvas with only top 20% of the texture
|
|
||||||
const finalHeight = Math.ceil(textureHeight * 0.4)
|
|
||||||
const canvas = createCanvas(textureWidth, finalHeight)
|
|
||||||
const ctx = canvas.getContext('2d')
|
|
||||||
if (ctx) {
|
|
||||||
// Draw only the top portion
|
|
||||||
ctx.drawImage(
|
|
||||||
tempCanvas,
|
|
||||||
0,
|
|
||||||
0, // Start from top
|
|
||||||
textureWidth,
|
|
||||||
finalHeight,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
textureWidth,
|
|
||||||
finalHeight
|
|
||||||
)
|
|
||||||
|
|
||||||
const blob = await canvas.convertToBlob()
|
|
||||||
const url = URL.createObjectURL(blob)
|
|
||||||
fireImageUrls.push(url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setFireTextures(fireImageUrls)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load textures initially
|
|
||||||
if (appViewer.resourcesManager.currentResources) {
|
|
||||||
void loadTextures()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up listener for texture updates
|
|
||||||
const onAssetsUpdated = () => {
|
|
||||||
void loadTextures()
|
|
||||||
}
|
|
||||||
appViewer.resourcesManager.on('assetsTexturesUpdated', onAssetsUpdated)
|
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
return () => {
|
|
||||||
appViewer.resourcesManager.off('assetsTexturesUpdated', onAssetsUpdated)
|
|
||||||
// Cleanup texture URLs
|
|
||||||
for (const url of fireTextures) URL.revokeObjectURL(url)
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
if (!onFire || fireTextures.length === 0 || perspective !== 'first_person') return null
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className='fire-renderer-container'
|
|
||||||
style={{
|
|
||||||
position: 'fixed',
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
height: '20dvh',
|
|
||||||
pointerEvents: 'none',
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'flex-end',
|
|
||||||
overflow: 'hidden',
|
|
||||||
zIndex: -1
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
backgroundImage: `url(${fireTextures[currentTextureIndex]})`,
|
|
||||||
backgroundSize: '50% 100%',
|
|
||||||
backgroundPosition: 'center',
|
|
||||||
backgroundRepeat: 'repeat-x',
|
|
||||||
opacity: 0.7,
|
|
||||||
filter: 'brightness(1.2) contrast(1.2)',
|
|
||||||
mixBlendMode: 'screen'
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
--offset: calc(-1 * (52px + (9px * (4 * var(--kind) + var(--lightened) * 2))));
|
--offset: calc(-1 * (52px + (9px * (4 * var(--kind) + var(--lightened) * 2))));
|
||||||
--bg-x: calc(-1 * (16px + 9px * var(--lightened)));
|
--bg-x: calc(-1 * (16px + 9px * var(--lightened)));
|
||||||
--bg-y: calc(-1 * 27px);
|
--bg-y: calc(-1 * 27px);
|
||||||
|
pointer-events: none;
|
||||||
image-rendering: pixelated;
|
image-rendering: pixelated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import { useRef, useEffect } from 'react'
|
||||||
import { subscribe, useSnapshot } from 'valtio'
|
import { subscribe, useSnapshot } from 'valtio'
|
||||||
import { useUtilsEffect } from '@zardoy/react-util'
|
import { useUtilsEffect } from '@zardoy/react-util'
|
||||||
import { getThreeJsRendererMethods } from 'renderer/viewer/three/threeJsMethods'
|
import { getThreeJsRendererMethods } from 'renderer/viewer/three/threeJsMethods'
|
||||||
import { isItemActivatableMobile } from 'mineflayer-mouse/dist/activatableItemsMobile'
|
|
||||||
import { options } from '../optionsStorage'
|
import { options } from '../optionsStorage'
|
||||||
import { activeModalStack, isGameActive, miscUiState } from '../globalState'
|
import { activeModalStack, isGameActive, miscUiState } from '../globalState'
|
||||||
import { onCameraMove, CameraMoveEvent } from '../cameraRotationControls'
|
import { onCameraMove, CameraMoveEvent } from '../cameraRotationControls'
|
||||||
|
|
@ -78,10 +77,7 @@ function GameInteractionOverlayInner ({
|
||||||
if (options.touchInteractionType === 'classic') {
|
if (options.touchInteractionType === 'classic') {
|
||||||
virtualClickTimeout ??= setTimeout(() => {
|
virtualClickTimeout ??= setTimeout(() => {
|
||||||
virtualClickActive = true
|
virtualClickActive = true
|
||||||
// If held item is activatable, use right click instead of left
|
document.dispatchEvent(new MouseEvent('mousedown', { button: 0 }))
|
||||||
const heldItemName = bot?.heldItem?.name
|
|
||||||
const isOnlyActivatable = heldItemName && isItemActivatableMobile(heldItemName, loadedData)
|
|
||||||
document.dispatchEvent(new MouseEvent('mousedown', { button: isOnlyActivatable ? 2 : 0 }))
|
|
||||||
}, touchStartBreakingBlockMs)
|
}, touchStartBreakingBlockMs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -154,23 +150,16 @@ function GameInteractionOverlayInner ({
|
||||||
|
|
||||||
if (virtualClickActive) {
|
if (virtualClickActive) {
|
||||||
// button 0 is left click
|
// button 0 is left click
|
||||||
// If held item is activatable, use right click instead of left
|
document.dispatchEvent(new MouseEvent('mouseup', { button: 0 }))
|
||||||
const heldItemName = bot?.heldItem?.name
|
|
||||||
const isOnlyActivatable = heldItemName && isItemActivatableMobile(heldItemName, loadedData)
|
|
||||||
document.dispatchEvent(new MouseEvent('mouseup', { button: isOnlyActivatable ? 2 : 0 }))
|
|
||||||
virtualClickActive = false
|
virtualClickActive = false
|
||||||
} else if (!capturedPointer.active.activateCameraMove && (Date.now() - capturedPointer.active.time < touchStartBreakingBlockMs)) {
|
} else if (!capturedPointer.active.activateCameraMove && (Date.now() - capturedPointer.active.time < touchStartBreakingBlockMs)) {
|
||||||
// single click action
|
// single click action
|
||||||
const MOUSE_BUTTON_RIGHT = 2
|
const MOUSE_BUTTON_RIGHT = 2
|
||||||
const MOUSE_BUTTON_LEFT = 0
|
const MOUSE_BUTTON_LEFT = 0
|
||||||
const heldItemName = bot?.heldItem?.name
|
|
||||||
const isOnlyActivatable = heldItemName && isItemActivatableMobile(heldItemName, loadedData)
|
|
||||||
const gonnaAttack = !!bot.mouse.getCursorState().entity || !!videoCursorInteraction()
|
const gonnaAttack = !!bot.mouse.getCursorState().entity || !!videoCursorInteraction()
|
||||||
// If not attacking entity and item is activatable, use right click for breaking
|
document.dispatchEvent(new MouseEvent('mousedown', { button: gonnaAttack ? MOUSE_BUTTON_LEFT : MOUSE_BUTTON_RIGHT }))
|
||||||
const useButton = !gonnaAttack && isOnlyActivatable ? MOUSE_BUTTON_RIGHT : (gonnaAttack ? MOUSE_BUTTON_LEFT : MOUSE_BUTTON_RIGHT)
|
|
||||||
document.dispatchEvent(new MouseEvent('mousedown', { button: useButton }))
|
|
||||||
bot.mouse.update()
|
bot.mouse.update()
|
||||||
document.dispatchEvent(new MouseEvent('mouseup', { button: useButton }))
|
document.dispatchEvent(new MouseEvent('mouseup', { button: gonnaAttack ? MOUSE_BUTTON_LEFT : MOUSE_BUTTON_RIGHT }))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (screenTouches > 0) {
|
if (screenTouches > 0) {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
--offset: calc(-1 * (52px + (9px * (4 * var(--kind) + var(--lightened) * 2)) ));
|
--offset: calc(-1 * (52px + (9px * (4 * var(--kind) + var(--lightened) * 2)) ));
|
||||||
--bg-x: calc(-1 * (16px + 9px * var(--lightened)));
|
--bg-x: calc(-1 * (16px + 9px * var(--lightened)));
|
||||||
--bg-y: calc(-1 * var(--hardcore) * 45px);
|
--bg-y: calc(-1 * var(--hardcore) * 45px);
|
||||||
|
pointer-events: none;
|
||||||
image-rendering: pixelated;
|
image-rendering: pixelated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,15 @@ import { useEffect, useRef, useState } from 'react'
|
||||||
import { motion, AnimatePresence } from 'framer-motion'
|
import { motion, AnimatePresence } from 'framer-motion'
|
||||||
import { createPortal } from 'react-dom'
|
import { createPortal } from 'react-dom'
|
||||||
import { subscribe, useSnapshot } from 'valtio'
|
import { subscribe, useSnapshot } from 'valtio'
|
||||||
import { openItemsCanvas, upInventoryItems } from '../inventoryWindows'
|
import { openItemsCanvas, openPlayerInventory, upInventoryItems } from '../inventoryWindows'
|
||||||
import { activeModalStack, isGameActive, miscUiState } from '../globalState'
|
import { activeModalStack, isGameActive, miscUiState } from '../globalState'
|
||||||
import { currentScaling } from '../scaleInterface'
|
import { currentScaling } from '../scaleInterface'
|
||||||
import { watchUnloadForCleanup } from '../gameUnload'
|
import { watchUnloadForCleanup } from '../gameUnload'
|
||||||
import { getItemNameRaw } from '../mineflayer/items'
|
import { getItemNameRaw } from '../mineflayer/items'
|
||||||
import { isInRealGameSession } from '../utils'
|
import { isInRealGameSession } from '../utils'
|
||||||
import { triggerCommand } from '../controls'
|
|
||||||
import MessageFormattedString from './MessageFormattedString'
|
import MessageFormattedString from './MessageFormattedString'
|
||||||
import SharedHudVars from './SharedHudVars'
|
import SharedHudVars from './SharedHudVars'
|
||||||
|
import { packetsReplayState } from './state/packetsReplayState'
|
||||||
|
|
||||||
|
|
||||||
const ItemName = ({ itemKey }: { itemKey: string }) => {
|
const ItemName = ({ itemKey }: { itemKey: string }) => {
|
||||||
|
|
@ -75,8 +75,6 @@ const HotbarInner = () => {
|
||||||
const container = useRef<HTMLDivElement>(null!)
|
const container = useRef<HTMLDivElement>(null!)
|
||||||
const [itemKey, setItemKey] = useState('')
|
const [itemKey, setItemKey] = useState('')
|
||||||
const hasModals = useSnapshot(activeModalStack).length
|
const hasModals = useSnapshot(activeModalStack).length
|
||||||
const { currentTouch, appConfig } = useSnapshot(miscUiState)
|
|
||||||
const mobileOpenInventory = currentTouch && !appConfig?.disabledCommands?.includes('general.inventory')
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
|
|
@ -107,7 +105,7 @@ const HotbarInner = () => {
|
||||||
canvasManager.setScale(currentScaling.scale)
|
canvasManager.setScale(currentScaling.scale)
|
||||||
|
|
||||||
canvasManager.windowHeight = 25 * canvasManager.scale
|
canvasManager.windowHeight = 25 * canvasManager.scale
|
||||||
canvasManager.windowWidth = (210 - (inv.inventory.supportsOffhand ? 0 : 25) + (mobileOpenInventory ? 28 : 0)) * canvasManager.scale
|
canvasManager.windowWidth = (210 - (inv.inventory.supportsOffhand ? 0 : 25) + (miscUiState.currentTouch ? 28 : 0)) * canvasManager.scale
|
||||||
}
|
}
|
||||||
setSize()
|
setSize()
|
||||||
watchUnloadForCleanup(subscribe(currentScaling, setSize))
|
watchUnloadForCleanup(subscribe(currentScaling, setSize))
|
||||||
|
|
@ -115,19 +113,17 @@ const HotbarInner = () => {
|
||||||
container.current.appendChild(inv.canvas)
|
container.current.appendChild(inv.canvas)
|
||||||
const upHotbarItems = () => {
|
const upHotbarItems = () => {
|
||||||
if (!appViewer.resourcesManager?.itemsAtlasParser) return
|
if (!appViewer.resourcesManager?.itemsAtlasParser) return
|
||||||
globalThis.debugHotbarItems = upInventoryItems(true, inv)
|
upInventoryItems(true, inv)
|
||||||
}
|
}
|
||||||
|
|
||||||
canvasManager.canvas.onclick = (e) => {
|
canvasManager.canvas.onclick = (e) => {
|
||||||
if (!isGameActive(true)) return
|
if (!isGameActive(true)) return
|
||||||
const pos = inv.canvasManager.getMousePos(inv.canvas, e)
|
const pos = inv.canvasManager.getMousePos(inv.canvas, e)
|
||||||
if (canvasManager.canvas.width - pos.x < 35 * inv.canvasManager.scale && mobileOpenInventory) {
|
if (canvasManager.canvas.width - pos.x < 35 * inv.canvasManager.scale) {
|
||||||
triggerCommand('general.inventory', true)
|
openPlayerInventory()
|
||||||
triggerCommand('general.inventory', false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
globalThis.debugUpHotbarItems = upHotbarItems
|
|
||||||
upHotbarItems()
|
upHotbarItems()
|
||||||
bot.inventory.on('updateSlot', upHotbarItems)
|
bot.inventory.on('updateSlot', upHotbarItems)
|
||||||
appViewer.resourcesManager.on('assetsTexturesUpdated', upHotbarItems)
|
appViewer.resourcesManager.on('assetsTexturesUpdated', upHotbarItems)
|
||||||
|
|
@ -184,8 +180,17 @@ const HotbarInner = () => {
|
||||||
})
|
})
|
||||||
document.addEventListener('touchend', (e) => {
|
document.addEventListener('touchend', (e) => {
|
||||||
if (touchStart && (e.target as HTMLElement).closest('.hotbar') && Date.now() - touchStart > 700) {
|
if (touchStart && (e.target as HTMLElement).closest('.hotbar') && Date.now() - touchStart > 700) {
|
||||||
triggerCommand('general.dropStack', true)
|
// drop item
|
||||||
triggerCommand('general.dropStack', false)
|
bot._client.write('block_dig', {
|
||||||
|
'status': 4,
|
||||||
|
'location': {
|
||||||
|
'x': 0,
|
||||||
|
'z': 0,
|
||||||
|
'y': 0
|
||||||
|
},
|
||||||
|
'face': 0,
|
||||||
|
sequence: 0
|
||||||
|
})
|
||||||
}
|
}
|
||||||
touchStart = 0
|
touchStart = 0
|
||||||
})
|
})
|
||||||
|
|
@ -201,28 +206,17 @@ const HotbarInner = () => {
|
||||||
<ItemName itemKey={itemKey} />
|
<ItemName itemKey={itemKey} />
|
||||||
<Portal>
|
<Portal>
|
||||||
<div
|
<div
|
||||||
className='hotbar-fullscreen-container'
|
className='hotbar' ref={container} style={{
|
||||||
style={{
|
|
||||||
position: 'fixed',
|
position: 'fixed',
|
||||||
top: 0,
|
|
||||||
left: 0,
|
left: 0,
|
||||||
width: '100dvw',
|
right: 0,
|
||||||
height: '100dvh',
|
|
||||||
zIndex: hasModals ? 1 : 8,
|
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
pointerEvents: 'none',
|
zIndex: hasModals ? 1 : 8,
|
||||||
}}>
|
|
||||||
<div
|
|
||||||
className='hotbar'
|
|
||||||
ref={container}
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
pointerEvents: 'none',
|
pointerEvents: 'none',
|
||||||
bottom: 'var(--hud-bottom-raw)'
|
bottom: 'var(--hud-bottom-raw)'
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
</Portal>
|
</Portal>
|
||||||
</SharedHudVars>
|
</SharedHudVars>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
import { useRef, useState, useMemo } from 'react'
|
import { useRef, useState, useMemo } from 'react'
|
||||||
import { GameMode } from 'mineflayer'
|
import { GameMode } from 'mineflayer'
|
||||||
import { useSnapshot } from 'valtio'
|
|
||||||
import { options } from '../optionsStorage'
|
|
||||||
import { armor } from './armorValues'
|
import { armor } from './armorValues'
|
||||||
import HealthBar from './HealthBar'
|
import HealthBar from './HealthBar'
|
||||||
import FoodBar from './FoodBar'
|
import FoodBar from './FoodBar'
|
||||||
|
|
@ -10,8 +8,6 @@ import BreathBar from './BreathBar'
|
||||||
import './HealthBar.css'
|
import './HealthBar.css'
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const { disabledUiParts } = useSnapshot(options)
|
|
||||||
|
|
||||||
const [damaged, setDamaged] = useState(false)
|
const [damaged, setDamaged] = useState(false)
|
||||||
const [healthValue, setHealthValue] = useState(bot.health)
|
const [healthValue, setHealthValue] = useState(bot.health)
|
||||||
const [food, setFood] = useState(bot.food)
|
const [food, setFood] = useState(bot.food)
|
||||||
|
|
@ -95,7 +91,7 @@ export default () => {
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return <div className='hud-bars-container'>
|
return <div className='hud-bars-container'>
|
||||||
{!disabledUiParts.includes('health-bar') && <HealthBar
|
<HealthBar
|
||||||
gameMode={gameMode}
|
gameMode={gameMode}
|
||||||
isHardcore={isHardcore}
|
isHardcore={isHardcore}
|
||||||
damaged={damaged}
|
damaged={damaged}
|
||||||
|
|
@ -106,12 +102,12 @@ export default () => {
|
||||||
setEffectToAdd(null)
|
setEffectToAdd(null)
|
||||||
setEffectToRemove(null)
|
setEffectToRemove(null)
|
||||||
}}
|
}}
|
||||||
/>}
|
/>
|
||||||
{!disabledUiParts.includes('armor-bar') && <ArmorBar
|
<ArmorBar
|
||||||
armorValue={armorValue}
|
armorValue={armorValue}
|
||||||
style={gameMode !== 'survival' && gameMode !== 'adventure' ? { display: 'none' } : { display: 'flex' }}
|
style={gameMode !== 'survival' && gameMode !== 'adventure' ? { display: 'none' } : { display: 'flex' }}
|
||||||
/>}
|
/>
|
||||||
{!disabledUiParts.includes('food-bar') && <FoodBar
|
<FoodBar
|
||||||
gameMode={gameMode}
|
gameMode={gameMode}
|
||||||
food={food}
|
food={food}
|
||||||
effectToAdd={effectToAdd}
|
effectToAdd={effectToAdd}
|
||||||
|
|
@ -120,9 +116,9 @@ export default () => {
|
||||||
setEffectToAdd(null)
|
setEffectToAdd(null)
|
||||||
setEffectToRemove(null)
|
setEffectToRemove(null)
|
||||||
}}
|
}}
|
||||||
/>}
|
/>
|
||||||
{!disabledUiParts.includes('breath-bar') && <BreathBar
|
<BreathBar
|
||||||
oxygen={gameMode !== 'survival' && gameMode !== 'adventure' ? 0 : oxygen}
|
oxygen={gameMode !== 'survival' && gameMode !== 'adventure' ? 0 : oxygen}
|
||||||
/>}
|
/>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { Effect } from 'mineflayer'
|
||||||
import { inGameError } from '../utils'
|
import { inGameError } from '../utils'
|
||||||
import { fsState } from '../loadSave'
|
import { fsState } from '../loadSave'
|
||||||
import { gameAdditionalState, miscUiState } from '../globalState'
|
import { gameAdditionalState, miscUiState } from '../globalState'
|
||||||
|
import { options } from '../optionsStorage'
|
||||||
import IndicatorEffects, { EffectType, defaultIndicatorsState } from './IndicatorEffects'
|
import IndicatorEffects, { EffectType, defaultIndicatorsState } from './IndicatorEffects'
|
||||||
import { images } from './effectsImages'
|
import { images } from './effectsImages'
|
||||||
|
|
||||||
|
|
@ -66,6 +67,7 @@ export default ({ displayEffects = true, displayIndicators = true }: { displayEf
|
||||||
const { mesherWork } = useSnapshot(appViewer.rendererState).world
|
const { mesherWork } = useSnapshot(appViewer.rendererState).world
|
||||||
|
|
||||||
const { hasErrors } = useSnapshot(miscUiState)
|
const { hasErrors } = useSnapshot(miscUiState)
|
||||||
|
const { disabledUiParts } = useSnapshot(options)
|
||||||
const { isReadonly, openReadOperations, openWriteOperations } = useSnapshot(fsState)
|
const { isReadonly, openReadOperations, openWriteOperations } = useSnapshot(fsState)
|
||||||
const { noConnection, poorConnection } = useSnapshot(gameAdditionalState)
|
const { noConnection, poorConnection } = useSnapshot(gameAdditionalState)
|
||||||
const allIndicators: typeof defaultIndicatorsState = {
|
const allIndicators: typeof defaultIndicatorsState = {
|
||||||
|
|
@ -120,7 +122,7 @@ export default ({ displayEffects = true, displayIndicators = true }: { displayEf
|
||||||
return <IndicatorEffects
|
return <IndicatorEffects
|
||||||
indicators={allIndicators}
|
indicators={allIndicators}
|
||||||
effects={effects}
|
effects={effects}
|
||||||
displayIndicators={displayIndicators}
|
displayIndicators
|
||||||
displayEffects={displayEffects}
|
displayEffects
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
.monaco-editor-container {
|
|
||||||
position: fixed;
|
|
||||||
inset: 0;
|
|
||||||
z-index: 1000;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
padding: 16px;
|
|
||||||
background-color: rgba(0, 0, 0, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
.monaco-editor-title {
|
|
||||||
font-size: 20px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: #fff;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.monaco-editor-wrapper {
|
|
||||||
position: relative;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
max-width: 80vw;
|
|
||||||
max-height: 80vh;
|
|
||||||
border: 3px solid #000;
|
|
||||||
background-color: #000;
|
|
||||||
padding: 3px;
|
|
||||||
box-shadow: inset 0 0 0 1px #fff, inset 0 0 0 2px #000;
|
|
||||||
}
|
|
||||||
|
|
||||||
.monaco-editor-close {
|
|
||||||
position: fixed;
|
|
||||||
top: 16px;
|
|
||||||
left: 16px;
|
|
||||||
z-index: 1001;
|
|
||||||
cursor: pointer;
|
|
||||||
padding: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
.monaco-editor-container {
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
.monaco-editor-wrapper {
|
|
||||||
max-width: 100%;
|
|
||||||
max-height: 100%;
|
|
||||||
border-radius: 0;
|
|
||||||
}
|
|
||||||
.monaco-editor-close {
|
|
||||||
top: 8px;
|
|
||||||
left: 8px;
|
|
||||||
}
|
|
||||||
.monaco-editor-title {
|
|
||||||
/* todo: make it work on mobile */
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue