Omnistudent's MAD HACKZ tutorials!!!

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Omnistudent's MAD HACKZ tutorials!!!

by OmniStudent » Sat Nov 17, 2012 16:50

Greetings!

HACKZ part:
In this thread I intend to publish the results of my fidgeting with the game in a learn-as-you-screw-around school of didactics:
MAD part:
I don't know what I'm doing, but I'm taking others' scraps of work and trying it out until it works on my computer.

I'm using a macbook pro with

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
OSX 10.6.8
Xcode 3.2.6
macports
irrlicht 1.8


+ other libraries I can write about if anyone's interested,

but some of this info may be of use to other operating systems as well.

This is partly for my own benefit, as a remainder, and partly for others who wish this info to be written down in one place.

Please feel free to provide any critique or tips on how to do this stuff better and closer to best practice.
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Sat Nov 17, 2012 17:29

[OSX]
How to install a fresh minetest copy

To be able to mess around with the minetest files, its nice to have a fresh copy to modify, instead of one that has been tainted by former experiments.

Here's how I do it on OSX 10.6:

You need Xcode installed, it should be on one of the OS disks you got with the computer.
You can also get it from https://developer.apple.com/xcode/

The cmake command and later the xcode compilation needs other libraries to be in place, most prominently Irrlicht.
I used macports to get some, and compiled Irrlicht.a 1.8.1 myself and put it in /usr/local/lib/ (hidden dir)
See this thread for hints on installing the correct libraries: http://minetest.net/forum/viewtopic.php?pid=50877#p50877

Download the most recent minetest_game from https://github.com/celeron55/minetest_game/archive/master.zip to /Users/me/Downloads/

In command window, do the following (NOT lines beginning with # : those are COMMENT lines)

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
# Go to your home dir
cd /Users/me/
# Make a new directory for minetest
mkdir mt_new
# Go to new directory
cd mt_new
# Start doing savvy stuff described by Mrscotty in
# http://minetest.net/forum/viewtopic.php?pid=52187#p52187
git clone https://github.com/celeron55/minetest.git minetest

# Go into newly created minecraft dir
cd minetest
# Go into games dir
cd games
# Place the minecraft_game file you downloaded here
cp /Users/me/Downloads/minetest_game-master.zip .
# unzip it
unzip minetest_game-master.zip
# rename it to minetest_game
cp -R minetest_game-master minetest_game
# Go back to minecraft directory
cd ..
# Continue savvy stuff by Mrscotty and Toabi to make OSX version
git remote add toabi https://github.com/toabi/minetest.git
git fetch toabi
git checkout cmake-osx
git rebase master
# Make the Xcode project file
cmake -v -G Xcode .
# Open finder in a window with the Xcode project
open .


open minetest.xcodeproj with Xcode

Choose Active Configuration:Release and Active Target:package
Build (<command-B>)
minetest-0.4.3-osx.dmg should appear in the same folder as the xcode project file.
It is mountable and contains the minetest.App that starts the game.
Last edited by OmniStudent on Tue Nov 20, 2012 10:32, edited 1 time in total.
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Sat Nov 17, 2012 17:35

[ANY, some OSX]
How to modify a lua.init file to allow wood+wood=coal in furnace

I panicked when I could not make coal from wood using a furnace like in Minecraft,
so I searched out the offending file and changed it!!!

The OSX application FileMerge,
in /Developer/Applications/Utilities/ on a mac with xcode installed
is very useful for comparing folders and finding what files are different in them.
With FileMerge, I saw that
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest_game/mods/default/init.lua

were different between a game that did allow wood+wood=coal.
Using MacVim's File->SplitDiff with...
I found the difference was in the below register_craft command.

Copy the game.app (that is the file named minetest, with the minetest icon)
to a permanent place, like Applications or you home folder. I used my home folder,
/Users/me/

Then edit the file
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
[yourdir]/minetest.app/Contents/Resources/games/minetest_game/mods/default/init.lua


I use macvim, but any text editor should do.

At line 473, under

--
-- Cooking recipes
--

, add the code

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_craft({
    type = "cooking",
    output = "default:coal_lump",
    recipe = "default:tree",
})


(I found this code in the games/minimal/mods/default/init.lua)
Save init.lua
Start minetest.
Make coal.
Last edited by OmniStudent on Sat Nov 17, 2012 20:43, edited 1 time in total.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Sat Nov 17, 2012 17:55

OmniStudent wrote:(I found this code in the games/minimal/mods/default/lua.init)
Save lua.init

It is init.lua
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Sat Nov 17, 2012 19:22

PilzAdam wrote:
OmniStudent wrote:(I found this code in the games/minimal/mods/default/lua.init)
Save lua.init

It is init.lua


THANKS!

It would have been even more confusing with that!

[FIXED]
Last edited by OmniStudent on Sat Nov 17, 2012 19:26, edited 1 time in total.
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Sat Nov 17, 2012 20:25

[C++]
How to make minetest react to a custom key

To make further experiments, its nice to have a button that tells minetest when to start whatever it is your trying to do.
You can assign a keyboard key and have minetest react to it by modifying two files:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest/source/game.cpp


and
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest/src/defaultsettings.cpp



Adding a key to a keymap_SuperSpecial
---------------------------------------------
We start by adding a key to defaultsettings.cpp, assigning keymap_SuperSpecial to the key X, denoted KEY_KEY_X.

open minetest/src/defaultsettings.cpp in a text editor. This part is copied from the line enabling chat, KEY_KEY_T, so just insert a similar line below
settings->setDefault("keymap_chat", "KEY_KEY_T");

that goes
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
settings->setDefault("keymap_SuperSpecial", "KEY_KEY_X");
.
(around line 41)

save defaultsettings.cpp




Adding reaction to SuperSpecial in game.cpp
--------------------------------------------------
Most of game.cpp consists of a function the_game([input_stuff]), in which an infinite loop
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
/*
        Main loop
*/


runs which appear to be the main loop of the client.
The main loop queries an object named input for "key settings".
A "key setting" is exactly what we added to defaultsettings.cpp, our keymap_SuperSpecial.

We insert a new elseif - block around line 1544 just below the "keymap_chat" block that this was modelled on, replacing all this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    else if(input->wasKeyDown(getKeySetting("keymap_chat")))
        {
            TextDest *dest = new TextDestChat(&client);

            (new GUITextInputMenu(guienv, guiroot, -1,
                    &g_menumgr, dest,
                    L""))->drop();
        }


with this:


Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
else if(input->wasKeyDown(getKeySetting("keymap_chat")))
        {
            TextDest *dest = new TextDestChat(&client);

            (new GUITextInputMenu(guienv, guiroot, -1,
                    &g_menumgr, dest,
                    L""))->drop();
        }



else if(input->wasKeyDown(getKeySetting("keymap_SuperSpecial")))
        {
            infostream<<"the_game: " <<"MESSAGE FROM SUPERSPECIAL"<<std::endl;

            statustext = L"--- SUPERSPECIAL TRIGGERED!!!---";
            statustext_time = 0;
        }






Save game.cpp

Recompile and run minetest.

In the game, press the x key on the keyboard.

The message --- SUPERSPECIAL TRIGGERED!!!--- should now appear on your screen!

The infostream line in the superspecial function writes a line to debug.txt, which can be read to see what happens behind the scenes on the game.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
            statustext = L"--- SUPERSPECIAL TRIGGERED!!!---";
            statustext_time = 0;


Sets a message to appear on the client screen. I wonder how the statustext_time variable works.
 

User avatar
Calinou
Member
 
Posts: 3124
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou

by Calinou » Sat Nov 17, 2012 21:13

Some additional info for OS X users that do not have a OS X DVD:
you can find Xcode here: https://developer.apple.com/xcode/

Maybe you should add it to your compiling tutorial. :)
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Mon Nov 19, 2012 19:14

Calinou wrote:Some additional info for OS X users that do not have a OS X DVD:
you can find Xcode here: https://developer.apple.com/xcode/

Maybe you should add it to your compiling tutorial. :)


FIXED!
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Mon Nov 19, 2012 20:00

[C++]
How to make left mouse button move you forward (and do your mining reclined in a couch)

Having to keep a hand on the keyboard for moving can sometimes be way to strenous,
especially when doing brain-dead dig-everywhere mining.

This hack makes you move forward when clicking the mouse at air, allowing you to dig until
there's nothing there, then move forward so you can reach more stuff to dig.

The functions that determine player input are located in the main loop in the source file src/game.cpp.

The main doings in game.cpp is performed inside the the_game function, stretching from line 854 to the end of the game.cpp file (row 2921)

Inside the_game is an infinite loop starting with

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
for(;;)


This loop is called "Main loop" in the comment lines.
It stretching from lines 1274 to 2879 (almost to the end of the file)

Direct handling of user input start of line 1483:

The movement keys on the keyboard are checked at line 1874,
called Player speed control in a comment line
which checks for pressed keyboard keys and and sends keypress info using a PlayerControl object, which it sends somewhere using client.setPlayerControl (probably to some method for sending info to the server).
The info packed intothe PlayerControl object are a bunch of true/false variables in the order (forward, back, left,rigtht + some other info).
You can check the behaviour of this by changing forward to always being true, to get a game in which you are constantly moving forward:

on line 1886 to 1896 of game.cpp, change
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
            PlayerControl control(
                input->isKeyDown(getKeySetting("keymap_forward")),
                input->isKeyDown(getKeySetting("keymap_backward")),
                input->isKeyDown(getKeySetting("keymap_left")),
                input->isKeyDown(getKeySetting("keymap_right")),
                input->isKeyDown(getKeySetting("keymap_jump")),
                input->isKeyDown(getKeySetting("keymap_special1")),
                input->isKeyDown(getKeySetting("keymap_sneak")),
                camera_pitch,
                camera_yaw
            );


to

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
            PlayerControl control(
                //input->isKeyDown(getKeySetting("keymap_forward")),
                true,
                input->isKeyDown(getKeySetting("keymap_backward")),
                input->isKeyDown(getKeySetting("keymap_left")),
                input->isKeyDown(getKeySetting("keymap_right")),
                input->isKeyDown(getKeySetting("keymap_jump")),
                input->isKeyDown(getKeySetting("keymap_special1")),
                input->isKeyDown(getKeySetting("keymap_sneak")),
                camera_pitch,
                camera_yaw
            );


Detecting when you should move forward instead of doing "left-mouse button":


There is conveniently already a function for telling wether you "hit the air", but its down on line 2384, after a bunch of other calculations for mouse button input.

It looks like this

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
        else if(input->getLeftState())
        {
            // When button is held down in air, show continuous animation
            left_punch = true;
        }



, and sets a variable left_punch to tell wether you "hit air" or not.

I can't see a reason for sending the movement info to client.setPlayerControl that early in the code way up on line 1896. Its located before all mouse actions have been calculated but we need the left_punch calculation performed there.
I'm moving the "Player speed control" section of the program down to line 2389, which is AFTER the loop has investigated if we're hitting air or not:
(NOTE that I don't know what the hell I'm doing, there may be a perfectly good reason for having the code where it is).

Cut this (line 1873 to 1898) :

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
/*
            Player speed control
        */
        {
            /*bool a_up,
            bool a_down,
            bool a_left,
            bool a_right,
            bool a_jump,
            bool a_superspeed,
            bool a_sneak,
            float a_pitch,
            float a_yaw*/
            PlayerControl control(
                input->isKeyDown(getKeySetting("keymap_forward")),
                input->isKeyDown(getKeySetting("keymap_backward")),
                input->isKeyDown(getKeySetting("keymap_left")),
                input->isKeyDown(getKeySetting("keymap_right")),
                input->isKeyDown(getKeySetting("keymap_jump")),
                input->isKeyDown(getKeySetting("keymap_special1")),
                input->isKeyDown(getKeySetting("keymap_sneak")),
                camera_pitch,
                camera_yaw
            );
            client.setPlayerControl(control);
        }



and paste it just underneath this:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
else if(input->getLeftState())
        {
            // When button is held down in air, show continuous animation
            left_punch = true;
        }


on line 2389.
All we have done so far is changing the order of some commands. If you compile and run the game now, where will be no differences.
[Anticlimax - continued in post below]
 

OmniStudent
Member
 
Posts: 261
Joined: Sat Nov 03, 2012 06:40

by OmniStudent » Tue Nov 20, 2012 19:29

How to make left mouse button move you forward, continued

Finally, instead of just sending the control object as it is, we send a different version of it if the left mouse button was pushed (left_punch==true). In this version of the control object, we report the forward button as being pressed wether its actually being pressed or not.

Replace the old player control section:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
/*
            Player speed control
        */
        {
            /*bool a_up,
            bool a_down,
            bool a_left,
            bool a_right,
            bool a_jump,
            bool a_superspeed,
            bool a_sneak,
            float a_pitch,
            float a_yaw*/
            PlayerControl control(
                input->isKeyDown(getKeySetting("keymap_forward")),
                input->isKeyDown(getKeySetting("keymap_backward")),
                input->isKeyDown(getKeySetting("keymap_left")),
                input->isKeyDown(getKeySetting("keymap_right")),
                input->isKeyDown(getKeySetting("keymap_jump")),
                input->isKeyDown(getKeySetting("keymap_special1")),
                input->isKeyDown(getKeySetting("keymap_sneak")),
                camera_pitch,
                camera_yaw
            );
            client.setPlayerControl(control);
        }


with this :

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
 if (left_punch){
                        PlayerControl control(
                true,
                //input->isKeyDown(getKeySetting("keymap_forward")),
                input->isKeyDown(getKeySetting("keymap_backward")),
                input->isKeyDown(getKeySetting("keymap_left")),
                input->isKeyDown(getKeySetting("keymap_right")),
                input->isKeyDown(getKeySetting("keymap_jump")),
                input->isKeyDown(getKeySetting("keymap_special1")),
                input->isKeyDown(getKeySetting("keymap_sneak")),
                camera_pitch,
                camera_yaw
            );
            left_punch = false;
            client.setPlayerControl(control);
}
            else{
                        PlayerControl control(
                //true,
                input->isKeyDown(getKeySetting("keymap_forward")),
                input->isKeyDown(getKeySetting("keymap_backward")),
                input->isKeyDown(getKeySetting("keymap_left")),
                input->isKeyDown(getKeySetting("keymap_right")),
                input->isKeyDown(getKeySetting("keymap_jump")),
                input->isKeyDown(getKeySetting("keymap_special1")),
                input->isKeyDown(getKeySetting("keymap_sneak")),
                camera_pitch,
                camera_yaw
            );
            client.setPlayerControl(control);
}


Now save game.cpp and compile.

Open the game, play it and do all your mining with one hand!
 


Return to Minetest General

Who is online

Users browsing this forum: No registered users and 19 guests

cron