forked from VoxeLibre/VoxeLibre
Compare commits
15 Commits
89f8fdc8cb
...
59e7611eda
Author | SHA1 | Date |
---|---|---|
teknomunk | 59e7611eda | |
teknomunk | 7d5b276bd8 | |
teknomunk | c7bfc7a20e | |
teknomunk | 90268a1854 | |
teknomunk | 01972af586 | |
teknomunk | 0973d7e806 | |
teknomunk | fb7fa1b473 | |
teknomunk | aa073247b3 | |
teknomunk | 426af2eb5f | |
the-real-herowl | 32b334322b | |
grorp | 88c3c4558b | |
grorp | 3954acdfb7 | |
grorp | 02b354f54a | |
grorp | cb624fe1d9 | |
grorp | bd9ab16762 |
|
@ -309,6 +309,31 @@ function mcl_autogroup.get_wear(toolname, diggroup)
|
|||
return math.ceil(65535 / uses)
|
||||
end
|
||||
|
||||
local GROUP_MAP = {
|
||||
["choppy"] = "axey",
|
||||
["oddly_breakable_by_hand"] = "handy",
|
||||
["cracky"] = "pickaxey",
|
||||
["crumbly"] = "shovely",
|
||||
["snappy"] = "shearsy",
|
||||
}
|
||||
|
||||
function mcl_autogroup.group_compatibility(groups)
|
||||
local grouped = false
|
||||
for name,old_group_value in pairs(groups) do
|
||||
local new_group = GROUP_MAP[name]
|
||||
if new_group then
|
||||
groups[new_group] = old_group_value
|
||||
end
|
||||
if mcl_autogroup.registered_diggroups[name] then
|
||||
grouped = true
|
||||
end
|
||||
end
|
||||
|
||||
if not grouped then
|
||||
groups.handy = 1
|
||||
end
|
||||
end
|
||||
|
||||
local function overwrite()
|
||||
-- Refresh, now that all groups are known.
|
||||
hardness_values = get_hardness_values_for_groups()
|
||||
|
@ -317,8 +342,22 @@ local function overwrite()
|
|||
-- hardness_value. Used for quick lookup.
|
||||
local hardness_lookup = get_hardness_lookup_for_groups(hardness_values)
|
||||
|
||||
local count = 0
|
||||
for nname, ndef in pairs(minetest.registered_nodes) do
|
||||
count = count + 1
|
||||
local newgroups = table.copy(ndef.groups)
|
||||
|
||||
if not newgroups.unbreakable and not newgroups.indestructible then
|
||||
ndef.diggable = true
|
||||
mcl_autogroup.group_compatibility(newgroups)
|
||||
if not ndef._mcl_hardness then
|
||||
ndef._mcl_hardness = 0
|
||||
end
|
||||
end
|
||||
|
||||
-- Make sure compatibility groups are present for the below logic
|
||||
ndef.groups = newgroups
|
||||
|
||||
if (nname ~= "ignore" and ndef.diggable) then
|
||||
-- Automatically assign the "solid" group for solid nodes
|
||||
if (ndef.walkable == nil or ndef.walkable == true)
|
||||
|
@ -363,6 +402,7 @@ local function overwrite()
|
|||
})
|
||||
end
|
||||
end
|
||||
minetest.log("verbose","Total registered nodes: "..count)
|
||||
|
||||
for tname, tdef in pairs(minetest.registered_items) do
|
||||
-- Assign groupcaps for digging the registered digging groups
|
||||
|
|
|
@ -1,28 +1,34 @@
|
|||
# mcl_autogroup
|
||||
# `mcl_autogroup`
|
||||
This mod emulates digging times from MC.
|
||||
|
||||
## mcl_autogroup.can_harvest(nodename, toolname, player)
|
||||
Return true if `nodename` can be dig with `toolname` by <player>.
|
||||
* nodename: string, valid nodename
|
||||
* toolname: (optional) string, valid toolname
|
||||
* player: (optinal) ObjectRef, valid player
|
||||
## `mcl_autogroup.can_harvest(nodename, toolname, player)`
|
||||
Return true if `nodename` can be dug with `toolname` by `player`.
|
||||
|
||||
## mcl_autogroup.get_groupcaps(toolname, efficiency)
|
||||
* `nodename`: string, valid nodename
|
||||
* `toolname`: (optional) string, valid toolname
|
||||
* `player`: (optinal) ObjectRef, valid player
|
||||
|
||||
## `mcl_autogroup.get_groupcaps(toolname, efficiency)`
|
||||
This function is used to calculate diggroups for tools.
|
||||
WARNING: This function can only be called after mod initialization.
|
||||
* toolname: string, name of the tool being enchanted (like "mcl_tools:diamond_pickaxe")
|
||||
* efficiency: (optional) integer, the efficiency level the tool is enchanted with (default 0)
|
||||
* `toolname`: string, name of the tool being enchanted (like `"mcl_tools:diamond_pickaxe"`)
|
||||
* `efficiency`: (optional) integer, the efficiency level the tool is enchanted with (default 0)
|
||||
|
||||
## mcl_autogroup.get_wear(toolname, diggroup)
|
||||
## `mcl_autogroup.get_wear(toolname, diggroup)`
|
||||
Return the max wear of `toolname` with `diggroup`
|
||||
WARNING: This function can only be called after mod initialization.
|
||||
* toolname: string, name of the tool used
|
||||
* diggroup: string, the name of the diggroup the tool is used on
|
||||
* `toolname`: string, name of the tool used
|
||||
* `diggroup`: string, the name of the diggroup the tool is used on
|
||||
|
||||
## mcl_autogroup.register_diggroup(group, def)
|
||||
* group: string, name of the group to register as a digging group
|
||||
* def: (optional) table, table with information about the diggroup (defaults to {} if unspecified)
|
||||
* level: (optional) string, if specified it is an array containing the names of the different digging levels the digging group supports
|
||||
## `mcl_autogroup.register_diggroup(group, def)`
|
||||
* `group`: string, name of the group to register as a digging group
|
||||
* `def`: (optional) table, table with information about the diggroup (defaults to `{}` if unspecified)
|
||||
* `level`: (optional) string, if specified it is an array containing the names of the different digging levels the digging group supports
|
||||
|
||||
## mcl_autogroup.registered_diggroups
|
||||
## `mcl_autogroup.registered_diggroups`
|
||||
List of registered diggroups, indexed by name.
|
||||
|
||||
## `mcl_autogroup.group_compatibility(groups, node_def)`
|
||||
Adds VoxeLibre-equivalent groups to `node_def.groups`.
|
||||
* `groups` - A list of groups to add compatiblity groups for. Normally this is a copy of `node_def.groups`.
|
||||
* `node_def` - The node defintion to update groups for.
|
||||
|
|
|
@ -418,6 +418,18 @@ minetest.register_on_joinplayer(function(player)
|
|||
end
|
||||
end)
|
||||
|
||||
---@param player mt.PlayerObjectRef
|
||||
local function is_touch_enabled(playername)
|
||||
-- Minetest < 5.7.0 support
|
||||
if not minetest.get_player_window_information then
|
||||
return false
|
||||
end
|
||||
local window = minetest.get_player_window_information(playername)
|
||||
-- Always return a boolean (not nil) to avoid false-negatives when
|
||||
-- comparing to a boolean later.
|
||||
return window and window.touch_controls or false
|
||||
end
|
||||
|
||||
---@param player mt.PlayerObjectRef
|
||||
function mcl_inventory.set_creative_formspec(player)
|
||||
local playername = player:get_player_name()
|
||||
|
@ -566,8 +578,10 @@ function mcl_inventory.set_creative_formspec(player)
|
|||
bg_img = "crafting_creative_inactive" .. button_bg_postfix[this_tab] .. ".png"
|
||||
end
|
||||
return table.concat({
|
||||
"style[" .. this_tab .. ";border=false;bgimg=;bgimg_pressed=;noclip=true]",
|
||||
"image[" .. offset[this_tab] .. ";1.5,1.44;" .. bg_img .. "]",
|
||||
"style[" .. this_tab .. ";border=false;bgimg=;bgimg_pressed=]",
|
||||
"style[" .. this_tab .. "_outer;border=false;bgimg=" .. bg_img ..
|
||||
";bgimg_pressed=" .. bg_img .. "]",
|
||||
"button[" .. offset[this_tab] .. ";1.5,1.44;" .. this_tab .. "_outer;]",
|
||||
"item_image_button[" .. boffset[this_tab] .. ";1,1;" .. tab_icon[this_tab] .. ";" .. this_tab .. ";]",
|
||||
})
|
||||
end
|
||||
|
@ -577,11 +591,21 @@ function mcl_inventory.set_creative_formspec(player)
|
|||
caption = "label[0.375,0.375;" .. F(C(mcl_formspec.label_color, filtername[name])) .. "]"
|
||||
end
|
||||
|
||||
local touch_enabled = is_touch_enabled(playername)
|
||||
players[playername].last_touch_enabled = touch_enabled
|
||||
|
||||
local formspec = table.concat({
|
||||
"formspec_version[6]",
|
||||
"size[13,8.75]",
|
||||
-- Original formspec height was 8.75, increased to include tab buttons.
|
||||
-- This avoids tab buttons going off-screen with high scaling values.
|
||||
"size[13,11.43]",
|
||||
-- Use as much space as possible on mobile - the tab buttons are a lot
|
||||
-- of padding already.
|
||||
touch_enabled and "padding[-0.015,-0.015]" or "",
|
||||
|
||||
"style_type[image;noclip=true]",
|
||||
"no_prepend[]", mcl_vars.gui_nonbg, mcl_vars.gui_bg_color,
|
||||
"background9[0,1.34;13,8.75;mcl_base_textures_background9.png;;7]",
|
||||
"container[0,1.34]",
|
||||
|
||||
-- Hotbar
|
||||
mcl_formspec.get_itemslot_bg_v4(0.375, 7.375, 9, 1),
|
||||
|
@ -638,6 +662,7 @@ function mcl_inventory.set_creative_formspec(player)
|
|||
"set_focus[search;true]",
|
||||
})
|
||||
end
|
||||
formspec = formspec .. "container_end[]"
|
||||
if pagenum then formspec = formspec .. "p" .. tostring(pagenum) end
|
||||
player:set_inventory_formspec(formspec)
|
||||
end
|
||||
|
@ -655,54 +680,54 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
|
||||
local name = player:get_player_name()
|
||||
|
||||
if fields.blocks then
|
||||
if fields.blocks or fields.blocks_outer then
|
||||
if players[name].page == "blocks" then return end
|
||||
set_inv_page("blocks", player)
|
||||
page = "blocks"
|
||||
elseif fields.deco then
|
||||
elseif fields.deco or fields.deco_outer then
|
||||
if players[name].page == "deco" then return end
|
||||
set_inv_page("deco", player)
|
||||
page = "deco"
|
||||
elseif fields.redstone then
|
||||
elseif fields.redstone or fields.redstone_outer then
|
||||
if players[name].page == "redstone" then return end
|
||||
set_inv_page("redstone", player)
|
||||
page = "redstone"
|
||||
elseif fields.rail then
|
||||
elseif fields.rail or fields.rail_outer then
|
||||
if players[name].page == "rail" then return end
|
||||
set_inv_page("rail", player)
|
||||
page = "rail"
|
||||
elseif fields.misc then
|
||||
elseif fields.misc or fields.misc_outer then
|
||||
if players[name].page == "misc" then return end
|
||||
set_inv_page("misc", player)
|
||||
page = "misc"
|
||||
elseif fields.nix then
|
||||
elseif fields.nix or fields.nix_outer then
|
||||
set_inv_page("all", player)
|
||||
page = "nix"
|
||||
elseif fields.food then
|
||||
elseif fields.food or fields.food_outer then
|
||||
if players[name].page == "food" then return end
|
||||
set_inv_page("food", player)
|
||||
page = "food"
|
||||
elseif fields.tools then
|
||||
elseif fields.tools or fields.tools_outer then
|
||||
if players[name].page == "tools" then return end
|
||||
set_inv_page("tools", player)
|
||||
page = "tools"
|
||||
elseif fields.combat then
|
||||
elseif fields.combat or fields.combat_outer then
|
||||
if players[name].page == "combat" then return end
|
||||
set_inv_page("combat", player)
|
||||
page = "combat"
|
||||
elseif fields.mobs then
|
||||
elseif fields.mobs or fields.mobs_outer then
|
||||
if players[name].page == "mobs" then return end
|
||||
set_inv_page("mobs", player)
|
||||
page = "mobs"
|
||||
elseif fields.brew then
|
||||
elseif fields.brew or fields.brew_outer then
|
||||
if players[name].page == "brew" then return end
|
||||
set_inv_page("brew", player)
|
||||
page = "brew"
|
||||
elseif fields.matr then
|
||||
elseif fields.matr or fields.matr_outer then
|
||||
if players[name].page == "matr" then return end
|
||||
set_inv_page("matr", player)
|
||||
page = "matr"
|
||||
elseif fields.inv then
|
||||
elseif fields.inv or fields.inv_outer then
|
||||
if players[name].page == "inv" then return end
|
||||
page = "inv"
|
||||
elseif fields.search == "" and not fields.creative_next and not fields.creative_prev then
|
||||
|
@ -818,3 +843,19 @@ minetest.register_on_player_inventory_action(function(player, action, inventory,
|
|||
player:get_inventory():set_stack("main", inventory_info.index, stack)
|
||||
end
|
||||
end)
|
||||
|
||||
-- This is necessary because get_player_window_information may return nil in
|
||||
-- on_joinplayer.
|
||||
-- (Also, Minetest plans to add support for toggling touchscreen mode in-game.)
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
|
||||
if minetest.is_creative_enabled(name) then
|
||||
local touch_enabled = is_touch_enabled(name)
|
||||
if touch_enabled ~= players[name].last_touch_enabled then
|
||||
mcl_inventory.set_creative_formspec(player)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -169,6 +169,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula
|
|||
return itemstack
|
||||
end,
|
||||
groups = {weapon=1,weapon_ranged=1,bow=1,cannot_block=1,enchantability=1},
|
||||
touch_interaction = "short_dig_long_place",
|
||||
_mcl_uses = 385,
|
||||
})
|
||||
|
||||
|
@ -235,6 +236,7 @@ for level=0, 2 do
|
|||
on_place = function(itemstack)
|
||||
return itemstack
|
||||
end,
|
||||
touch_interaction = "short_dig_long_place",
|
||||
_mcl_uses = 385,
|
||||
})
|
||||
end
|
||||
|
|
|
@ -159,6 +159,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula
|
|||
return itemstack
|
||||
end,
|
||||
groups = {weapon=1,weapon_ranged=1,crossbow=1,cannot_block=1,enchantability=1},
|
||||
touch_interaction = "short_dig_long_place",
|
||||
_mcl_uses = 326,
|
||||
})
|
||||
|
||||
|
@ -194,6 +195,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula
|
|||
return itemstack
|
||||
end,
|
||||
groups = {weapon=1,weapon_ranged=1,crossbow=1,cannot_block=1,enchantability=1,not_in_creative_inventory=1},
|
||||
touch_interaction = "short_dig_long_place",
|
||||
_mcl_uses = 326,
|
||||
})
|
||||
|
||||
|
@ -257,6 +259,7 @@ for level=0, 2 do
|
|||
on_place = function(itemstack)
|
||||
return itemstack
|
||||
end,
|
||||
touch_interaction = "short_dig_long_place",
|
||||
_mcl_uses = 385,
|
||||
})
|
||||
end
|
||||
|
|
|
@ -728,7 +728,7 @@ minetest.register_node("mcl_core:bedrock", {
|
|||
S("In the End dimension, starting a fire on this block will create an eternal fire."),
|
||||
tiles = {"mcl_core_bedrock.png"},
|
||||
stack_max = 64,
|
||||
groups = {creative_breakable=1, building_block=1, material_stone=1},
|
||||
groups = {creative_breakable=1, building_block=1, material_stone=1, unbreakable=1},
|
||||
sounds = mcl_sounds.node_sound_stone_defaults(),
|
||||
is_ground_content = false,
|
||||
on_blast = function() end,
|
||||
|
|
|
@ -6,6 +6,7 @@ minetest.register_tool("mcl_spyglass:spyglass",{
|
|||
inventory_image = "mcl_spyglass.png",
|
||||
stack_max = 1,
|
||||
_mcl_toollike_wield = true,
|
||||
touch_interaction = "short_dig_long_place",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
|
Loading…
Reference in New Issue