diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 44ec35cc..6c2214ef 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -347,6 +347,10 @@ function core.item_place(itemstack, placer, pointed_thing, param2) return itemstack end +function core.item_secondary_use(itemstack, placer) + return itemstack +end + function core.item_drop(itemstack, dropper, pos) if dropper and dropper:is_player() then local v = dropper:get_look_dir() @@ -605,6 +609,7 @@ core.craftitemdef_default = { -- Interaction callbacks on_place = redef_wrapper(core, 'item_place'), -- core.item_place on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop + on_secondary_use = redef_wrapper(core, 'item_secondary_use'), on_use = nil, } @@ -622,6 +627,7 @@ core.tooldef_default = { -- Interaction callbacks on_place = redef_wrapper(core, 'item_place'), -- core.item_place + on_secondary_use = redef_wrapper(core, 'item_secondary_use'), on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop on_use = nil, } @@ -640,6 +646,7 @@ core.noneitemdef_default = { -- This is used for the hand and unknown items -- Interaction callbacks on_place = redef_wrapper(core, 'item_place'), + on_secondary_use = redef_wrapper(core, 'item_secondary_use'), on_drop = nil, on_use = nil, } diff --git a/builtin/game/register.lua b/builtin/game/register.lua index 00bb2327..992fdf74 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -272,6 +272,7 @@ core.register_item(":unknown", { description = "Unknown Item", inventory_image = "unknown_item.png", on_place = core.item_place, + on_secondary_use = core.item_secondary_use, on_drop = core.item_drop, groups = {not_in_creative_inventory=1}, diggable = true, diff --git a/cmake/Modules/FindLua.cmake b/cmake/Modules/FindLua.cmake deleted file mode 100644 index 479dfcf4..00000000 --- a/cmake/Modules/FindLua.cmake +++ /dev/null @@ -1,25 +0,0 @@ - -option(ENABLE_LUAJIT "Enable LuaJIT support" TRUE) -mark_as_advanced(LUA_LIBRARY LUA_INCLUDE_DIR) -set(USE_LUAJIT FALSE) - -if(ENABLE_LUAJIT) - find_library(LUA_LIBRARY luajit - NAMES luajit-5.1) - find_path(LUA_INCLUDE_DIR luajit.h - NAMES luajit.h - PATH_SUFFIXES luajit-2.0) - if(LUA_LIBRARY AND LUA_INCLUDE_DIR) - set(USE_LUAJIT TRUE) - endif() -else() - message (STATUS "LuaJIT detection disabled! (ENABLE_LUAJIT=0)") -endif() - -if(NOT USE_LUAJIT) - message(STATUS "LuaJIT not found, using bundled Lua.") - set(LUA_LIBRARY "lua") - set(LUA_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lua/src") - add_subdirectory(lua) -endif() - diff --git a/cmake/Modules/FindLuaJIT.cmake b/cmake/Modules/FindLuaJIT.cmake new file mode 100644 index 00000000..e4335d83 --- /dev/null +++ b/cmake/Modules/FindLuaJIT.cmake @@ -0,0 +1,50 @@ +# Locate LuaJIT library +# This module defines +# LUAJIT_FOUND, if false, do not try to link to Lua +# LUA_INCLUDE_DIR, where to find lua.h +# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) +# +# This module is similar to FindLua51.cmake except that it finds LuaJit instead. + +FIND_PATH(LUA_INCLUDE_DIR luajit.h + HINTS + $ENV{LUA_DIR} + PATH_SUFFIXES include/luajit-2.0 include/luajit-5_1-2.0 include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +FIND_LIBRARY(LUA_LIBRARY + NAMES luajit-5.1 + HINTS + $ENV{LUA_DIR} + PATH_SUFFIXES lib64 lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw + /opt/local + /opt/csw + /opt +) + +IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/luajit.h") + FILE(STRINGS "${LUA_INCLUDE_DIR}/luajit.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"LuaJIT .+\"") + + STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"LuaJIT ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}") + UNSET(lua_version_str) +ENDIF() + +INCLUDE(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LUAJIT_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaJit + REQUIRED_VARS LUA_LIBRARY LUA_INCLUDE_DIR + VERSION_VAR LUA_VERSION_STRING) + +MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARY LUA_MATH_LIBRARY) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 1dbf6d6f..f09b9e22 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -763,7 +763,7 @@ Creates veins of ore varying in density by according to the intersection of two instances of 3d perlin noise with diffferent seeds, both described by `noise_params`. `random_factor` varies the influence random chance has on placement of an ore inside the vein, which is `1` by default. Note that -modifying this parameter may require adjusting `noise_threshhold`. +modifying this parameter may require adjusting `noise_threshold`. The parameters `clust_scarcity`, `clust_num_ores`, and `clust_size` are ignored by this ore type. This ore type is difficult to control since it is sensitive to small changes. The following is a decent set of parameters to work from: @@ -777,7 +777,7 @@ to small changes. The following is a decent set of parameters to work from: persist = 0.5, flags = "eased", }, - noise_threshhold = 1.6 + noise_threshold = 1.6 WARNING: Use this ore type *very* sparingly since it is ~200x more computationally expensive than any other ore. @@ -1921,7 +1921,11 @@ Call these functions only at load time! * Should be called by the authentication handler if privileges changes. * To report everybody, set `name=nil`. * `minetest.get_password_hash(name, raw_password)` - * Convert a name-password pair to a password hash that Minetest can use + * Convert a name-password pair to a password hash that Minetest can use. + * The returned value alone is not a good basis for password checks based + * on comparing the password hash in the database with the password hash + * from the function, with an externally provided password, as the hash + * in the db might use the new SRP verifier format. * `minetest.string_to_privs(str)`: returns `{priv1=true,...}` * `minetest.privs_to_string(privs)`: returns `"priv1,priv2,..."` * Convert between two privilege representations @@ -3303,6 +3307,11 @@ Definition tables --[[ ^ Shall place item and return the leftover itemstack ^ default: minetest.item_place ]] + on_secondary_use = func(itemstack, user, pointed_thing), + --[[ + ^ Same as on_place but called when pointing at nothing. + ^ pointed_thing : always { type = "nothing" } + ]] on_drop = func(itemstack, dropper, pos), --[[ ^ Shall drop item and return the leftover itemstack @@ -3563,7 +3572,7 @@ Definition tables y_max = 64, flags = "", -- ^ Attributes for this ore generation - noise_threshhold = 0.5, + noise_threshold = 0.5, -- ^ If noise is above this threshold, ore is placed. Not needed for a uniform distribution noise_params = {offset=0, scale=1, spread={x=100, y=100, z=100}, seed=23, octaves=3, persist=0.70} -- ^ NoiseParams structure describing the perlin noise used for ore distribution. @@ -3578,6 +3587,51 @@ Definition tables -- ^ Can be a list of (or a single) biome names, IDs, or definitions. } +### Biome definition (`register_biome`) + + { + name = "tundra", + node_dust = "default:snow", + -- ^ Node dropped onto upper surface after all else is generated. + node_top = "default:dirt_with_snow", + depth_top = 1, + -- ^ Node forming surface layer of biome and thickness of this layer. + node_filler = "default:permafrost", + depth_filler = 3, + -- ^ Node forming lower layer of biome and thickness of this layer. + node_stone = "default:bluestone", + -- ^ Node that replaces all stone nodes between roughly y_min and y_max. + node_water_top = "default:ice", + depth_water_top = 10, + -- ^ Node forming a surface layer in seawater with the defined thickness. + node_water = "", + -- ^ Node that replaces all seawater nodes not in the defined surface layer. + node_river_water = "default:ice", + -- ^ Node that replaces river water in mapgens that use default:river_water. + y_min = 1, + y_max = 31000, + -- ^ Lower and upper limits for biome. + -- ^ Because biome is not recalculated for every node in a node column + -- ^ some biome materials can exceed their limits, especially stone. + -- ^ For each node column in a mapchunk, biome is only recalculated at column + -- ^ top and at each of these surfaces: + -- ^ Ground below air, water below air, ground below water. + -- ^ The selected biome then stays in effect for all nodes below until + -- ^ column base or the next biome recalculation. + heat_point = 0, + humidity_point = 50, + -- ^ Characteristic average temperature and humidity for the biome. + -- ^ These values create 'biome points' on a voronoi diagram that has heat + -- ^ and humidity as axes. The resulting voronoi cells determine which + -- ^ heat/humidity points belong to which biome, and therefore determine + -- ^ the area and location of each biome in the world. + -- ^ The biome points need to be carefully and evenly spaced on the voronoi + -- ^ diagram to result in roughly equal size biomes. + -- ^ Heat and humidity have average values of 50, vary mostly between + -- ^ 0 and 100 but also often exceed these values. + -- ^ Heat is not in degrees celcius, both values are abstract. + } + ### Decoration definition (`register_decoration`) { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dfbd2f5d..6256a850 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -155,8 +155,23 @@ if(ENABLE_FREETYPE) endif() endif(ENABLE_FREETYPE) - -find_package(Lua REQUIRED) +# LuaJIT +option(ENABLE_LUAJIT "Enable LuaJIT support" TRUE) +set(USE_LUAJIT FALSE) +if(ENABLE_LUAJIT) + find_package(LuaJIT) + if(LUAJIT_FOUND) + set(USE_LUAJIT TRUE) + endif(LUAJIT_FOUND) +else() + message (STATUS "LuaJIT detection disabled! (ENABLE_LUAJIT=0)") +endif() +if(NOT USE_LUAJIT) + message(STATUS "LuaJIT not found, using bundled Lua.") + set(LUA_LIBRARY "lua") + set(LUA_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/lua/src") + add_subdirectory(lua) +endif() find_package(GMP REQUIRED) diff --git a/src/cguittfont/CMakeLists.txt b/src/cguittfont/CMakeLists.txt index 7717a2f9..6cd35f31 100644 --- a/src/cguittfont/CMakeLists.txt +++ b/src/cguittfont/CMakeLists.txt @@ -2,7 +2,7 @@ # Do not add CGUITTFont.cpp to the line below. # xCGUITTFont.cpp is a wrapper file that includes # additional required headers. -add_library(cguittfont xCGUITTFont.cpp) +add_library(cguittfont STATIC xCGUITTFont.cpp) if(FREETYPE_PKGCONFIG_FOUND) set_target_properties(cguittfont diff --git a/src/client.cpp b/src/client.cpp index cb6a1154..f92de640 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -946,6 +946,7 @@ void Client::interact(u8 action, const PointedThing& pointed) 2: digging completed 3: place block or item (to abovesurface) 4: use item + 5: perform secondary action of item */ NetworkPacket pkt(TOSERVER_INTERACT, 1 + 2 + 0); diff --git a/src/dungeongen.cpp b/src/dungeongen.cpp index 7ffdd1c1..047a0812 100644 --- a/src/dungeongen.cpp +++ b/src/dungeongen.cpp @@ -65,6 +65,9 @@ DungeonGen::DungeonGen(Mapgen *mapgen, DungeonParams *dparams) dp.np_wetness = nparams_dungeon_wetness; dp.np_density = nparams_dungeon_density; } + + // For mapgens using river water + dp.c_river_water = mg->ndef->getId("mapgen_river_water_source"); } @@ -87,7 +90,7 @@ void DungeonGen::generate(u32 bseed, v3s16 nmin, v3s16 nmax) u32 i = vm->m_area.index(nmin.X, y, z); for (s16 x = nmin.X; x <= nmax.X; x++) { content_t c = vm->m_data[i].getContent(); - if (c == CONTENT_AIR || c == dp.c_water) + if (c == CONTENT_AIR || c == dp.c_water || c == dp.c_river_water) vm->m_flags[i] |= VMANIP_FLAG_DUNGEON_PRESERVE; i++; } @@ -389,7 +392,8 @@ void DungeonGen::makeCorridor(v3s16 doorplace, v3s16 doordir, if (partcount != 0) p.Y += make_stairs; - if (vm->m_area.contains(p) && vm->m_area.contains(p + v3s16(0, 1, 0))) { + if (vm->m_area.contains(p) && vm->m_area.contains(p + v3s16(0, 1, 0)) && + vm->m_area.contains(v3s16(p.X - dir.X, p.Y - 1, p.Z - dir.Z))) { if (make_stairs) { makeFill(p + v3s16(-1, -1, -1), dp.holesize + v3s16(2, 3, 2), diff --git a/src/dungeongen.h b/src/dungeongen.h index ffeb7354..fa28331b 100644 --- a/src/dungeongen.h +++ b/src/dungeongen.h @@ -40,6 +40,7 @@ int dir_to_facedir(v3s16 d); struct DungeonParams { content_t c_water; + content_t c_river_water; content_t c_cobble; content_t c_moss; content_t c_stair; diff --git a/src/game.cpp b/src/game.cpp index 8aac70bd..6e4eb9af 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1536,6 +1536,7 @@ protected: void processPlayerInteraction(std::vector &highlight_boxes, GameRunData *runData, f32 dtime, bool show_hud, bool show_debug); + void handlePointingAtNothing(GameRunData *runData, const ItemStack &playerItem); void handlePointingAtNode(GameRunData *runData, const PointedThing &pointed, const ItemDefinition &playeritem_def, const ToolCapabilities &playeritem_toolcap, f32 dtime); @@ -3621,6 +3622,8 @@ void Game::processPlayerInteraction(std::vector &highlight_boxes, } else if (input->getLeftState()) { // When button is held down in air, show continuous animation runData->left_punch = true; + } else if (input->getRightClicked()) { + handlePointingAtNothing(runData, playeritem); } runData->pointed_old = pointed; @@ -3636,6 +3639,15 @@ void Game::processPlayerInteraction(std::vector &highlight_boxes, } +void Game::handlePointingAtNothing(GameRunData *runData, const ItemStack &playerItem) +{ + infostream << "Right Clicked in Air" << std::endl; + PointedThing fauxPointed; + fauxPointed.type = POINTEDTHING_NOTHING; + client->interact(5, fauxPointed); +} + + void Game::handlePointingAtNode(GameRunData *runData, const PointedThing &pointed, const ItemDefinition &playeritem_def, const ToolCapabilities &playeritem_toolcap, f32 dtime) diff --git a/src/mapgen_flat.cpp b/src/mapgen_flat.cpp index 1b41d0ac..c961d755 100644 --- a/src/mapgen_flat.cpp +++ b/src/mapgen_flat.cpp @@ -148,8 +148,8 @@ MapgenFlatParams::MapgenFlatParams() np_terrain = NoiseParams(0, 1, v3f(600, 600, 600), 7244, 5, 0.6, 2.0); np_filler_depth = NoiseParams(0, 1.2, v3f(150, 150, 150), 261, 3, 0.7, 2.0); - np_cave1 = NoiseParams(0, 12, v3f(128, 128, 128), 52534, 4, 0.5, 2.0); - np_cave2 = NoiseParams(0, 12, v3f(128, 128, 128), 10325, 4, 0.5, 2.0); + np_cave1 = NoiseParams(0, 12, v3f(96, 96, 96), 52534, 4, 0.5, 2.0); + np_cave2 = NoiseParams(0, 12, v3f(96, 96, 96), 10325, 4, 0.5, 2.0); } @@ -559,7 +559,7 @@ void MapgenFlat::generateCaves(s16 max_stone_y) for (s16 x = node_min.X; x <= node_max.X; x++, vi++, index++) { float d1 = contour(noise_cave1->result[index]); float d2 = contour(noise_cave2->result[index]); - if (d1 * d2 > 0.4f) { + if (d1 * d2 > 0.3f) { content_t c = vm->m_data[vi].getContent(); if (!ndef->get(c).is_ground_content || c == CONTENT_AIR) continue; @@ -574,7 +574,7 @@ void MapgenFlat::generateCaves(s16 max_stone_y) return; PseudoRandom ps(blockseed + 21343); - u32 bruises_count = (ps.range(1, 4) == 1) ? ps.range(1, 2) : 0; + u32 bruises_count = ps.range(0, 2); for (u32 i = 0; i < bruises_count; i++) { CaveV5 cave(this, &ps); cave.makeCave(node_min, node_max, max_stone_y); diff --git a/src/mapgen_fractal.cpp b/src/mapgen_fractal.cpp index eff280c7..ca0d58aa 100644 --- a/src/mapgen_fractal.cpp +++ b/src/mapgen_fractal.cpp @@ -154,8 +154,8 @@ MapgenFractalParams::MapgenFractalParams() np_seabed = NoiseParams(-14, 9, v3f(600, 600, 600), 41900, 5, 0.6, 2.0); np_filler_depth = NoiseParams(0, 1.2, v3f(150, 150, 150), 261, 3, 0.7, 2.0); - np_cave1 = NoiseParams(0, 12, v3f(128, 128, 128), 52534, 4, 0.5, 2.0); - np_cave2 = NoiseParams(0, 12, v3f(128, 128, 128), 10325, 4, 0.5, 2.0); + np_cave1 = NoiseParams(0, 12, v3f(96, 96, 96), 52534, 4, 0.5, 2.0); + np_cave2 = NoiseParams(0, 12, v3f(96, 96, 96), 10325, 4, 0.5, 2.0); } @@ -624,7 +624,7 @@ void MapgenFractal::generateCaves(s16 max_stone_y) for (s16 x = node_min.X; x <= node_max.X; x++, vi++, index++) { float d1 = contour(noise_cave1->result[index]); float d2 = contour(noise_cave2->result[index]); - if (d1 * d2 > 0.4f) { + if (d1 * d2 > 0.3f) { content_t c = vm->m_data[vi].getContent(); if (!ndef->get(c).is_ground_content || c == CONTENT_AIR) continue; @@ -639,7 +639,7 @@ void MapgenFractal::generateCaves(s16 max_stone_y) return; PseudoRandom ps(blockseed + 21343); - u32 bruises_count = (ps.range(1, 4) == 1) ? ps.range(1, 2) : 0; + u32 bruises_count = ps.range(0, 2); for (u32 i = 0; i < bruises_count; i++) { CaveV5 cave(this, &ps); cave.makeCave(node_min, node_max, max_stone_y); diff --git a/src/mapgen_v5.cpp b/src/mapgen_v5.cpp index 12099dc2..0465e81c 100644 --- a/src/mapgen_v5.cpp +++ b/src/mapgen_v5.cpp @@ -518,7 +518,7 @@ void MapgenV5::generateCaves(int max_stone_y) for (s16 x = node_min.X; x <= node_max.X; x++, i++, index++) { float d1 = contour(noise_cave1->result[index]); float d2 = contour(noise_cave2->result[index]); - if (d1*d2 > 0.125) { + if (d1 * d2 > 0.125f) { content_t c = vm->m_data[i].getContent(); if (!ndef->get(c).is_ground_content || c == CONTENT_AIR) continue; @@ -533,7 +533,7 @@ void MapgenV5::generateCaves(int max_stone_y) return; PseudoRandom ps(blockseed + 21343); - u32 bruises_count = (ps.range(1, 4) == 1) ? ps.range(1, 2) : 0; + u32 bruises_count = ps.range(0, 2); for (u32 i = 0; i < bruises_count; i++) { CaveV5 cave(this, &ps); cave.makeCave(node_min, node_max, max_stone_y); diff --git a/src/mapgen_v7.cpp b/src/mapgen_v7.cpp index a5280428..6f49e113 100644 --- a/src/mapgen_v7.cpp +++ b/src/mapgen_v7.cpp @@ -157,8 +157,8 @@ MapgenV7Params::MapgenV7Params() np_ridge_uwater = NoiseParams(0, 1, v3f(1000, 1000, 1000), 85039, 5, 0.6, 2.0); np_mountain = NoiseParams(-0.6, 1, v3f(250, 350, 250), 5333, 5, 0.63, 2.0); np_ridge = NoiseParams(0, 1, v3f(100, 100, 100), 6467, 4, 0.75, 2.0); - np_cave1 = NoiseParams(0, 12, v3f(100, 100, 100), 52534, 4, 0.5, 2.0); - np_cave2 = NoiseParams(0, 12, v3f(100, 100, 100), 10325, 4, 0.5, 2.0); + np_cave1 = NoiseParams(0, 12, v3f(96, 96, 96), 52534, 4, 0.5, 2.0); + np_cave2 = NoiseParams(0, 12, v3f(96, 96, 96), 10325, 4, 0.5, 2.0); } @@ -870,7 +870,7 @@ void MapgenV7::generateCaves(s16 max_stone_y) for (s16 x = node_min.X; x <= node_max.X; x++, i++, index++) { float d1 = contour(noise_cave1->result[index]); float d2 = contour(noise_cave2->result[index]); - if (d1 * d2 > 0.3) { + if (d1 * d2 > 0.3f) { content_t c = vm->m_data[i].getContent(); if (!ndef->get(c).is_ground_content || c == CONTENT_AIR) continue; @@ -882,7 +882,7 @@ void MapgenV7::generateCaves(s16 max_stone_y) } PseudoRandom ps(blockseed + 21343); - u32 bruises_count = (ps.range(1, 4) == 1) ? ps.range(1, 2) : 0; + u32 bruises_count = ps.range(0, 2); for (u32 i = 0; i < bruises_count; i++) { CaveV7 cave(this, &ps); cave.makeCave(node_min, node_max, max_stone_y); diff --git a/src/mg_ore.h b/src/mg_ore.h index ff8387dc..59ad633f 100644 --- a/src/mg_ore.h +++ b/src/mg_ore.h @@ -61,7 +61,7 @@ public: s16 y_max; u8 ore_param2; // to set node-specific attributes u32 flags; // attributes for this ore - float nthresh; // threshhold for noise at which an ore is placed + float nthresh; // threshold for noise at which an ore is placed NoiseParams np; // noise for distribution of clusters (NULL for uniform scattering) Noise *noise; std::set biomes; diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index af203b8b..7e0591e3 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -1653,6 +1653,23 @@ void Server::handleCommand_Interact(NetworkPacket* pkt) } } // action == 4 + + /* + 5: rightclick air + */ + else if (action == 5) { + ItemStack item = playersao->getWieldedItem(); + + actionstream << player->getName() << " activates " + << item.name << std::endl; + + if (m_script->item_OnSecondaryUse( + item, playersao)) { + if( playersao->setWieldedItem(item)) { + SendInventory(playersao); + } + } + } /* diff --git a/src/noise.cpp b/src/noise.cpp index b1b70253..2ddc3926 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -99,17 +99,17 @@ u32 PcgRandom::range(u32 bound) Using rand() % 3, the number 0 would be twice as likely to appear. With a very large RNG range, the effect becomes less prevalent but still present. This can be solved by modifying the range of the RNG - to become a multiple of bound by dropping values above the a threshhold. - In our example, threshhold == 4 - 3 = 1 % 3 == 1, so reject 0, thus + to become a multiple of bound by dropping values above the a threshold. + In our example, threshold == 4 - 3 = 1 % 3 == 1, so reject 0, thus making the range 3 with no bias. This loop looks dangerous, but will always terminate due to the RNG's property of uniformity. */ - u32 threshhold = -bound % bound; + u32 threshold = -bound % bound; u32 r; - while ((r = next()) < threshhold) + while ((r = next()) < threshold) ; return r % bound; diff --git a/src/script/cpp_api/s_item.cpp b/src/script/cpp_api/s_item.cpp index f6e1858f..03c8f296 100644 --- a/src/script/cpp_api/s_item.cpp +++ b/src/script/cpp_api/s_item.cpp @@ -110,6 +110,32 @@ bool ScriptApiItem::item_OnUse(ItemStack &item, return true; } +bool ScriptApiItem::item_OnSecondaryUse(ItemStack &item, ServerActiveObject *user) +{ + SCRIPTAPI_PRECHECKHEADER + + int error_handler = PUSH_ERROR_HANDLER(L); + + if (!getItemCallback(item.name.c_str(), "on_secondary_use")) + return false; + + LuaItemStack::create(L, item); + objectrefGetOrCreate(L, user); + PointedThing pointed; + pointed.type = POINTEDTHING_NOTHING; + pushPointedThing(pointed); + PCALL_RES(lua_pcall(L, 3, 1, error_handler)); + if (!lua_isnil(L, -1)) { + try { + item = read_item(L, -1, getServer()); + } catch (LuaError &e) { + throw LuaError(std::string(e.what()) + ". item=" + item.name); + } + } + lua_pop(L, 2); // Pop item and error handler + return true; +} + bool ScriptApiItem::item_OnCraft(ItemStack &item, ServerActiveObject *user, const InventoryList *old_craft_grid, const InventoryLocation &craft_inv) { diff --git a/src/script/cpp_api/s_item.h b/src/script/cpp_api/s_item.h index 61d73a18..43512361 100644 --- a/src/script/cpp_api/s_item.h +++ b/src/script/cpp_api/s_item.h @@ -42,6 +42,8 @@ public: ServerActiveObject *placer, const PointedThing &pointed); bool item_OnUse(ItemStack &item, ServerActiveObject *user, const PointedThing &pointed); + bool item_OnSecondaryUse(ItemStack &item, + ServerActiveObject *user); bool item_OnCraft(ItemStack &item, ServerActiveObject *user, const InventoryList *old_craft_grid, const InventoryLocation &craft_inv); bool item_CraftPredict(ItemStack &item, ServerActiveObject *user, diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 932fadea..c0da0e06 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -944,10 +944,19 @@ int ModApiMapgen::l_register_ore(lua_State *L) ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 1); ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 1); ore->clust_size = getintfield_default(L, index, "clust_size", 0); - ore->nthresh = getfloatfield_default(L, index, "noise_threshhold", 0); ore->noise = NULL; ore->flags = 0; + //// Get noise_threshold + warn_if_field_exists(L, index, "noise_threshhold", + "Deprecated: new name is \"noise_threshold\"."); + + int nthresh; + if (!getintfield(L, index, "noise_threshold", nthresh) && + !getintfield(L, index, "noise_threshhold", nthresh)) + nthresh = 0; + ore->nthresh = nthresh; + //// Get y_min/y_max warn_if_field_exists(L, index, "height_min", "Deprecated: new name is \"y_min\"."); diff --git a/src/sound_openal.cpp b/src/sound_openal.cpp index 17e44d82..d6f67474 100644 --- a/src/sound_openal.cpp +++ b/src/sound_openal.cpp @@ -269,7 +269,6 @@ private: OnDemandSoundFetcher *m_fetcher; ALCdevice *m_device; ALCcontext *m_context; - bool m_can_vorbis; int m_next_id; std::map > m_buffers; std::map m_sounds_playing; @@ -280,7 +279,6 @@ public: m_fetcher(fetcher), m_device(NULL), m_context(NULL), - m_can_vorbis(false), m_next_id(1), m_is_initialized(false) { @@ -295,14 +293,6 @@ public: return; } - if(alcIsExtensionPresent(m_device, "EXT_vorbis")){ - infostream<<"Audio: Vorbis extension present"<