Sorry if this has been asked before but I am trying to invert the mouse Y axis in Minecraft PI but cant find a solution to this as there are no options available in Minecraft PI. Would/can I write a python script that runs in the background to do this?


Unfortunately Minecraft Pi Edition's Python API is rather limited. Per the documentation there are only three fields to set via world.setting() or player.setting(), and you can confirm this by running strings minecraft-pi and inspecting the output.

You may have considered using xinput list and xinput set-prop. Whether this works could depend on your particular mouse hardware, but from what I can tell changing the coordinate transform matrix would only affect the 2D cursor position, not mouse look (controlled instead by delta movements).

Update: There's Phirel's patch to enable survival mode. It also happens to enable basic options in the GUI, including "Invert X-axis" (confusing terminology: invert Y direction ~= flip about X axis)

You can read below for my other approach using SDL.

One way to effectively mod this closed-source executable is to intercept SDL function calls with your own modified SDL.

sudo apt install libx11-dev libxext-dev
curl -O https://www.libsdl.org/release/SDL-1.2.15.tar.gz
tar xvf SDL-1.2.15.tar.gz
cd SDL-1.2.15

To invert the mouse Y, find the part of the library where it normally sends the deltaY value and invert it!

--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -185,7 +185,7 @@ printf("Mouse event didn't change state - dropped!\n");
                event.motion.x = X;
                event.motion.y = Y;
                event.motion.xrel = Xrel;
-               event.motion.yrel = Yrel;
+               event.motion.yrel = -Yrel;
                if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) {
                        posted = 1;

then build and inject your modified library to test:

LD_PRELOAD=$(pwd)/build/.libs/libSDL-1.2.so.0 minecraft-pi

Or if you have enabled full OpenGL with KMS, you may have to avoid the script at /usr/bin/minecraft-pi overriding with its own LD_PRELOAD setting. More complicated, but you can inject the Mesa wrapper alongside like so:

(cd /opt/minecraft-pi && \
 LD_PRELOAD="$(cd -)/build/.libs/libSDL-1.2.so.0 libbcm_host.so.1.0" \
 LD_LIBRARY_PATH=lib/mesa \

One cool perk of this approach is that because mouse look uses relative movements while you're leaving the absolute Y position untouched, cursor movement still functions as before.

If you wish to make further modifications or need to debug your changes, add printf() statements, rebuild, and rerun.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.