Compare commits

..

10 Commits

Author SHA1 Message Date
1F616EMO~nya
c2d82a615f
Fix regression from #16: unable to use crate if left while using one (#17) 2024-04-25 21:44:11 +02:00
1F616EMO~nya
b7bed50ac7
Fix rare crash and irrecoverable operator state (#16)
* Fix rare crash and irrecoverable operator state

* Do not restore if the player is not an operator

* Fix typo
2024-04-16 13:47:54 +02:00
Niklp
af87d6278c
Add player_monoids support (#15) 2023-10-07 11:23:18 +02:00
Joachim Stolberg
c0cd005c4b
Merge pull request #14 from SwissalpS/patch-1
Update README.md
2023-06-23 21:42:28 +02:00
Luke aka SwissalpS
d5ae08f8d1
Update README.md
some language fixes.
2023-06-23 21:18:46 +02:00
Joachim Stolberg
00b14a2c37
Merge pull request #13 from Montandalar/nodrops
Remove drops from tower crane nodes
2023-03-06 16:31:51 +01:00
Blockhead
e208ad199c Remove drops from tower crane nodes
This prevents players from illegally obtaining those nodes through mods like
digtron or the technic mining drill, at least in some instances.
2023-03-06 22:30:44 +11:00
jolesh
0e90cf0a4d
Add Esperanto translation (#12) 2022-11-05 10:01:35 +01:00
Emojigit
3975b970ee
Add light to the crane top (#11) 2021-04-28 18:57:22 +02:00
Joachim Stolberg
599b2c93c6 Fix 'minetest.setting_* functions are deprecated' issues 2021-03-13 20:14:37 +01:00
8 changed files with 93 additions and 35 deletions

View File

@ -13,14 +13,14 @@ The size of the crane (which is the construction area) and the rope length can b
## Introduction
* Place the crane base block.
The crane arm will later be build in the same direction you are currently looking
The crane arm will later be built in the same direction the player is looking.
* Right-click the crane base block and set the crane dimensions in height and width (between 8 and 32 by default).
The crane will be build according to this settings.
The crane will be built according to these settings.
If there is not enough free space for the crane mast/arm or the potential construction area of the
crane intersects a protected area from another player, the crane will not be build.
crane intersects a protected area from another player, the crane will not be built.
* Right-click the crane switch block to start the crane (get fly privs). The player will be placed in front of the crane.
* Right-click the crane switch block to start the crane (get fly privs). The player is placed in front of the crane.
* To remove the crane, destroy the base block.
@ -33,8 +33,9 @@ default
# License
Copyright (C) 2017-2020 Joachim Stolberg
Code: Licensed under the GNU LGPL version 2.1 or later. See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt
Textures: CC0 (by Ammoth)
Textures: Mostly CC0 (by Ammoth)
* `morelights_extras_blocklight.png`: CC BY-SA 4.0 (by random-geek)
# History:
* 2017-06-04 v0.01 first version

View File

@ -11,13 +11,13 @@
-- Maximum crane height in blocks (8..n)
towercrane.max_height = tonumber(minetest.setting_get("towercrane_max_height")) or 32
towercrane.max_height = tonumber(minetest.settings:get("towercrane_max_height")) or 32
-- Maximum crane width in blocks (8..n)
towercrane.max_width = tonumber(minetest.setting_get("towercrane_max_width")) or 32
towercrane.max_width = tonumber(minetest.settings:get("towercrane_max_width")) or 32
-- Crane rope lenght in block (max_height .. max_height+x)
towercrane.rope_length = tonumber(minetest.setting_get("towercrane_rope_length")) or 40
towercrane.rope_length = tonumber(minetest.settings:get("towercrane_rope_length")) or 40
-- Recipe available (true/false)
towercrane.recipe = tonumber(minetest.setting_get("towercrane_recipe")) or true
towercrane.recipe = tonumber(minetest.settings:get("towercrane_recipe")) or true

View File

@ -10,6 +10,7 @@
]]--
local DAYS_WITHOUT_USE = 72 * 5
local mod_player_monoids = minetest.get_modpath("player_monoids")
-- for lazy programmers
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
@ -69,25 +70,30 @@ end
local function set_operator_privs(player, pos)
local privs = minetest.get_player_privs(player:get_player_name())
local physics = player:get_physics_override()
local meta = player:get_meta()
-- Check access conflicts with other mods
if meta:get_int("player_physics_locked") == 0 then
if pos and meta and privs and physics then
if pos and meta and privs then
meta:set_string("towercrane_pos", P2S(pos))
-- store the player privs default values
meta:set_string("towercrane_fast", privs["fast"] and "true" or "false")
meta:set_string("towercrane_fly", privs["fly"] and "true" or "false")
meta:set_int("towercrane_speed", physics.speed)
-- set operator privs
meta:set_int("towercrane_isoperator", 1)
meta:set_int("player_physics_locked", 1)
privs["fly"] = true
privs["fast"] = nil
physics.speed = 0.7
-- write back
player:set_physics_override(physics)
minetest.set_player_privs(player:get_player_name(), privs)
if mod_player_monoids then
player_monoids.speed:add_change(player, 0.7, "towercrane:crane")
else
local physics = player:get_physics_override()
meta:set_int("towercrane_speed", physics.speed)
physics.speed = 0.7
-- write back
player:set_physics_override(physics)
end
return true
end
end
@ -96,24 +102,29 @@ end
local function reset_operator_privs(player)
local privs = minetest.get_player_privs(player:get_player_name())
local physics = player:get_physics_override()
local meta = player:get_meta()
if meta and privs and physics then
if meta and privs and meta:get_int("towercrane_isoperator") ~= 0 then
meta:set_string("towercrane_pos", "")
-- restore the player privs default values
meta:set_int("towercrane_isoperator", 0)
meta:set_int("player_physics_locked", 0)
privs["fast"] = meta:get_string("towercrane_fast") == "true" or nil
privs["fly"] = meta:get_string("towercrane_fly") == "true" or nil
physics.speed = meta:get_int("towercrane_speed")
if physics.speed == 0 then physics.speed = 1 end
minetest.set_player_privs(player:get_player_name(), privs)
-- delete stored default values
meta:set_string("towercrane_fast", "")
meta:set_string("towercrane_fly", "")
meta:set_string("towercrane_speed", "")
-- write back
player:set_physics_override(physics)
minetest.set_player_privs(player:get_player_name(), privs)
if mod_player_monoids then
player_monoids.speed:del_change(player, "towercrane:crane")
else
local physics = player:get_physics_override()
physics.speed = meta:get_int("towercrane_speed")
meta:set_string("towercrane_speed", "")
if physics.speed == 0 then physics.speed = 1 end
-- write back
player:set_physics_override(physics)
end
end
end
@ -259,6 +270,7 @@ minetest.register_node("towercrane:mast_ctrl_on", {
meta:set_string("infotext", S("Switch crane on/off"))
end,
drop = "",
paramtype = "light",
paramtype2 = "facedir",
light_source = 3,
@ -284,8 +296,14 @@ minetest.register_node("towercrane:mast_ctrl_off", {
if set_operator_privs(clicker, pos) then
start_crane(pos, clicker)
local pos1, pos2 = calc_construction_area(pos)
-- control player every second
minetest.after(1, control_player, pos, pos1, pos2, clicker:get_player_name())
if pos1 and pos2 then
-- control player every second
minetest.after(1, control_player, pos, pos1, pos2, clicker:get_player_name())
else
-- Something weird happened, restore privileges
stop_crane(pos, clicker)
reset_operator_privs(clicker)
end
end
end
end,
@ -296,6 +314,7 @@ minetest.register_node("towercrane:mast_ctrl_off", {
meta:set_string("infotext", S("Switch crane on/off"))
end,
drop = "",
paramtype = "light",
paramtype2 = "facedir",
sunlight_propagates = true,
@ -306,9 +325,10 @@ minetest.register_node("towercrane:mast_ctrl_off", {
minetest.register_on_joinplayer(function(player)
local pos = get_my_crane_pos(player)
if pos then
reset_operator_privs(player)
stop_crane(pos, player)
end
-- To recover from a crash, this must be done unconditionally
reset_operator_privs(player)
end)
minetest.register_on_leaveplayer(function(player)

View File

@ -9,7 +9,7 @@
Nodes Meta data
+--------+
+--------+
| | - last_known_pos as "(x,y,z)"
| switch | - last_used
| | - running
@ -26,7 +26,7 @@ local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local S2P = minetest.string_to_pos
-- crane minimum size
local MIN_SIZE = 8
local MIN_SIZE = 8
towercrane = {}
@ -53,7 +53,7 @@ local function formspec(height, width)
return "size[5,4]"..
"label[0,0;"..S("Construction area size").."]" ..
"field[1,1.5;3,1;size;height,width;"..text.."]" ..
"button_exit[1,2;2,1;exit;"..S("Build").."]"
"button_exit[1,2;2,1;exit;"..S("Build").."]"
end
local function get_node_lvm(pos)
@ -154,7 +154,7 @@ end
local function construct_crane(pos, dir, height, width)
local add = function(pos, node_name, tArg)
minetest.add_node(pos, {
name = node_name,
name = node_name,
param2 = minetest.dir_to_facedir(tArg.dir)})
end
local tArg = {dir = dir}
@ -229,7 +229,7 @@ local function build_crane_up(pos, owner, height, width)
", "..S("Crane size")..": "..height..","..width)
meta:set_string("formspec", formspec(height, width))
else
chat(owner, S("Area is protected or too less space for the crane!"))
chat(owner, S("Area is protected or not enough space for the crane!"))
end
end
else
@ -292,7 +292,7 @@ minetest.register_node("towercrane:base", {
return true
end,
-- evaluate user input (height, width),
-- evaluate user input (height, width),
-- destroy old crane and build a new one with
-- the given size
on_receive_fields = function(pos, formname, fields, player)
@ -324,7 +324,7 @@ minetest.register_node("towercrane:base", {
end
return true
end,
on_destruct = function(pos)
towercrane.get_crane_down(pos)
end,
@ -333,13 +333,15 @@ minetest.register_node("towercrane:base", {
minetest.register_node("towercrane:balance", {
description = S("Tower Crane Balance"),
tiles = {
"towercrane_base.png^towercrane_screws.png",
"towercrane_base.png^towercrane_screws.png^morelights_extras_blocklight.png",
},
paramtype = "light",
paramtype2 = "facedir",
light_source = 12,
sunlight_propagates = true,
is_ground_content = false,
groups = {crumbly=0, not_in_creative_inventory=1},
drop = "",
})
minetest.register_node("towercrane:mast", {
@ -357,6 +359,7 @@ minetest.register_node("towercrane:mast", {
sunlight_propagates = true,
is_ground_content = false,
groups = {crumbly=0, not_in_creative_inventory=1},
drop = "",
})
minetest.register_node("towercrane:arm", {
@ -374,6 +377,7 @@ minetest.register_node("towercrane:arm", {
sunlight_propagates = true,
is_ground_content = false,
groups = {crumbly=0, not_in_creative_inventory=1},
drop = "",
})
minetest.register_node("towercrane:arm2", {
@ -391,6 +395,7 @@ minetest.register_node("towercrane:arm2", {
sunlight_propagates = true,
is_ground_content = false,
groups = {crumbly=0, not_in_creative_inventory=1},
drop = "",
})
if towercrane.recipe then
@ -411,4 +416,3 @@ towercrane.turnright = turnright
towercrane.turnleft = turnleft
towercrane.is_my_crane = is_my_crane
towercrane.get_crane_data = get_crane_data

16
locale/template.txt Normal file
View File

@ -0,0 +1,16 @@
# textdomain: towercrane
Area is protected.=
Tower Crane Mast Ctrl On=
Switch crane on/off=
Tower Crane Mast Ctrl Off=
Construction area size=
Build=
Owner=
Crane size=
Area is protected or too less space for the crane!=
Invalid input!=
Tower Crane Base=
Tower Crane Balance=
Tower Crane Mast=
Tower Crane Arm=
Tower Crane Arm2=

16
locale/towercrane.eo.tr Normal file
View File

@ -0,0 +1,16 @@
# textdomain: towercrane
Area is protected.=Areo estas protektita.
Tower Crane Mast Ctrl On=Turgruomasta Kontrolo Enŝaltita
Switch crane on/off=Ŝaltu/malŝaltu gruon
Tower Crane Mast Ctrl Off=Turgruomasta Kontrolo Malŝaltita
Construction area size=Konstrua area grandeco
Build=Konstruita
Owner=Posedanto
Crane size=Gruo grandeco
Area is protected or not enough space for the crane!=Areo estas protektita aŭ ne sufice da spaco por la gruo!
Invalid input!=Nevalida enigo!
Tower Crane Base=Bazo de Turgruo
Tower Crane Balance=Ekvilibro de Turgruo
Tower Crane Mast=Masto de Turgruo
Tower Crane Arm=Brako de Turgruo
Tower Crane Arm2=Brako2 de Turgruo

View File

@ -1,3 +1,4 @@
name = towercrane
depends = default
optional_depends = player_monoids
description = A crane for easier construction of buildings. The crane forms a working area in which the player gets fly privs.

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B