Compare commits

..

11 Commits

Author SHA1 Message Date
loosewheel
3150c50312 Add files via upload 2022-02-22 14:38:06 +10:00
loosewheel
e507646519 Add files via upload 2022-02-22 14:04:04 +10:00
loosewheel
2f99a60cbd Add files via upload 2022-02-22 14:02:10 +10:00
loosewheel
e9cf28a648 Add files via upload 2022-02-22 13:59:52 +10:00
loosewheel
ebe1720922 Add files via upload 2022-02-22 13:58:38 +10:00
loosewheel
61e20f57ed Add files via upload 2022-02-22 13:58:03 +10:00
loosewheel
eaf6a679c3 Add files via upload 2022-02-19 14:08:26 +10:00
loosewheel
f41ab00398 Add files via upload 2022-02-19 14:06:27 +10:00
loosewheel
7f42fde4a0 Add files via upload 2022-02-19 14:04:44 +10:00
loosewheel
6f8a194042 Add files via upload 2022-02-16 01:49:12 +10:00
loosewheel
84ddc82c95 Add files via upload 2022-02-16 01:46:56 +10:00
19 changed files with 1874 additions and 97 deletions

View File

@@ -140,9 +140,10 @@ local function camera_scan (pos, resolution, distance)
tpos = vector.round ({ x = horz + pos.x, y = pos.y - vert, z = (dist * dir.z) + pos.z })
end
if last_pos and vector.equals (last_pos, tpos) then
image[y][x] = last_color
if last_color then
image[y][x] = last_color
end
else
local entity = get_entity (tpos)
@@ -151,13 +152,11 @@ local function camera_scan (pos, resolution, distance)
last_color = string.format ("00%02X00", color)
image[y][x] = last_color
last_pos = tpos
elseif entity == 2 then
local color = (((distance - dist) / distance) * 98) + 30
last_color = string.format ("0000%02X", color)
image[y][x] = last_color
last_pos = tpos
else
local node = utils.get_far_node (tpos)
@@ -166,12 +165,13 @@ local function camera_scan (pos, resolution, distance)
last_color = string.format ("%02X%02X%02X", color, color, color)
image[y][x] = last_color
last_pos = tpos
else
last_pos = nil
last_color = nil
end
end
end
last_pos = tpos
end
end
end
@@ -198,8 +198,6 @@ local function send_scan (pos)
channel,
image)
end
end
end
@@ -208,14 +206,14 @@ end
local function after_place_node (pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta (pos)
local spec =
"formspec_version[3]\n"..
"size[8.5,5.5;true]\n"..
"field[1.0,1.0;4.0,0.8;channel;Channel;${channel}]\n"..
"button[5.5,1.0;2.0,0.8;setchannel;Set]\n"..
"field[1.0,2.5;4.0,0.8;distance;Distance;${distance}]\n"..
"button[5.5,2.5;2.0,0.8;setdistance;Set]\n"..
"field[1.0,4.0;4.0,0.8;resolution;Resolution;${resolution}]\n"..
"button[5.5,4.0;2.0,0.8;setresolution;Set]\n"
"formspec_version[3]"..
"size[8.5,5.5;true]"..
"field[1.0,1.0;4.0,0.8;channel;Channel;${channel}]"..
"button[5.5,1.0;2.0,0.8;setchannel;Set]"..
"field[1.0,2.5;4.0,0.8;distance;Distance;${distance}]"..
"button[5.5,2.5;2.0,0.8;setdistance;Set]"..
"field[1.0,4.0;4.0,0.8;resolution;Resolution;${resolution}]"..
"button[5.5,4.0;2.0,0.8;setresolution;Set]"
meta:set_string ("formspec", spec)
meta:set_string ("distance", "5")
@@ -271,7 +269,7 @@ local function on_receive_fields (pos, formname, fields, sender)
local meta = minetest.get_meta (pos)
if meta then
local resolution = math.max (tonumber (fields.resolution) or 1, 1)
local resolution = math.min (math.max (tonumber (fields.resolution) or 1, 1), 128)
fields.resolution = tostring (resolution)
meta:set_string ("resolution", tostring (resolution))
@@ -375,10 +373,12 @@ local function digilines_support ()
send_scan (pos)
elseif m[1] == "distance" then
meta:set_string ("distance", tostring (tonumber (m[2] or 5) or 5))
local distance = math.min (math.max (tonumber (m[2] or 5) or 5, 1), 16)
meta:set_string ("distance", tostring (distance))
elseif m[1] == "resolution" then
meta:set_string ("resolution", tostring (tonumber (m[2] or 16) or 16))
local resolution = math.min (math.max (tonumber (m[2] or 16) or 16, 1), 128)
meta:set_string ("resolution", tostring (resolution))
end
end

View File

@@ -96,9 +96,25 @@ v0.1.16
v0.1.17
* Fixed unintended global variable in pistons.lua.
v0.1.18
* Added mesecons through wire.
v0.1.19
* Added camera.
v0.1.20
* Valid distance and resolution for camera set by digilines message.
* Imposed maximum resolution of 128 for cameras.
v0.1.21
* Minor bug fix, movefloor global.
* Fixed movefloor so player doesn't fall through floor.
* Transfer timer in moved nodes for pistons.
v0.1.22
* Added storage.

View File

@@ -23,6 +23,44 @@ minetest.register_craft( {
})
minetest.register_craft( {
output = "lwcomponents:storage_unit 2",
recipe = {
{ "default:steel_ingot", "group:wood", "group:wood" },
{ "group:wood", "", "group:wood" },
{ "group:wood", "group:wood", "default:chest" },
},
})
minetest.register_craft( {
output = "lwcomponents:storage_unit_locked 2",
recipe = {
{ "default:steel_ingot", "group:wood", "group:wood" },
{ "group:wood", "", "group:wood" },
{ "group:wood", "group:wood", "default:chest_locked" },
},
})
minetest.register_craft( {
output = "lwcomponents:storage_indexer",
recipe = {
{ "default:steel_ingot", "group:wood" },
{ "group:wood", "default:chest" }
},
})
minetest.register_craft( {
output = "lwcomponents:storage_indexer_locked",
recipe = {
{ "default:steel_ingot", "group:wood" },
{ "group:wood", "default:chest_locked" }
},
})
minetest.register_craft( {
output = "lwcomponents:cannon_shell 10",
recipe = {
@@ -332,7 +370,7 @@ end -- utils.digilines_supported and utils.digistuff_supported
if utils.mesecon_supported and mesecon.mvps_push then
if utils.mesecon_supported then
minetest.register_craft ({
output = "lwcomponents:movefloor",
@@ -343,7 +381,7 @@ minetest.register_craft ({
}
})
end -- utils.mesecon_supported and mesecon.mvps_push
end -- utils.mesecon_supported

View File

@@ -130,7 +130,7 @@ end
local function get_entity_height (objref)
if objref.get_luaentity then
entity = objref:get_luaentity ()
local entity = objref:get_luaentity ()
if entity and entity.name then
def = minetest.registered_entities[entity.name]

View File

@@ -13,8 +13,8 @@ Only the owner can dig or access the form of the locked version.
UI
Channel - digilines channel of camera.
Distance - the viewing distance forward from the camera (1 t0 16).
Resolution - the image resolution (for both width and height).
Distance - the viewing distance forward from the camera (1 to 16).
Resolution - the image resolution (for both width and height, 1 to 128).
Digilines messages

View File

@@ -1,6 +1,6 @@
MoveFloor
---------
* This block is only available if mesecons and mesecons_mvps is loaded.
* This block is only available if mesecons is loaded.
The MoveFloor block responds to a mesecons power source in the 4 horizontal
directions. If the power source is one higher the MoveFloor moves up to

99
docs/storage.txt Normal file
View File

@@ -0,0 +1,99 @@
Storage
-------
Storage is accommodated with two nodes, Storage Unit and Storage Indexer.
Storage units can be interacted with like a basic chest, each with 32 slots,
and visually join together when placed adjacent to each other. Units are
generally accessed via indexers, which action all adjoining units as a
single storage block. Multiple indexers can action a single storage block.
Only the owner can dig or access the form of the locked versions.
Unowned indexers can only access unowned units. Owned indexers can access
units of the same owner or unowned units.
UI
Search - top left.
List - left.
Channel - digilines channel of indexer.
Input - middle.
Output - top right.
Filter - center right.
Player inventor - lower right.
When the UI is accessed the storage is scanned, and its contents are
displayed in the list. The list contains the following columns:
Item button - pressing will place one of these items from storage into the
output.
10 button - pressing will place 10 of the item.
<stack> button - pressing places a full stack.
Count - the total number of this item in storage.
Description - description of the item.
Note that the 10 and stack buttons may vary in number or not appear
depending on the requirements of that item.
The form does not update while open. A request for more items than in
storage will only deliver the amount in storage.
Terms can be entered into the search field, and when enter is pressed or
the Search button is pressed, only items whose description contains these
terms are shown in the list. That is if they match any of the space
separated terms.
Any items placed into the input are placed into storage. If the filter
is clear all items are accepted. If the filter contains items only these
items will be accepted. Any items not accepted or that do not fit into
storage are placed into the output.
When items are placed into the filter a copy is used and the item returns
to where it was taken from. When items are removed from the filter they
are disposed of.
Hoppers placed to the top or sides of an indexer will feed items into the
input. Hoppers placed below an indexer will take items from the output.
Every 20 inputs the storage is consolidated to minimize fragmentation.
Digilines messages
"output <item> <count>"
or
{
action = "output",
item = "<item>",
count = <count>
}
Moves the item/s to the output. If count is omitted defaults to 1. If
the requested amount is greater than in storage, only the stored amount
is moved.
"inventory"
Sends a digilines message with it's own channel in the following form:
{
action = "inventory",
inventory = {
<items>
}
}
The inventory key is an indexed list of items in storage. Each item
entry is a table with the following keys:
{
name -- string, the name of the item, as <mod>:<name>
description -- string, description of the item, same as in UI
count -- number, the total number of this item in storage
custom -- true if a custom item (has metadata), false if not
pallet_index -- string if the item has a pallet index, otherwise nil
id -- string, unique id of the item in storage
}
The description is derived in the following manner: from a custom
description in metadata; if none then the short description from
the item's definition; if none then the description from the item's
definition; if none then the item's name, as <mod>:<name>.
Note: When sending output messages the simple item name, as <mod>:<name>,
will work for most items, but not for custom items. With custom items, or
to play it safe, use the table form of the output message and set the item
field with the id field for the item from a returned inventory.

View File

@@ -1,4 +1,4 @@
local version = "0.1.19"
local version = "0.1.22"
local mod_storage = minetest.get_mod_storage ()
@@ -37,6 +37,7 @@ loadfile (modpath.."/cannon_shell.lua") (utils)
loadfile (modpath.."/pistons.lua") (utils)
loadfile (modpath.."/through_wire.lua") (utils)
loadfile (modpath.."/camera.lua") (utils)
loadfile (modpath.."/storage.lua") (utils)
loadfile (modpath.."/extras.lua") (utils)
loadfile (modpath.."/digiswitch.lua") (utils)
loadfile (modpath.."/movefloor.lua") (utils)

View File

@@ -61,6 +61,16 @@ https://creativecommons.org/licenses/by/4.0/
lwmovefloor.ogg
---------------
https://www.freesoundslibrary.com/elevator-sound-effect-elevator-ride-doors-closing-and-opening/
License: Attribution 4.0 International (CC BY 4.0). You are allowed to use
sound effects free of charge and royalty free in your multimedia projects
for commercial or non-commercial purposes.
Media license
-------------
siren images derived from images from https://openclipart.org, which is
@@ -72,6 +82,9 @@ public domain.
camera lens images derived from images from https://openclipart.org, which
is public domain.
storage nodes images derived from images from https://openclipart.org, which
is public domain.
player button images derived from mesecons button image.
cannon firing and explosion sound from tnt (TumeniNodes/steveygos93),

View File

@@ -3,7 +3,7 @@ local S = utils.S
if utils.mesecon_supported and mesecon.mvps_push then
if utils.mesecon_supported then
@@ -21,14 +21,10 @@ local mesecon_rules =
-- use mesecons movestone settings
local timer_interval = 1 / mesecon.setting ("movestone_speed", 3)
local max_push = 3
local max_pull = 3
-- helper functions:
local function get_movefloor_direction (rulename)
if rulename.y > 0 then
return { x = 0, y = 1, z = 0 }
@@ -38,6 +34,7 @@ local function get_movefloor_direction (rulename)
end
local function add_movefloor_list (pos, list)
for i = 1, #list do
if list[i].x == pos.x and
@@ -76,10 +73,289 @@ end
-- copied from mesecons movestone
local function movefloor_move (pos, node, rulename, is_sticky)
local function get_node_height (node)
local height = 0
local def = minetest.registered_nodes[node.name]
if def and type (def.collision_box) == "table" then
if def.collision_box.type and def.collision_box.type == "regular" then
height = 1
else
for _, box in pairs (def.collision_box) do
if type (box) == "table" then
if type (box[5]) == "number" then
height = box[5]
else
for _, b in ipairs (box) do
if type (b[5]) == "number" and b[5] > height then
height = b[5]
end
end
end
end
end
end
end
return height
end
local function get_affected_nodes (floor_list)
local list = { }
local max_height = 0
local protected = false
for _, fpos in ipairs (floor_list) do
for y = 0, max_push, 1 do
local npos = vector.add (fpos, { x = 0, y = y, z = 0 })
local node = utils.get_far_node (npos)
if node and node.name ~= "air" then
local meta = minetest.get_meta (npos)
local timer = minetest.get_node_timer (npos)
local h = get_node_height (node) + npos.y - fpos.y - 0.5
list[#list + 1] =
{
pos = npos,
node = node,
meta = (meta and meta:to_table ()),
timeout = (timer and timer:get_timeout ()) or 0,
elapsed = (timer and timer:get_elapsed ()) or 0
}
if h > max_height then
max_height = h
end
if utils.is_protected (npos, nil) then
protected = true
end
end
end
end
return list, math.ceil (max_height), protected
end
local function get_entity_height (obj, base)
local height = 0
if obj.get_pos then
local pos = obj:get_pos ()
if obj.get_luaentity then
local entity = obj:get_luaentity ()
if entity and entity.name then
local def = minetest.registered_entities[entity.name]
if def and type (def.collisionbox) == "table" and
type (def.collisionbox[5]) == "number" then
height = def.collisionbox[5] + pos.y - base
end
end
end
local props = obj:get_properties ()
if props and props.collisionbox and type (props.collisionbox) == "table" and
type (props.collisionbox[5]) == "number" then
if props.collisionbox[5] > height then
height = props.collisionbox[5] + pos.y - base
end
end
end
return height
end
local function get_affected_entities (floor_list)
local list = { }
local max_height = 0
for _, fpos in pairs (floor_list) do
local min_pos = vector.subtract (fpos, { x = 0.4999, y = 0.4999, z = 0.4999 })
local max_pos = vector.add (fpos, { x = 0.4999, y = max_push + 0.4999, z = 0.4999 })
local objects = minetest.get_objects_in_area (min_pos, max_pos)
for _, obj in ipairs (objects) do
local h = get_entity_height (obj, fpos.y + 0.5)
list[#list + 1] =
{
pos = obj:get_pos (),
obj = obj
}
if h > max_height then
max_height = h
end
end
end
return list, math.ceil (max_height)
end
local function is_obstructed (floor_list, height)
for _, fpos in pairs (floor_list) do
local npos = vector.add (fpos, { x = 0, y = height, z = 0 })
if utils.is_protected (npos, nil) then
return true
end
local node = utils.get_far_node (npos)
if node and node.name ~= "air" then
local def = minetest.registered_nodes[node.name]
if not def or not def.buildable_to then
return true
end
end
end
return false
end
local function move_entities (list, move, players)
for _, entry in ipairs (list) do
if entry.obj then
if players or not entry.obj:is_player () then
local pos = nil
if entry.obj:is_player () then
pos = vector.add (entry.pos, { x = move.x, y = move.y + 0.1, z = move.z })
else
pos = vector.add (entry.pos, move)
end
if entry.obj.move_to then
entry.obj:move_to (pos)
elseif entry.set_pos then
entry.obj:set_pos (pos)
end
end
end
end
end
local function update_player_position (list)
for _, entry in ipairs (list) do
local player = minetest.get_player_by_name (entry.name)
if player then
local pos = player:get_pos ()
if pos.y < entry.pos.y then
pos.y = entry.pos.y + 0.1
player:set_pos (pos)
end
end
end
end
local function queue_player_update (list, move)
local players = { }
for _, entry in ipairs (list) do
if entry.obj and entry.obj:is_player () then
players[#players + 1] =
{
pos = vector.add (entry.pos, move),
name = entry.obj:get_player_name ()
}
end
end
if #players > 0 then
minetest.after(0.1, update_player_position, players)
end
end
local function move_nodes (list, move)
if move.y > 0 then
for i = #list, 1, -1 do
local pos = vector.add (list[i].pos, move)
minetest.remove_node (list[i].pos)
minetest.set_node (pos, list[i].node)
if list[i].meta then
local meta = minetest.get_meta (pos)
if meta then
meta:from_table (list[i].meta)
end
end
if list[i].timeout > 0 then
timer = minetest.get_node_timer (pos)
if timer then
timer:set (list[i].timeout, list[i].elapsed)
end
end
end
else
for i = 1, #list, 1 do
local pos = vector.add (list[i].pos, move)
minetest.remove_node (list[i].pos)
minetest.set_node (pos, list[i].node)
if list[i].meta then
local meta = minetest.get_meta (pos)
if meta then
meta:from_table (list[i].meta)
end
end
if list[i].timeout > 0 then
timer = minetest.get_node_timer (pos)
if timer then
timer:set (list[i].timeout, list[i].elapsed)
end
end
end
end
end
local function check_for_falling (list)
for _, pos in ipairs (list) do
minetest.check_for_falling (vector.add (pos, { x = 0, y = max_push + 1, z = 0 }))
end
end
local function movefloor_move (pos, node, rulename)
local direction = get_movefloor_direction (rulename)
local play_sound = false
local list =
{
@@ -88,68 +364,34 @@ local function movefloor_move (pos, node, rulename, is_sticky)
find_adjoining_movefloor (pos, list)
for i = 1, #list do
local frontpos = vector.add (list[i], direction)
local meta = minetest.get_meta (list[i])
local owner = meta:get_string ("owner")
local continue = true
local nodes, height, protected = get_affected_nodes (list)
-- ### Step 1: Push nodes in front ###
local success, stack, oldstack = mesecon.mvps_push (frontpos, direction, max_push, owner)
if not success then
if stack == "protected" then
meta:set_string ("infotext", "Can't move: protected area on the way")
else
minetest.get_node_timer (list[i]):start (timer_interval)
continue = false
end
end
if continue then
mesecon.mvps_move_objects (frontpos, direction, oldstack)
-- ### Step 2: Move the movestone ###
minetest.set_node (frontpos, node)
local meta2 = minetest.get_meta (frontpos)
meta2:set_string ("owner", owner)
minetest.remove_node (list[i])
mesecon.on_dignode (list[i], node)
mesecon.on_placenode (frontpos, node)
minetest.get_node_timer (frontpos):start (timer_interval)
play_sound = true
-- ### Step 3: If sticky, pull stack behind ###
if is_sticky and direction.y < 0 then
local backpos = vector.subtract (list[i], direction)
success, stack, oldstack = mesecon.mvps_pull_all (backpos, direction, max_pull, owner)
if success then
mesecon.mvps_move_objects (backpos, vector.multiply (direction, -1), oldstack, -1)
end
end
-- ### Step 4: Let things fall ###
minetest.check_for_falling (vector.add (list[i], { x = 0, y = 1, z = 0 }))
end
end
if play_sound then
minetest.sound_play("movestone", { pos = list[i], max_hear_distance = 20, gain = 0.5 }, true)
end
end
local function on_timer (pos, elapsed)
local sourcepos = mesecon.is_powered (pos)
if not sourcepos then
if protected then
return
end
local rulename = vector.subtract (sourcepos[1], pos)
local entities, h = get_affected_entities (list)
mesecon.activate (pos, minetest.get_node (pos), rulename, 0)
if h > height then
height = h
end
if is_obstructed (list, (direction.y > 0 and height + 1) or -1) then
return
end
if direction.y > 0 then
move_entities (entities, direction, true)
move_nodes (nodes, direction)
queue_player_update (entities, direction)
else
move_nodes (nodes, direction)
move_entities (entities, direction, false)
check_for_falling (list)
queue_player_update (entities, direction)
end
minetest.sound_play ("lwmovefloor", { pos = pos, max_hear_distance = 10, gain = 1.0 }, true)
end
@@ -164,8 +406,8 @@ local function mesecon_support ()
action_on = function (pos, node, rulename)
-- do something to turn the effector on
if rulename and not minetest.get_node_timer (pos):is_started () then
movefloor_move (pos, node, rulename, true)
if rulename then
movefloor_move (pos, node, rulename)
end
end
}
@@ -190,8 +432,6 @@ minetest.register_node("lwcomponents:movefloor", {
groups = { cracky = 2 },
sounds = default.node_sound_wood_defaults (),
mesecons = mesecon_support (),
on_timer = on_timer,
})

View File

@@ -120,6 +120,9 @@ local function push_nodes (pos, extent)
end
local tmeta = cmeta:to_table ()
local ctimer = minetest.get_node_timer (cpos)
local ctimeout = (ctimer and ctimer:get_timeout ()) or 0
local celapsed = (ctimer and ctimer:get_elapsed ()) or 0
push_entities (cpos, vec)
@@ -136,6 +139,14 @@ local function push_nodes (pos, extent)
cmeta:from_table (tmeta)
end
if ctimeout > 0 then
ctimer = minetest.get_node_timer (last)
if ctimer then
ctimer:set (ctimeout, celapsed)
end
end
last = cpos
end
end
@@ -161,6 +172,9 @@ local function pull_node (pos, extent)
if cmeta then
local tpos = vector.subtract (cpos, vec)
local tmeta = cmeta:to_table ()
local ctimer = minetest.get_node_timer (cpos)
local ctimeout = (ctimer and ctimer:get_timeout ()) or 0
local celapsed = (ctimer and ctimer:get_elapsed ()) or 0
minetest.remove_node (cpos)
minetest.set_node (tpos, cnode)
@@ -172,6 +186,14 @@ local function pull_node (pos, extent)
cmeta:from_table (tmeta)
end
end
if ctimeout > 0 then
ctimer = minetest.get_node_timer (tpos)
if ctimer then
ctimer:set (ctimeout, celapsed)
end
end
end
end
end

View File

@@ -13,7 +13,7 @@ CC BY-SA 3.0
Version
=======
0.1.19
0.1.22
Minetest Version
@@ -67,6 +67,7 @@ Various components for mesecons and digilines.
* Digiswitch, digilines controlled mesecons power.
* Movefloor, similar to vertical mesecons movestone.
* Camera, takes a representative image.
* Storage, indexed storage units.
* Mesecons Through Wire, transmits through 1 to 2 solid blocks.
* Solid color conductor blocks, same as Solid Color Block but also mesecons
and digilines conductor.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View File

@@ -10,7 +10,10 @@ utils.settings.alert_handler_errors =
minetest.settings:get_bool ("lwcomponents_alert_handler_errors", true)
utils.settings.max_piston_nodes =
tonumber(minetest.settings:get("lwcomponents_max_piston_nodes") or 15)
tonumber (minetest.settings:get ("lwcomponents_max_piston_nodes") or 15)
utils.settings.default_stack_max =
tonumber (minetest.settings:get ("default_stack_max")) or 99

BIN
sounds/lwmovefloor.ogg Normal file

Binary file not shown.

1344
storage.lua Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB