Skip to content

Commit

Permalink
changing min render to 16, uses existing minecraft options.txt if exists
Browse files Browse the repository at this point in the history
- version bump so people don't use the outdated install defaults
  • Loading branch information
jgaribsin committed Mar 21, 2024
1 parent e35491d commit 7b3228e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/providers/DownloadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
};
Expand Down
5 changes: 3 additions & 2 deletions src/providers/DownloadResourcePack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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!';

Expand Down
40 changes: 32 additions & 8 deletions src/providers/UpdateMinecraftOpts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {};

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(':');
Expand All @@ -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());
Expand All @@ -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
Expand All @@ -49,5 +73,5 @@ export function updateMinecraftOpts(filename: string) {
(key) => (newOptions += `${key}:${options[key]}\n`)
);

fs.writeFileSync(filename, newOptions);
fs.writeFileSync(drehmalOpts, newOptions);
}

0 comments on commit 7b3228e

Please sign in to comment.