diff --git a/.clang-format b/.clang-format index dc7380ffd..0db8ab167 100644 --- a/.clang-format +++ b/.clang-format @@ -29,3 +29,4 @@ AlignAfterOpenBracket: DontAlign ContinuationIndentWidth: 16 ConstructorInitializerIndentWidth: 16 BreakConstructorInitializers: AfterColon +AlwaysBreakTemplateDeclarations: Yes diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index b234fb283..b01a89509 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -43,6 +43,12 @@ Contributions are welcome! Here's how you can help: 4. The code's interfaces are well designed, regardless of other aspects that might need more work in the future. 5. It uses protocols and formats which include the required compatibility. +### Important note about automated GitHub checks + +When you submit a pull request, GitHub automatically runs checks on the Minetest Engine combined with your changes. One of these checks is called 'cpp lint / clang format', which checks code formatting. Because formatting for readability requires human judgement this check often fails and often makes unsuitable formatting requests which make code readability worse. + +If this check fails, look at the details to check for any clear mistakes and correct those. However, you should not apply everything ClangFormat requests. Ignore requests that make code readability worse and any other clearly unsuitable requests. Discuss in the pull request with a core developer about how to progress. + ## Issues If you experience an issue, we would like to know the details - especially when a stable release is on the way. diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml new file mode 100644 index 000000000..0fcfe2390 --- /dev/null +++ b/.github/workflows/android.yml @@ -0,0 +1,42 @@ +name: android + +# build on c/cpp changes or workflow changes +on: + push: + paths: + - 'lib/**.[ch]' + - 'lib/**.cpp' + - 'src/**.[ch]' + - 'src/**.cpp' + - 'build/android/**' + - '.github/workflows/android.yml' + pull_request: + paths: + - 'lib/**.[ch]' + - 'lib/**.cpp' + - 'src/**.[ch]' + - 'src/**.cpp' + - 'build/android/**' + - '.github/workflows/android.yml' + +jobs: + build: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Build with Gradle + run: cd build/android; ./gradlew assemblerelease + - name: Save armeabi artifact + uses: actions/upload-artifact@v2 + with: + name: Minetest-armeabi-v7a.apk + path: build/android/app/build/outputs/apk/release/app-armeabi-v7a-release-unsigned.apk + - name: Save arm64 artifact + uses: actions/upload-artifact@v2 + with: + name: Minetest-arm64-v8a.apk + path: build/android/app/build/outputs/apk/release/app-arm64-v8a-release-unsigned.apk diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 74a01b19e..46afe9f6f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,9 +55,8 @@ jobs: - uses: actions/checkout@v2 - name: Install deps run: | - sudo apt-get install g++-8 gcc-8 -qyy source ./util/ci/common.sh - install_linux_deps + install_linux_deps g++-8 - name: Build run: | @@ -99,11 +98,8 @@ jobs: - uses: actions/checkout@v2 - name: Install deps run: | - sudo apt-get install clang-9 valgrind -qyy source ./util/ci/common.sh - install_linux_deps - env: - WITH_LUAJIT: 1 + install_linux_deps clang-9 valgrind libluajit-5.1-dev - name: Build run: | @@ -111,6 +107,7 @@ jobs: env: CC: clang-9 CXX: clang++-9 + CMAKE_FLAGS: "-DREQUIRE_LUAJIT=1" - name: Test run: | @@ -188,7 +185,7 @@ jobs: - uses: actions/checkout@v2 - name: Install compiler run: | - sudo apt-get install gettext -qyy + sudo apt-get update -q && sudo apt-get install gettext -qyy wget http://minetest.kitsunemimi.pw/mingw-w64-i686_9.2.0_ubuntu18.04.tar.xz -O mingw.tar.xz sudo tar -xaf mingw.tar.xz -C /usr @@ -206,7 +203,7 @@ jobs: - uses: actions/checkout@v2 - name: Install compiler run: | - sudo apt-get install gettext -qyy + sudo apt-get update -q && sudo apt-get install gettext -qyy wget http://minetest.kitsunemimi.pw/mingw-w64-x86_64_9.2.0_ubuntu18.04.tar.xz -O mingw.tar.xz sudo tar -xaf mingw.tar.xz -C /usr diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d03b7b601..0441aeaa1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,12 +18,12 @@ variables: - mkdir cmakebuild - mkdir -p artifact/minetest/usr/ - cd cmakebuild - - cmake -DCMAKE_INSTALL_PREFIX=../artifact/minetest/usr/ -DCMAKE_BUILD_TYPE=Release -DRUN_IN_PLACE=FALSE -DENABLE_GETTEXT=TRUE -DBUILD_SERVER=TRUE .. + - cmake -DCMAKE_INSTALL_PREFIX=../artifact/minetest/usr/ -DCMAKE_BUILD_TYPE=Release -DRUN_IN_PLACE=FALSE -DENABLE_GETTEXT=TRUE -DENABLE_SYSTEM_JSONCPP=TRUE -DBUILD_SERVER=TRUE .. - make -j2 - make install artifacts: when: on_success - expire_in: 2h + expire_in: 1h paths: - artifact/* @@ -34,15 +34,14 @@ variables: - apt-get install -y git - mkdir -p build/deb/minetest/DEBIAN/ - cp misc/debpkg-control build/deb/minetest/DEBIAN/control - - cp -Rp artifact/minetest/usr build/deb/minetest/ + - cp -a artifact/minetest/usr build/deb/minetest/ script: - - git clone $MINETEST_GAME_REPO build/deb/minetest/usr/share/minetest/games/minetest - - rm -Rf build/deb/minetest/usr/share/minetest/games/minetest/.git + - git clone $MINETEST_GAME_REPO build/deb/minetest/usr/share/minetest/games/minetest_game + - rm -rf build/deb/minetest/usr/share/minetest/games/minetest/.git - sed -i 's/DATEPLACEHOLDER/'$(date +%y.%m.%d)'/g' build/deb/minetest/DEBIAN/control - sed -i 's/LEVELDB_PLACEHOLDER/'$LEVELDB_PKG'/g' build/deb/minetest/DEBIAN/control - cd build/deb/ && dpkg-deb -b minetest/ && mv minetest.deb ../../ artifacts: - when: on_success expire_in: 90 day paths: - ./*.deb @@ -51,44 +50,14 @@ variables: stage: deploy before_script: - apt-get update -y - - apt-get install -y libc6 libcurl3-gnutls libfreetype6 libirrlicht1.8 $LEVELDB_PKG liblua5.1-0 libluajit-5.1-2 libopenal1 libstdc++6 libvorbisfile3 libx11-6 zlib1g script: - - dpkg -i ./*.deb + - apt-get install -y ./*.deb + - minetest --version ## ## Debian ## -# Jessie - -build:debian-8: - extends: .build_template - image: debian:8 - before_script: - - echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu trusty main" > /etc/apt/sources.list.d/uptodate-toolchain.list - - apt-key adv --keyserver keyserver.ubuntu.com --recv BA9EF27F - - apt-get update -y - - apt-get -y install build-essential gcc-6 g++-6 libirrlicht-dev cmake libbz2-dev libpng-dev libjpeg-dev libxxf86vm-dev libgl1-mesa-dev libsqlite3-dev libogg-dev libvorbis-dev libopenal-dev libcurl4-gnutls-dev libfreetype6-dev zlib1g-dev libgmp-dev libjsoncpp-dev - variables: - CC: gcc-6 - CXX: g++-6 - -package:debian-8: - extends: .debpkg_template - image: debian:8 - dependencies: - - build:debian-8 - variables: - LEVELDB_PKG: libleveldb1 - -deploy:debian-8: - extends: .debpkg_install - image: debian:8 - dependencies: - - package:debian-8 - variables: - LEVELDB_PKG: libleveldb1 - # Stretch build:debian-9: @@ -101,7 +70,7 @@ build:debian-9: package:debian-9: extends: .debpkg_template image: debian:9 - dependencies: + needs: - build:debian-9 variables: LEVELDB_PKG: libleveldb1v5 @@ -109,12 +78,10 @@ package:debian-9: deploy:debian-9: extends: .debpkg_install image: debian:9 - dependencies: + needs: - package:debian-9 - variables: - LEVELDB_PKG: libleveldb1v5 -# Stretch +# Buster build:debian-10: extends: .build_template @@ -126,7 +93,7 @@ build:debian-10: package:debian-10: extends: .debpkg_template image: debian:10 - dependencies: + needs: - build:debian-10 variables: LEVELDB_PKG: libleveldb1d @@ -134,44 +101,13 @@ package:debian-10: deploy:debian-10: extends: .debpkg_install image: debian:10 - dependencies: + needs: - package:debian-10 - variables: - LEVELDB_PKG: libleveldb1d + ## ## Ubuntu ## -# Trusty - -build:ubuntu-14.04: - extends: .build_template - image: ubuntu:trusty - before_script: - - echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu trusty main" > /etc/apt/sources.list.d/uptodate-toolchain.list - - apt-key adv --keyserver keyserver.ubuntu.com --recv BA9EF27F - - apt-get update -y - - apt-get -y install build-essential gcc-6 g++-6 libirrlicht-dev cmake libbz2-dev libpng-dev libjpeg-dev libxxf86vm-dev libgl1-mesa-dev libsqlite3-dev libogg-dev libvorbis-dev libopenal-dev libcurl4-gnutls-dev libfreetype6-dev zlib1g-dev libgmp-dev libjsoncpp-dev - variables: - CC: gcc-6 - CXX: g++-6 - -package:ubuntu-14.04: - extends: .debpkg_template - image: ubuntu:trusty - dependencies: - - build:ubuntu-14.04 - variables: - LEVELDB_PKG: libleveldb1 - -deploy:ubuntu-14.04: - extends: .debpkg_install - image: ubuntu:trusty - dependencies: - - package:ubuntu-14.04 - variables: - LEVELDB_PKG: libleveldb1 - # Xenial build:ubuntu-16.04: @@ -184,7 +120,7 @@ build:ubuntu-16.04: package:ubuntu-16.04: extends: .debpkg_template image: ubuntu:xenial - dependencies: + needs: - build:ubuntu-16.04 variables: LEVELDB_PKG: libleveldb1v5 @@ -192,25 +128,45 @@ package:ubuntu-16.04: deploy:ubuntu-16.04: extends: .debpkg_install image: ubuntu:xenial - dependencies: + needs: - package:ubuntu-16.04 + +# Bionic + +build:ubuntu-18.04: + extends: .build_template + image: ubuntu:bionic + before_script: + - apt-get update -y + - apt-get -y install build-essential libirrlicht-dev cmake libbz2-dev libpng-dev libjpeg-dev libxxf86vm-dev libgl1-mesa-dev libsqlite3-dev libogg-dev libvorbis-dev libopenal-dev libcurl4-gnutls-dev libfreetype6-dev zlib1g-dev libgmp-dev libjsoncpp-dev + +package:ubuntu-18.04: + extends: .debpkg_template + image: ubuntu:bionic + needs: + - build:ubuntu-18.04 variables: LEVELDB_PKG: libleveldb1v5 +deploy:ubuntu-18.04: + extends: .debpkg_install + image: ubuntu:bionic + needs: + - package:ubuntu-18.04 + ## ## Fedora ## -# Do we need to support this old version ? -build:fedora-24: +# Fedora 28 <-> RHEL 8 +build:fedora-28: extends: .build_template - image: fedora:24 + image: fedora:28 before_script: - - dnf -y install make automake gcc gcc-c++ kernel-devel cmake libcurl* openal* libvorbis* libXxf86vm-devel libogg-devel freetype-devel mesa-libGL-devel zlib-devel jsoncpp-devel irrlicht-devel bzip2-libs gmp-devel sqlite-devel luajit-devel leveldb-devel ncurses-devel doxygen spatialindex-devel bzip2-devel - + - dnf -y install make automake gcc gcc-c++ kernel-devel cmake libcurl-devel openal-soft-devel libvorbis-devel libXxf86vm-devel libogg-devel freetype-devel mesa-libGL-devel zlib-devel jsoncpp-devel irrlicht-devel gmp-devel sqlite-devel luajit-devel leveldb-devel ncurses-devel spatialindex-devel ## -## Mingw for Windows +## MinGW for Windows ## .generic_win_template: @@ -218,68 +174,63 @@ build:fedora-24: before_script: - apt-get update -y - apt-get install -y wget xz-utils unzip git cmake gettext - - wget -q http://minetest.kitsunemimi.pw/mingw-w64-${WIN_ARCH}_9.2.0_ubuntu18.04.tar.xz -O mingw.tar.xz + - wget -nv http://minetest.kitsunemimi.pw/mingw-w64-${WIN_ARCH}_9.2.0_ubuntu18.04.tar.xz -O mingw.tar.xz - tar -xaf mingw.tar.xz -C /usr .build_win_template: extends: .generic_win_template stage: build artifacts: - when: on_success - expire_in: 2h + expire_in: 1h paths: - - build/* + - build/minetest/_build/* .package_win_template: extends: .generic_win_template stage: package script: - - cd build/minetest/_build - - make package - - cd ../../../ - - mkdir minetest-win-${WIN_ARCH} - - unzip build/minetest/_build/minetest-*-win*.zip -d minetest-win-${WIN_ARCH} - - cp /usr/${WIN_ARCH}-w64-mingw32/bin/libgcc*.dll minetest-win-${WIN_ARCH}/minetest-*-win*/bin - - cp /usr/${WIN_ARCH}-w64-mingw32/bin/libstdc++*.dll minetest-win-${WIN_ARCH}/minetest-*-win*/bin - - cp /usr/${WIN_ARCH}-w64-mingw32/bin/libwinpthread*.dll minetest-win-${WIN_ARCH}/minetest-*-win*/bin + - unzip build/minetest/_build/minetest-*.zip + - cp -p /usr/${WIN_ARCH}-w64-mingw32/bin/libgcc*.dll minetest-*-win*/bin/ + - cp -p /usr/${WIN_ARCH}-w64-mingw32/bin/libstdc++*.dll minetest-*-win*/bin/ + - cp -p /usr/${WIN_ARCH}-w64-mingw32/bin/libwinpthread*.dll minetest-*-win*/bin/ artifacts: - when: on_success expire_in: 90 day paths: - - minetest-win-*/* + - minetest-*-win*/* build:win32: extends: .build_win_template script: - ./util/buildbot/buildwin32.sh build variables: - NO_PACKAGE: "1" WIN_ARCH: "i686" package:win32: extends: .package_win_template - dependencies: + needs: - build:win32 variables: - NO_PACKAGE: "1" WIN_ARCH: "i686" + build:win64: extends: .build_win_template script: - ./util/buildbot/buildwin64.sh build variables: - NO_PACKAGE: "1" WIN_ARCH: "x86_64" package:win64: extends: .package_win_template - dependencies: + needs: - build:win64 variables: - NO_PACKAGE: "1" WIN_ARCH: "x86_64" +## +## Docker +## + package:docker: stage: package image: docker:stable @@ -293,6 +244,10 @@ package:docker: - docker push ${CONTAINER_IMAGE}/server:$CI_COMMIT_REF_NAME - docker push ${CONTAINER_IMAGE}/server:latest +## +## Gitlab Pages (Lua API documentation) +## + pages: stage: deploy image: python:3.8 @@ -308,3 +263,31 @@ pages: only: - master +## +## AppImage +## + +package:appimage-client: + stage: package + image: appimagecrafters/appimage-builder + needs: + - build:ubuntu-18.04 + before_script: + - apt-get update -y + - apt-get install -y git wget + # Collect files + - mkdir AppDir + - cp -a artifact/minetest/usr/ AppDir/usr/ + - rm AppDir/usr/bin/minetestserver + - cp -a clientmods AppDir/usr/share/minetest + script: + - git clone $MINETEST_GAME_REPO AppDir/usr/share/minetest/games/minetest_game + - rm -rf AppDir/usr/share/minetest/games/minetest/.git + - export VERSION=$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA + # Remove PrefersNonDefaultGPU property due to validation errors + - sed -i '/PrefersNonDefaultGPU/d' AppDir/usr/share/applications/net.minetest.minetest.desktop + - appimage-builder --skip-test + artifacts: + expire_in: 90 day + paths: + - ./*.AppImage diff --git a/.luacheckrc b/.luacheckrc index 3ab6e10c8..e010ab95c 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -72,3 +72,11 @@ files["builtin/mainmenu"] = { "PLATFORM", }, } + +files["builtin/common/tests"] = { + read_globals = { + "describe", + "it", + "assert", + }, +} diff --git a/.mailmap b/.mailmap index c487460a0..fcc763411 100644 --- a/.mailmap +++ b/.mailmap @@ -1,33 +1,67 @@ +# Documentation: https://git-scm.com/docs/git-check-mailmap#_mapping_authors + 0gb.us <0gb.us@0gb.us> -Calinou -Perttu Ahola celeron55 +Calinou +Calinou +Perttu Ahola Perttu Ahola celeron55 -Craig Robbins +Zeno- +Zeno- +Diego Martínez Diego Martínez +Ilya Zhuravlev Ilya Zhuravlev kwolekr -PilzAdam PilzAdam -PilzAdam Pilz Adam -PilzAdam PilzAdam +PilzAdam +PilzAdam proller proller RealBadAngel RealBadAngel Selat ShadowNinja ShadowNinja -Shen Zheyu arsdragonfly -Pavel Elagin elagin -Esteban I. Ruiz Moreno Esteban I. RM -manuel duarte manuel joaquim -manuel duarte sweetbomber -Diego Martínez kaeza -Diego Martínez Diego Martinez -Lord James Lord89James -BlockMen Block Men -sfan5 Sfan5 -DannyDark dannydark -Ilya Pavlov Ilya -Ilya Zhuravlev xyzz +Esteban I. Ruiz Moreno +Esteban I. Ruiz Moreno +Lord James +BlockMen +sfan5 +DannyDark +Ilya Pavlov sapier sapier sapier sapier - +SmallJoker +Loïc Blot +Loïc Blot +numzero Vitaliy +numzero +Jean-Patrick Guerrero +Jean-Patrick Guerrero +HybridDog <3192173+HybridDog@users.noreply.github.com> +srfqi +Dániel Juhász +rubenwardy +rubenwardy +Paul Ouellette +Vanessa Dannenberg +ClobberXD +ClobberXD +ClobberXD <36130650+ClobberXD@users.noreply.github.com> +Auke Kok +Auke Kok +Desour +Nathanaël Courant +Ezhh +paramat +paramat +lhofhansl +red-001 +Wuzzy +Wuzzy +Jordach +MoNTE48 +v-rob +v-rob <31123645+v-rob@users.noreply.github.com> +EvidenceB <49488517+EvidenceBKidscode@users.noreply.github.com> +gregorycu +Rogier +Rogier diff --git a/AppImageBuilder.yml b/AppImageBuilder.yml new file mode 100644 index 000000000..9ecad5d8e --- /dev/null +++ b/AppImageBuilder.yml @@ -0,0 +1,51 @@ +version: 1 + +AppDir: + path: ./AppDir + + app_info: + id: minetest + name: Minetest + icon: minetest + version: !ENV ${VERSION} + exec: usr/bin/minetest + exec_args: $@ + runtime: + env: + APPDIR_LIBRARY_PATH: $APPDIR/usr/lib/x86_64-linux-gnu + + apt: + arch: amd64 + sources: + - sourceline: deb http://archive.ubuntu.com/ubuntu/ bionic main universe + key_url: 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3b4fe6acc0b21f32' + - sourceline: deb http://archive.ubuntu.com/ubuntu/ bionic-updates main universe + - sourceline: deb http://archive.ubuntu.com/ubuntu/ bionic-backports main universe + - sourceline: deb http://archive.ubuntu.com/ubuntu/ bionic-security main universe + + include: + - libirrlicht1.8 + - libxxf86vm1 + - libgl1-mesa-glx + - libsqlite3-0 + - libogg0 + - libvorbis0a + - libopenal1 + - libcurl3-gnutls + - libfreetype6 + - zlib1g + - libgmp10 + - libjsoncpp1 + + files: + exclude: + - usr/share/man + - usr/share/doc/*/README.* + - usr/share/doc/*/changelog.* + - usr/share/doc/*/NEWS.* + - usr/share/doc/*/TODO.* + +AppImage: + update-information: None + sign-key: None + arch: x86_64 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5673a26f4..460411dc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,11 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 3.5) -if(${CMAKE_VERSION} STREQUAL "2.8.2") - # Bug http://vtk.org/Bug/view.php?id=11020 - message(WARNING "CMake/CPack version 2.8.2 will not create working .deb packages!") -endif() +cmake_policy(SET CMP0025 OLD) # This can be read from ${PROJECT_NAME} after project() is called project(multicraft) set(PROJECT_NAME_CAPITALIZED "MultiCraft") -# Works only for cmake 3.1 and greater set(CMAKE_CXX_STANDARD 11) set(GCC_MINIMUM_VERSION "4.8") set(CLANG_MINIMUM_VERSION "3.4") @@ -250,15 +246,15 @@ cpack_add_component(Docs cpack_add_component(SUBGAME_MINETEST_GAME DISPLAY_NAME "Minetest Game" - DESCRIPTION "The official subgame for the Minetest engine, that can easily extended by mods." - GROUP "Subgames" + DESCRIPTION "The default game bundled in the Minetest engine. Mainly used as a modding base." + GROUP "Games" ) cpack_add_component(SUBGAME_MINIMAL DISPLAY_NAME "Development Test" - DESCRIPTION "A minimal test game helping to develop the engine." + DESCRIPTION "A basic testing environment used for engine development and sometimes for testing mods." DISABLED #DISABLED does not mean it is disabled, and is just not selected by default. - GROUP "Subgames" + GROUP "Games" ) cpack_add_component_group(Subgames @@ -279,11 +275,12 @@ if(WIN32) set(CPACK_GENERATOR ZIP) else() - set(CPACK_GENERATOR WIX ZIP) + set(CPACK_GENERATOR WIX) set(CPACK_PACKAGE_NAME "${PROJECT_NAME_CAPITALIZED}") - set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME_CAPITALIZED}") + set(CPACK_PACKAGE_INSTALL_DIRECTORY ".") set(CPACK_PACKAGE_EXECUTABLES ${PROJECT_NAME} "${PROJECT_NAME_CAPITALIZED}") set(CPACK_CREATE_DESKTOP_LINKS ${PROJECT_NAME}) + set(CPACK_PACKAGING_INSTALL_PREFIX "/${PROJECT_NAME_CAPITALIZED}") set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/misc/multicraft-icon.ico") # Supported languages can be found at diff --git a/Dockerfile b/Dockerfile index 51e13f848..1732f4d55 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ WORKDIR /usr/src/multicraft RUN apk add --no-cache git build-base irrlicht-dev cmake bzip2-dev libpng-dev \ jpeg-dev libxxf86vm-dev mesa-dev sqlite-dev libogg-dev \ libvorbis-dev openal-soft-dev curl-dev freetype-dev zlib-dev \ - gmp-dev jsoncpp-dev postgresql-dev ca-certificates && \ + gmp-dev jsoncpp-dev postgresql-dev luajit-dev ca-certificates && \ git clone --depth=1 -b ${MINETEST_GAME_VERSION} https://github.com/minetest/minetest_game.git ./games/minetest_game && \ rm -fr ./games/minetest_game/.git @@ -51,7 +51,7 @@ RUN mkdir build && \ FROM alpine:3.11 -RUN apk add --no-cache sqlite-libs curl gmp libstdc++ libgcc libpq && \ +RUN apk add --no-cache sqlite-libs curl gmp libstdc++ libgcc libpq luajit && \ adduser -D multicraft --uid 30000 -h /var/lib/multicraft && \ chown -R multicraft:multicraft /var/lib/multicraft diff --git a/LICENSE.txt b/LICENSE.txt index d7000c063..9ee533f18 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -10,6 +10,9 @@ http://creativecommons.org/licenses/by-sa/3.0/ textures/base/pack/refresh.png is under the Apache 2 license https://www.apache.org/licenses/LICENSE-2.0.html +Textures by Zughy are under CC BY-SA 4.0 +https://creativecommons.org/licenses/by-sa/4.0/ + Authors of media files ----------------------- Everything not listed in here: @@ -22,6 +25,8 @@ paramat: textures/base/pack/menu_header.png textures/base/pack/next_icon.png textures/base/pack/prev_icon.png + textures/base/pack/clear.png + textures/base/pack/search.png rubenwardy, paramat: textures/base/pack/start_icon.png @@ -44,6 +49,14 @@ srifqi textures/base/pack/joystick_off.png textures/base/pack/minimap_btn.png +Zughy: + textures/base/pack/cdb_add.png + textures/base/pack/cdb_clear.png + textures/base/pack/cdb_downloading.png + textures/base/pack/cdb_queued.png + textures/base/pack/cdb_update.png + textures/base/pack/cdb_viewonline.png + License of Minetest source code ------------------------------- diff --git a/README.md b/README.md index 63ba0ea51..3a33bb4b8 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,10 @@ Table of Contents Further documentation ---------------------- -- Minetest Website: http://minetest.net/ -- Minetest Wiki: http://wiki.minetest.net/ -- Minetest Developer wiki: http://dev.minetest.net/ -- Minetest Forum: http://forum.minetest.net/ +- Minetest Website: https://minetest.net/ +- Minetest Wiki: https://wiki.minetest.net/ +- Minetest Developer wiki: https://dev.minetest.net/ +- Minetest Forum: https://forum.minetest.net/ - Minetest GitHub: https://github.com/minetest/minetest/ - [doc/](doc/) directory of source distribution @@ -141,7 +141,7 @@ For Debian/Ubuntu users: For Fedora users: sudo dnf install make automake gcc gcc-c++ kernel-devel cmake libcurl-devel openal-soft-devel libvorbis-devel libXxf86vm-devel libogg-devel freetype-devel mesa-libGL-devel zlib-devel jsoncpp-devel irrlicht-devel bzip2-libs gmp-devel sqlite-devel luajit-devel leveldb-devel ncurses-devel doxygen spatialindex-devel bzip2-devel - + For Arch users: sudo pacman -S base-devel libcurl-gnutls cmake libxxf86vm irrlicht libpng sqlite libogg libvorbis openal freetype2 jsoncpp gmp luajit leveldb ncurses @@ -296,13 +296,14 @@ It is highly recommended to use vcpkg as package manager. After you successfully built vcpkg you can easily install the required libraries: ```powershell -vcpkg install irrlicht zlib curl[winssl] openal-soft libvorbis libogg sqlite3 freetype luajit --triplet x64-windows +vcpkg install irrlicht zlib curl[winssl] openal-soft libvorbis libogg sqlite3 freetype luajit gmp jsoncpp --triplet x64-windows ``` - `curl` is optional, but required to read the serverlist, `curl[winssl]` is required to use the content store. - `openal-soft`, `libvorbis` and `libogg` are optional, but required to use sound. - `freetype` is optional, it allows true-type font rendering. - `luajit` is optional, it replaces the integrated Lua interpreter with a faster just-in-time interpreter. +- `gmp` and `jsoncpp` are optional, otherwise the bundled versions will be compiled There are other optional libraries, but they are not tested if they can build and link correctly. @@ -335,7 +336,7 @@ This is outdated and not recommended. Follow the instructions on https://dev.min Run the following script in PowerShell: ```powershell -cmake . -G"Visual Studio 15 2017 Win64" -DCMAKE_TOOLCHAIN_FILE=D:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_GETTEXT=0 -DENABLE_CURSES=0 +cmake . -G"Visual Studio 15 2017 Win64" -DCMAKE_TOOLCHAIN_FILE=D:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_GETTEXT=OFF -DENABLE_CURSES=OFF -DENABLE_SYSTEM_JSONCPP=ON cmake --build . --config Release ``` Make sure that the right compiler is selected and the path to the vcpkg toolchain is correct. diff --git a/build/android/app/src/main/java/com/multicraft/game/CustomEditText.java b/build/android/app/src/main/java/com/multicraft/game/CustomEditText.java index 03e9e827e..c32d68325 100644 --- a/build/android/app/src/main/java/com/multicraft/game/CustomEditText.java +++ b/build/android/app/src/main/java/com/multicraft/game/CustomEditText.java @@ -26,6 +26,8 @@ import android.view.inputmethod.InputMethodManager; import androidx.appcompat.widget.AppCompatEditText; +import java.util.Objects; + public class CustomEditText extends AppCompatEditText { public CustomEditText(Context context) { super(context); @@ -36,7 +38,7 @@ public class CustomEditText extends AppCompatEditText { if (keyCode == KeyEvent.KEYCODE_BACK) { InputMethodManager mgr = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - mgr.hideSoftInputFromWindow(this.getWindowToken(), 0); + Objects.requireNonNull(mgr).hideSoftInputFromWindow(this.getWindowToken(), 0); } return false; } diff --git a/builtin/client/chatcommands.lua b/builtin/client/chatcommands.lua index 5cb1b40bb..0e8d4dd03 100644 --- a/builtin/client/chatcommands.lua +++ b/builtin/client/chatcommands.lua @@ -23,6 +23,11 @@ core.register_on_sending_chat_message(function(message) return true end + -- Run core.registered_on_chatcommand callbacks. + if core.run_callbacks(core.registered_on_chatcommand, 5, cmd, param) then + return true + end + local cmd_def = core.registered_chatcommands[cmd] if cmd_def then core.set_last_run_mod(cmd_def.mod_origin) diff --git a/builtin/client/register.lua b/builtin/client/register.lua index c1b4965c1..27a6b02d9 100644 --- a/builtin/client/register.lua +++ b/builtin/client/register.lua @@ -4,6 +4,13 @@ core.callback_origins = {} local getinfo = debug.getinfo debug.getinfo = nil +--- Runs given callbacks. +-- +-- Note: this function is also called from C++ +-- @tparam table callbacks a table with registered callbacks, like `core.registered_on_*` +-- @tparam number mode a RunCallbacksMode, as defined in src/script/common/c_internal.h +-- @param ... arguments for the callback +-- @return depends on mode function core.run_callbacks(callbacks, mode, ...) assert(type(callbacks) == "table") local cb_len = #callbacks @@ -63,6 +70,7 @@ core.registered_on_mods_loaded, core.register_on_mods_loaded = make_registration core.registered_on_shutdown, core.register_on_shutdown = make_registration() core.registered_on_receiving_chat_message, core.register_on_receiving_chat_message = make_registration() core.registered_on_sending_chat_message, core.register_on_sending_chat_message = make_registration() +core.registered_on_chatcommand, core.register_on_chatcommand = make_registration() core.registered_on_death, core.register_on_death = make_registration() core.registered_on_hp_modification, core.register_on_hp_modification = make_registration() core.registered_on_damage_taken, core.register_on_damage_taken = make_registration() diff --git a/builtin/common/after.lua b/builtin/common/after.lua index b314711c9..e20f292f0 100644 --- a/builtin/common/after.lua +++ b/builtin/common/after.lua @@ -31,11 +31,13 @@ function core.after(after, func, ...) assert(tonumber(after) and type(func) == "function", "Invalid minetest.after invocation") local expire = time + after - jobs[#jobs + 1] = { + local new_job = { func = func, expire = expire, arg = {...}, - mod_origin = core.get_last_run_mod() + mod_origin = core.get_last_run_mod(), } + jobs[#jobs + 1] = new_job time_next = math.min(time_next, expire) + return { cancel = function() new_job.func = function() end end } end diff --git a/builtin/common/information_formspecs.lua b/builtin/common/information_formspecs.lua index 3e604b6d4..b121a85b4 100644 --- a/builtin/common/information_formspecs.lua +++ b/builtin/common/information_formspecs.lua @@ -118,7 +118,7 @@ core.register_on_player_receive_fields(function(player, formname, fields) return end - local event = minetest.explode_table_event(fields.list) + local event = core.explode_table_event(fields.list) if event.type ~= "INV" then local name = player:get_player_name() core.show_formspec(name, "__builtin:help_cmds", diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index 8d830f1f1..3438f414e 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -696,3 +696,7 @@ function core.privs_to_string(privs, delim) end return table.concat(list, delim) end + +function core.is_nan(number) + return number ~= number +end diff --git a/builtin/common/tests/vector_spec.lua b/builtin/common/tests/vector_spec.lua index 6f308a4a8..0f287363a 100644 --- a/builtin/common/tests/vector_spec.lua +++ b/builtin/common/tests/vector_spec.lua @@ -44,6 +44,10 @@ describe("vector", function() assert.same({ x = 2, y = 4, z = 6 }, vector.add(vector.new(1, 2, 3), { x = 1, y = 2, z = 3 })) end) + it("offset()", function() + assert.same({ x = 41, y = 52, z = 63 }, vector.offset(vector.new(1, 2, 3), 40, 50, 60)) + end) + -- This function is needed because of floating point imprecision. local function almost_equal(a, b) if type(a) == "number" then diff --git a/builtin/common/vector.lua b/builtin/common/vector.lua index 83d8417e1..28d8e117d 100644 --- a/builtin/common/vector.lua +++ b/builtin/common/vector.lua @@ -139,6 +139,12 @@ function vector.divide(a, b) end end +function vector.offset(v, x, y, z) + return {x = v.x + x, + y = v.y + y, + z = v.z + z} +end + function vector.sort(a, b) return {x = min(a.x, b.x), y = min(a.y, b.y), z = min(a.z, b.z)}, {x = max(a.x, b.x), y = max(a.y, b.y), z = max(a.z, b.z)} diff --git a/builtin/fstk/ui.lua b/builtin/fstk/ui.lua index c12961927..30a3f42f8 100644 --- a/builtin/fstk/ui.lua +++ b/builtin/fstk/ui.lua @@ -18,6 +18,8 @@ ui = {} ui.childlist = {} ui.default = nil +-- Whether fstk is currently showing its own formspec instead of active ui elements. +ui.overridden = false -------------------------------------------------------------------------------- function ui.add(child) @@ -58,6 +60,7 @@ local maintab = core.settings:get("maintab_LAST") local connect_time = tonumber(core.settings:get("connect_time")) function ui.update() + ui.overridden = false local formspec = {} -- attempt auto restart @@ -93,6 +96,7 @@ function ui.update() "button[2,6.6;4,1;btn_reconnect_yes;" .. fgettext("Reconnect") .. "]", "button[8,6.6;4,1;btn_reconnect_no;" .. fgettext("Close") .. "]" } + ui.overridden = true elseif gamedata ~= nil and gamedata.errormessage ~= nil then local error_message = core.formspec_escape(gamedata.errormessage) @@ -119,6 +123,7 @@ function ui.update() error_title, error_message), restart_btn } + ui.overridden = true else local active_toplevel_ui_elements = 0 for key,value in pairs(ui.childlist) do @@ -221,6 +226,16 @@ end -------------------------------------------------------------------------------- core.event_handler = function(event) + -- Handle error messages + if ui.overridden then + if event == "MenuQuit" then + gamedata.errormessage = nil + gamedata.reconnect_requested = false + ui.update() + end + return + end + if ui.handle_events(event) then ui.update() return diff --git a/builtin/game/chat.lua b/builtin/game/chat.lua index 69c4f5b31..5343b07a5 100644 --- a/builtin/game/chat.lua +++ b/builtin/game/chat.lua @@ -58,6 +58,11 @@ core.register_on_chat_message(function(name, message) param = param or "" + -- Run core.registered_on_chatcommands callbacks. + if core.run_callbacks(core.registered_on_chatcommands, 5, name, cmd, param) then + return true + end + local cmd_def = core.registered_chatcommands[cmd] if not cmd_def then core.chat_send_player(name, "-!- Invalid command: " .. cmd) @@ -66,8 +71,17 @@ core.register_on_chat_message(function(name, message) local has_privs, missing_privs = core.check_player_privs(name, cmd_def.privs) if has_privs then core.set_last_run_mod(cmd_def.mod_origin) - local _, result = cmd_def.func(name, param) - if result then + local success, result = cmd_def.func(name, param) + if success == false and result == nil then + core.chat_send_player(name, "-!- Invalid command usage") + local help_def = core.registered_chatcommands["help"] + if help_def then + local _, helpmsg = help_def.func(name, cmd) + if helpmsg then + core.chat_send_player(name, helpmsg) + end + end + elseif result then core.chat_send_player(name, result) end else @@ -1093,10 +1107,10 @@ core.register_chatcommand("last-login", { local pauth = core.get_auth_handler().get_auth(param) if pauth and pauth.last_login and pauth.last_login ~= -1 then -- Time in UTC, ISO 8601 format - return true, "Last login time was " .. + return true, param.."'s last login time was " .. os.date("!%Y-%m-%dT%H:%M:%SZ", pauth.last_login) end - return false, "Last login time is unknown" + return false, param.."'s last login time is unknown" end, }) diff --git a/builtin/game/deprecated.lua b/builtin/game/deprecated.lua index 20f0482eb..c5c7848f5 100644 --- a/builtin/game/deprecated.lua +++ b/builtin/game/deprecated.lua @@ -1,28 +1,5 @@ -- Minetest: builtin/deprecated.lua --- --- Default material types --- -local function digprop_err() - core.log("deprecated", "The core.digprop_* functions are obsolete and need to be replaced by item groups.") -end - -core.digprop_constanttime = digprop_err -core.digprop_stonelike = digprop_err -core.digprop_dirtlike = digprop_err -core.digprop_gravellike = digprop_err -core.digprop_woodlike = digprop_err -core.digprop_leaveslike = digprop_err -core.digprop_glasslike = digprop_err - -function core.node_metadata_inventory_move_allow_all() - core.log("deprecated", "core.node_metadata_inventory_move_allow_all is obsolete and does nothing.") -end - -function core.add_to_creative_inventory(itemstring) - core.log("deprecated", "core.add_to_creative_inventory is obsolete and does nothing.") -end - -- -- EnvRef -- @@ -77,7 +54,7 @@ core.setting_save = setting_proxy("write") function core.register_on_auth_fail(func) core.log("deprecated", "core.register_on_auth_fail " .. - "is obsolete and should be replaced by " .. + "is deprecated and should be replaced by " .. "core.register_on_authplayer instead.") core.register_on_authplayer(function (player_name, ip, is_success) diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua index b4b0458ad..cc15b5542 100644 --- a/builtin/game/falling.lua +++ b/builtin/game/falling.lua @@ -90,6 +90,9 @@ core.register_entity(":__builtin:falling_node", { local textures if def.tiles and def.tiles[1] then local tile = def.tiles[1] + if def.drawtype == "torchlike" and def.paramtype2 ~= "wallmounted" then + tile = def.tiles[2] or def.tiles[1] + end if type(tile) == "table" then tile = tile.name end @@ -133,7 +136,7 @@ core.register_entity(":__builtin:falling_node", { -- Set collision box (certain nodeboxes only for now) local nb_types = {fixed=true, leveled=true, connected=true} if def.drawtype == "nodebox" and def.node_box and - nb_types[def.node_box.type] then + nb_types[def.node_box.type] and def.node_box.fixed then local box = table.copy(def.node_box.fixed) if type(box[1]) == "table" then box = #box == 1 and box[1] or nil -- We can only use a single box @@ -150,9 +153,13 @@ core.register_entity(":__builtin:falling_node", { -- Rotate entity if def.drawtype == "torchlike" then - self.object:set_yaw(pi*0.25) - elseif (node.param2 ~= 0 and (def.wield_image == "" - or def.wield_image == nil)) + if def.paramtype2 == "wallmounted" then + self.object:set_yaw(pi*0.25) + else + self.object:set_yaw(-pi*0.25) + end + elseif ((node.param2 ~= 0 or def.drawtype == "nodebox" or def.drawtype == "mesh") + and (def.wield_image == "" or def.wield_image == nil)) or def.drawtype == "signlike" or def.drawtype == "mesh" or def.drawtype == "normal" @@ -167,16 +174,30 @@ core.register_entity(":__builtin:falling_node", { elseif (def.paramtype2 == "wallmounted" or def.paramtype2 == "colorwallmounted") then local rot = node.param2 % 8 local pitch, yaw, roll = 0, 0, 0 - if rot == 1 then - pitch, yaw = pi, pi - elseif rot == 2 then - pitch, yaw = pi/2, pi/2 - elseif rot == 3 then - pitch, yaw = pi/2, -pi/2 - elseif rot == 4 then - pitch, yaw = pi/2, pi - elseif rot == 5 then - pitch, yaw = pi/2, 0 + if def.drawtype == "nodebox" or def.drawtype == "mesh" then + if rot == 0 then + pitch, yaw = pi/2, 0 + elseif rot == 1 then + pitch, yaw = -pi/2, pi + elseif rot == 2 then + pitch, yaw = 0, pi/2 + elseif rot == 3 then + pitch, yaw = 0, -pi/2 + elseif rot == 4 then + pitch, yaw = 0, pi + end + else + if rot == 1 then + pitch, yaw = pi, pi + elseif rot == 2 then + pitch, yaw = pi/2, pi/2 + elseif rot == 3 then + pitch, yaw = pi/2, -pi/2 + elseif rot == 4 then + pitch, yaw = pi/2, pi + elseif rot == 5 then + pitch, yaw = pi/2, 0 + end end if def.drawtype == "signlike" then pitch = pitch - pi/2 @@ -185,7 +206,7 @@ core.register_entity(":__builtin:falling_node", { elseif rot == 1 then yaw = yaw - pi/2 end - elseif def.drawtype == "mesh" or def.drawtype == "normal" then + elseif def.drawtype == "mesh" or def.drawtype == "normal" or def.drawtype == "nodebox" then if rot >= 0 and rot <= 1 then roll = roll + pi else diff --git a/builtin/game/features.lua b/builtin/game/features.lua index a15475333..36ff1f0b0 100644 --- a/builtin/game/features.lua +++ b/builtin/game/features.lua @@ -17,6 +17,8 @@ core.features = { area_store_persistent_ids = true, pathfinder_works = true, object_step_has_moveresult = true, + direct_velocity_on_players = true, + use_texture_alpha_string_modes = true, } function core.has_feature(arg) diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 859b7dfb0..074eb4ffc 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -676,12 +676,13 @@ function core.node_dig(pos, node, digger) local diggername = user_name(digger) local log = make_log(diggername) local def = core.registered_nodes[node.name] + -- Copy pos because the callback could modify it if def and (not def.diggable or - (def.can_dig and not def.can_dig(pos, digger))) then + (def.can_dig and not def.can_dig(vector.new(pos), digger))) then log("info", diggername .. " tried to dig " .. node.name .. " which is not diggable " .. core.pos_to_string(pos)) - return + return false end if core.is_protected(pos, diggername) then @@ -690,7 +691,7 @@ function core.node_dig(pos, node, digger) .. " at protected position " .. core.pos_to_string(pos)) core.record_protection_violation(pos, diggername) - return + return false end log('action', diggername .. " digs " @@ -773,6 +774,8 @@ function core.node_dig(pos, node, digger) local node_copy = {name=node.name, param1=node.param1, param2=node.param2} callback(pos_copy, node_copy, digger) end + + return true end function core.itemstring_with_palette(item, palette_index) @@ -800,7 +803,7 @@ end -- Item definition defaults -- -local default_stack_max = tonumber(minetest.settings:get("default_stack_max")) or 64 +local default_stack_max = tonumber(core.settings:get("default_stack_max")) or 64 core.nodedef_default = { -- Item properties @@ -829,10 +832,6 @@ core.nodedef_default = { on_receive_fields = nil, - on_metadata_inventory_move = core.node_metadata_inventory_move_allow_all, - on_metadata_inventory_offer = core.node_metadata_inventory_offer_allow_all, - on_metadata_inventory_take = core.node_metadata_inventory_take_allow_all, - -- Node properties drawtype = "normal", visual_scale = 1.0, @@ -843,7 +842,6 @@ core.nodedef_default = { -- {name="", backface_culling=true}, -- {name="", backface_culling=true}, --}, - alpha = 255, post_effect_color = {a=0, r=0, g=0, b=0}, paramtype = "none", paramtype2 = "none", diff --git a/builtin/game/item_entity.lua b/builtin/game/item_entity.lua index 5e50077ac..5eefb5985 100644 --- a/builtin/game/item_entity.lua +++ b/builtin/game/item_entity.lua @@ -100,8 +100,9 @@ core.register_entity(":__builtin:item", { local max_count = stack:get_stack_max() local count = min(stack:get_count(), max_count) local size = 0.2 + 0.1 * (count / max_count) ^ (1 / 3) - local def = core.registered_nodes[itemname] - local glow = def and floor(def.light_source / 2 + 0.5) + local def = core.registered_items[itemname] + local glow = def and def.light_source and + floor(def.light_source / 2 + 0.5) self.object:set_properties({ is_visible = true, diff --git a/builtin/game/knockback.lua b/builtin/game/knockback.lua index 561734000..a95c43a47 100644 --- a/builtin/game/knockback.lua +++ b/builtin/game/knockback.lua @@ -43,5 +43,5 @@ core.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool return -- barely noticeable, so don't even send end - player:add_player_velocity(kdir) + player:add_velocity(kdir) end) diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua index d6b052e9b..acf3608d2 100644 --- a/builtin/game/misc.lua +++ b/builtin/game/misc.lua @@ -285,3 +285,26 @@ end function core.cancel_shutdown_requests() core.request_shutdown("", false, -1) end + + +-- Callback handling for dynamic_add_media + +local dynamic_add_media_raw = core.dynamic_add_media_raw +core.dynamic_add_media_raw = nil +function core.dynamic_add_media(filepath, callback) + local ret = dynamic_add_media_raw(filepath) + if ret == false then + return ret + end + if callback == nil then + core.log("deprecated", "Calling minetest.dynamic_add_media without ".. + "a callback is deprecated and will stop working in future versions.") + else + -- At the moment async loading is not actually implemented, so we + -- immediately call the callback ourselves + for _, name in ipairs(ret) do + callback(name) + end + end + return true +end diff --git a/builtin/game/register.lua b/builtin/game/register.lua index 0956d7ddb..c2a686806 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -332,13 +332,6 @@ for name in pairs(forbidden_item_names) do register_alias_raw(name, "") end - --- Obsolete: --- Aliases for core.register_alias (how ironic...) --- core.alias_node = core.register_alias --- core.alias_tool = core.register_alias --- core.alias_craftitem = core.register_alias - -- -- Built-in node definitions. Also defined in C. -- @@ -611,6 +604,7 @@ core.unregister_biome = make_wrap_deregistration(core.register_biome, core.clear_registered_biomes, core.registered_biomes) core.registered_on_chat_messages, core.register_on_chat_message = make_registration() +core.registered_on_chatcommands, core.register_on_chatcommand = make_registration() core.registered_globalsteps, core.register_globalstep = make_registration() core.registered_playerevents, core.register_playerevent = make_registration() core.registered_on_mods_loaded, core.register_on_mods_loaded = make_registration() @@ -639,6 +633,7 @@ core.registered_can_bypass_userlimit, core.register_can_bypass_userlimit = make_ core.registered_on_modchannel_message, core.register_on_modchannel_message = make_registration() core.registered_on_player_inventory_actions, core.register_on_player_inventory_action = make_registration() core.registered_allow_player_inventory_actions, core.register_allow_player_inventory_action = make_registration() +core.registered_on_rightclickplayers, core.register_on_rightclickplayer = make_registration() -- diff --git a/builtin/init.lua b/builtin/init.lua index b602d6a38..602ca0b4f 100644 --- a/builtin/init.lua +++ b/builtin/init.lua @@ -41,9 +41,20 @@ if INIT == "game" then assert(not core.get_http_api) elseif INIT == "mainmenu" then local mm_script = core.settings:get("main_menu_script") + local custom_loaded = false if mm_script and mm_script ~= "" then - dofile(mm_script) - else + local testfile = io.open(mm_script, "r") + if testfile then + testfile:close() + dofile(mm_script) + custom_loaded = true + core.log("info", "Loaded custom main menu script: "..mm_script) + else + core.log("error", "Failed to load custom main menu script: "..mm_script) + core.log("info", "Falling back to default main menu script") + end + end + if not custom_loaded then dofile(core.get_mainmenu_path() .. DIR_DELIM .. "init.lua") end elseif INIT == "async" then diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index 1d453f21e..a1ac00113 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -56,29 +56,6 @@ function image_column(tooltip) "11=" .. core.formspec_escape(defaulttexturedir .. "server_ping_1.png") end --------------------------------------------------------------------------------- -function order_favorite_list(list, mobile) - local res = {} - local non_mobile_servers = {} - -- orders the multicraft list before support - for i = 1, #list do - local fav = list[i] - if mobile and not fav.mobile_friendly then - non_mobile_servers[("%s:%s"):format(fav.address, fav.port)] = fav - elseif fav.server_id == "multicraft" then - res[#res + 1] = fav - end - end - for i = 1, #list do - local fav = list[i] - if (mobile and fav.mobile_friendly or not mobile) and - is_server_protocol_compat(fav.proto_min, fav.proto_max) and - fav.server_id ~= "multicraft" then - res[#res + 1] = fav - end - end - return res, non_mobile_servers -end -------------------------------------------------------------------------------- function render_serverlist_row(spec, is_favorite, is_approved) @@ -93,7 +70,7 @@ function render_serverlist_row(spec, is_favorite, is_approved) if spec.name then text = text .. core.formspec_escape(spec.name:trim()) elseif spec.address then - text = text .. spec.address:trim() + text = text .. core.formspec_escape(spec.address:trim()) if spec.port then text = text .. ":" .. spec.port end @@ -166,35 +143,15 @@ end -------------------------------------------------------------------------------- os.tempfolder = function() - if core.settings:get("TMPFolder") then - return core.settings:get("TMPFolder") .. DIR_DELIM .. "MT_" .. math.random(0,10000) - end + local temp = core.get_temp_path() + return temp .. DIR_DELIM .. "MT_" .. math.random(0, 10000) +end - local filetocheck = os.tmpname() - os.remove(filetocheck) - - -- luacheck: ignore - -- https://blogs.msdn.microsoft.com/vcblog/2014/06/18/c-runtime-crt-features-fixes-and-breaking-changes-in-visual-studio-14-ctp1/ - -- The C runtime (CRT) function called by os.tmpname is tmpnam. - -- Microsofts tmpnam implementation in older CRT / MSVC releases is defective. - -- tmpnam return values starting with a backslash characterize this behavior. - -- https://sourceforge.net/p/mingw-w64/bugs/555/ - -- MinGW tmpnam implementation is forwarded to the CRT directly. - -- https://sourceforge.net/p/mingw-w64/discussion/723797/thread/55520785/ - -- MinGW links to an older CRT release (msvcrt.dll). - -- Due to legal concerns MinGW will never use a newer CRT. - -- - -- Make use of TEMP to compose the temporary filename if an old - -- style tmpnam return value is detected. - if filetocheck:sub(1, 1) == "\\" then - local tempfolder = os.getenv("TEMP") - return tempfolder .. filetocheck - end - - local randname = "MTTempModFolder_" .. math.random(0,10000) - local backstring = filetocheck:reverse() - return filetocheck:sub(0, filetocheck:len() - backstring:find(DIR_DELIM) + 1) .. - randname +-------------------------------------------------------------------------------- +os.tmpname = function() + local path = os.tempfolder() + io.open(path, "w"):close() + return path end -------------------------------------------------------------------------------- @@ -226,42 +183,6 @@ function menu_handle_key_up_down(fields, textlist, settingname) return false end --------------------------------------------------------------------------------- -function asyncOnlineFavourites(mobile) - if not menudata.public_known then - menudata.public_known = {{ - name = fgettext("Loading..."), - description = fgettext_ne("Try reenabling public serverlist and check your internet connection.") - }} - end - menudata.favorites = menudata.public_known - menudata.favorites_is_public = true - - if not menudata.public_downloading then - menudata.public_downloading = true - else - return - end - - core.handle_async( - function(param) - return core.get_favorites("online") - end, - nil, - function(result) - menudata.public_downloading = nil - local favs, non_mobile = order_favorite_list(result, mobile) - if favs[1] then - menudata.public_known = favs - menudata.favorites = menudata.public_known - menudata.favorites_is_public = true - menudata.non_mobile_servers = non_mobile - end - core.event_handler("Refresh") - end - ) -end - -------------------------------------------------------------------------------- function text2textlist(xpos, ypos, width, height, tl_name, textlen, text, transparency) local textlines = core.wrap_text(text, textlen, true) diff --git a/builtin/mainmenu/dlg_config_world.lua b/builtin/mainmenu/dlg_config_world.lua index 0da87e965..7446abd8f 100644 --- a/builtin/mainmenu/dlg_config_world.lua +++ b/builtin/mainmenu/dlg_config_world.lua @@ -76,7 +76,7 @@ local function get_formspec(data) "label[1.75,0;" .. data.worldspec.name .. "]" if mod.is_modpack or mod.type == "game" then - local info = minetest.formspec_escape( + local info = core.formspec_escape( core.get_content_info(mod.path).description) if info == "" then if mod.is_modpack then diff --git a/builtin/mainmenu/dlg_contentstore.lua b/builtin/mainmenu/dlg_contentstore.lua index 8c23052dc..d61cecd69 100644 --- a/builtin/mainmenu/dlg_contentstore.lua +++ b/builtin/mainmenu/dlg_contentstore.lua @@ -15,7 +15,7 @@ --with this program; if not, write to the Free Software Foundation, Inc., --51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -if not minetest.get_http_api then +if not core.get_http_api then function create_store_dlg() return messagebox("store", fgettext("ContentDB is not available when Minetest was compiled without cURL")) @@ -23,9 +23,11 @@ if not minetest.get_http_api then return end -local store = { packages = {}, packages_full = {} } +-- Unordered preserves the original order of the ContentDB API, +-- before the package list is ordered based on installed state. +local store = { packages = {}, packages_full = {}, packages_full_unordered = {} } -local http = minetest.get_http_api() +local http = core.get_http_api() -- Screenshot local screenshot_dir = core.get_cache_path() .. DIR_DELIM .. "cdb" @@ -45,6 +47,9 @@ local filter_types_titles = { fgettext("Texture packs"), } +local number_downloading = 0 +local download_queue = {} + local filter_types_type = { nil, "game", @@ -67,12 +72,14 @@ local function download_package(param) end end -local function start_install(calling_dialog, package) +local function start_install(package) local params = { package = package, filename = os.tempfolder() .. "_MODNAME_" .. package.name .. ".zip", } + number_downloading = number_downloading + 1 + local function callback(result) if result.successful then local path, msg = pkgmgr.install(package.type, @@ -124,9 +131,20 @@ local function start_install(calling_dialog, package) end package.downloading = false + + number_downloading = number_downloading - 1 + + local next = download_queue[1] + if next then + table.remove(download_queue, 1) + + start_install(next) + end + ui.update() end + package.queued = false package.downloading = true if not core.handle_async(download_package, params, callback) then @@ -136,6 +154,341 @@ local function start_install(calling_dialog, package) end end +local function queue_download(package) + local max_concurrent_downloads = tonumber(core.settings:get("contentdb_max_concurrent_downloads")) + if number_downloading < max_concurrent_downloads then + start_install(package) + else + table.insert(download_queue, package) + package.queued = true + end +end + +local function get_raw_dependencies(package) + if package.raw_deps then + return package.raw_deps + end + + local url_fmt = "/api/packages/%s/dependencies/?only_hard=1&protocol_version=%s&engine_version=%s" + local version = core.get_version() + local base_url = core.settings:get("contentdb_url") + local url = base_url .. url_fmt:format(package.id, core.get_max_supp_proto(), version.string) + + local response = http.fetch_sync({ url = url }) + if not response.succeeded then + return + end + + local data = core.parse_json(response.data) or {} + + local content_lookup = {} + for _, pkg in pairs(store.packages_full) do + content_lookup[pkg.id] = pkg + end + + for id, raw_deps in pairs(data) do + local package2 = content_lookup[id:lower()] + if package2 and not package2.raw_deps then + package2.raw_deps = raw_deps + + for _, dep in pairs(raw_deps) do + local packages = {} + for i=1, #dep.packages do + packages[#packages + 1] = content_lookup[dep.packages[i]:lower()] + end + dep.packages = packages + end + end + end + + return package.raw_deps +end + +local function has_hard_deps(raw_deps) + for i=1, #raw_deps do + if not raw_deps[i].is_optional then + return true + end + end + + return false +end + +-- Recursively resolve dependencies, given the installed mods +local function resolve_dependencies_2(raw_deps, installed_mods, out) + local function resolve_dep(dep) + -- Check whether it's already installed + if installed_mods[dep.name] then + return { + is_optional = dep.is_optional, + name = dep.name, + installed = true, + } + end + + -- Find exact name matches + local fallback + for _, package in pairs(dep.packages) do + if package.type ~= "game" then + if package.name == dep.name then + return { + is_optional = dep.is_optional, + name = dep.name, + installed = false, + package = package, + } + elseif not fallback then + fallback = package + end + end + end + + -- Otherwise, find the first mod that fulfils it + if fallback then + return { + is_optional = dep.is_optional, + name = dep.name, + installed = false, + package = fallback, + } + end + + return { + is_optional = dep.is_optional, + name = dep.name, + installed = false, + } + end + + for _, dep in pairs(raw_deps) do + if not dep.is_optional and not out[dep.name] then + local result = resolve_dep(dep) + out[dep.name] = result + if result and result.package and not result.installed then + local raw_deps2 = get_raw_dependencies(result.package) + if raw_deps2 then + resolve_dependencies_2(raw_deps2, installed_mods, out) + end + end + end + end + + return true +end + +-- Resolve dependencies for a package, calls the recursive version. +local function resolve_dependencies(raw_deps, game) + assert(game) + + local installed_mods = {} + + local mods = {} + pkgmgr.get_game_mods(game, mods) + for _, mod in pairs(mods) do + installed_mods[mod.name] = true + end + + for _, mod in pairs(pkgmgr.global_mods:get_list()) do + installed_mods[mod.name] = true + end + + local out = {} + if not resolve_dependencies_2(raw_deps, installed_mods, out) then + return nil + end + + local retval = {} + for _, dep in pairs(out) do + retval[#retval + 1] = dep + end + + table.sort(retval, function(a, b) + return a.name < b.name + end) + + return retval +end + +local install_dialog = {} +function install_dialog.get_formspec() + local package = install_dialog.package + local raw_deps = install_dialog.raw_deps + local will_install_deps = install_dialog.will_install_deps + + local selected_game_idx = 1 + local selected_gameid = core.settings:get("menu_last_game") + local games = table.copy(pkgmgr.games) + for i=1, #games do + if selected_gameid and games[i].id == selected_gameid then + selected_game_idx = i + end + + games[i] = core.formspec_escape(games[i].name) + end + + local selected_game = pkgmgr.games[selected_game_idx] + local deps_to_install = 0 + local deps_not_found = 0 + + install_dialog.dependencies = resolve_dependencies(raw_deps, selected_game) + local formatted_deps = {} + for _, dep in pairs(install_dialog.dependencies) do + formatted_deps[#formatted_deps + 1] = "#fff" + formatted_deps[#formatted_deps + 1] = core.formspec_escape(dep.name) + if dep.installed then + formatted_deps[#formatted_deps + 1] = "#ccf" + formatted_deps[#formatted_deps + 1] = fgettext("Already installed") + elseif dep.package then + formatted_deps[#formatted_deps + 1] = "#cfc" + formatted_deps[#formatted_deps + 1] = fgettext("$1 by $2", dep.package.title, dep.package.author) + deps_to_install = deps_to_install + 1 + else + formatted_deps[#formatted_deps + 1] = "#f00" + formatted_deps[#formatted_deps + 1] = fgettext("Not found") + deps_not_found = deps_not_found + 1 + end + end + + local message_bg = "#3333" + local message + if will_install_deps then + message = fgettext("$1 and $2 dependencies will be installed.", package.title, deps_to_install) + else + message = fgettext("$1 will be installed, and $2 dependencies will be skipped.", package.title, deps_to_install) + end + if deps_not_found > 0 then + message = fgettext("$1 required dependencies could not be found.", deps_not_found) .. + " " .. fgettext("Please check that the base game is correct.", deps_not_found) .. + "\n" .. message + message_bg = mt_color_orange + end + + local formspec = { + "formspec_version[3]", + "size[7,7.85]", + "style[title;border=false]", + "box[0,0;7,0.5;#3333]", + "button[0,0;7,0.5;title;", fgettext("Install $1", package.title) , "]", + + "container[0.375,0.70]", + + "label[0,0.25;", fgettext("Base Game:"), "]", + "dropdown[2,0;4.25,0.5;gameid;", table.concat(games, ","), ";", selected_game_idx, "]", + + "label[0,0.8;", fgettext("Dependencies:"), "]", + + "tablecolumns[color;text;color;text]", + "table[0,1.1;6.25,3;packages;", table.concat(formatted_deps, ","), "]", + + "container_end[]", + + "checkbox[0.375,5.1;will_install_deps;", + fgettext("Install missing dependencies"), ";", + will_install_deps and "true" or "false", "]", + + "box[0,5.4;7,1.2;", message_bg, "]", + "textarea[0.375,5.5;6.25,1;;;", message, "]", + + "container[1.375,6.85]", + "button[0,0;2,0.8;install_all;", fgettext("Install"), "]", + "button[2.25,0;2,0.8;cancel;", fgettext("Cancel"), "]", + "container_end[]", + } + + return table.concat(formspec, "") +end + +function install_dialog.handle_submit(this, fields) + if fields.cancel then + this:delete() + return true + end + + if fields.will_install_deps ~= nil then + install_dialog.will_install_deps = core.is_yes(fields.will_install_deps) + return true + end + + if fields.install_all then + queue_download(install_dialog.package) + + if install_dialog.will_install_deps then + for _, dep in pairs(install_dialog.dependencies) do + if not dep.is_optional and not dep.installed and dep.package then + queue_download(dep.package) + end + end + end + + this:delete() + return true + end + + if fields.gameid then + for _, game in pairs(pkgmgr.games) do + if game.name == fields.gameid then + core.settings:set("menu_last_game", game.id) + break + end + end + return true + end + + return false +end + +function install_dialog.create(package, raw_deps) + install_dialog.dependencies = nil + install_dialog.package = package + install_dialog.raw_deps = raw_deps + install_dialog.will_install_deps = true + return dialog_create("install_dialog", + install_dialog.get_formspec, + install_dialog.handle_submit, + nil) +end + + +local confirm_overwrite = {} +function confirm_overwrite.get_formspec() + local package = confirm_overwrite.package + + return "size[11.5,4.5,true]" .. + "label[2,2;" .. + fgettext("\"$1\" already exists. Would you like to overwrite it?", package.name) .. "]".. + "style[install;bgcolor=red]" .. + "button[3.25,3.5;2.5,0.5;install;" .. fgettext("Overwrite") .. "]" .. + "button[5.75,3.5;2.5,0.5;cancel;" .. fgettext("Cancel") .. "]" +end + +function confirm_overwrite.handle_submit(this, fields) + if fields.cancel then + this:delete() + return true + end + + if fields.install then + this:delete() + confirm_overwrite.callback() + return true + end + + return false +end + +function confirm_overwrite.create(package, callback) + assert(type(package) == "table") + assert(type(callback) == "function") + + confirm_overwrite.package = package + confirm_overwrite.callback = callback + return dialog_create("confirm_overwrite", + confirm_overwrite.get_formspec, + confirm_overwrite.handle_submit, + nil) +end + + local function get_file_extension(path) local parts = path:split(".") return parts[#parts] @@ -203,7 +556,7 @@ function store.load() end end - local timeout = tonumber(minetest.settings:get("curl_file_download_timeout")) + local timeout = tonumber(core.settings:get("curl_file_download_timeout")) local response = http.fetch_sync({ url = url, timeout = timeout }) if not response.succeeded then return @@ -224,6 +577,7 @@ function store.load() end end + store.packages_full_unordered = store.packages_full store.packages = store.packages_full store.loaded = true end @@ -232,7 +586,7 @@ function store.update_paths() local mod_hash = {} pkgmgr.refresh_globals() for _, mod in pairs(pkgmgr.global_mods:get_list()) do - if mod.author then + if mod.author and mod.release > 0 then mod_hash[mod.author:lower() .. "/" .. mod.name] = mod end end @@ -240,14 +594,14 @@ function store.update_paths() local game_hash = {} pkgmgr.update_gamelist() for _, game in pairs(pkgmgr.games) do - if game.author ~= "" then + if game.author ~= "" and game.release > 0 then game_hash[game.author:lower() .. "/" .. game.id] = game end end local txp_hash = {} for _, txp in pairs(pkgmgr.get_texture_packs()) do - if txp.author then + if txp.author and txp.release > 0 then txp_hash[txp.author:lower() .. "/" .. txp.name] = txp end end @@ -271,6 +625,33 @@ function store.update_paths() end end +function store.sort_packages() + local ret = {} + + -- Add installed content + for i=1, #store.packages_full_unordered do + local package = store.packages_full_unordered[i] + if package.path then + ret[#ret + 1] = package + end + end + + -- Sort installed content by title + table.sort(ret, function(a, b) + return a.title < b.title + end) + + -- Add uninstalled content + for i=1, #store.packages_full_unordered do + local package = store.packages_full_unordered[i] + if not package.path then + ret[#ret + 1] = package + end + end + + store.packages_full = ret +end + function store.filter_packages(query) if query == "" and filter_type == 1 then store.packages = store.packages_full @@ -282,7 +663,7 @@ function store.filter_packages(query) table.insert(keywords, word) end - local function matches_keywords(package, keywords) + local function matches_keywords(package) for k = 1, #keywords do local keyword = keywords[k] @@ -299,12 +680,11 @@ function store.filter_packages(query) store.packages = {} for _, package in pairs(store.packages_full) do - if (query == "" or matches_keywords(package, keywords)) and + if (query == "" or matches_keywords(package)) and (filter_type == 1 or package.type == filter_types_type[filter_type]) then store.packages[#store.packages + 1] = package end end - end function store.get_formspec(dlgdata) @@ -317,7 +697,6 @@ function store.get_formspec(dlgdata) local W = 15.75 local H = 9.5 - local formspec if #store.packages_full > 0 then formspec = { @@ -326,11 +705,15 @@ function store.get_formspec(dlgdata) "background[0,0;0,0;" .. core.formspec_escape(defaulttexturedir .. "bg_common.png") .. ";true;32]", "position[0.5,0.55]", + + "style[status,downloading,queued;border=false]", + "container[0.375,0.375]", - "field[0,0;10.225,0.8;search_string;;", core.formspec_escape(search_string), "]", + "field[0,0;7.225,0.8;search_string;;", core.formspec_escape(search_string), "]", "field_close_on_enter[search_string;false]", - "button[10.225,0;2,0.8;search;", fgettext("Search"), "]", - "dropdown[12.6,0;2.4,0.8;type;", table.concat(filter_types_titles, ","), ";", filter_type, "]", + "image_button[7.3,0;0.8,0.8;", core.formspec_escape(defaulttexturedir .. "search.png"), ";search;]", + "image_button[8.125,0;0.8,0.8;", core.formspec_escape(defaulttexturedir .. "clear.png"), ";clear;]", + "dropdown[9.6,0;2.4,0.8;type;", table.concat(filter_types_titles, ","), ";", filter_type, "]", "container_end[]", -- Page nav buttons @@ -349,6 +732,35 @@ function store.get_formspec(dlgdata) "container_end[]", } + if number_downloading > 0 then + formspec[#formspec + 1] = "button[12.75,0.375;2.625,0.8;downloading;" + if #download_queue > 0 then + formspec[#formspec + 1] = fgettext("$1 downloading,\n$2 queued", number_downloading, #download_queue) + else + formspec[#formspec + 1] = fgettext("$1 downloading...", number_downloading) + end + formspec[#formspec + 1] = "]" + else + local num_avail_updates = 0 + for i=1, #store.packages_full do + local package = store.packages_full[i] + if package.path and package.installed_release < package.release and + not (package.downloading or package.queued) then + num_avail_updates = num_avail_updates + 1 + end + end + + if num_avail_updates == 0 then + formspec[#formspec + 1] = "button[12.75,0.375;2.625,0.8;status;" + formspec[#formspec + 1] = fgettext("No updates") + formspec[#formspec + 1] = "]" + else + formspec[#formspec + 1] = "button[12.75,0.375;2.625,0.8;update_all;" + formspec[#formspec + 1] = fgettext("Update All [$1]", num_avail_updates) + formspec[#formspec + 1] = "]" + end + end + if #store.packages == 0 then formspec[#formspec + 1] = "label[4,3;" formspec[#formspec + 1] = fgettext("No results") @@ -367,11 +779,17 @@ function store.get_formspec(dlgdata) } end + -- download/queued tooltips always have the same message + local tooltip_colors = ";#dff6f5;#302c2e]" + formspec[#formspec + 1] = "tooltip[downloading;" .. fgettext("Downloading...") .. tooltip_colors + formspec[#formspec + 1] = "tooltip[queued;" .. fgettext("Queued") .. tooltip_colors + local start_idx = (cur_page - 1) * num_per_page + 1 for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do local package = store.packages[i] + local container_y = (i - start_idx) * 1.375 + (2*0.375 + 0.8) formspec[#formspec + 1] = "container[0.375," - formspec[#formspec + 1] = (i - start_idx) * 1.375 + (2*0.375 + 0.8) + formspec[#formspec + 1] = container_y formspec[#formspec + 1] = "]" -- image @@ -382,55 +800,55 @@ function store.get_formspec(dlgdata) -- title formspec[#formspec + 1] = "label[1.875,0.1;" formspec[#formspec + 1] = core.formspec_escape( - minetest.colorize(mt_color_green, package.title) .. - minetest.colorize("#BFBFBF", " by " .. package.author)) + core.colorize(mt_color_green, package.title) .. + core.colorize("#BFBFBF", " by " .. package.author)) formspec[#formspec + 1] = "]" -- buttons - local description_width = W - 0.375*5 - 1 - 2*1.5 + local left_base = "image_button[-1.55,0;0.7,0.7;" .. core.formspec_escape(defaulttexturedir) formspec[#formspec + 1] = "container[" formspec[#formspec + 1] = W - 0.375*2 formspec[#formspec + 1] = ",0.1]" if package.downloading then - formspec[#formspec + 1] = "style[download;border=false]" - - formspec[#formspec + 1] = "button[-3.5,0;2,0.8;download;" - formspec[#formspec + 1] = fgettext("Downloading...") - formspec[#formspec + 1] = "]" + formspec[#formspec + 1] = "animated_image[-1.7,-0.15;1,1;downloading;" + formspec[#formspec + 1] = core.formspec_escape(defaulttexturedir) + formspec[#formspec + 1] = "cdb_downloading.png;3;400;]" + elseif package.queued then + formspec[#formspec + 1] = left_base + formspec[#formspec + 1] = core.formspec_escape(defaulttexturedir) + formspec[#formspec + 1] = "cdb_queued.png;queued]" elseif not package.path then - formspec[#formspec + 1] = "button[-3,0;1.5,0.8;install_" - formspec[#formspec + 1] = tostring(i) - formspec[#formspec + 1] = ";" - formspec[#formspec + 1] = fgettext("Install") - formspec[#formspec + 1] = "]" + local elem_name = "install_" .. i .. ";" + formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#71aa34]" + formspec[#formspec + 1] = left_base .. "cdb_add.png;" .. elem_name .. "]" + formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Install") .. tooltip_colors else if package.installed_release < package.release then - description_width = description_width - 1.5 -- The install_ action also handles updating - formspec[#formspec + 1] = "button[-4.5,0;1.5,0.8;install_" - formspec[#formspec + 1] = tostring(i) - formspec[#formspec + 1] = ";" - formspec[#formspec + 1] = fgettext("Update") - formspec[#formspec + 1] = "]" - end + local elem_name = "install_" .. i .. ";" + formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#28ccdf]" + formspec[#formspec + 1] = left_base .. "cdb_update.png;" .. elem_name .. "]" + formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Update") .. tooltip_colors + else - formspec[#formspec + 1] = "button[-3,0;1.5,0.8;uninstall_" - formspec[#formspec + 1] = tostring(i) - formspec[#formspec + 1] = ";" - formspec[#formspec + 1] = fgettext("Uninstall") - formspec[#formspec + 1] = "]" + local elem_name = "uninstall_" .. i .. ";" + formspec[#formspec + 1] = "style[" .. elem_name .. "bgcolor=#a93b3b]" + formspec[#formspec + 1] = left_base .. "cdb_clear.png;" .. elem_name .. "]" + formspec[#formspec + 1] = "tooltip[" .. elem_name .. fgettext("Uninstall") .. tooltip_colors + end end - formspec[#formspec + 1] = "button[-1.5,0;1.5,0.8;view_" - formspec[#formspec + 1] = tostring(i) - formspec[#formspec + 1] = ";" - formspec[#formspec + 1] = fgettext("View") - formspec[#formspec + 1] = "]" + local web_elem_name = "view_" .. i .. ";" + formspec[#formspec + 1] = "image_button[-0.7,0;0.7,0.7;" .. + core.formspec_escape(defaulttexturedir) .. "cdb_viewonline.png;" .. web_elem_name .. "]" + formspec[#formspec + 1] = "tooltip[" .. web_elem_name .. + fgettext("View more information in a web browser") .. tooltip_colors formspec[#formspec + 1] = "container_end[]" -- description + local description_width = W - 0.375*5 - 0.85 - 2*0.7 formspec[#formspec + 1] = "textarea[1.855,0.3;" formspec[#formspec + 1] = tostring(description_width) formspec[#formspec + 1] = ",0.8;;;" @@ -451,6 +869,13 @@ function store.handle_submit(this, fields) return true end + if fields.clear then + search_string = "" + cur_page = 1 + store.filter_packages("") + return true + end + if fields.back then this:delete() return true @@ -492,6 +917,17 @@ function store.handle_submit(this, fields) end end + if fields.update_all then + for i=1, #store.packages_full do + local package = store.packages_full[i] + if package.path and package.installed_release < package.release and + not (package.downloading or package.queued) then + queue_download(package) + end + end + return true + end + local start_idx = (cur_page - 1) * num_per_page + 1 assert(start_idx ~= nil) for i=start_idx, math.min(#store.packages, start_idx+num_per_page-1) do @@ -499,21 +935,54 @@ function store.handle_submit(this, fields) assert(package) if fields["install_" .. i] then - start_install(this, package) + local install_parent + if package.type == "mod" then + install_parent = core.get_modpath() + elseif package.type == "game" then + install_parent = core.get_gamepath() + elseif package.type == "txp" then + install_parent = core.get_texturepath() + else + error("Unknown package type: " .. package.type) + end + + + local function on_confirm() + local deps = get_raw_dependencies(package) + if deps and has_hard_deps(deps) then + local dlg = install_dialog.create(package, deps) + dlg:set_parent(this) + this:hide() + dlg:show() + else + queue_download(package) + end + end + + if not package.path and core.is_dir(install_parent .. DIR_DELIM .. package.name) then + local dlg = confirm_overwrite.create(package, on_confirm) + dlg:set_parent(this) + this:hide() + dlg:show() + else + on_confirm() + end + return true end if fields["uninstall_" .. i] then - local dlg_delmod = create_delete_content_dlg(package) - dlg_delmod:set_parent(this) + local dlg = create_delete_content_dlg(package) + dlg:set_parent(this) this:hide() - dlg_delmod:show() + dlg:show() return true end if fields["view_" .. i] then - local url = ("%s/packages/%s?protocol_version=%d"):format( - core.settings:get("contentdb_url"), package.id, core.get_max_supp_proto()) + local url = ("%s/packages/%s/%s?protocol_version=%d"):format( + core.settings:get("contentdb_url"), + package.author, package.name, core.get_max_supp_proto()) core.open_url(url) return true end @@ -527,6 +996,9 @@ function create_store_dlg(type) store.load() end + store.update_paths() + store.sort_packages() + search_string = "" cur_page = 1 diff --git a/builtin/mainmenu/dlg_create_world.lua b/builtin/mainmenu/dlg_create_world.lua index ffa78acbc..88215ce1b 100644 --- a/builtin/mainmenu/dlg_create_world.lua +++ b/builtin/mainmenu/dlg_create_world.lua @@ -61,6 +61,7 @@ local flag_checkboxes = { fgettext("Low humidity and high heat causes shallow or dry rivers") }, }, flat = { + cb_caverns, { "hills", fgettext("Hills"), "hills" }, { "lakes", fgettext("Lakes"), "lakes" }, }, @@ -366,8 +367,18 @@ local function create_world_buttonhandler(this, fields) local gameindex = core.get_textlist_index("games") if gameindex ~= nil then + -- For unnamed worlds use the generated name 'world', + -- where the number increments: it is set to 1 larger than the largest + -- generated name number found. if worldname == "" then - worldname = "World " .. math.random(1000, 9999) + local worldnum_max = 0 + for _, world in ipairs(menudata.worldlist:get_list()) do + if world.name:match("^World %d+$") then + local worldnum = tonumber(world.name:sub(6)) + worldnum_max = math.max(worldnum_max, worldnum) + end + end + worldname = "World " .. worldnum_max + 1 end core.settings:set("fixed_map_seed", fields["te_seed"]) @@ -436,7 +447,7 @@ local function create_world_buttonhandler(this, fields) end if fields["mgv6_biomes"] then - local entry = minetest.formspec_escape(fields["mgv6_biomes"]) + local entry = core.formspec_escape(fields["mgv6_biomes"]) for b=1, #mgv6_biomes do if entry == mgv6_biomes[b][1] then local ftable = core.settings:get_flags("mgv6_spflags") diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index e3f00623e..913a15454 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -19,6 +19,7 @@ mt_color_grey = "#AAAAAA" mt_color_blue = "#6389FF" mt_color_green = "#72FF63" mt_color_dark_green = "#25C191" +mt_color_orange = "#FF8800" local menupath = core.get_mainmenu_path() local basepath = core.get_builtin_path() @@ -34,6 +35,7 @@ dofile(basepath .. "fstk" .. DIR_DELIM .. "ui.lua") dofile(menupath .. DIR_DELIM .. "async_event.lua") dofile(menupath .. DIR_DELIM .. "common.lua") dofile(menupath .. DIR_DELIM .. "pkgmgr.lua") +dofile(menupath .. DIR_DELIM .. "serverlistmgr.lua") dofile(menupath .. DIR_DELIM .. "textures.lua") dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua") @@ -77,7 +79,34 @@ local function main_event_handler(tabview, event) end -------------------------------------------------------------------------------- -function menudata.init_tabs() +local function init_globals() + -- Init gamedata + gamedata.worldindex = 0 + + menudata.worldlist = filterlist.create( + core.get_worlds, + compare_worlds, + -- Unique id comparison function + function(element, uid) + return element.name == uid + end, + -- Filter function + function(element, gameid) + return element.gameid == gameid + end + ) + + menudata.worldlist:add_sort_mechanism("alphabetic", sort_worlds_alphabetic) + menudata.worldlist:set_sortmode("alphabetic") + + if not core.settings:get("menu_last_game") then + local default_game = core.settings:get("default_game") or "minetest" + core.settings:set("menu_last_game", default_game) + end + + mm_texture.init() + + -- Create main tabview local tv_main = tabview_create("maintab", {x = 12, y = 5.4}, {x = 0, y = 0}) for i = 1, #pkgmgr.games do @@ -116,6 +145,15 @@ function menudata.init_tabs() end end + -- In case the folder of the last selected game has been deleted, + -- display "Minetest" as a header + if tv_main.current_tab == "local" then + local game = pkgmgr.find_by_gameid(core.settings:get("menu_last_game")) + if game == nil then + mm_texture.reset() + end + end + ui.set_default("maintab") tv_main:show() diff --git a/builtin/mainmenu/pkgmgr.lua b/builtin/mainmenu/pkgmgr.lua index 88ab48d2b..4eb81dfaf 100644 --- a/builtin/mainmenu/pkgmgr.lua +++ b/builtin/mainmenu/pkgmgr.lua @@ -72,6 +72,34 @@ local function cleanup_path(temppath) return temppath end +local function load_texture_packs(txtpath, retval) + local list = core.get_dir_list(txtpath, true) + local current_texture_path = core.settings:get("texture_path") + + for _, item in ipairs(list) do + if item ~= "base" then + local name = item + + local path = txtpath .. DIR_DELIM .. item .. DIR_DELIM + if path == current_texture_path then + name = fgettext("$1 (Enabled)", name) + end + + local conf = Settings(path .. "texture_pack.conf") + + retval[#retval + 1] = { + name = item, + author = conf:get("author"), + release = tonumber(conf:get("release")) or 0, + list_name = name, + type = "txp", + path = path, + enabled = path == current_texture_path, + } + end + end +end + function get_mods(path,retval,modpack) local mods = core.get_dir_list(path, true) @@ -107,12 +135,12 @@ function get_mods(path,retval,modpack) -- Read from config toadd.name = name toadd.author = mod_conf.author - toadd.release = tonumber(mod_conf.release or "0") + toadd.release = tonumber(mod_conf.release) or 0 toadd.path = prefix toadd.type = "mod" -- Check modpack.txt - -- Note: modpack.conf is already checked above + -- Note: modpack.conf is already checked above local modpackfile = io.open(prefix .. DIR_DELIM .. "modpack.txt") if modpackfile then modpackfile:close() @@ -136,32 +164,13 @@ pkgmgr = {} function pkgmgr.get_texture_packs() local txtpath = core.get_texturepath() - local list = core.get_dir_list(txtpath, true) + local txtpath_system = core.get_texturepath_share() local retval = {} - local current_texture_path = core.settings:get("texture_path") - - for _, item in ipairs(list) do - if item ~= "base" then - local name = item - - local path = txtpath .. DIR_DELIM .. item .. DIR_DELIM - if path == current_texture_path then - name = fgettext("$1 (Enabled)", name) - end - - local conf = Settings(path .. "texture_pack.conf") - - retval[#retval + 1] = { - name = item, - author = conf:get("author"), - release = tonumber(conf:get("release") or "0"), - list_name = name, - type = "txp", - path = path, - enabled = path == current_texture_path, - } - end + load_texture_packs(txtpath, retval) + -- on portable versions these two paths coincide. It avoids loading the path twice + if txtpath ~= txtpath_system then + load_texture_packs(txtpath_system, retval) end table.sort(retval, function(a, b) @@ -404,18 +413,7 @@ function pkgmgr.is_modpack_entirely_enabled(data, name) end ---------- toggles or en/disables a mod or modpack and its dependencies -------- -function pkgmgr.enable_mod(this, toset) - local list = this.data.list:get_list() - local mod = list[this.data.selected_mod] - - -- Game mods can't be enabled or disabled - if mod.is_game_content then - return - end - - local toggled_mods = {} - - local enabled_mods = {} +local function toggle_mod_or_modpack(list, toggled_mods, enabled_mods, toset, mod) if not mod.is_modpack then -- Toggle or en/disable the mod if toset == nil then @@ -434,23 +432,29 @@ function pkgmgr.enable_mod(this, toset) -- interleaved unsupported for i = 1, #list do if list[i].modpack == mod.name then - if toset == nil then - toset = not list[i].enabled - end - if list[i].enabled ~= toset then - list[i].enabled = toset - toggled_mods[#toggled_mods+1] = list[i].name - end - if toset then - enabled_mods[list[i].name] = true - end + toggle_mod_or_modpack(list, toggled_mods, enabled_mods, toset, list[i]) end end end +end + +function pkgmgr.enable_mod(this, toset) + local list = this.data.list:get_list() + local mod = list[this.data.selected_mod] + + -- Game mods can't be enabled or disabled + if mod.is_game_content then + return + end + + local toggled_mods = {} + local enabled_mods = {} + toggle_mod_or_modpack(list, toggled_mods, enabled_mods, toset, mod) + if not toset then -- Mod(s) were disabled, so no dependencies need to be enabled table.sort(toggled_mods) - minetest.log("info", "Following mods were disabled: " .. + core.log("info", "Following mods were disabled: " .. table.concat(toggled_mods, ", ")) return end @@ -487,7 +491,7 @@ function pkgmgr.enable_mod(this, toset) enabled_mods[name] = true local mod_to_enable = list[mod_ids[name]] if not mod_to_enable then - minetest.log("warning", "Mod dependency \"" .. name .. + core.log("warning", "Mod dependency \"" .. name .. "\" not found!") else if mod_to_enable.enabled == false then @@ -508,7 +512,7 @@ function pkgmgr.enable_mod(this, toset) -- Log the list of enabled mods table.sort(toggled_mods) - minetest.log("info", "Following mods were enabled: " .. + core.log("info", "Following mods were enabled: " .. table.concat(toggled_mods, ", ")) end diff --git a/builtin/mainmenu/serverlistmgr.lua b/builtin/mainmenu/serverlistmgr.lua new file mode 100644 index 000000000..964d0c584 --- /dev/null +++ b/builtin/mainmenu/serverlistmgr.lua @@ -0,0 +1,252 @@ +--Minetest +--Copyright (C) 2020 rubenwardy +-- +--This program is free software; you can redistribute it and/or modify +--it under the terms of the GNU Lesser General Public License as published by +--the Free Software Foundation; either version 2.1 of the License, or +--(at your option) any later version. +-- +--This program is distributed in the hope that it will be useful, +--but WITHOUT ANY WARRANTY; without even the implied warranty of +--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +--GNU Lesser General Public License for more details. +-- +--You should have received a copy of the GNU Lesser General Public License along +--with this program; if not, write to the Free Software Foundation, Inc., +--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +serverlistmgr = {} + +-------------------------------------------------------------------------------- +local function order_server_list(list) + local res = {} + --orders the favorite list after support + for i = 1, #list do + local fav = list[i] + if is_server_protocol_compat(fav.proto_min, fav.proto_max) then + res[#res + 1] = fav + end + end + for i = 1, #list do + local fav = list[i] + if not is_server_protocol_compat(fav.proto_min, fav.proto_max) then + res[#res + 1] = fav + end + end + return res +end + +local public_downloading = false + +-------------------------------------------------------------------------------- +function serverlistmgr.sync() + if not serverlistmgr.servers then + serverlistmgr.servers = {{ + name = fgettext("Loading..."), + description = fgettext_ne("Try reenabling public serverlist and check your internet connection.") + }} + end + + local serverlist_url = core.settings:get("serverlist_url") or "" + if not core.get_http_api or serverlist_url == "" then + serverlistmgr.servers = {{ + name = fgettext("Public server list is disabled"), + description = "" + }} + return + end + + if public_downloading then + return + end + public_downloading = true + + core.handle_async( + function(param) + local http = core.get_http_api() + local url = ("%s/list?proto_version_min=%d&proto_version_max=%d"):format( + core.settings:get("serverlist_url"), + core.get_min_supp_proto(), + core.get_max_supp_proto()) + + local response = http.fetch_sync({ url = url }) + if not response.succeeded then + return {} + end + + local retval = core.parse_json(response.data) + return retval and retval.list or {} + end, + nil, + function(result) + public_downloading = nil + local favs = order_server_list(result) + if favs[1] then + serverlistmgr.servers = favs + end + core.event_handler("Refresh") + end + ) +end + +-------------------------------------------------------------------------------- +local function get_favorites_path(folder) + local base = core.get_user_path() .. DIR_DELIM .. "client" .. DIR_DELIM .. "serverlist" .. DIR_DELIM + if folder then + return base + end + return base .. core.settings:get("serverlist_file") +end + +-------------------------------------------------------------------------------- +local function save_favorites(favorites) + local filename = core.settings:get("serverlist_file") + -- If setting specifies legacy format change the filename to the new one + if filename:sub(#filename - 3):lower() == ".txt" then + core.settings:set("serverlist_file", filename:sub(1, #filename - 4) .. ".json") + end + + assert(core.create_dir(get_favorites_path(true))) + core.safe_file_write(get_favorites_path(), core.write_json(favorites)) +end + +-------------------------------------------------------------------------------- +function serverlistmgr.read_legacy_favorites(path) + local file = io.open(path, "r") + if not file then + return nil + end + + local lines = {} + for line in file:lines() do + lines[#lines + 1] = line + end + file:close() + + local favorites = {} + + local i = 1 + while i < #lines do + local function pop() + local line = lines[i] + i = i + 1 + return line and line:trim() + end + + if pop():lower() == "[server]" then + local name = pop() + local address = pop() + local port = tonumber(pop()) + local description = pop() + + if name == "" then + name = nil + end + + if description == "" then + description = nil + end + + if not address or #address < 3 then + core.log("warning", "Malformed favorites file, missing address at line " .. i) + elseif not port or port < 1 or port > 65535 then + core.log("warning", "Malformed favorites file, missing port at line " .. i) + elseif (name and name:upper() == "[SERVER]") or + (address and address:upper() == "[SERVER]") or + (description and description:upper() == "[SERVER]") then + core.log("warning", "Potentially malformed favorites file, overran at line " .. i) + else + favorites[#favorites + 1] = { + name = name, + address = address, + port = port, + description = description + } + end + end + end + + return favorites +end + +-------------------------------------------------------------------------------- +local function read_favorites() + local path = get_favorites_path() + + -- If new format configured fall back to reading the legacy file + if path:sub(#path - 4):lower() == ".json" then + local file = io.open(path, "r") + if file then + local json = file:read("*all") + file:close() + return core.parse_json(json) + end + + path = path:sub(1, #path - 5) .. ".txt" + end + + local favs = serverlistmgr.read_legacy_favorites(path) + if favs then + save_favorites(favs) + os.remove(path) + end + return favs +end + +-------------------------------------------------------------------------------- +local function delete_favorite(favorites, del_favorite) + for i=1, #favorites do + local fav = favorites[i] + + if fav.address == del_favorite.address and fav.port == del_favorite.port then + table.remove(favorites, i) + return + end + end +end + +-------------------------------------------------------------------------------- +function serverlistmgr.get_favorites() + if serverlistmgr.favorites then + return serverlistmgr.favorites + end + + serverlistmgr.favorites = {} + + -- Add favorites, removing duplicates + local seen = {} + for _, fav in ipairs(read_favorites() or {}) do + local key = ("%s:%d"):format(fav.address:lower(), fav.port) + if not seen[key] then + seen[key] = true + serverlistmgr.favorites[#serverlistmgr.favorites + 1] = fav + end + end + + return serverlistmgr.favorites +end + +-------------------------------------------------------------------------------- +function serverlistmgr.add_favorite(new_favorite) + assert(type(new_favorite.port) == "number") + + -- Whitelist favorite keys + new_favorite = { + name = new_favorite.name, + address = new_favorite.address, + port = new_favorite.port, + description = new_favorite.description, + } + + local favorites = serverlistmgr.get_favorites() + delete_favorite(favorites, new_favorite) + table.insert(favorites, 1, new_favorite) + save_favorites(favorites) +end + +-------------------------------------------------------------------------------- +function serverlistmgr.delete_favorite(del_favorite) + local favorites = serverlistmgr.get_favorites() + delete_favorite(favorites, del_favorite) + save_favorites(favorites) +end diff --git a/builtin/mainmenu/tab_credits.lua b/builtin/mainmenu/tab_credits.lua index 1f643e02e..010cc1dbe 100644 --- a/builtin/mainmenu/tab_credits.lua +++ b/builtin/mainmenu/tab_credits.lua @@ -36,28 +36,37 @@ local core_developers = { "Nathanaël Courant (Nore/Ekdohibs) ", "Loic Blot (nerzhul/nrz) ", "paramat", - "Auke Kok (sofar) ", "Andrew Ward (rubenwardy) ", "Krock/SmallJoker ", "Lars Hofhansl ", + "Pierre-Yves Rollo ", + "v-rob ", } +-- For updating active/previous contributors, see the script in ./util/gather_git_credits.py + local active_contributors = { - "Hugues Ross [Formspecs]", + "Wuzzy [devtest game, visual corrections]", + "Zughy [Visual improvements, various fixes]", "Maksim (MoNTE48) [Android]", - "DS [Formspecs]", - "pyrollo [Formspecs: Hypertext]", - "v-rob [Formspecs]", - "Jordach [set_sky]", - "random-geek [Formspecs]", - "Wuzzy [Pathfinder, builtin, translations]", - "ANAND (ClobberXD) [Fixes, per-player FOV]", - "Warr1024 [Fixes]", - "Paul Ouellette (pauloue) [Fixes, Script API]", - "Jean-Patrick G (kilbith) [Audiovisuals]", - "HybridDog [Script API]", + "numzero [Graphics and rendering]", + "appgurueu [Various internal fixes]", + "Desour [Formspec and vector API changes]", + "HybridDog [Rendering fixes and documentation]", + "Hugues Ross [Graphics-related improvements]", + "ANAND (ClobberXD) [Mouse buttons rebinding]", + "luk3yx [Fixes]", + "hecks [Audiovisuals, Lua API]", + "LoneWolfHT [Object crosshair, documentation fixes]", + "Lejo [Server-related improvements]", + "EvidenceB [Compass HUD element]", + "Paul Ouellette (pauloue) [Lua API, documentation]", + "TheTermos [Collision detection, physics]", + "David CARLIER [Unix & Haiku build fixes]", "dcbrwn [Object shading]", - "srifqi [Fixes]", + "Elias Fleckenstein [API features/fixes]", + "Jean-Patrick Guerrero (kilbith) [model element, visual fixes]", + "k.h.lai [Memory leak fixes, documentation]", } local previous_core_developers = { @@ -73,30 +82,23 @@ local previous_core_developers = { "sapier", "Zeno", "ShadowNinja ", + "Auke Kok (sofar) ", } local previous_contributors = { "Nils Dagsson Moskopp (erlehmann) [Minetest Logo]", - "Dániel Juhász (juhdanad) ", "red-001 ", - "numberZero [Audiovisuals: meshgen]", "Giuseppe Bilotta", + "Dániel Juhász (juhdanad) ", "MirceaKitsune ", "Constantin Wenger (SpeedProg)", "Ciaran Gultnieks (CiaranG)", "stujones11 [Android UX improvements]", - "Jeija [HTTP, particles]", - "Vincent Glize (Dumbeldor) [Cleanups, CSM APIs]", - "Ben Deutsch [Rendering, Fixes, SQLite auth]", - "TeTpaAka [Hand overriding, nametag colors]", - "Rui [Sound Pitch]", - "Duane Robertson [MGValleys]", - "Raymoo [Tool Capabilities]", "Rogier [Fixes]", "Gregory Currie (gregorycu) [optimisation]", - "TriBlade9 [Audiovisuals]", - "T4im [Profiler]", - "Jurgen Doser (doserj) ", + "srifqi [Fixes]", + "JacobF", + "Jeija [HTTP, particles]", } local function buildCreditList(source) @@ -116,7 +118,7 @@ return { "MultiCraft Open Source Project, ver. " .. version.string .. "\n" .. "Copyright (C) 2014-2021 MultiCraft Development Team\n" .. "Licence: LGPLv3.0+ and CC-BY-SA 4.0, Home page: http://multicraft.world\n" .. - "Created and Powered by Minetest Engine, ver. 5.3.0]" .. + "Created and Powered by Minetest Engine, ver. 5.4.1]" .. -- "button[10,-0.5;2,2;homepage;multicraft.world]" .. "tablecolumns[color;text]" .. "tableoptions[background=#999999;highlight=#00000000;border=true]" .. @@ -132,10 +134,23 @@ return { "#FFFF00," .. fgettext("Previous Contributors") .. ",," .. buildCreditList(previous_contributors) .. "," .. ";1]" + + if PLATFORM ~= "Android" then + fs = fs .. "tooltip[userdata;" .. + fgettext("Opens the directory that contains user-provided worlds, games, mods,\n" .. + "and texture packs in a file manager / explorer.") .. "]" + fs = fs .. "button[0,4.75;3.5,1;userdata;" .. fgettext("Open User Data Directory") .. "]" + end + + return fs end, cbf_button_handler = function(this, fields, name, tabdata) if fields.homepage then core.open_url("http://multicraft.world") end + + if fields.userdata then + core.open_dir(core.get_user_path()) + end end, } diff --git a/builtin/mainmenu/tab_local.lua b/builtin/mainmenu/tab_local.lua index 949042062..f18e8209c 100644 --- a/builtin/mainmenu/tab_local.lua +++ b/builtin/mainmenu/tab_local.lua @@ -19,9 +19,13 @@ local lang = core.settings:get("language") if not lang or lang == "" then lang = os.getenv("LANG") end local mobile = PLATFORM == "Android" or PLATFORM == "iOS" -local function current_game() - local last_game_id = core.settings:get("menu_last_game") - local game = pkgmgr.find_by_gameid(last_game_id) +local enable_gamebar = PLATFORM ~= "Android" +local current_game, singleplayer_refresh_gamebar + +if enable_gamebar then + function current_game() + local last_game_id = core.settings:get("menu_last_game") + local game = pkgmgr.find_by_gameid(last_game_id) return game end diff --git a/builtin/mainmenu/tab_online.lua b/builtin/mainmenu/tab_online.lua index de209753c..b37c562df 100644 --- a/builtin/mainmenu/tab_online.lua +++ b/builtin/mainmenu/tab_online.lua @@ -24,11 +24,11 @@ local function get_formspec(tabview, name, tabdata) -- Update the cached supported proto info, -- it may have changed after a change by the settings menu. common_update_cached_supp_proto() - local fav_selected + local selected if menudata.search_result then - fav_selected = menudata.search_result[tabdata.fav_selected] + selected = menudata.search_result[tabdata.selected] else - fav_selected = menudata.favorites[tabdata.fav_selected] + selected = serverlistmgr.servers[tabdata.selected] end if not tabdata.search_for then @@ -88,7 +88,7 @@ local function get_formspec(tabview, name, tabdata) -- Password retval = retval .. "pwdfield[10.45,1.8;1.95,0.39;te_pwd;;" .. pwd .. "]" - if tabdata.fav_selected and fav_selected then + if tabdata.selected and selected then if gamedata.fav then retval = retval .. "image_button[7.1,4.91;0.83,0.83;" .. esc(defaulttexturedir .. "trash.png") .. ";btn_delete_favorite;;true;false]" @@ -115,10 +115,9 @@ local function get_formspec(tabview, name, tabdata) "table[-0.09,0.7;6.99,4.93;favourites;" if menudata.search_result then + local favs = serverlistmgr.get_favorites() for i = 1, #menudata.search_result do - local favs = core.get_favorites("local") local server = menudata.search_result[i] - for fav_id = 1, #favs do if server.address == favs[fav_id].address and server.port == favs[fav_id].port then @@ -133,18 +132,18 @@ local function get_formspec(tabview, name, tabdata) retval = retval .. render_serverlist_row(server, server.is_favorite, server.server_id == "multicraft") end - elseif #menudata.favorites > 0 then - local favs = core.get_favorites("local") + elseif #serverlistmgr.servers > 0 then + local favs = serverlistmgr.get_favorites() if #favs > 0 then for i = 1, #favs do - for j = 1, #menudata.favorites do - if menudata.favorites[j].address == favs[i].address and - menudata.favorites[j].port == favs[i].port then - table.insert(menudata.favorites, i, table.remove(menudata.favorites, j)) + for j = 1, #serverlistmgr.servers do + if serverlistmgr.servers[j].address == favs[i].address and + serverlistmgr.servers[j].port == favs[i].port then + table.insert(serverlistmgr.servers, i, table.remove(serverlistmgr.servers, j)) + end end - end - if favs[i].address ~= menudata.favorites[i].address then - table.insert(menudata.favorites, i, favs[i]) + if favs[i].address ~= serverlistmgr.servers[i].address then + table.insert(serverlistmgr.servers, i, favs[i]) end end end @@ -156,8 +155,8 @@ local function get_formspec(tabview, name, tabdata) end end - if tabdata.fav_selected then - retval = retval .. ";" .. tabdata.fav_selected .. "]" + if tabdata.selected then + retval = retval .. ";" .. tabdata.selected .. "]" else retval = retval .. ";0]" end @@ -167,7 +166,7 @@ end -------------------------------------------------------------------------------- local function main_button_handler(tabview, fields, name, tabdata) - local serverlist = menudata.search_result or menudata.favorites + local serverlist = menudata.search_result or serverlistmgr.servers if fields.te_name then gamedata.playername = fields.te_name @@ -188,8 +187,7 @@ local function main_button_handler(tabview, fields, name, tabdata) if event.type == "DCL" then if event.row <= #serverlist then - if menudata.favorites_is_public and - not is_server_protocol_compat_or_error( + if not is_server_protocol_compat_or_error( fav.proto_min, fav.proto_max) then return true end @@ -218,7 +216,7 @@ local function main_button_handler(tabview, fields, name, tabdata) if event.type == "CHG" then if event.row <= #serverlist then gamedata.fav = false - local favs = core.get_favorites("local") + local favs = serverlistmgr.get_favorites() local address = fav.address local port = fav.port gamedata.serverdescription = fav.description @@ -234,28 +232,28 @@ local function main_button_handler(tabview, fields, name, tabdata) core.settings:set("address", address) core.settings:set("remote_port", port) end - tabdata.fav_selected = event.row + tabdata.selected = event.row end return true end end if fields.key_up or fields.key_down then - local fav_idx = core.get_table_index("favourites") + local fav_idx = core.get_table_index("favorites") local fav = serverlist[fav_idx] if fav_idx then if fields.key_up and fav_idx > 1 then fav_idx = fav_idx - 1 - elseif fields.key_down and fav_idx < #menudata.favorites then + elseif fields.key_down and fav_idx < #serverlistmgr.servers then fav_idx = fav_idx + 1 end else fav_idx = 1 end - if not menudata.favorites or not fav then - tabdata.fav_selected = 0 + if not serverlistmgr.servers or not fav then + tabdata.selected = 0 return true end @@ -267,27 +265,33 @@ local function main_button_handler(tabview, fields, name, tabdata) core.settings:set("remote_port", port) end - tabdata.fav_selected = fav_idx + tabdata.selected = fav_idx return true end if fields.btn_delete_favorite then - local current_favourite = core.get_table_index("favourites") - if not current_favourite then return end + local current_favorite = core.get_table_index("favorites") + if not current_favorite then return end - core.delete_favorite(current_favourite) - asyncOnlineFavourites(mobile_only) - tabdata.fav_selected = nil + serverlistmgr.delete_favorite(serverlistmgr.servers[current_favorite]) + serverlistmgr.sync() + tabdata.selected = nil return true end + if fields.btn_mp_clear then + tabdata.search_for = "" + menudata.search_result = nil + return true + end + if fields.btn_mp_search or fields.key_enter_field == "te_search" then - tabdata.fav_selected = 1 + tabdata.selected = 1 local input = fields.te_search:lower() tabdata.search_for = fields.te_search - if #menudata.favorites < 2 then + if #serverlistmgr.servers < 2 then return true end @@ -307,8 +311,8 @@ local function main_button_handler(tabview, fields, name, tabdata) -- Search the serverlist local search_result = {} - for i = 1, #menudata.favorites do - local server = menudata.favorites[i] + for i = 1, #serverlistmgr.servers do + local server = serverlistmgr.servers[i] local found = 0 for k = 1, #keywords do local keyword = keywords[k] @@ -325,7 +329,7 @@ local function main_button_handler(tabview, fields, name, tabdata) end end if found > 0 then - local points = (#menudata.favorites - i) / 5 + found + local points = (#serverlistmgr.servers - i) / 5 + found server.points = points table.insert(search_result, server) end @@ -344,13 +348,13 @@ local function main_button_handler(tabview, fields, name, tabdata) end if fields.btn_mp_refresh then - asyncOnlineFavourites(mobile_only) + serverlistmgr.sync() return true end if fields.btn_mp_mobile then mobile_only = not mobile_only - asyncOnlineFavourites(mobile_only) + serverlistmgr.sync() return true end @@ -359,26 +363,32 @@ local function main_button_handler(tabview, fields, name, tabdata) gamedata.playername = fields.te_name gamedata.password = fields.te_pwd gamedata.address = fields.te_address - gamedata.port = fields.te_port + gamedata.port = tonumber(fields.te_port) gamedata.selected_world = 0 - local fav_idx = core.get_table_index("favourites") + local fav_idx = core.get_table_index("favorites") local fav = serverlist[fav_idx] if fav_idx and fav_idx <= #serverlist and - fav.address == fields.te_address and - fav.port == fields.te_port then + fav.address == gamedata.address and + fav.port == gamedata.port then + + serverlistmgr.add_favorite(fav) gamedata.servername = fav.name gamedata.serverdescription = fav.description - if menudata.favorites_is_public and - not is_server_protocol_compat_or_error( + if not is_server_protocol_compat_or_error( fav.proto_min, fav.proto_max) then return true end else gamedata.servername = "" gamedata.serverdescription = "" + + serverlistmgr.add_favorite({ + address = gamedata.address, + port = gamedata.port, + }) end local auto_connect = false @@ -403,7 +413,7 @@ end local function on_change(type, old_tab, new_tab) if type == "LEAVE" then return end - asyncOnlineFavourites(mobile_only) + serverlistmgr.sync() end -------------------------------------------------------------------------------- diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index f2e593457..875f4bff6 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -172,8 +172,8 @@ local function formspec(tabview, name, tabdata) end tab_string = tab_string .. - "button[8,4.75;3.95,1;btn_change_keys;" - .. fgettext("Change Keys") .. "]" + "button[8,4.75;3.95,1;btn_change_keys;" + .. fgettext("Change Keys") .. "]" tab_string = tab_string .. "button[0,4.75;3.95,1;btn_advanced_settings;" diff --git a/builtin/mainmenu/tests/favorites_wellformed.txt b/builtin/mainmenu/tests/favorites_wellformed.txt new file mode 100644 index 000000000..8b87b4398 --- /dev/null +++ b/builtin/mainmenu/tests/favorites_wellformed.txt @@ -0,0 +1,29 @@ +[server] + +127.0.0.1 +30000 + + +[server] + +localhost +30000 + + +[server] + +vps.rubenwardy.com +30001 + + +[server] + +gundul.ddnss.de +39155 + + +[server] +VanessaE's Dreambuilder creative Server +daconcepts.com +30000 +VanessaE's Dreambuilder creative-mode server. Lots of mods, whitelisted buckets. diff --git a/builtin/mainmenu/tests/serverlistmgr_spec.lua b/builtin/mainmenu/tests/serverlistmgr_spec.lua new file mode 100644 index 000000000..148e9b794 --- /dev/null +++ b/builtin/mainmenu/tests/serverlistmgr_spec.lua @@ -0,0 +1,36 @@ +_G.core = {} +_G.unpack = table.unpack +_G.serverlistmgr = {} + +dofile("builtin/common/misc_helpers.lua") +dofile("builtin/mainmenu/serverlistmgr.lua") + +local base = "builtin/mainmenu/tests/" + +describe("legacy favorites", function() + it("loads well-formed correctly", function() + local favs = serverlistmgr.read_legacy_favorites(base .. "favorites_wellformed.txt") + + local expected = { + { + address = "127.0.0.1", + port = 30000, + }, + + { address = "localhost", port = 30000 }, + + { address = "vps.rubenwardy.com", port = 30001 }, + + { address = "gundul.ddnss.de", port = 39155 }, + + { + address = "daconcepts.com", + port = 30000, + name = "VanessaE's Dreambuilder creative Server", + description = "VanessaE's Dreambuilder creative-mode server. Lots of mods, whitelisted buckets." + }, + } + + assert.same(expected, favs) + end) +end) diff --git a/builtin/profiler/instrumentation.lua b/builtin/profiler/instrumentation.lua index 2a18af113..9f4e87f4f 100644 --- a/builtin/profiler/instrumentation.lua +++ b/builtin/profiler/instrumentation.lua @@ -160,6 +160,7 @@ local function init() -- Simple iteration would ignore lookup via __index. local entity_instrumentation = { "on_activate", + "on_deactivate", "on_step", "on_punch", "on_rightclick", diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index f7f017dfd..f800f71ab 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -110,9 +110,9 @@ doubletap_jump (Double tap jump for fly) bool false # enabled. always_fly_fast (Always fly and fast) bool true -# The time in seconds it takes between repeated right clicks when holding the right -# mouse button. -repeat_rightclick_time (Rightclick repetition interval) float 0.25 0.001 +# The time in seconds it takes between repeated node placements when holding +# the place button. +repeat_place_time (Place repetition interval) float 0.25 0.001 # Automatically jump up single-node obstacles. autojump (Automatic jumping) bool false @@ -152,6 +152,9 @@ joystick_type (Joystick type) enum auto auto,generic,xbox # when holding down a joystick button combination. repeat_joystick_button_time (Joystick button repetition interval) float 0.17 0.001 +# The deadzone of the joystick +joystick_deadzone (Joystick deadzone) int 2048 + # The sensitivity of the joystick axes for moving the # ingame view frustum around. joystick_frustum_sensitivity (Joystick frustum sensitivity) float 170 @@ -182,6 +185,14 @@ keymap_jump (Jump key) key KEY_SPACE # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 keymap_sneak (Sneak key) key KEY_LSHIFT +# Key for digging. +# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 +keymap_dig (Dig key) key KEY_LBUTTON + +# Key for placing. +# See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 +keymap_place (Place key) key KEY_RBUTTON + # Key for opening the inventory. # See http://irrlicht.sourceforge.net/docu/namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3 keymap_inventory (Inventory key) key KEY_KEY_I @@ -440,6 +451,10 @@ keymap_decrease_viewing_range_min (View range decrease key) key - [**Basic] +# Whether nametag backgrounds should be shown by default. +# Mods may still set a background. +show_nametag_backgrounds (Show nametag backgrounds by default) bool true + # Enable vertex buffer objects. # This should greatly improve graphics performance. enable_vbo (VBO) bool true @@ -505,8 +520,13 @@ texture_clean_transparent (Clean transparent textures) bool false # texture autoscaling. texture_min_size (Minimum texture size) int 64 -# Experimental option, might cause visible spaces between blocks -# when set to higher number than 0. +# Use multi-sample antialiasing (MSAA) to smooth out block edges. +# This algorithm smooths out the 3D viewport while keeping the image sharp, +# but it doesn't affect the insides of textures +# (which is especially noticeable with transparent textures). +# Visible spaces appear between nodes when shaders are disabled. +# If set to 0, MSAA is disabled. +# A restart is required after changing this option. fsaa (FSAA) enum 0 0,1,2,4,8,16 # Undersampling is similar to using a lower screen resolution, but it applies @@ -573,15 +593,15 @@ arm_inertia (Arm inertia) bool true # to not waste CPU power for no benefit. fps_max (Maximum FPS) int 60 1 -# Maximum FPS when game is paused. -pause_fps_max (FPS in pause menu) int 20 1 +# Maximum FPS when the window is not focused, or when the game is paused. +fps_max_unfocused (FPS when unfocused or paused) int 20 1 # Open the pause menu when the window's focus is lost. Does not pause if a formspec is # open. pause_on_lost_focus (Pause on lost window focus) bool false # View distance in nodes. -viewing_range (Viewing range) int 100 20 4000 +viewing_range (Viewing range) int 190 20 4000 # Camera 'near clipping plane' distance in nodes, between 0 and 0.25 # Only works on GLES platforms. Most users will not need to change this. @@ -704,9 +724,11 @@ selectionbox_color (Selection box color) string (0,0,0) selectionbox_width (Selection box width) int 2 1 5 # Crosshair color (R,G,B). +# Also controls the object crosshair color crosshair_color (Crosshair color) string (255,255,255) # Crosshair alpha (opaqueness, between 0 and 255). +# Also controls the object crosshair color crosshair_alpha (Crosshair alpha) int 255 0 255 # Maximum number of recent chat messages to show @@ -780,7 +802,8 @@ world_aligned_mode (World-aligned textures mode) enum enable disable,enable,forc autoscale_mode (Autoscaling mode) enum disable disable,enable,force # Show entity selection boxes -show_entity_selectionbox (Show entity selection boxes) bool true +# A restart is required after changing this. +show_entity_selectionbox (Show entity selection boxes) bool false [*Menus] @@ -945,7 +968,7 @@ serverlist_url (Serverlist URL) string servers.minetest.net # File in client/serverlist/ that contains your favorite servers displayed in the # Multiplayer Tab. -serverlist_file (Serverlist file) string favoriteservers.txt +serverlist_file (Serverlist file) string favoriteservers.json # Maximum size of the out chat queue. # 0 to disable queueing and -1 to make the queue size unlimited. @@ -962,7 +985,7 @@ client_unload_unused_data_timeout (Mapblock unload timeout) int 600 # Maximum number of mapblocks for client to be kept in memory. # Set to -1 for unlimited amount. -client_mapblock_limit (Mapblock limit) int 5000 +client_mapblock_limit (Mapblock limit) int 7500 # Whether to show the client debug info (has the same effect as hitting F5). show_debug (Show debug info) bool false @@ -1032,6 +1055,13 @@ full_block_send_enable_min_time_from_building (Delay in sending blocks after bui # client number. max_packets_per_iteration (Max. packets per iteration) int 1024 +# ZLib compression level to use when sending mapblocks to the client. +# -1 - Zlib's default compression level +# 0 - no compresson, fastest +# 9 - best compression, slowest +# (levels 1-3 use Zlib's "fast" method, 4-9 use the normal method) +map_compression_level_net (Map Compression Level for Network Transfer) int -1 -1 9 + [*Game] # Default game when creating a new world. @@ -1059,7 +1089,7 @@ default_stack_max (Default stack size) int 99 # Enable players getting damage and dying. enable_damage (Damage) bool false -# Enable creative mode for new created maps. +# Enable creative mode for all players creative_mode (Creative) bool false # A chosen map seed for a new map, leave empty for random. @@ -1121,17 +1151,17 @@ ask_reconnect_on_crash (Ask to reconnect after crash) bool false # Setting this larger than active_block_range will also cause the server # to maintain active objects up to this distance in the direction the # player is looking. (This can avoid mobs suddenly disappearing from view) -active_object_send_range_blocks (Active object send range) int 4 +active_object_send_range_blocks (Active object send range) int 8 # The radius of the volume of blocks around every player that is subject to the # active block stuff, stated in mapblocks (16 nodes). # In active blocks objects are loaded and ABMs run. # This is also the minimum range in which active objects (mobs) are maintained. # This should be configured together with active_object_send_range_blocks. -active_block_range (Active block range) int 3 +active_block_range (Active block range) int 4 # From how far blocks are sent to clients, stated in mapblocks (16 nodes). -max_block_send_distance (Max block send distance) int 10 +max_block_send_distance (Max block send distance) int 12 # Maximum number of forceloaded mapblocks. max_forceloaded_blocks (Maximum forceloaded blocks) int 16 @@ -1204,10 +1234,10 @@ movement_gravity (Gravity) float 9.81 [**Advanced] # Handling for deprecated Lua API calls: -# - legacy: (try to) mimic old behaviour (default for release). -# - log: mimic and log backtrace of deprecated call (default for debug). +# - none: Do not log deprecated calls +# - log: mimic and log backtrace of deprecated call (default). # - error: abort on usage of deprecated call (suggested for mod developers). -deprecated_lua_api_handling (Deprecated Lua API handling) enum legacy legacy,log,error +deprecated_lua_api_handling (Deprecated Lua API handling) enum log none,log,error # Number of extra blocks that can be loaded by /clearobjects at once. # This is a trade-off between sqlite transaction overhead and @@ -1224,6 +1254,13 @@ max_objects_per_block (Maximum objects per block) int 64 # See https://www.sqlite.org/pragma.html#pragma_synchronous sqlite_synchronous (Synchronous SQLite) enum 2 0,1,2 +# ZLib compression level to use when saving mapblocks to disk. +# -1 - Zlib's default compression level +# 0 - no compresson, fastest +# 9 - best compression, slowest +# (levels 1-3 use Zlib's "fast" method, 4-9 use the normal method) +map_compression_level_disk (Map Compression Level for Disk Storage) int 3 -1 9 + # Length of a server tick and the interval at which objects are generally updated over # network. dedicated_server_step (Dedicated server step) float 0.09 @@ -1234,6 +1271,10 @@ active_block_mgmt_interval (Active block management interval) float 2.0 # Length of time between Active Block Modifier (ABM) execution cycles abm_interval (ABM interval) float 1.0 +# The time budget allowed for ABMs to execute on each step +# (as a fraction of the ABM Interval) +abm_time_budget (ABM time budget) float 0.2 0.1 0.9 + # Length of time between NodeTimer execution cycles nodetimer_interval (NodeTimer interval) float 0.2 @@ -1394,12 +1435,6 @@ curl_file_download_timeout (cURL file download timeout) int 300000 # Makes DirectX work with LuaJIT. Disable if it causes troubles. high_precision_fpu (High-precision FPU) bool true -# Changes the main menu UI: -# - Full: Multiple singleplayer worlds, game choice, texture pack chooser, etc. -# - Simple: One singleplayer world, no game or texture pack choosers. May be -# necessary for smaller screens. -main_menu_style (Main menu style) enum full full,simple - # Replaces the default main menu with a custom one. main_menu_script (Main menu script) string @@ -1419,7 +1454,7 @@ mg_name (Mapgen name) enum v7 v7,valleys,carpathian,v5,flat,fractal,singlenode,v water_level (Water level) int 1 # From how far blocks are generated for clients, stated in mapblocks (16 nodes). -max_block_generate_distance (Max block generate distance) int 8 +max_block_generate_distance (Max block generate distance) int 10 # Limit of map generation, in nodes, in all 6 directions from (0, 0, 0). # Only mapchunks completely within the mapgen limit are generated. @@ -1429,7 +1464,7 @@ mapgen_limit (Map generation limit) int 31000 0 31000 # Global map generation attributes. # In Mapgen v6 the 'decorations' flag controls all decorations except trees # and junglegrass, in all other mapgens this flag controls all decorations. -mg_flags (Mapgen flags) flags caves,dungeons,light,decorations,biomes caves,dungeons,light,decorations,biomes,nocaves,nodungeons,nolight,nodecorations,nobiomes +mg_flags (Mapgen flags) flags caves,dungeons,light,decorations,biomes,ores caves,dungeons,light,decorations,biomes,ores,nocaves,nodungeons,nolight,nodecorations,nobiomes,noores [*Biome API temperature and humidity noise parameters] @@ -1820,7 +1855,7 @@ mgcarpathian_np_dungeons (Dungeon noise) noise_params_3d 0.9, 0.5, (500, 500, 50 # Map generation attributes specific to Mapgen Flat. # Occasional lakes and hills can be added to the flat world. -mgflat_spflags (Mapgen Flat specific flags) flags nolakes,nohills lakes,hills,nolakes,nohills +mgflat_spflags (Mapgen Flat specific flags) flags nolakes,nohills,nocaverns lakes,hills,caverns,nolakes,nohills,nocaverns # Y of flat ground. mgflat_ground_level (Ground level) int 8 @@ -1864,6 +1899,15 @@ mgflat_hill_threshold (Hill threshold) float 0.45 # Controls steepness/height of hills. mgflat_hill_steepness (Hill steepness) float 64.0 +# Y-level of cavern upper limit. +mgflat_cavern_limit (Cavern limit) int -256 + +# Y-distance over which caverns expand to full size. +mgflat_cavern_taper (Cavern taper) int 256 + +# Defines full size of caverns, smaller values create larger caverns. +mgflat_cavern_threshold (Cavern threshold) float 0.7 + # Lower Y limit of dungeons. mgflat_dungeon_ymin (Dungeon minimum Y) int -31000 @@ -1884,6 +1928,9 @@ mgflat_np_cave1 (Cave1 noise) noise_params_3d 0, 12, (61, 61, 61), 52534, 3, 0.5 # Second of two 3D noises that together define tunnels. mgflat_np_cave2 (Cave2 noise) noise_params_3d 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0 +# 3D noise defining giant caverns. +mgflat_np_cavern (Cavern noise) noise_params_3d 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0 + # 3D noise that determines number of dungeons per mapchunk. mgflat_np_dungeons (Dungeon noise) noise_params_3d 0.9, 0.5, (500, 500, 500), 0, 2, 0.8, 2.0 @@ -2126,15 +2173,15 @@ chunksize (Chunk size) int 5 enable_mapgen_debug_info (Mapgen debug) bool false # Maximum number of blocks that can be queued for loading. -emergequeue_limit_total (Absolute limit of queued blocks to emerge) int 512 +emergequeue_limit_total (Absolute limit of queued blocks to emerge) int 1024 # Maximum number of blocks to be queued that are to be loaded from file. # This limit is enforced per player. -emergequeue_limit_diskonly (Per-player limit of queued blocks load from disk) int 64 +emergequeue_limit_diskonly (Per-player limit of queued blocks load from disk) int 128 # Maximum number of blocks to be queued that are to be generated. # This limit is enforced per player. -emergequeue_limit_generate (Per-player limit of queued blocks to generate) int 64 +emergequeue_limit_generate (Per-player limit of queued blocks to generate) int 128 # Number of emerge threads to use. # Value 0: @@ -2160,3 +2207,7 @@ contentdb_url (ContentDB URL) string https://content.minetest.net # These flags are independent from Minetest versions, # so see a full list at https://content.minetest.net/help/content_flags/ contentdb_flag_blacklist (ContentDB Flag Blacklist) string nonfree, desktop_default + +# Maximum number of concurrent downloads. Downloads exceeding this limit will be queued. +# This should be lower than curl_parallel_limit. +contentdb_max_concurrent_downloads (ContentDB Max Concurrent Downloads) int 3 diff --git a/client/shaders/nodes_shader/opengl_fragment.glsl b/client/shaders/nodes_shader/opengl_fragment.glsl index a116fabc4..53e006a8c 100644 --- a/client/shaders/nodes_shader/opengl_fragment.glsl +++ b/client/shaders/nodes_shader/opengl_fragment.glsl @@ -15,13 +15,17 @@ varying vec3 vPosition; // precision must be considered). varying vec3 worldPosition; varying lowp vec4 varColor; +#ifdef GL_ES varying mediump vec2 varTexCoord; -varying mediump vec3 eyeVec; // divided by fogDistance +#else +centroid varying vec2 varTexCoord; +#endif +varying vec3 eyeVec; const float fogStart = FOG_START; const float fogShadingParameter = 1.0 / ( 1.0 - fogStart); -#ifdef ENABLE_TONE_MAPPING +#if ENABLE_TONE_MAPPING /* Hable's UC2 Tone mapping parameters A = 0.22; @@ -45,7 +49,7 @@ vec4 applyToneMapping(vec4 color) const float gamma = 1.6; const float exposureBias = 5.5; color.rgb = uncharted2Tonemap(exposureBias * color.rgb); - // Precalculated white_scale from + // Precalculated white_scale from //vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W)); vec3 whiteScale = vec3(1.036015346); color.rgb *= whiteScale; @@ -71,8 +75,8 @@ void main(void) color = base.rgb; vec4 col = vec4(color.rgb * varColor.rgb, 1.0); - -#ifdef ENABLE_TONE_MAPPING + +#if ENABLE_TONE_MAPPING col = applyToneMapping(col); #endif diff --git a/client/shaders/nodes_shader/opengl_vertex.glsl b/client/shaders/nodes_shader/opengl_vertex.glsl index 201d50b2b..0c345667e 100644 --- a/client/shaders/nodes_shader/opengl_vertex.glsl +++ b/client/shaders/nodes_shader/opengl_vertex.glsl @@ -17,8 +17,15 @@ varying vec3 vPosition; // precision must be considered). varying vec3 worldPosition; varying lowp vec4 varColor; +// The centroid keyword ensures that after interpolation the texture coordinates +// lie within the same bounds when MSAA is en- and disabled. +// This fixes the stripes problem with nearest-neighbour textures and MSAA. +#ifdef GL_ES varying mediump vec2 varTexCoord; -varying mediump vec3 eyeVec; +#else +centroid varying vec2 varTexCoord; +#endif +varying vec3 eyeVec; // Color of the light emitted by the light sources. const vec3 artificialLight = vec3(1.04, 1.04, 1.04); @@ -144,7 +151,9 @@ void main(void) color.xyz = color.zyx; // swap RGB order #endif // The alpha gives the ratio of sunlight in the incoming light. - color.rgb *= 2.0 * mix(artificialLight.rgb, dayLight.rgb, color.a); + float nightRatio = 1.0 - inVertexColor.a; + color.rgb = inVertexColor.rgb * (inVertexColor.a * dayLight.rgb + + nightRatio * artificialLight.rgb) * 2.0; color.a = 1.0; // Emphase blue a bit in darker places diff --git a/client/shaders/object_shader/opengl_fragment.glsl b/client/shaders/object_shader/opengl_fragment.glsl index 7ac182a63..9a81d8185 100644 --- a/client/shaders/object_shader/opengl_fragment.glsl +++ b/client/shaders/object_shader/opengl_fragment.glsl @@ -9,7 +9,11 @@ varying vec3 vNormal; varying vec3 vPosition; varying vec3 worldPosition; varying lowp vec4 varColor; +#ifdef GL_ES varying mediump vec2 varTexCoord; +#else +centroid varying vec2 varTexCoord; +#endif varying vec3 eyeVec; varying float vIDiff; @@ -19,7 +23,7 @@ const float BS = 10.0; const float fogStart = FOG_START; const float fogShadingParameter = 1.0 / (1.0 - fogStart); -#ifdef ENABLE_TONE_MAPPING +#if ENABLE_TONE_MAPPING /* Hable's UC2 Tone mapping parameters A = 0.22; @@ -43,7 +47,7 @@ vec4 applyToneMapping(vec4 color) const float gamma = 1.6; const float exposureBias = 5.5; color.rgb = uncharted2Tonemap(exposureBias * color.rgb); - // Precalculated white_scale from + // Precalculated white_scale from //vec3 whiteScale = 1.0 / uncharted2Tonemap(vec3(W)); vec3 whiteScale = vec3(1.036015346); color.rgb *= whiteScale; @@ -75,7 +79,7 @@ void main(void) col.rgb *= emissiveColor.rgb * vIDiff; -#ifdef ENABLE_TONE_MAPPING +#if ENABLE_TONE_MAPPING col = applyToneMapping(col); #endif diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl index e44984dc8..b4a4d0aaa 100644 --- a/client/shaders/object_shader/opengl_vertex.glsl +++ b/client/shaders/object_shader/opengl_vertex.glsl @@ -7,7 +7,11 @@ varying vec3 vNormal; varying vec3 vPosition; varying vec3 worldPosition; varying lowp vec4 varColor; +#ifdef GL_ES varying mediump vec2 varTexCoord; +#else +centroid varying vec2 varTexCoord; +#endif varying vec3 eyeVec; varying float vIDiff; diff --git a/clientmods/preview/init.lua b/clientmods/preview/init.lua index 089955d2f..977ed0ec3 100644 --- a/clientmods/preview/init.lua +++ b/clientmods/preview/init.lua @@ -109,6 +109,10 @@ core.register_on_sending_chat_message(function(message) return false end) +core.register_on_chatcommand(function(command, params) + print("[PREVIEW] caught command '"..command.."'. Parameters: '"..params.."'") +end) + -- This is an example function to ensure it's working properly, should be removed before merge core.register_on_hp_modification(function(hp) print("[PREVIEW] HP modified " .. hp) diff --git a/doc/builtin_entities.txt b/doc/builtin_entities.txt new file mode 100644 index 000000000..be3f73357 --- /dev/null +++ b/doc/builtin_entities.txt @@ -0,0 +1,101 @@ +# Builtin Entities +Minetest registers two entities by default: Falling nodes and dropped items. +This document describes how they behave and what you can do with them. + +## Falling node (`__builtin:falling_node`) + +This entity is created by `minetest.check_for_falling` in place of a node +with the special group `falling_node=1`. Falling nodes can also be created +artificially with `minetest.spawn_falling_node`. + +Needs manual initialization when spawned using `/spawnentity`. + +Default behaviour: + +* Falls down in a straight line (gravity = `movement_gravity` setting) +* Collides with `walkable` node +* Collides with all physical objects except players +* If the node group `float=1` is set, it also collides with liquid nodes +* When it hits a solid (=`walkable`) node, it will try to place itself as a + node, replacing the node above. + * If the falling node cannot replace the destination node, it is dropped. + * If the destination node is a leveled node (`paramtype2="leveled"`) of the + same node name, the levels of both are summed. + +### Entity fields + +* `set_node(self, node[, meta])` + * Function to initialize the falling node + * `node` and `meta` are explained below. + * The `meta` argument is optional. +* `node`: Node table of the node (`name`, `param1`, `param2`) that this + entity represents. Read-only. +* `meta`: Node metadata of the falling node. Will be used when the falling + nodes tries to place itself as a node. Read-only. + +### Rendering / supported nodes + +Falling nodes have visuals to look as close as possible to the original node. +This works for most drawtypes, but there are limitations. + +Supported drawtypes: + +* `normal` +* `signlike` +* `torchlike` +* `nodebox` +* `raillike` +* `glasslike` +* `glasslike_framed` +* `glasslike_framed_optional` +* `allfaces` +* `allfaces_optional` +* `firelike` +* `mesh` +* `fencelike` +* `liquid` +* `airlike` (not pointable) + +Other drawtypes still kinda work, but they might look weird. + +Supported `paramtype2` values: + +* `wallmounted` +* `facedir` +* `colorwallmounted` +* `colorfacedir` +* `color` + +## Dropped item stack (`__builtin:item`) + +This is an item stack in a collectable form. + +Common cases that spawn a dropped item: + +* Item dropped by player +* The root node of a node with the group `attached_node=1` is removed +* `minetest.add_item` is called + +Needs manual initialization when spawned using `/spawnentity`. + +### Behavior + +* Players can collect it by punching +* Lifespan is defined by the setting `item_entity_ttl` +* Slides on `slippery` nodes +* Subject to gravity (uses `movement_gravity` setting) +* Collides with `walkable` nodes +* Does not collide physical objects +* When it's inside a solid (`walkable=true`) node, it tries to escape to a + neighboring non-solid (`walkable=false`) node + +### Entity fields + +* `set_item(self, item)`: + * Function to initialize the dropped item + * `item` (type `ItemStack`) specifies the item to represent +* `age`: Age in seconds. Behaviour according to the setting `item_entity_ttl` +* `itemstring`: Itemstring of the item that this item entity represents. + Read-only. + +Other fields are for internal use only. diff --git a/doc/client_lua_api.txt b/doc/client_lua_api.txt index 462682a3a..ad9fa5e0f 100644 --- a/doc/client_lua_api.txt +++ b/doc/client_lua_api.txt @@ -1,4 +1,4 @@ -Minetest Lua Client Modding API Reference 5.3.0 +Minetest Lua Client Modding API Reference 5.4.0 ================================================ * More information at * Developer Wiki: @@ -620,7 +620,7 @@ Helper functions * `minetest.is_yes(arg)` * returns whether `arg` can be interpreted as yes * `minetest.is_nan(arg)` - * returns true true when the passed number represents NaN. + * returns true when the passed number represents NaN. * `table.copy(table)`: returns a table * returns a deep copy of `table` @@ -686,6 +686,11 @@ Call these functions only at load time! * Adds definition to minetest.registered_chatcommands * `minetest.unregister_chatcommand(name)` * Unregisters a chatcommands registered with register_chatcommand. +* `minetest.register_on_chatcommand(function(command, params))` + * Called always when a chatcommand is triggered, before `minetest.registered_chatcommands` + is checked to see if that the command exists, but after the input is parsed. + * Return `true` to mark the command as handled, which means that the default + handlers will be prevented. * `minetest.register_on_death(function())` * Called when the local player dies * `minetest.register_on_hp_modification(function(hp))` @@ -768,12 +773,15 @@ Call these functions only at load time! * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"` * `search_center` is an optional boolean (default: `false`) If true `pos` is also checked for the nodes -* `minetest.find_nodes_in_area(pos1, pos2, nodenames)`: returns a list of - positions. +* `minetest.find_nodes_in_area(pos1, pos2, nodenames, [grouped])` + * `pos1` and `pos2` are the min and max positions of the area to search. * `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"` - * First return value: Table with all node positions - * Second return value: Table with the count of each node with the node name - as index. + * If `grouped` is true the return value is a table indexed by node name + which contains lists of positions. + * If `grouped` is false or absent the return values are as follows: + first value: Table with all node positions + second value: Table with the count of each node with the node name + as index * Area volume is limited to 4,096,000 nodes * `minetest.find_nodes_in_area_under_air(pos1, pos2, nodenames)`: returns a list of positions. @@ -993,6 +1001,7 @@ Please do not try to access the reference until the camera is initialized, other ### LocalPlayer An interface to retrieve information about the player. +This object will only be available after the client is initialized. Earlier accesses will yield a `nil` value. Methods: @@ -1097,8 +1106,8 @@ Methods: aux1 = boolean, sneak = boolean, zoom = boolean, - LMB = boolean, - RMB = boolean, + dig = boolean, + place = boolean, } ``` diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 39bcd12cd..44ea03c28 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -62,12 +62,12 @@ Where `` is unique to each game. The game directory can contain the following files: * `game.conf`, with the following keys: - * `name`: Required, human readable name e.g. `name = Minetest` + * `name`: Required, a human readable title to address the game, e.g. `name = Minetest`. * `description`: Short description to be shown in the content tab * `allowed_mapgens = ` e.g. `allowed_mapgens = v5,v6,flat` - Mapgens not in this list are removed from the list of mapgens for - the game. + Mapgens not in this list are removed from the list of mapgens for the + game. If not specified, all mapgens are allowed. * `disallowed_mapgens = ` e.g. `disallowed_mapgens = v5,v6,flat` @@ -79,6 +79,10 @@ The game directory can contain the following files: e.g. `disallowed_mapgen_settings = mgv5_spflags` These settings are hidden for this game in the world creation dialog and game start menu. + * `author`: The author of the game. It only appears when downloaded from + ContentDB. + * `release`: Ignore this: Should only ever be set by ContentDB, as it is + an internal ID used to track versions. * `multicraft.conf`: Used to set default settings when running this game. * `settingtypes.txt`: @@ -134,9 +138,15 @@ Mods can be put in a subdirectory, if the parent directory, which otherwise should be a mod, contains a file named `modpack.conf`. The file is a key-value store of modpack details. -* `name`: The modpack name. +* `name`: The modpack name. Allows Minetest to determine the modpack name even + if the folder is wrongly named. * `description`: Description of mod to be shown in the Mods tab of the main menu. +* `author`: The author of the modpack. It only appears when downloaded from + ContentDB. +* `release`: Ignore this: Should only ever be set by ContentDB, as it is an + internal ID used to track versions. +* `title`: A human-readable title to address the modpack. Note: to support 0.4.x, please also create an empty modpack.txt file. @@ -152,7 +162,12 @@ Mod directory structure │   ├── models │   ├── textures │   │   ├── modname_stuff.png - │   │   └── modname_something_else.png + │   │   ├── modname_stuff_normal.png + │   │   ├── modname_something_else.png + │   │   ├── subfolder_foo + │   │   │ ├── modname_more_stuff.png + │   │   │ └── another_subfolder + │   │   └── bar_subfolder │   ├── sounds │   ├── media │   ├── locale @@ -176,6 +191,11 @@ A `Settings` file that provides meta information about the mod. loaded before this mod. * `optional_depends`: A comma separated list of optional dependencies. Like a dependency, but no error if the mod doesn't exist. +* `author`: The author of the mod. It only appears when downloaded from + ContentDB. +* `release`: Ignore this: Should only ever be set by ContentDB, as it is an + internal ID used to track versions. +* `title`: A human-readable title to address the mod. Note: to support 0.4.x, please also provide depends.txt. @@ -221,18 +241,23 @@ registered callbacks. `minetest.settings` can be used to read custom or existing settings at load time, if necessary. (See [`Settings`]) -### `models` - -Models for entities or meshnodes. - -### `textures`, `sounds`, `media` +### `textures`, `sounds`, `media`, `models`, `locale` Media files (textures, sounds, whatever) that will be transferred to the -client and will be available for use by the mod. +client and will be available for use by the mod and translation files for +the clients (see [Translations]). -### `locale` +It is suggested to use the folders for the purpous they are thought for, +eg. put textures into `textures`, translation files into `locale`, +models for entities or meshnodes into `models` et cetera. -Translation files for the clients. (See [Translations]) +These folders and subfolders can contain subfolders. +Subfolders with names starting with `_` or `.` are ignored. +If a subfolder contains a media file with the same name as a media file +in one of its parents, the parent's file is used. + +Although it is discouraged, a mod can overwrite a media file of any mod that it +depends on by supplying a file with an equal name. Naming conventions ------------------ @@ -378,11 +403,14 @@ stripping out the file extension: * e.g. `foomod_foothing.png` * e.g. `foomod_foothing` + Texture modifiers ----------------- There are various texture modifiers that can be used -to generate textures on-the-fly. +to let the client generate textures on-the-fly. +The modifiers are applied directly in sRGB colorspace, +i.e. without gamma-correction. ### Texture overlaying @@ -989,7 +1017,9 @@ The function of `param2` is determined by `paramtype2` in node definition. * `paramtype2 = "flowingliquid"` * Used by `drawtype = "flowingliquid"` and `liquidtype = "flowing"` * The liquid level and a flag of the liquid are stored in `param2` - * Bits 0-2: Liquid level (0-7). The higher, the more liquid is in this node + * Bits 0-2: Liquid level (0-7). The higher, the more liquid is in this node; + see `minetest.get_node_level`, `minetest.set_node_level` and `minetest.add_node_level` + to access/manipulate the content of this field * Bit 3: If set, liquid is flowing downwards (no graphical effect) * `paramtype2 = "wallmounted"` * Supported drawtypes: "torchlike", "signlike", "normal", "nodebox", "mesh" @@ -1220,6 +1250,9 @@ A box of a regular node would look like: {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, +To avoid collision issues, keep each value within the range of +/- 1.45. +This also applies to leveled nodeboxes, where the final height shall not +exceed this soft limit. @@ -1414,7 +1447,32 @@ Same as `image`, but does not accept a `position`; the position is instead deter * `world_pos`: World position of the waypoint. * `offset`: offset in pixels from position. +### `compass` +Displays an image oriented or translated according to current heading direction. + +* `size`: The size of this element. Negative values represent percentage + of the screen; e.g. `x=-100` means 100% (width). +* `scale`: Scale of the translated image (used only for dir = 2 or dir = 3). +* `text`: The name of the texture to use. +* `alignment`: The alignment of the image. +* `offset`: Offset in pixels from position. +* `dir`: How the image is rotated/translated: + * 0 - Rotate as heading direction + * 1 - Rotate in reverse direction + * 2 - Translate as landscape direction + * 3 - Translate in reverse direction + +If translation is chosen, texture is repeated horizontally to fill the whole element. + +### `minimap` + +Displays a minimap on the HUD. + +* `size`: Size of the minimap to display. Minimap should be a square to avoid + distortion. +* `alignment`: The alignment of the minimap. +* `offset`: offset in pixels from position. Representations of simple things ================================ @@ -1690,8 +1748,9 @@ to games. ### `ObjectRef` groups * `immortal`: Skips all damage and breath handling for an object. This group - will also hide the integrated HUD status bars for players, and is - automatically set to all players when damage is disabled on the server. + will also hide the integrated HUD status bars for players. It is + automatically set to all players when damage is disabled on the server and + cannot be reset (subject to change). * `punch_operable`: For entities; disables the regular damage mechanism for players punching it by hand or a non-tool item, so that it can do something else than take damage. @@ -1973,8 +2032,10 @@ Item metadata only contains a key-value store. Some of the values in the key-value store are handled specially: -* `description`: Set the item stack's description. Defaults to - `idef.description`. +* `description`: Set the item stack's description. + See also: `get_description` in [`ItemStack`] +* `short_description`: Set the item stack's short description. + See also: `get_short_description` in [`ItemStack`] * `color`: A `ColorString`, which sets the stack's color. * `palette_index`: If the item has a palette, this is used to get the current color from the palette. @@ -2057,6 +2118,22 @@ Examples list[current_player;craft;3,0;3,3;] list[current_player;craftpreview;7,1;1,1;] +Version History +--------------- + +* FORMSPEC VERSION 1: + * (too much) +* FORMSPEC VERSION 2: + * Forced real coordinates + * background9[]: 9-slice scaling parameters +* FORMSPEC VERSION 3: + * Formspec elements are drawn in the order of definition + * bgcolor[]: use 3 parameters (bgcolor, formspec (now an enum), fbgcolor) + * box[] and image[] elements enable clipping by default + * new element: scroll_container[] +* FORMSPEC VERSION 4: + * Allow dropdown indexing events + Elements -------- @@ -2068,6 +2145,7 @@ Elements * Clients older than this version can neither show newer elements nor display elements with new arguments correctly. * Available since feature `formspec_version_element`. +* See also: [Version History] ### `size[,,]` @@ -2152,7 +2230,8 @@ Elements * Show an inventory list if it has been sent to the client. Nothing will be shown if the inventory list is of size 0. * **Note**: With the new coordinate system, the spacing between inventory - slots is one-fourth the size of an inventory slot. + slots is one-fourth the size of an inventory slot by default. Also see + [Styling Formspecs] for changing the size of slots and spacing. ### `list[;;,;,;]` @@ -2220,6 +2299,21 @@ Elements * `frame duration`: Milliseconds between each frame. `0` means the frames don't advance. * `frame start` (Optional): The index of the frame to start on. Default `1`. +### `model[,;,;;;;;;;]` + +* Show a mesh model. +* `name`: Element name that can be used for styling +* `mesh`: The mesh model to use. +* `textures`: The mesh textures to use according to the mesh materials. + Texture names must be separated by commas. +* `rotation {X,Y}` (Optional): Initial rotation of the camera. + The axes are euler angles in degrees. +* `continuous` (Optional): Whether the rotation is continuous. Default `false`. +* `mouse control` (Optional): Whether the model can be controlled with the mouse. Default `true`. +* `frame loop range` (Optional): Range of the animation frames. + * Defaults to the full range of all available frames. + * Syntax: `,` + ### `item_image[,;,;]` * Show an inventory image of registered item/node @@ -2442,8 +2536,10 @@ Elements * Simple colored box * `color` is color specified as a `ColorString`. If the alpha component is left blank, the box will be semitransparent. + If the color is not specified, the box will use the options specified by + its style. If the color is specified, all styling options will be ignored. -### `dropdown[,;;;,, ...,;]` +### `dropdown[,;;;,, ...,;;]` * Show a dropdown field * **Important note**: There are two different operation modes: @@ -2454,8 +2550,12 @@ Elements * Fieldname data is transferred to Lua * Items to be shown in dropdown * Index of currently selected dropdown item +* `index event` (optional, allowed parameter since formspec version 4): Specifies the + event field value for selected items. + * `true`: Selected item index + * `false` (default): Selected item value -### `dropdown[,;,;;,, ...,;]` +### `dropdown[,;,;;,, ...,;;]` * Show a dropdown field * **Important note**: This syntax for dropdowns can only be used with the @@ -2468,6 +2568,10 @@ Elements * Fieldname data is transferred to Lua * Items to be shown in dropdown * Index of currently selected dropdown item +* `index event` (optional, allowed parameter since formspec version 4): Specifies the + event field value for selected items. + * `true`: Selected item index + * `false` (default): Selected item value ### `checkbox[,;;