Allow Changing Render Distance
minecraft-pi-reborn/pipeline/head This commit looks good Details

This commit is contained in:
TheBrokenRail 2021-02-01 19:35:30 -05:00
parent 04668f223e
commit 530e31820b
5 changed files with 36 additions and 1 deletions

View File

@ -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

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -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);