From 7b3228e856b678eee8ea757ad4936064a8c881ab Mon Sep 17 00:00:00 2001 From: jgaribsin Date: Thu, 21 Mar 2024 16:31:58 -0600 Subject: [PATCH] changing min render to 16, uses existing minecraft options.txt if exists - version bump so people don't use the outdated install defaults --- package.json | 2 +- src/providers/DownloadFile.ts | 2 +- src/providers/DownloadResourcePack.ts | 5 ++-- src/providers/UpdateMinecraftOpts.ts | 40 +++++++++++++++++++++------ 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index dbd48bf..62b57d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "drehmal-installer", - "version": "0.5.2", + "version": "0.5.3", "description": "Drehmal, Minecraft map installer", "productName": "Drehmal Installer", "author": "jgaribsin", diff --git a/src/providers/DownloadFile.ts b/src/providers/DownloadFile.ts index 0d132d7..25a0ff1 100644 --- a/src/providers/DownloadFile.ts +++ b/src/providers/DownloadFile.ts @@ -18,7 +18,7 @@ export function downloadFile( // User-Agent: github_username/project_name/1.56.0 (launcher.com) const options = { headers: { - 'User-Agent': 'Drehmal-Team/installer/0.5.2 (drehmal.net)', + 'User-Agent': 'Drehmal-Team/installer/0.5.3 (drehmal.net)', // 'accept-encoding': 'gzip, deflate, br', }, }; diff --git a/src/providers/DownloadResourcePack.ts b/src/providers/DownloadResourcePack.ts index 7bd06eb..ca95ca2 100644 --- a/src/providers/DownloadResourcePack.ts +++ b/src/providers/DownloadResourcePack.ts @@ -10,7 +10,7 @@ const fs = require('fs'); export async function downloadResourcePack(ref: Ref) { const { resourcePack } = storeToRefs(useSourcesStore()); - const { drehmalDir } = storeToRefs(useInstallerStore()); + const { drehmalDir, minecraftDir } = storeToRefs(useInstallerStore()); const { processingResourcepack } = storeToRefs(useStateStore()); ref.value.label = 'Downloading resource pack'; @@ -30,9 +30,10 @@ export async function downloadResourcePack(ref: Ref) { ref.value.label = 'Updating video settings'; const optionsFilePath = path.join(drehmalDir.value, 'options.txt'); + const oldOpts = path.join(minecraftDir.value, 'options.txt'); console.log(`Updating Minecraft options in file: ${optionsFilePath}`); - updateMinecraftOpts(optionsFilePath); + updateMinecraftOpts(optionsFilePath, oldOpts); ref.value.label = 'Resource pack downloaded!'; diff --git a/src/providers/UpdateMinecraftOpts.ts b/src/providers/UpdateMinecraftOpts.ts index 19ddf8f..a5f4809 100644 --- a/src/providers/UpdateMinecraftOpts.ts +++ b/src/providers/UpdateMinecraftOpts.ts @@ -3,14 +3,29 @@ import { useSourcesStore } from 'src/stores/SourcesStore'; const fs = require('fs'); -export function updateMinecraftOpts(filename: string) { +export function updateMinecraftOpts(drehmalOpts: string, oldOpts: string) { // Create object to store the options as a json object for easy access const options: Record = {}; - if (fs.existsSync(filename)) { - console.log(`Options file found at "${filename}"!`); + if (fs.existsSync(drehmalOpts)) { + console.log(`Drehmal options file found at "${drehmalOpts}"!`); // Parse options file into an array of strings for each line - const lines: string[] = fs.readFileSync(filename, 'utf-8').split('\n'); + const lines: string[] = fs.readFileSync(drehmalOpts, 'utf-8').split('\n'); + // add each option to the created object + lines.forEach((line) => { + const [key, value] = line.split(':'); + if (key && value) { + options[key.trim()] = value.trim(); + } + }); + } else if (fs.existsSync(oldOpts)) { + // TODO: repeat above check for original .minecraft dir, otherwise create a new options file + console.log( + `Drehmal options not found - falling back to MC options "${oldOpts}"...` + ); + console.log(`Minecraft options file found at "${oldOpts}"!`); + // Parse options file into an array of strings for each line + const lines: string[] = fs.readFileSync(oldOpts, 'utf-8').split('\n'); // add each option to the created object lines.forEach((line) => { const [key, value] = line.split(':'); @@ -19,9 +34,11 @@ export function updateMinecraftOpts(filename: string) { } }); } else { - console.log(`Options file not found at "${filename}" - will be created...`); + console.log( + `Options file not found at "${oldOpts}" - creating new with defaults...` + ); // Ensure render distance is set to minimum if the file doesn't exist - options['renderDistance'] = '8'; + options['renderDistance'] = '16'; } const { resourcePack } = storeToRefs(useSourcesStore()); @@ -33,7 +50,14 @@ export function updateMinecraftOpts(filename: string) { // disable clouds, gets in the way of towers/structures options['renderClouds'] = 'false'; // increase render distance to required minimum (consider scale based on memory allocation) - if (parseInt(options['renderDistance']) < 8) options['renderDistance'] = '8'; + if (parseInt(options['renderDistance']) < 16) + options['renderDistance'] = '16'; + // if master volume is too low, set it to 50% (MC defaults this to 100% on first run if missing) + if ( + options['soundCategory_master'] !== undefined && + parseInt(options['soundCategory_master']) < 0.5 + ) + options['soundCategory_master'] = '0.5'; // maximise unfocused chat size so players can properly use menus options['chatHeightUnfocused'] = '1.0'; // ensure custom music is enabled @@ -49,5 +73,5 @@ export function updateMinecraftOpts(filename: string) { (key) => (newOptions += `${key}:${options[key]}\n`) ); - fs.writeFileSync(filename, newOptions); + fs.writeFileSync(drehmalOpts, newOptions); }