@kzheart_/mc-pilot 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -106,6 +106,21 @@ function substitute(template, variables) {
106
106
  return template.replace(/\$\{([^}]+)\}/g, (_, key) => variables[key] ?? "");
107
107
  }
108
108
 
109
+ function parseOptionalBoolean(value) {
110
+ if (value === undefined || value === null || value === "") {
111
+ return undefined;
112
+ }
113
+
114
+ const normalized = String(value).trim().toLowerCase();
115
+ if (["true", "1", "yes", "on"].includes(normalized)) {
116
+ return true;
117
+ }
118
+ if (["false", "0", "no", "off"].includes(normalized)) {
119
+ return false;
120
+ }
121
+ return undefined;
122
+ }
123
+
109
124
  async function ensureFile(filePath, downloadUrl) {
110
125
  try {
111
126
  await access(filePath);
@@ -170,7 +185,7 @@ async function syncConfiguredMod(gameDir) {
170
185
  await copyFile(sourceJar, targetJar);
171
186
  }
172
187
 
173
- async function ensureAutomationOptions(gameDir, server) {
188
+ async function ensureAutomationOptions(gameDir, server, mute) {
174
189
  const optionsPath = path.join(gameDir, "options.txt");
175
190
  const values = new Map();
176
191
 
@@ -191,6 +206,23 @@ async function ensureAutomationOptions(gameDir, server) {
191
206
  values.set("joinedFirstServer", "true");
192
207
  values.set("tutorialStep", "none");
193
208
  values.set("pauseOnLostFocus", "false");
209
+ if (mute !== undefined) {
210
+ const volume = mute ? "0.0" : "1.0";
211
+ for (const category of [
212
+ "master",
213
+ "music",
214
+ "record",
215
+ "weather",
216
+ "block",
217
+ "hostile",
218
+ "neutral",
219
+ "player",
220
+ "ambient",
221
+ "voice"
222
+ ]) {
223
+ values.set(`soundCategory_${category}`, volume);
224
+ }
225
+ }
194
226
  if (server) {
195
227
  values.set("lastServer", server);
196
228
  }
@@ -214,6 +246,7 @@ async function buildLaunchSpec(options) {
214
246
  const nativesDir = options["natives-dir"] || path.join(instanceRoot, "natives");
215
247
  const gameDir = path.join(instanceRoot, "minecraft");
216
248
  const packMeta = await readJson(path.join(instanceRoot, "mmc-pack.json"));
249
+ const mute = parseOptionalBoolean(process.env.MCT_CLIENT_MUTE);
217
250
  await syncBuiltMod(instanceRoot, repoRoot, selectedVariant);
218
251
  const componentMetas = new Map();
219
252
  for (const component of packMeta.components) {
@@ -263,7 +296,7 @@ async function buildLaunchSpec(options) {
263
296
  const accountName = process.env.MCT_CLIENT_ACCOUNT || options.account || "TEST1";
264
297
  const accountUuid = offlineUuid(accountName);
265
298
  const server = process.env.MCT_CLIENT_SERVER || "";
266
- await ensureAutomationOptions(gameDir, server);
299
+ await ensureAutomationOptions(gameDir, server, mute);
267
300
  const [serverHost, serverPort = "25565"] = server.split(":");
268
301
  const classpath = [
269
302
  path.join(librariesRoot, mainJarPath),
@@ -316,12 +349,13 @@ async function buildManifestLaunchSpec(options) {
316
349
 
317
350
  const manifest = await readJson(manifestPath);
318
351
  const gameDir = manifest.gameDir;
352
+ const mute = parseOptionalBoolean(process.env.MCT_CLIENT_MUTE);
319
353
  await syncConfiguredMod(gameDir);
320
354
 
321
355
  const accountName = process.env.MCT_CLIENT_ACCOUNT || options.account || "TEST1";
322
356
  const accountUuid = offlineUuid(accountName);
323
357
  const server = process.env.MCT_CLIENT_SERVER || "";
324
- await ensureAutomationOptions(gameDir, server);
358
+ await ensureAutomationOptions(gameDir, server, mute);
325
359
  const [serverHost, serverPort = "25565"] = server.split(":");
326
360
  const substitutions = {
327
361
  auth_player_name: accountName,