From 530e31820bcd625655f49f93b7265157e618ece6 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Mon, 1 Feb 2021 19:35:30 -0500 Subject: [PATCH] Allow Changing Render Distance --- debian/client/common/usr/bin/minecraft-pi | 6 +++- .../minecraft-pi/client/docker-compose.yml | 1 + .../minecraft-pi/client/docker-compose.yml | 1 + mods/src/minecraft.h | 1 + mods/src/options/options.c | 28 +++++++++++++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/debian/client/common/usr/bin/minecraft-pi b/debian/client/common/usr/bin/minecraft-pi index e4c6998..b2e58fd 100755 --- a/debian/client/common/usr/bin/minecraft-pi +++ b/debian/client/common/usr/bin/minecraft-pi @@ -22,12 +22,16 @@ export DOCKER_COMPOSE_YML="/usr/share/minecraft-pi/client/docker-compose.yml" # Ensure Features Are Selected if [ -z "${MCPI_FEATURES+x}" ]; then - MCPI_FEATURES="$(eval "zenity --class \"${ZENITY_CLASS}\" --list --checklist --width=600 --height=600 --column 'Enabled' --column 'Feature' ${AVAILABLE_FEATURES}")" + MCPI_FEATURES="$(eval "zenity --class \"${ZENITY_CLASS}\" --list --checklist --width 400 --height 400 --column 'Enabled' --column 'Feature' ${AVAILABLE_FEATURES}")" +fi +if [ -z "${MCPI_RENDER_DISTANCE+x}" ]; then + MCPI_RENDER_DISTANCE="$(zenity --class "${ZENITY_CLASS}" --list --radiolist --width 400 --height 400 --text 'Minecraft Render Distance:' --column 'Selected' --column 'Name' FALSE 'Far' FALSE 'Normal' TRUE 'Short' FALSE 'Tiny')" fi if [ -z "${MCPI_USERNAME+x}" ]; then MCPI_USERNAME="$(zenity --class "${ZENITY_CLASS}" --entry --text 'Minecraft Username:' --entry-text 'StevePi')" fi export MCPI_FEATURES +export MCPI_RENDER_DISTANCE export MCPI_USERNAME # Allow X11 Connections From Root diff --git a/debian/client/native/usr/share/minecraft-pi/client/docker-compose.yml b/debian/client/native/usr/share/minecraft-pi/client/docker-compose.yml index 1a0e95b..ec2ac8a 100644 --- a/debian/client/native/usr/share/minecraft-pi/client/docker-compose.yml +++ b/debian/client/native/usr/share/minecraft-pi/client/docker-compose.yml @@ -14,5 +14,6 @@ services: - 'HOME=/home' - 'DISPLAY=unix${DISPLAY}' - 'MCPI_FEATURES=${MCPI_FEATURES}' + - 'MCPI_RENDER_DISTANCE=${MCPI_RENDER_DISTANCE}' - 'MCPI_USERNAME=${MCPI_USERNAME}' - 'MCPI_MODE=native' diff --git a/debian/client/virgl/usr/share/minecraft-pi/client/docker-compose.yml b/debian/client/virgl/usr/share/minecraft-pi/client/docker-compose.yml index 8b90a50..d84d328 100644 --- a/debian/client/virgl/usr/share/minecraft-pi/client/docker-compose.yml +++ b/debian/client/virgl/usr/share/minecraft-pi/client/docker-compose.yml @@ -13,5 +13,6 @@ services: - 'HOME=/home' - 'DISPLAY=unix${DISPLAY}' - 'MCPI_FEATURES=${MCPI_FEATURES}' + - 'MCPI_RENDER_DISTANCE=${MCPI_RENDER_DISTANCE}' - 'MCPI_USERNAME=${MCPI_USERNAME}' - 'MCPI_MODE=virgl' diff --git a/mods/src/minecraft.h b/mods/src/minecraft.h index fee6a44..60744c4 100644 --- a/mods/src/minecraft.h +++ b/mods/src/minecraft.h @@ -115,6 +115,7 @@ static uint32_t Options_3d_anaglyph_property_offset = 0x15; // unsigned char / b static uint32_t Options_ambient_occlusion_property_offset = 0x18; // unsigned char / bool static uint32_t Options_hide_gui_property_offset = 0xec; // unsigned char / bool static uint32_t Options_third_person_property_offset = 0xed; // unsigned char / bool +static uint32_t Options_render_distance_property_offset = 0x10; // int32_t // MouseBuildInput diff --git a/mods/src/options/options.c b/mods/src/options/options.c index f309a0d..cee45c4 100644 --- a/mods/src/options/options.c +++ b/mods/src/options/options.c @@ -13,6 +13,24 @@ static uint32_t LevelData_getSpawnMobs_injection(__attribute__((unused)) unsigne return mob_spawning; } +// Get Custom Render Distance +static int get_render_distance() { + char *distance_str = getenv("MCPI_RENDER_DISTANCE"); + if (distance_str == NULL) { + distance_str = "Short"; + } + if (strcmp("Far", distance_str) == 0) { + return 0; + } else if (strcmp("Normal", distance_str) == 0) { + return 1; + } else if (strcmp("Short", distance_str) == 0) { + return 2; + } else if (strcmp("Tiny", distance_str) == 0) { + return 3; + } else { + ERR("Invalid Render Distance: %s", distance_str); + } +} // Get Custom Username static char *get_username() { char *username = getenv("MCPI_USERNAME"); @@ -26,6 +44,7 @@ static int fancy_graphics; static int peaceful_mode; static int anaglyph; static int smooth_lighting; +static int render_distance; // Configure Options static void Minecraft_init_injection(unsigned char *this) { // Call Original Method @@ -42,6 +61,8 @@ static void Minecraft_init_injection(unsigned char *this) { *(options + Options_3d_anaglyph_property_offset) = anaglyph; // Smooth Lighting *(options + Options_ambient_occlusion_property_offset) = smooth_lighting; + // Render Distance + *(int32_t *) (options + Options_render_distance_property_offset) = render_distance; } // Enable Touch GUI @@ -71,6 +92,13 @@ void init_options() { peaceful_mode = feature_has("Peaceful Mode"); // 3D Anaglyph anaglyph = feature_has("3D Anaglyph"); + // Render Distance + if (!is_server) { + render_distance = get_render_distance(); + INFO("Setting Render Distance: %i", render_distance); + } else { + render_distance = 3; + } // Set Options overwrite_calls((void *) Minecraft_init, Minecraft_init_injection);