45 Commits

Author SHA1 Message Date
Jeija
2a61e8bea6 Merge branch 'master' of https://github.com/Jeija/minetest-mod-mesecons into next 2013-03-26 15:14:12 +01:00
Jeija
36bcce57b0 Add table.* to luacontroller sandbox 2013-03-26 15:12:56 +01:00
Jeija
6cf713098a Make pistons use the 6d facedir feature 2013-03-24 20:56:46 +01:00
Anthony Zhang
21550b3727 Explicit tables of luacontroller environment. 2013-03-23 18:41:44 -04:00
Anthony Zhang
6983db6d82 Add math library to luacontroller, and make sure to copy stuff so code can't get out of the sandbox. 2013-03-23 17:49:25 -04:00
Anthony Zhang
1ff437b7b0 Don't forget sticky movestones! 2013-03-16 21:18:36 -04:00
Anthony Zhang
5f9e655c13 Add MOVESTONE_MAXIMUM_PUSH setting. 2013-03-15 19:53:09 -04:00
Anthony Zhang
3c3e45c7ea Avoid corrupting metadata. 2013-03-15 17:46:59 -04:00
Anthony Zhang
5fd1cf5c80 Use formspec_escape when available. 2013-03-15 17:21:16 -04:00
Anthony Zhang
e1211729cc Avoid borking the luacontroller if the code uses square brackets. When the next stable MT is released, uncomment the formspec_escape call to take advantave of formspec escaping. 2013-03-15 17:07:15 -04:00
Anthony Zhang
588e41c786 Up/down pistons should also have special rules excluding the pusher side (rotated versions of normal pistons). 2013-03-14 14:19:02 -04:00
Anthony Zhang
79bb4a3433 Lots of bugs in movestones fixed:
* Movestones no longer eat nodes when running off the track.
* Movestones no longer eat nodes when colliding with an mvps stopper.
* Movestones no longer pass through mvps stoppers.
* Movestones do not eat nodes when they are suddenly placed in the entity's path.
2013-03-14 13:44:49 -04:00
Anthony Zhang
e1577eba46 Revert additional piston rules. 2013-03-11 17:49:07 -04:00
Anthony Zhang
4406654fa4 Support metadata in piston pushing (so that microcontrollers and such can be pushed), support pushing chests (not locked ones though), and add two missing rules for pistons (z- top and bottom, but not z- itself). This still avoids the piston pushing power source issue. 2013-03-11 17:37:50 -04:00
Anthony Zhang
db90c1cb4b Add /hp command to set the HP of a given player, requires the ban privelege. 2013-03-07 16:47:32 -05:00
Anthony Zhang
3792b692aa Digging and footstep sounds for everything that needs them! Plus, pushing buttons, punching switches, and flipping levers all make sounds. 2013-03-06 20:51:57 -05:00
Jeija
84d5546df1 Merge pull request #82 from Jat15/patch-1
Fix bug texture in mesewire for 0.4 stable
2013-03-05 09:36:07 -08:00
Jat
629a52af11 Fix bug texture in mesewire for 0.4 stable 2013-03-04 19:56:43 +01:00
khonkhortisan
4c0988ceab Merge pull request #80 from khonkhortisan/master
Vertical piston selection boxes
2013-03-02 22:24:29 -08:00
khonkhortisan
ac23eb070a Make vertical piston pusher selection boxes match their horizontal
equivalents
2013-03-02 22:22:43 -08:00
Jeija
e707afef1a Don't totally force deactivation of block two below the pressure plate if connected to a receptor 2013-02-24 19:09:07 +01:00
Jeija
2848df007e Bugfix: Also deactivate the block two below when digging a pressure plate 2013-02-24 19:03:28 +01:00
Jeija
c9e89189eb Improved object detector craft recipe, picture soon available on mesecons.net 2013-02-22 19:49:03 +01:00
Jeija
36263d481a Add (shaped) craft recipe for vertical mesecons
* Craft them from three wires in a vertical row
* Craft them back into mesecons by just putting one of them in the grid
2013-02-22 19:37:05 +01:00
Jeija
a0920104fc Object Detector, cleanup and different behaviour:
* Name to scan for can be specified by right-clicking it
* It can receive digiline signals that change the name to scan for
* A sign above it for the name doesn't work anymore (this features wasn't used often anyway)
2013-02-22 19:23:28 +01:00
Jeija
cc41f136cc More distinguishable inventory image for the luacontroller (not wield
item, just top)
2013-02-19 16:58:17 +01:00
Jeija
8827cfd66f Merge branch 'luacontroller' 2013-02-19 16:54:53 +01:00
Jeija
d36dd865ad Fix onstate corner drop
I blame khonkhortisan
2013-02-19 16:42:33 +01:00
khonkhortisan
ad9dde706e Merge pull request #77 from khonkhortisan/master
mesecons_extrawires:insulated_off
2013-02-18 10:38:05 -08:00
Kyle
09ac201bac Fix the nodename of a drop 2013-02-18 10:27:11 -08:00
Jeija
1c4ab938ad Fix a dumb bug that conflicted with different things in the luacontroller 2013-02-12 10:58:29 +01:00
Jeija
eeed4f148d Fix odd behaviour when using interrupts in the luacontroller 2013-02-12 10:25:24 +01:00
Jeija
10ea3c971b Merge branch 'master' into luacontroller 2013-02-11 08:03:08 +01:00
Jeija
591e2d7cde LuaController: Queue setting the ports (wait for pending operations) 2013-02-10 23:10:22 +01:00
Jeija
59cd72191b Add tostring, tonumber, string to luacontroller, prohibit 'function' 2013-01-22 21:15:49 +01:00
Jeija
2b30360da2 Bugfix for the luacontroller that occured when two events occur at the
same time (output connected to input).
The behaviour of the controller can now be described this way:
The luacontroller sets port A, then B, then C, then D; if it is
interrupted by another event during that time it stops and let the
second event do the job.
2013-01-22 18:26:27 +01:00
Jeija
18da94006a Lots of bugfixes concerning the luacontroller
- Bug when using NOT-Gates
- Moved error label a little downwards
- On digiline event, msg and channel are now in event.*, not in
event.iid.*
2013-01-20 18:00:33 +01:00
Jeija
ef087f2bb6 Fix Bug: Wrong usage of action_on/action_off instead of action_change 2013-01-19 23:37:03 +01:00
Jeija
62ddebaecb Add support in luacontroller for a not yet released mod called 'digilines' 2013-01-19 21:45:39 +01:00
Jeija
fc384aedbb Remove unused variable 2013-01-19 12:04:10 +01:00
Jeija
ec517becab Texture the LuaController formspec 2013-01-19 12:03:27 +01:00
Jeija
0d44144421 Bugfixes and improved stability of the luacontroller 2013-01-14 17:58:14 +01:00
Jeija
240fb83e8b Implement interrupt(time, iid): The whole code is called again after a
certain amount of time.
Whenever it is called, an event is set.
Possible events are: program, interrupt, on and off
It also contains additional information (on/off -> event.in; interrupt ->
event.iid)
iid must be an integer or string value, otherwise the interrupt is not active
2013-01-13 17:33:16 +01:00
Jeija
e297a02ec2 Implement a memory for the controller (accesible via mem.) and cleanup code
Based on PilzAdam's code.
2013-01-13 11:08:13 +01:00
Jeija
bd749ec4d4 Add luacontroller, a microcontroller that you can code in lua.
It still misses some functionality such as a persistent memory and a
timer, but that is subject to change. The code runs in a sandbox.
Speaking long term this will hopefully replace the old controller.
2013-01-13 00:18:25 +01:00
41 changed files with 755 additions and 504 deletions

View File

@@ -98,7 +98,7 @@ function mesecon:receptor_off(pos, rules)
if not mesecon:connected_to_receptor(np) then if not mesecon:connected_to_receptor(np) then
mesecon:turnoff(np, rulename) mesecon:turnoff(np, rulename)
else else
mesecon:changesignal(np, minetest.env:get_node(np), rulename) mesecon:changesignal(np, minetest.env:get_node(np), rulename, mesecon.state.off)
end end
end end
end end

View File

@@ -24,7 +24,7 @@
-- SIGNALS -- SIGNALS
-- mesecon:activate(pos, node) --> Activates the effector node at the specific pos (calls nodedef.mesecons.effector.action_on) -- mesecon:activate(pos, node) --> Activates the effector node at the specific pos (calls nodedef.mesecons.effector.action_on)
-- mesecon:deactivate(pos, node) --> Deactivates the effector node at the specific pos (calls nodedef.mesecons.effector.action_off) -- mesecon:deactivate(pos, node) --> Deactivates the effector node at the specific pos (calls nodedef.mesecons.effector.action_off)
-- mesecon:changesignal(pos, node) --> Changes the effector node at the specific pos (calls nodedef.mesecons.effector.action_change) -- mesecon:changesignal(pos, node, rulename, newstate) --> Changes the effector node at the specific pos (calls nodedef.mesecons.effector.action_change)
-- RULES -- RULES
-- mesecon:add_rules(name, rules) | deprecated? --> Saves rules table by name -- mesecon:add_rules(name, rules) | deprecated? --> Saves rules table by name
@@ -193,10 +193,10 @@ function mesecon:deactivate(pos, node, rulename)
end end
end end
function mesecon:changesignal(pos, node, rulename) function mesecon:changesignal(pos, node, rulename, newstate)
local effector = mesecon:get_effector(node.name) local effector = mesecon:get_effector(node.name)
if effector and effector.action_change then if effector and effector.action_change then
effector.action_change (pos, node, rulename) effector.action_change (pos, node, rulename, newstate)
end end
end end
@@ -299,7 +299,7 @@ function mesecon:turnon(pos, rulename)
end end
end end
elseif mesecon:is_effector(node.name) then elseif mesecon:is_effector(node.name) then
mesecon:changesignal(pos, node, rulename) mesecon:changesignal(pos, node, rulename, mesecon.state.on)
if mesecon:is_effector_off(node.name) then if mesecon:is_effector_off(node.name) then
mesecon:activate(pos, node, rulename) mesecon:activate(pos, node, rulename)
end end
@@ -322,7 +322,7 @@ function mesecon:turnoff(pos, rulename)
end end
end end
elseif mesecon:is_effector(node.name) then elseif mesecon:is_effector(node.name) then
mesecon:changesignal(pos, node, rulename) mesecon:changesignal(pos, node, rulename, mesecon.state.off)
if mesecon:is_effector_on(node.name) if mesecon:is_effector_on(node.name)
and not mesecon:is_powered(pos) then and not mesecon:is_powered(pos) then
mesecon:deactivate(pos, node, rulename) mesecon:deactivate(pos, node, rulename)

View File

@@ -4,3 +4,4 @@ NEW_STYLE_WIRES = true -- true = new nodebox wires, false = old raillike wires
PRESSURE_PLATE_INTERVAL = 0.1 PRESSURE_PLATE_INTERVAL = 0.1
OBJECT_DETECTOR_RADIUS = 6 OBJECT_DETECTOR_RADIUS = 6
PISTON_MAXIMUM_PUSH = 15 PISTON_MAXIMUM_PUSH = 15
MOVESTONE_MAXIMUM_PUSH = 100

View File

@@ -9,6 +9,7 @@ minetest.register_node("mesecons_blinkyplant:blinky_plant_off", {
walkable = false, walkable = false,
groups = {dig_immediate=3, mesecon = 2}, groups = {dig_immediate=3, mesecon = 2},
description="Blinky Plant", description="Blinky Plant",
sounds = default.node_sound_leaves_defaults(),
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1}, fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
@@ -29,6 +30,7 @@ minetest.register_node("mesecons_blinkyplant:blinky_plant_on", {
drop='"mesecons_blinkyplant:blinky_plant_off" 1', drop='"mesecons_blinkyplant:blinky_plant_off" 1',
light_source = LIGHT_MAX-7, light_source = LIGHT_MAX-7,
description = "Blinky Plant", description = "Blinky Plant",
sounds = default.node_sound_leaves_defaults(),
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1}, fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},

View File

@@ -6,6 +6,7 @@ mesecon.button_turnoff = function (pos)
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
if node.name=="mesecons_button:button_on" then --has not been dug if node.name=="mesecons_button:button_on" then --has not been dug
mesecon:swap_node(pos, "mesecons_button:button_off") mesecon:swap_node(pos, "mesecons_button:button_off")
minetest.sound_play("mesecons_button_pop", {pos=pos})
local rules = mesecon.rules.buttonlike_get(node) local rules = mesecon.rules.buttonlike_get(node)
mesecon:receptor_off(pos, rules) mesecon:receptor_off(pos, rules)
end end
@@ -42,8 +43,10 @@ minetest.register_node("mesecons_button:button_off", {
on_punch = function (pos, node) on_punch = function (pos, node)
mesecon:swap_node(pos, "mesecons_button:button_on") mesecon:swap_node(pos, "mesecons_button:button_on")
mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node)) mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node))
minetest.sound_play("mesecons_button_push", {pos=pos})
minetest.after(1, mesecon.button_turnoff, pos) minetest.after(1, mesecon.button_turnoff, pos)
end, end,
sounds = default.node_sound_stone_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.off, state = mesecon.state.off,
rules = mesecon.rules.buttonlike_get rules = mesecon.rules.buttonlike_get
@@ -80,6 +83,7 @@ minetest.register_node("mesecons_button:button_on", {
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon_needs_receiver = 1},
drop = 'mesecons_button:button_off', drop = 'mesecons_button:button_off',
description = "Button", description = "Button",
sounds = default.node_sound_stone_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.on, state = mesecon.state.on,
rules = mesecon.rules.buttonlike_get rules = mesecon.rules.buttonlike_get

Binary file not shown.

Binary file not shown.

View File

@@ -3,7 +3,7 @@ minetest.register_chatcommand("say", {
description = "Say <text> as the server", description = "Say <text> as the server",
privs = {server=true}, privs = {server=true},
func = function(name, param) func = function(name, param)
minetest.chat_send_all(param) minetest.chat_send_all(name .. ": " .. param)
end end
}) })
@@ -20,6 +20,20 @@ minetest.register_chatcommand("tell", {
end end
}) })
minetest.register_chatcommand("hp", {
params = "<name> <value>",
description = "Set health of <name> to <value> hitpoints",
privs = {ban=true},
func = function(name, param)
local found, _, target, value = param:find("^([^%s]+)%s+(%d+)$")
if found == nil then
minetest.chat_send_player(name, "Invalid usage: " .. param)
return
end
minetest.get_player_by_name(target):set_hp(value)
end
})
local initialize_data = function(meta, player, command, param) local initialize_data = function(meta, player, command, param)
meta:set_string("formspec", meta:set_string("formspec",
"invsize[9,6;]" .. "invsize[9,6;]" ..
@@ -152,6 +166,7 @@ minetest.register_node("mesecons_commandblock:commandblock_off", {
local owner = minetest.env:get_meta(pos):get_string("owner") local owner = minetest.env:get_meta(pos):get_string("owner")
return owner == "" or owner == player:get_player_name() return owner == "" or owner == player:get_player_name()
end, end,
sounds = default.node_sound_stone_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_on = commandblock_action_on action_on = commandblock_action_on
}} }}
@@ -169,6 +184,7 @@ minetest.register_node("mesecons_commandblock:commandblock_on", {
local owner = minetest.env:get_meta(pos):get_string("owner") local owner = minetest.env:get_meta(pos):get_string("owner")
return owner == "" or owner == player:get_player_name() return owner == "" or owner == player:get_player_name()
end, end,
sounds = default.node_sound_stone_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_off = commandblock_action_off action_off = commandblock_action_off
}} }}

View File

@@ -153,6 +153,7 @@ doors:register_door("doors:door_wood", {
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,door=1}, groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,door=1},
tiles_bottom = {"door_wood_b.png", "door_brown.png"}, tiles_bottom = {"door_wood_b.png", "door_brown.png"},
tiles_top = {"door_wood_a.png", "door_brown.png"}, tiles_top = {"door_wood_a.png", "door_brown.png"},
sounds = default.node_sound_wood_defaults(),
}) })
doors:register_door("doors:door_steel", { doors:register_door("doors:door_steel", {
@@ -162,4 +163,5 @@ doors:register_door("doors:door_steel", {
tiles_bottom = {"door_steel_b.png", "door_grey.png"}, tiles_bottom = {"door_steel_b.png", "door_grey.png"},
tiles_top = {"door_steel_a.png", "door_grey.png"}, tiles_top = {"door_steel_a.png", "door_grey.png"},
only_placer_can_open = true, only_placer_can_open = true,
sounds = default.node_sound_stone_defaults(),
}) })

View File

@@ -110,6 +110,7 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
end, end,
delayer_time = delaytime, delayer_time = delaytime,
delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i), delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i),
sounds = default.node_sound_stone_defaults(),
mesecons = { mesecons = {
receptor = receptor =
{ {

View File

@@ -1,7 +1,48 @@
-- Object detector -- Object detector
-- Detects all entities in a certain radius -- Detects players in a certain radius
-- The radius can be specified in mesecons/settings.lua -- The radius can be specified in mesecons/settings.lua
local object_detector_make_formspec = function (pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", "size[9,2.5]" ..
"field[0.3, 0;9,2;scanname;Name of player to scan for (empty for any):;${scanname}]"..
"field[0.3,1.5;4,2;digiline_channel;Digiline Channel (optional):;${digiline_channel}]")
end
local object_detector_on_receive_fields = function (pos, formname, fields)
local meta = minetest.env:get_meta(pos)
meta:set_string("scanname", fields.scanname)
meta:set_string("digiline_channel", fields.digiline_channel)
object_detector_make_formspec(pos)
end
-- returns true if player was found, false if not
local object_detector_scan = function (pos)
local objs = minetest.env:get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS)
for k, obj in pairs(objs) do
local isname = obj:get_player_name() -- "" is returned if it is not a player; "" ~= nil!
local scanname = minetest.env:get_meta(pos):get_string("scanname")
if (isname == scanname and isname ~= "") or (isname ~= "" and scanname == "") then -- player with scanname found or not scanname specified
return true
end
end
return false
end
-- set player name when receiving a digiline signal on a specific channel
object_detector_digiline = {
effector = {
action = function (pos, node, channel, msg)
local meta = minetest.env:get_meta(pos)
local active_channel = meta:get_string("digiline_channel")
if channel == active_channel then
meta:set_string("scanname", msg)
object_detector_make_formspec(pos)
end
end,
}
}
minetest.register_node("mesecons_detector:object_detector_off", { minetest.register_node("mesecons_detector:object_detector_off", {
tiles = {"default_steel_block.png", "default_steel_block.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png"}, tiles = {"default_steel_block.png", "default_steel_block.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png"},
paramtype = "light", paramtype = "light",
@@ -10,7 +51,11 @@ minetest.register_node("mesecons_detector:object_detector_off", {
description="Player Detector", description="Player Detector",
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.off state = mesecon.state.off
}} }},
on_construct = object_detector_make_formspec,
on_receive_fields = object_detector_on_receive_fields,
sounds = default.node_sound_stone_defaults(),
digiline = object_detector_digiline
}) })
minetest.register_node("mesecons_detector:object_detector_on", { minetest.register_node("mesecons_detector:object_detector_on", {
@@ -21,15 +66,19 @@ minetest.register_node("mesecons_detector:object_detector_on", {
drop = 'mesecons_detector:object_detector_off', drop = 'mesecons_detector:object_detector_off',
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.on state = mesecon.state.on
}} }},
on_construct = object_detector_make_formspec,
on_receive_fields = object_detector_on_receive_fields,
sounds = default.node_sound_stone_defaults(),
digiline = object_detector_digiline
}) })
minetest.register_craft({ minetest.register_craft({
output = 'mesecons_detector:object_detector_off', output = 'mesecons_detector:object_detector_off',
recipe = { recipe = {
{"default:steelblock", '', "default:steelblock"}, {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
{"default:steelblock", "mesecons_microcontroller:microcontroller0000", "default:steelblock"}, {"default:steel_ingot", "mesecons_luacontroller:luacontroller0000", "default:steel_ingot"},
{"default:steelblock", "group:mesecon_conductor_craftable", "default:steelblock"}, {"default:steel_ingot", "group:mesecon_conductor_craftable", "default:steel_ingot"},
} }
}) })
@@ -37,20 +86,11 @@ minetest.register_abm(
{nodenames = {"mesecons_detector:object_detector_off"}, {nodenames = {"mesecons_detector:object_detector_off"},
interval = 1.0, interval = 1.0,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos)
local objs = minetest.env:get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS) if object_detector_scan(pos) then
for k, obj in pairs(objs) do mesecon:swap_node(pos, "mesecons_detector:object_detector_on")
if obj:get_entity_name()~="mesecons_pistons:piston_pusher_sticky" and obj:get_entity_name()~="mesecons_pistons:piston_pusher_normal" and obj:get_player_name()~=nil then
if minetest.env:get_node({x=pos.x, y=pos.y-1, z=pos.z}).name=="default:sign_wall" then
if obj:get_player_name()~=minetest.env:get_meta({x=pos.x, y=pos.y-1, z=pos.z}):get_string("text") then
return
end
end
local objpos=obj:getpos()
minetest.env:add_node(pos, {name="mesecons_detector:object_detector_on"})
mesecon:receptor_on(pos) mesecon:receptor_on(pos)
end end
end
end, end,
}) })
@@ -58,24 +98,9 @@ minetest.register_abm(
{nodenames = {"mesecons_detector:object_detector_on"}, {nodenames = {"mesecons_detector:object_detector_on"},
interval = 1.0, interval = 1.0,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos)
local objs = minetest.env:get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS) if not object_detector_scan(pos) then
local objectfound=0 mesecon:swap_node(pos, "mesecons_detector:object_detector_off")
for k, obj in pairs(objs) do
if obj:get_entity_name()~="mesecons_pistons:piston_pusher_sticky" and obj:get_entity_name()~="mesecons_pistons:piston_pusher_normal" and obj~=nil
and obj:get_player_name()~=nil then
if minetest.env:get_node({x=pos.x, y=pos.y-1, z=pos.z}).name=="default:sign_wall" then
if minetest.env:get_meta({x=pos.x, y=pos.y-1, z=pos.z}):get_string("text")== obj:get_player_name() then
objectfound=objectfound+1
end
else
-- Detected object is not piston pusher - will be changed if every entity has a type (like entity_type=mob)
objectfound=objectfound + 1
end
end
end
if objectfound==0 then
minetest.env:add_node(pos, {name="mesecons_detector:object_detector_off"})
mesecon:receptor_off(pos) mesecon:receptor_off(pos)
end end
end, end,

View File

@@ -38,7 +38,7 @@ minetest.register_node("mesecons_extrawires:corner_on", {
selection_box = corner_selectionbox, selection_box = corner_selectionbox,
node_box = corner_nodebox, node_box = corner_nodebox,
groups = {dig_immediate = 3, not_in_creative_inventory = 1}, groups = {dig_immediate = 3, not_in_creative_inventory = 1},
drop = "mesecons_extrawires:insulated_off", drop = "mesecons_extrawires:corner_off",
mesecons = {conductor = mesecons = {conductor =
{ {
state = mesecon.state.on, state = mesecon.state.on,

View File

@@ -10,7 +10,7 @@ local mesewire_rules =
minetest.register_node(":default:mese", { minetest.register_node(":default:mese", {
description = "Mese Block", description = "Mese Block",
tiles = {"default_mese_block.png"}, tiles = {minetest.registered_nodes["default:mese"].tiles[1]},
is_ground_content = true, is_ground_content = true,
groups = {cracky=1}, groups = {cracky=1},
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
@@ -22,7 +22,7 @@ minetest.register_node(":default:mese", {
}) })
minetest.register_node("mesecons_extrawires:mese_powered", { minetest.register_node("mesecons_extrawires:mese_powered", {
tiles = {"default_mese_block.png^[brighten"}, tiles = {minetest.registered_nodes["default:mese"].tiles[1].."^[brighten"},
is_ground_content = true, is_ground_content = true,
groups = {cracky=1, not_in_creative_inventory = 1}, groups = {cracky=1, not_in_creative_inventory = 1},
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),

View File

@@ -201,3 +201,17 @@ minetest.register_node("mesecons_extrawires:vertical_bottom_off", {
after_place_node = vertical_update, after_place_node = vertical_update,
after_dig_node = vertical_update after_dig_node = vertical_update
}) })
minetest.register_craft({
output = "mesecons_extrawires:vertical_off 3",
recipe = {
{"mesecons:wire_00000000_off"},
{"mesecons:wire_00000000_off"},
{"mesecons:wire_00000000_off"}
}
})
minetest.register_craft({
output = "mesecons:wire_00000000_off",
recipe = {{"mesecons_extrawires:vertical_off"}}
})

View File

@@ -156,6 +156,7 @@ for _, gate in ipairs(gates) do
end, end,
groups = groups, groups = groups,
drop = drop, drop = drop,
sounds = default.node_sound_stone_defaults(),
mesecons_gate = gate.name, mesecons_gate = gate.name,
mesecons = mesecons =
{ {

View File

@@ -23,6 +23,7 @@ minetest.register_node("mesecons_hydroturbine:hydro_turbine_off", {
{-0.45, 1.15, -0.1, 0.45, 1.45, 0.1}, {-0.45, 1.15, -0.1, 0.45, 1.45, 0.1},
{-0.1, 1.15, -0.45, 0.1, 1.45, 0.45}}, {-0.1, 1.15, -0.45, 0.1, 1.45, 0.45}},
}, },
sounds = default.node_sound_stone_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.off state = mesecon.state.off
}} }}
@@ -49,6 +50,7 @@ minetest.register_node("mesecons_hydroturbine:hydro_turbine_on", {
{-0.5, 1.15, -0.1, 0.5, 1.45, 0.1}, {-0.5, 1.15, -0.1, 0.5, 1.45, 0.1},
{-0.1, 1.15, -0.5, 0.1, 1.45, 0.5}}, {-0.1, 1.15, -0.5, 0.1, 1.45, 0.5}},
}, },
sounds = default.node_sound_stone_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.on state = mesecon.state.on
}} }}

View File

@@ -22,6 +22,7 @@ minetest.register_node("mesecons_lamp:lamp_on", {
selection_box = mesecon_lamp_box, selection_box = mesecon_lamp_box,
groups = {dig_immediate=3,not_in_creative_inventory=1, mesecon_effector_on = 1}, groups = {dig_immediate=3,not_in_creative_inventory=1, mesecon_effector_on = 1},
drop='"mesecons_lamp:lamp_off" 1', drop='"mesecons_lamp:lamp_off" 1',
sounds = default.node_sound_glass_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_off = function (pos, node) action_off = function (pos, node)
mesecon:swap_node(pos, "mesecons_lamp:lamp_off") mesecon:swap_node(pos, "mesecons_lamp:lamp_off")
@@ -42,6 +43,7 @@ minetest.register_node("mesecons_lamp:lamp_off", {
selection_box = mesecon_lamp_box, selection_box = mesecon_lamp_box,
groups = {dig_immediate=3, mesecon_receptor_off = 1, mesecon_effector_off = 1}, groups = {dig_immediate=3, mesecon_receptor_off = 1, mesecon_effector_off = 1},
description="Meselamp", description="Meselamp",
sounds = default.node_sound_glass_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_on = function (pos, node) action_on = function (pos, node)
mesecon:swap_node(pos, "mesecons_lamp:lamp_on") mesecon:swap_node(pos, "mesecons_lamp:lamp_on")

View File

@@ -4,6 +4,7 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
inventory_image = minetest.inventorycube(texture_off), inventory_image = minetest.inventorycube(texture_off),
groups = {cracky=2, mesecon_effector_off = 1, mesecon = 2}, groups = {cracky=2, mesecon_effector_off = 1, mesecon = 2},
description=name.." Lightstone", description=name.." Lightstone",
sounds = default.node_sound_stone_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_on = function (pos, node) action_on = function (pos, node)
mesecon:swap_node(pos, "mesecons_lightstone:lightstone_" .. name .. "_on") mesecon:swap_node(pos, "mesecons_lightstone:lightstone_" .. name .. "_on")
@@ -16,6 +17,7 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
groups = {cracky=2,not_in_creative_inventory=1, mesecon = 2}, groups = {cracky=2,not_in_creative_inventory=1, mesecon = 2},
drop = "node mesecons_lightstone:lightstone_" .. name .. "_off 1", drop = "node mesecons_lightstone:lightstone_" .. name .. "_off 1",
light_source = LIGHT_MAX-2, light_source = LIGHT_MAX-2,
sounds = default.node_sound_stone_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_off = function (pos, node) action_off = function (pos, node)
mesecon:swap_node(pos, "mesecons_lightstone:lightstone_" .. name .. "_off") mesecon:swap_node(pos, "mesecons_lightstone:lightstone_" .. name .. "_off")

View File

@@ -0,0 +1 @@
mesecons

View File

@@ -0,0 +1,510 @@
-- Reference
-- ports = get_real_portstates(pos): gets if inputs are powered from outside
-- newport = merge_portstates(state1, state2): just does result = state1 or state2 for every port
-- action_setports(pos, ports, vports): activates/deactivates the mesecons according to the portstates (helper for action)
-- action(pos, ports): Applies new portstates to a luacontroller at pos
-- lc_update(pos): updates the controller at pos by executing the code
-- reset_meta (pos, code, errmsg): performs a software-reset, installs new code and prints error messages
-- reset (pos): performs a hardware reset, turns off all ports
--
-- The Sandbox
-- The whole code of the controller runs in a sandbox,
-- a very restricted environment.
-- However, as this does not prevent you from using e.g. loops,
-- we need to check for these prohibited commands first.
-- Actually the only way to damage the server is to
-- use too much memory from the sandbox.
-- You can add more functions to the environment
-- (see where local env is defined)
-- Something nice to play is is appending minetest.env to it.
local BASENAME = "mesecons_luacontroller:luacontroller"
local rules = {}
rules.a = {x = -1, y = 0, z = 0, name="A"}
rules.b = {x = 0, y = 0, z = 1, name="B"}
rules.c = {x = 1, y = 0, z = 0, name="C"}
rules.d = {x = 0, y = 0, z = -1, name="D"}
------------------
-- Action stuff --
------------------
-- These helpers are required to set the portstates of the luacontroller
local get_real_portstates = function(pos) -- determine if ports are powered (by itself or from outside)
ports = {
a = mesecon:is_power_on(mesecon:addPosRule(pos, rules.a))
and mesecon:rules_link(mesecon:addPosRule(pos, rules.a), pos),
b = mesecon:is_power_on(mesecon:addPosRule(pos, rules.b))
and mesecon:rules_link(mesecon:addPosRule(pos, rules.b), pos),
c = mesecon:is_power_on(mesecon:addPosRule(pos, rules.c))
and mesecon:rules_link(mesecon:addPosRule(pos, rules.c), pos),
d = mesecon:is_power_on(mesecon:addPosRule(pos, rules.d))
and mesecon:rules_link(mesecon:addPosRule(pos, rules.d), pos),
}
return ports
end
local merge_portstates = function (ports, vports)
local npo = {a=false, b=false, c=false, d=false}
npo.a = vports.a or ports.a
npo.b = vports.b or ports.b
npo.c = vports.c or ports.c
npo.d = vports.d or ports.d
return npo
end
local generate_name = function (ports, overwrite)
local overwrite = overwrite or {}
local d = overwrite.d or (ports.d and 1 or 0)
local c = overwrite.c or (ports.c and 1 or 0)
local b = overwrite.b or (ports.b and 1 or 0)
local a = overwrite.a or (ports.a and 1 or 0)
return BASENAME..d..c..b..a
end
local setport = function (pos, rule, ignore, state, ports)
local ignorename = generate_name(ports, ignore)
mesecon:swap_node(pos, ignorename)
if state then
mesecon:receptor_on(pos, {rule})
else
mesecon:receptor_off(pos, {rule})
end
if minetest.env:get_node(pos).name ~= ignorename then
return true -- overridden by second process
end
return false -- success
end
local action = function (pos, ports, forcereset)
local name = minetest.env:get_node(pos).name
local vports = minetest.registered_nodes[name].virtual_portstates
local newname = generate_name(ports)
if name ~= newname and vports then
local rules_on = {}
local rules_off = {}
local ignore = {}
local interrupted
if ports.a ~= vports.a then interrupted = setport(pos, rules.a, {a = 2}, ports.a, ports) end
if interrupted and not forcereset then return end
if ports.b ~= vports.b then interrupted = setport(pos, rules.b, {b = 2}, ports.b, ports) end
if interrupted and not forcereset then return end
if ports.c ~= vports.c then interrupted = setport(pos, rules.c, {c = 2}, ports.c, ports) end
if interrupted and not forcereset then return end
if ports.d ~= vports.d then interrupted = setport(pos, rules.d, {d = 2}, ports.d, ports) end
if interrupted and not forcereset then return end
mesecon:swap_node(pos, newname)
end
end
local delayedaction = function (params)
action(params.pos, params.ports)
end
--------------------
-- Overheat stuff --
--------------------
local heat = function (meta) -- warm up
h = meta:get_int("heat")
if h ~= nil then
meta:set_int("heat", h + 1)
end
end
local cool = function (meta) -- cool down after a while
h = meta:get_int("heat")
if h ~= nil then
meta:set_int("heat", h - 1)
end
end
local overheat = function (meta) -- determine if too hot
h = meta:get_int("heat")
if h == nil then return true end -- if nil then overheat
if h > 20 then
return true
else
return false
end
end
local overheat_off = function(pos)
mesecon:receptor_off(pos, mesecon.rules.flat)
end
-------------------
-- Parsing stuff --
-------------------
local code_prohibited = function(code)
-- Clean code
local prohibited = {"while", "for", "repeat", "until", "function"}
for _, p in ipairs(prohibited) do
if string.find(code, p) then
return "Prohibited command: "..p
end
end
end
local safeprint = function(param)
print(dump(param))
end
local interrupt = function(params)
lc_update(params.pos, {type="interrupt", iid = params.iid})
end
local getinterrupt = function(pos)
local interrupt = function (time, iid) -- iid = interrupt id
if type(time) ~= "number" then return end
local iid = iid or math.random()
local meta = minetest.env:get_meta(pos)
local interrupts = minetest.deserialize(meta:get_string("lc_interrupts")) or {}
table.insert (interrupts, iid)
meta:set_string("lc_interrupts", minetest.serialize(interrupts))
minetest.after(time, interrupt, {pos=pos, iid = iid})
end
return interrupt
end
local getdigiline_send = function (pos)
local digiline_send = function (channel, msg)
if digiline then
digiline:receptor_send(pos, digiline.rules.default, channel, msg)
end
end
return digiline_send
end
local create_environment = function(pos, mem, event)
-- Gather variables for the environment
local vports = minetest.registered_nodes[minetest.env:get_node(pos).name].virtual_portstates
vports = {a = vports.a, b = vports.b, c = vports.c, d = vports.d}
local rports = get_real_portstates(pos)
return {
print = safeprint,
pin = merge_portstates(vports, rports),
port = vports,
interrupt = getinterrupt(pos),
digiline_send = getdigiline_send(pos),
mem = mem,
tostring = tostring,
tonumber = tonumber,
string = {
byte = string.byte,
char = string.char,
find = string.find,
format = string.format,
gmatch = string.gmatch,
gsub = string.gsub,
len = string.len,
lower = string.lower,
match = string.match,
rep = string.rep,
reverse = string.reverse,
sub = string.sub,
},
math = {
abs = math.abs,
acos = math.acos,
asin = math.asin,
atan = math.atan,
atan2 = math.atan2,
ceil = math.ceil,
cos = math.cos,
cosh = math.cosh,
deg = math.deg,
exp = math.exp,
floor = math.floor,
fmod = math.fmod,
frexp = math.frexp,
huge = math.huge,
ldexp = math.ldexp,
log = math.log,
log10 = math.log10,
max = math.max,
min = math.min,
modf = math.modf,
pi = math.pi,
pow = math.pow,
rad = math.rad,
random = math.random,
sin = math.sin,
sinh = math.sinh,
sqrt = math.sqrt,
tan = math.tan,
tanh = math.tanh,
},
table = {
insert = table.insert,
maxn = table.maxn,
remove = table.remove,
sort = table.sort
},
event = event,
}
end
local create_sandbox = function (code, env)
-- Create Sandbox
if code:byte(1) == 27 then
return _, "You Hacker You! Don't use binary code!"
end
f, msg = loadstring(code)
if not f then return _, msg end
setfenv(f, env)
return f
end
local do_overheat = function (pos, meta)
-- Overheat protection
heat(meta)
minetest.after(0.5, cool, meta)
if overheat(meta) then
minetest.env:remove_node(pos)
minetest.after(0.2, overheat_off, pos) -- wait for pending operations
minetest.env:add_item(pos, BASENAME.."0000")
return true
end
end
local load_memory = function(meta)
return minetest.deserialize(meta:get_string("lc_memory")) or {}
end
local save_memory = function(meta, mem)
meta:set_string("lc_memory", minetest.serialize(mem))
end
local interrupt_allow = function (meta, event)
if event.type ~= "interrupt" then return true end
local interrupts = minetest.deserialize(meta:get_string("lc_interrupts")) or {}
for _, i in ipairs(interrupts) do
if minetest.serialize(i) == minetest.serialize(event.iid) then
return true
end
end
return false
end
local ports_invalid = function (var)
if type(var) == "table" then
return false
end
return "The ports you set are invalid"
end
----------------------
-- Parsing function --
----------------------
lc_update = function (pos, event)
local meta = minetest.env:get_meta(pos)
if not interrupt_allow(meta, event) then return end
if do_overheat(pos, meta) then return end
-- load code & mem from memory
local mem = load_memory(meta)
local code = meta:get_string("code")
-- make sure code is ok and create environment
local prohibited = code_prohibited(code)
if prohibited then return prohibited end
local env = create_environment(pos, mem, event)
-- create the sandbox and execute code
local chunk, msg = create_sandbox (code, env)
if not chunk then return msg end
local success, msg = pcall(f)
if not success then return msg end
if ports_invalid(env.port) then return ports_invalid(env.port) end
save_memory(meta, mem)
-- Actually set the ports
minetest.after(0, delayedaction, {pos = pos, ports = env.port})
end
local reset_meta = function(pos, code, errmsg)
local meta = minetest.env:get_meta(pos)
meta:set_string("code", code)
if minetest.formspec_escape then
code = minetest.formspec_escape(code or "")
errmsg = minetest.formspec_escape(errmsg or "")
else
code = string.gsub(code or "", "%[", "(") -- would otherwise
code = string.gsub(code, "%]", ")") -- corrupt formspec
errmsg = string.gsub(errmsg or "", "%[", "(") -- would otherwise
errmsg = string.gsub(errmsg, "%]", ")") -- corrupt formspec
end
meta:set_string("formspec", "size[10,8]"..
"background[-0.2,-0.25;10.4,8.75;jeija_luac_background.png]"..
"textarea[0.2,0.6;10.2,5;code;;"..code.."]"..
"image_button[3.75,6;2.5,1;jeija_luac_runbutton.png;program;]"..
"image_button_exit[9.72,-0.25;0.425,0.4;jeija_close_window.png;exit;]"..
"label[0.1,5;"..errmsg.."]")
meta:set_int("heat", 0)
end
local reset = function (pos)
minetest.env:get_meta(pos):set_string("lc_interrupts", "")
action(pos, {a=false, b=false, c=false, d=false}, true)
end
-- ______
-- |
-- | | |
-- |___| | __ ___ _ __ _ _
-- | | | | |\ | | |_| | | | | |_ |_|
-- | |______ |__| | \| | | \ |__| |_ |_ |_ |\
--
-----------------------
-- Node Registration --
-----------------------
local output_rules={}
local input_rules={}
local nodebox = {
type = "fixed",
fixed = {
{ -8/16, -8/16, -8/16, 8/16, -7/16, 8/16 }, -- bottom slab
{ -5/16, -7/16, -5/16, 5/16, -6/16, 5/16 }, -- circuit board
{ -3/16, -6/16, -3/16, 3/16, -5/16, 3/16 }, -- IC
}
}
local selectionbox = {
type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, -5/16, 8/16 },
}
local digiline = {
receptor = {},
effector = {
action = function (pos, node, channel, msg)
lc_update (pos, {type = "digiline", channel = channel, msg = msg})
end
}
}
for a = 0, 2 do -- 0 = off; 1 = on; 2 = ignore
for b = 0, 2 do
for c = 0, 2 do
for d = 0, 2 do
local cid = tostring(d)..tostring(c)..tostring(b)..tostring(a)
local nodename = BASENAME..cid
local top = "jeija_luacontroller_top.png"
if a == 1 then
top = top.."^jeija_luacontroller_LED_A.png"
end
if b == 1 then
top = top.."^jeija_luacontroller_LED_B.png"
end
if c == 1 then
top = top.."^jeija_luacontroller_LED_C.png"
end
if d == 1 then
top = top.."^jeija_luacontroller_LED_D.png"
end
if a + b + c + d ~= 0 then
groups = {dig_immediate=2, not_in_creative_inventory=1}
else
groups = {dig_immediate=2}
end
output_rules[cid] = {}
input_rules[cid] = {}
if (a == 1) then table.insert(output_rules[cid], rules.a) end
if (b == 1) then table.insert(output_rules[cid], rules.b) end
if (c == 1) then table.insert(output_rules[cid], rules.c) end
if (d == 1) then table.insert(output_rules[cid], rules.d) end
if (a == 0) then table.insert(input_rules[cid], rules.a) end
if (b == 0) then table.insert(input_rules[cid], rules.b) end
if (c == 0) then table.insert(input_rules[cid], rules.c) end
if (d == 0) then table.insert(input_rules[cid], rules.d) end
local mesecons = {
effector =
{
rules = input_rules[cid],
action_change = function (pos, _, rulename, newstate)
lc_update(pos, {type=newstate, pin=rulename})
end,
},
receptor =
{
state = mesecon.state.on,
rules = output_rules[cid]
}
}
minetest.register_node(nodename, {
description = "Luacontroller",
drawtype = "nodebox",
tiles = {
top,
"jeija_microcontroller_bottom.png",
"jeija_microcontroller_sides.png",
"jeija_microcontroller_sides.png",
"jeija_microcontroller_sides.png",
"jeija_microcontroller_sides.png"
},
inventory_image = top,
paramtype = "light",
groups = groups,
drop = BASENAME.."0000",
sunlight_propagates = true,
selection_box = selectionbox,
node_box = nodebox,
on_construct = reset_meta,
on_receive_fields = function(pos, formname, fields)
reset(pos)
reset_meta(pos, fields.code)
local err = lc_update(pos, {type="program"})
if err then print(err) end
reset_meta(pos, fields.code, err)
end,
sounds = default.node_sound_stone_defaults(),
mesecons = mesecons,
digiline = digiline,
is_luacontroller = true,
virtual_portstates = { a = a == 1, -- virtual portstates are
b = b == 1, -- the ports the the
c = c == 1, -- controller powers itself
d = d == 1},-- so those that light up
after_dig_node = function (pos, node)
mesecon:receptor_off(pos, output_rules)
end,
})
end
end
end
end
------------------------
-- Craft Registration --
------------------------
minetest.register_craft({
output = BASENAME.."0000 2",
recipe = {
{'mesecons_materials:silicon', 'mesecons_materials:silicon', 'group:mesecon_conductor_craftable'},
{'mesecons_materials:silicon', 'mesecons_materials:silicon', 'group:mesecon_conductor_craftable'},
{'group:mesecon_conductor_craftable', 'group:mesecon_conductor_craftable', ''},
}
})

View File

@@ -128,6 +128,7 @@ minetest.register_node(nodename, {
yc_reset (pos) yc_reset (pos)
update_yc(pos) update_yc(pos)
end, end,
sounds = default.node_sound_stone_defaults(),
mesecons = mesecons, mesecons = mesecons,
after_dig_node = function (pos, node) after_dig_node = function (pos, node)
rules = mesecon:get_rules(node.name) rules = mesecon:get_rules(node.name)

View File

@@ -61,21 +61,11 @@ minetest.register_node("mesecons_movestones:movestone", {
legacy_facedir_simple = true, legacy_facedir_simple = true,
groups = {cracky=3}, groups = {cracky=3},
description="Movestone", description="Movestone",
sounds = default.node_sound_stone_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_on = function (pos, node) action_on = function (pos, node)
local direction=mesecon:get_movestone_direction(pos) local direction=mesecon:get_movestone_direction(pos)
if not direction then return end if not direction then return end
local checknode={}
local collpos={x=pos.x, y=pos.y, z=pos.z}
repeat -- Check if it collides with a stopper
collpos = mesecon:addPosRule(collpos, direction)
checknode=minetest.env:get_node(collpos)
if mesecon:is_mvps_stopper(checknode.name, direction) then
return
end
until checknode.name=="air"
or checknode.name=="ignore"
or not(minetest.registered_nodes[checknode.name].liquidtype == "none")
minetest.env:remove_node(pos) minetest.env:remove_node(pos)
mesecon:update_autoconnect(pos) mesecon:update_autoconnect(pos)
minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity") minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity")
@@ -97,17 +87,27 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
on_step = function(self, dtime) on_step = function(self, dtime)
local pos = self.object:getpos() local pos = self.object:getpos()
pos.x, pos.y, pos.z = math.floor(pos.x), math.floor(pos.y), math.floor(pos.z)
local direction = mesecon:get_movestone_direction(pos) local direction = mesecon:get_movestone_direction(pos)
if not direction then if not direction then
local name = minetest.env:get_node(pos).name
if name ~= "air" and name ~= "ignore" and minetest.registered_nodes[name].liquidtype == "none" then
mesecon:mvps_push(pos, direction, MOVESTONE_MAXIMUM_PUSH)
end
minetest.env:add_node(pos, {name="mesecons_movestones:movestone"})
self.object:remove()
return
end
local np = mesecon:addPosRule(pos, direction)
if not mesecon:mvps_push(np, direction, MOVESTONE_MAXIMUM_PUSH) then
minetest.env:add_node(pos, {name="mesecons_movestones:movestone"}) minetest.env:add_node(pos, {name="mesecons_movestones:movestone"})
self.object:remove() self.object:remove()
return return
end end
self.object:setvelocity({x=direction.x*2, y=direction.y*2, z=direction.z*2}) self.object:setvelocity({x=direction.x*2, y=direction.y*2, z=direction.z*2})
mesecon:mvps_push(pos, direction, 100)
end, end,
}) })
@@ -131,30 +131,11 @@ minetest.register_node("mesecons_movestones:sticky_movestone", {
legacy_facedir_simple = true, legacy_facedir_simple = true,
groups = {cracky=3}, groups = {cracky=3},
description="Sticky Movestone", description="Sticky Movestone",
sounds = default.node_sound_stone_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_on = function (pos, node) action_on = function (pos, node)
local direction=mesecon:get_movestone_direction(pos) local direction=mesecon:get_movestone_direction(pos)
if not direction then return end if not direction then return end
local checknode={}
local collpos={x=pos.x, y=pos.y, z=pos.z}
repeat -- Check if it collides with a stopper
collpos = mesecon:addPosRule(collpos, direction)
checknode=minetest.env:get_node(collpos)
if mesecon:is_mvps_stopper(checknode.name, direction) then
return
end
until checknode.name=="air"
or checknode.name=="ignore"
or not(minetest.registered_nodes[checknode.name].liquidtype == "none")
repeat -- Check if it collides with a stopper (pull direction)
collpos={x=collpos.x-direction.x, y=collpos.y-direction.y, z=collpos.z-direction.z}
checknode=minetest.env:get_node(collpos)
if mesecon:is_mvps_stopper(checknode.name, direction) then
return
end
until checknode.name=="air"
or checknode.name=="ignore"
or not(minetest.registered_nodes[checknode.name].liquidtype == "none")
minetest.env:remove_node(pos) minetest.env:remove_node(pos)
mesecon:update_autoconnect(pos) mesecon:update_autoconnect(pos)
minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity") minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity")
@@ -183,10 +164,21 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
on_step = function(self, dtime) on_step = function(self, dtime)
local pos = self.object:getpos() local pos = self.object:getpos()
local colp = pos pos.x, pos.y, pos.z = math.floor(pos.x), math.floor(pos.y), math.floor(pos.z)
local direction=mesecon:get_movestone_direction(colp) local direction = mesecon:get_movestone_direction(pos)
if not direction then if not direction then
local name = minetest.env:get_node(pos).name
if name ~= "air" and name ~= "ignore" and minetest.registered_nodes[name].liquidtype == "none" then
mesecon:mvps_push(pos, direction, MOVESTONE_MAXIMUM_PUSH)
end
minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"})
self.object:remove()
return
end
local np = mesecon:addPosRule(pos, direction)
if not mesecon:mvps_push(np, direction, MOVESTONE_MAXIMUM_PUSH) then
minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"}) minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"})
self.object:remove() self.object:remove()
return return
@@ -194,8 +186,6 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
self.object:setvelocity({x=direction.x*2, y=direction.y*2, z=direction.z*2}) self.object:setvelocity({x=direction.x*2, y=direction.y*2, z=direction.z*2})
mesecon:mvps_push(pos, direction, 100)
--STICKY --STICKY
mesecon:mvps_pull_all(pos, direction) mesecon:mvps_pull_all(pos, direction)
end, end,

View File

@@ -57,6 +57,7 @@ function mesecon:mvps_push(pos, dir, maximum) -- pos: pos of mvps; dir: directio
-- remove all nodes -- remove all nodes
for _, n in ipairs(nodes) do for _, n in ipairs(nodes) do
n.meta = minetest.env:get_meta(n.pos):to_table()
minetest.env:remove_node(n.pos) minetest.env:remove_node(n.pos)
end end
@@ -70,6 +71,7 @@ function mesecon:mvps_push(pos, dir, maximum) -- pos: pos of mvps; dir: directio
for _, n in ipairs(nodes) do for _, n in ipairs(nodes) do
np = mesecon:addPosRule(n.pos, dir) np = mesecon:addPosRule(n.pos, dir)
minetest.env:add_node(np, n.node) minetest.env:add_node(np, n.node)
minetest.env:get_meta(np):from_table(n.meta)
end end
for i in ipairs(nodes) do for i in ipairs(nodes) do
@@ -85,8 +87,10 @@ function mesecon:mvps_pull_single(pos, dir) -- pos: pos of mvps; direction: dire
if minetest.registered_nodes[nn.name].liquidtype == "none" if minetest.registered_nodes[nn.name].liquidtype == "none"
and not mesecon:is_mvps_stopper(nn, {x = -dir.x, y = -dir.y, z = -dir.z}, {{pos = np, node = nn}}, 1) then and not mesecon:is_mvps_stopper(nn, {x = -dir.x, y = -dir.y, z = -dir.z}, {{pos = np, node = nn}}, 1) then
local meta = minetest.env:get_meta(np):to_table()
minetest.env:remove_node(np) minetest.env:remove_node(np)
minetest.env:add_node(pos, nn) minetest.env:add_node(pos, nn)
minetest.env:get_meta(pos):from_table(meta)
nodeupdate(np) nodeupdate(np)
nodeupdate(pos) nodeupdate(pos)
@@ -107,7 +111,8 @@ function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: d
local oldpos = {x=lpos2.x+direction.x, y=lpos2.y+direction.y, z=lpos2.z+direction.z} local oldpos = {x=lpos2.x+direction.x, y=lpos2.y+direction.y, z=lpos2.z+direction.z}
repeat repeat
minetest.env:add_node(oldpos, {name=minetest.env:get_node(lpos2).name}) lnode2 = minetest.env:get_node(lpos2)
minetest.env:add_node(oldpos, {name=lnode2.name})
nodeupdate(oldpos) nodeupdate(oldpos)
oldpos = {x=lpos2.x, y=lpos2.y, z=lpos2.z} oldpos = {x=lpos2.x, y=lpos2.y, z=lpos2.z}
lpos2.x = lpos2.x-direction.x lpos2.x = lpos2.x-direction.x
@@ -118,6 +123,5 @@ function mesecon:mvps_pull_all(pos, direction) -- pos: pos of mvps; direction: d
minetest.env:remove_node(oldpos) minetest.env:remove_node(oldpos)
end end
mesecon:register_mvps_stopper("default:chest")
mesecon:register_mvps_stopper("default:chest_locked") mesecon:register_mvps_stopper("default:chest_locked")
mesecon:register_mvps_stopper("default:furnace") mesecon:register_mvps_stopper("default:furnace")

View File

@@ -14,6 +14,7 @@ minetest.register_node("mesecons_noteblock:noteblock", {
minetest.env:add_node(pos, {name = node.name, param2 = param2}) minetest.env:add_node(pos, {name = node.name, param2 = param2})
mesecon.noteblock_play(pos, param2) mesecon.noteblock_play(pos, param2)
end, end,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector = { -- play sound when activated mesecons = {effector = { -- play sound when activated
action_on = function (pos, node) action_on = function (pos, node)
mesecon.noteblock_play(pos, node.param2) mesecon.noteblock_play(pos, node.param2)

View File

@@ -1,43 +1,62 @@
-- Get mesecon rules of pistons -- Get mesecon rules of pistons
piston_rules = local piston_rules =
{{x=0, y=0, z=1}, --everything apart from z- (pusher side) {{x = 0, z = 0, y = 1}, -- everything apart from pusher side
{x=1, y=0, z=0}, {x = 1, z = 0, y = 1},
{x=-1, y=0, z=0}, {x = 1, z = 1, y = 1},
{x=1, y=1, z=0}, {x = 0, z = 1, y = 1},
{x=1, y=-1, z=0}, {x =-1, z = 0, y = 1},
{x=-1, y=1, z=0}, {x =-1, z =-1, y = 1},
{x=-1, y=-1, z=0}, {x = 0, z =-1, y = 1},
{x=0, y=1, z=1}, {x = 1, z =-1, y = 1},
{x=0, y=-1, z=1}} {x =-1, z = 1, y = 1},
local piston_get_rules = function (node) {x = 1, z = 0, y = 0},
local rules = piston_rules {x = 1, z = 1, y = 0},
for i = 1, node.param2 do {x = 0, z = 1, y = 0},
{x =-1, z = 0, y = 0},
{x =-1, z =-1, y = 0},
--{x = 0, z =-1, y = 0}, pusher side --> disabled
{x = 1, z =-1, y = 0},
{x =-1, z = 1, y = 0},
{x = 0, z = 0, y =-1},
{x = 1, z = 0, y =-1},
{x = 1, z = 1, y =-1},
{x = 0, z = 1, y =-1},
{x =-1, z = 0, y =-1},
{x =-1, z =-1, y =-1},
{x = 0, z =-1, y =-1},
{x = 1, z =-1, y =-1},
{x =-1, z = 1, y =-1}}
local piston_rotate_rules = function(param2, rules)
if param2 == 4 then
return mesecon:rotate_rules_up(mesecon:rotate_rules_left(rules))
end -- face up
if param2 == 6 then
return mesecon:rotate_rules_down(mesecon:rotate_rules_left(rules))
end -- face up
rules = mesecon:rotate_rules_down(rules)
for i = 1, param2 do
rules = mesecon:rotate_rules_left(rules) rules = mesecon:rotate_rules_left(rules)
end end
return rules return rules
end end
piston_facedir_direction = function (node) local piston_get_rules = function (node)
local rules = {{x = 0, y = 0, z = -1}} return piston_rotate_rules(node.param2, piston_rules)
for i = 1, node.param2 do
rules = mesecon:rotate_rules_left(rules)
end
return rules[1]
end end
piston_get_direction = function (dir, node) piston_facedir_direction = function (node)
if type(dir) == "function" then local rules = piston_rotate_rules(node.param2, {{x = 0, y = 0, z =-1}})
return dir(node) return rules[1]
else
return dir
end
end end
local piston_remove_pusher = function (pos, node) local piston_remove_pusher = function (pos, node)
pistonspec = minetest.registered_nodes[node.name].mesecons_piston pistonspec = minetest.registered_nodes[node.name].mesecons_piston
dir = piston_get_direction(pistonspec.dir, node) dir = piston_facedir_direction(node)
local pusherpos = mesecon:addPosRule(pos, dir) local pusherpos = mesecon:addPosRule(pos, dir)
local pushername = minetest.env:get_node(pusherpos).name local pushername = minetest.env:get_node(pusherpos).name
@@ -50,7 +69,7 @@ end
local piston_on = function (pos, node) local piston_on = function (pos, node)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
dir = piston_get_direction(pistonspec.dir, node) dir = piston_facedir_direction(node)
local np = mesecon:addPosRule(pos, dir) local np = mesecon:addPosRule(pos, dir)
success, stack = mesecon:mvps_push(np, dir, PISTON_MAXIMUM_PUSH) success, stack = mesecon:mvps_push(np, dir, PISTON_MAXIMUM_PUSH)
if success then if success then
@@ -66,7 +85,7 @@ local piston_off = function (pos, node)
piston_remove_pusher (pos, node) piston_remove_pusher (pos, node)
if pistonspec.sticky then if pistonspec.sticky then
dir = piston_get_direction(pistonspec.dir, node) dir = piston_facedir_direction(node)
pullpos = mesecon:addPosRule(pos, dir) pullpos = mesecon:addPosRule(pos, dir)
stack = mesecon:mvps_pull_single(pullpos, dir) stack = mesecon:mvps_pull_single(pullpos, dir)
mesecon:mvps_process_stack(stack) mesecon:mvps_process_stack(stack)
@@ -81,16 +100,20 @@ local piston_orientate = function (pos, placer)
local pitch = placer:get_look_pitch() * (180 / math.pi) local pitch = placer:get_look_pitch() * (180 / math.pi)
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
local pistonspec = minetest.registered_nodes[node.name].mesecons_piston
if pitch > 55 then --looking upwards if pitch > 55 then --looking upwards --> face down
minetest.env:add_node(pos, {name=pistonspec.piston_down}) minetest.env:set_node(pos, {name = node.name, param2 = 6})
elseif pitch < -55 then --looking downwards elseif pitch < -55 then --looking downwards --> face up
minetest.env:add_node(pos, {name=pistonspec.piston_up}) minetest.env:set_node(pos, {name = node.name, param2 = 4})
end end
end end
--
--
-- Node Registration
--
--
-- Horizontal pistons
local pt = 3/16 -- pusher thickness local pt = 3/16 -- pusher thickness
@@ -115,7 +138,6 @@ local piston_on_box = {
local pistonspec_normal = { local pistonspec_normal = {
offname = "mesecons_pistons:piston_normal_off", offname = "mesecons_pistons:piston_normal_off",
onname = "mesecons_pistons:piston_normal_on", onname = "mesecons_pistons:piston_normal_on",
dir = piston_facedir_direction,
pusher = "mesecons_pistons:piston_pusher_normal", pusher = "mesecons_pistons:piston_pusher_normal",
piston_down = "mesecons_pistons:piston_down_normal_off", piston_down = "mesecons_pistons:piston_down_normal_off",
piston_up = "mesecons_pistons:piston_up_normal_off", piston_up = "mesecons_pistons:piston_up_normal_off",
@@ -136,6 +158,7 @@ minetest.register_node("mesecons_pistons:piston_normal_off", {
paramtype2 = "facedir", paramtype2 = "facedir",
after_place_node = piston_orientate, after_place_node = piston_orientate,
mesecons_piston = pistonspec_normal, mesecons_piston = pistonspec_normal,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={ mesecons = {effector={
action_on = piston_on, action_on = piston_on,
rules = piston_get_rules rules = piston_get_rules
@@ -163,6 +186,7 @@ minetest.register_node("mesecons_pistons:piston_normal_on", {
node_box = piston_on_box, node_box = piston_on_box,
selection_box = piston_on_box, selection_box = piston_on_box,
mesecons_piston = pistonspec_normal, mesecons_piston = pistonspec_normal,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={ mesecons = {effector={
action_off = piston_off, action_off = piston_off,
rules = piston_get_rules rules = piston_get_rules
@@ -193,7 +217,6 @@ minetest.register_node("mesecons_pistons:piston_pusher_normal", {
local pistonspec_sticky = { local pistonspec_sticky = {
offname = "mesecons_pistons:piston_sticky_off", offname = "mesecons_pistons:piston_sticky_off",
onname = "mesecons_pistons:piston_sticky_on", onname = "mesecons_pistons:piston_sticky_on",
dir = piston_facedir_direction,
pusher = "mesecons_pistons:piston_pusher_sticky", pusher = "mesecons_pistons:piston_pusher_sticky",
sticky = true, sticky = true,
piston_down = "mesecons_pistons:piston_down_sticky_off", piston_down = "mesecons_pistons:piston_down_sticky_off",
@@ -215,6 +238,7 @@ minetest.register_node("mesecons_pistons:piston_sticky_off", {
paramtype2 = "facedir", paramtype2 = "facedir",
after_place_node = piston_orientate, after_place_node = piston_orientate,
mesecons_piston = pistonspec_sticky, mesecons_piston = pistonspec_sticky,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={ mesecons = {effector={
action_on = piston_on, action_on = piston_on,
rules = piston_get_rules rules = piston_get_rules
@@ -242,6 +266,7 @@ minetest.register_node("mesecons_pistons:piston_sticky_on", {
node_box = piston_on_box, node_box = piston_on_box,
selection_box = piston_on_box, selection_box = piston_on_box,
mesecons_piston = pistonspec_sticky, mesecons_piston = pistonspec_sticky,
sounds = default.node_sound_wood_defaults(),
mesecons = {effector={ mesecons = {effector={
action_off = piston_off, action_off = piston_off,
rules = piston_get_rules rules = piston_get_rules
@@ -267,357 +292,6 @@ minetest.register_node("mesecons_pistons:piston_pusher_sticky", {
node_box = piston_pusher_box, node_box = piston_pusher_box,
}) })
--
--
-- UP
--
--
local piston_up_pusher_box = {
type = "fixed",
fixed = {
{-2/16, -.5 - pt, -2/16, 2/16, .5, 2/16},
{-.5 , .5 - pt, -.5 , .5 , .5, .5},
}
}
local piston_up_on_box = {
type = "fixed",
fixed = {
{-.5, -.5, -.5 , .5, .5-pt, .5}
}
}
-- Normal
local pistonspec_normal_up = {
offname = "mesecons_pistons:piston_up_normal_off",
onname = "mesecons_pistons:piston_up_normal_on",
dir = {x = 0, y = 1, z = 0},
pusher = "mesecons_pistons:piston_up_pusher_normal"
}
-- offstate
minetest.register_node("mesecons_pistons:piston_up_normal_off", {
tiles = {
"mesecons_piston_pusher_front.png",
"mesecons_piston_back.png",
"mesecons_piston_left.png^[transformR270",
"mesecons_piston_right.png^[transformR90",
"mesecons_piston_bottom.png",
"mesecons_piston_top.png^[transformR180",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_normal_off",
mesecons_piston = pistonspec_normal_up,
mesecons = {effector={
action_on = piston_on,
}}
})
-- onstate
minetest.register_node("mesecons_pistons:piston_up_normal_on", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_on_front.png",
"mesecons_piston_back.png",
"mesecons_piston_left.png^[transformR270",
"mesecons_piston_right.png^[transformR90",
"mesecons_piston_bottom.png",
"mesecons_piston_top.png^[transformR180",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype = "light",
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_normal_off",
after_dig_node = piston_remove_pusher,
node_box = piston_up_on_box,
selection_box = piston_up_on_box,
mesecons_piston = pistonspec_normal_up,
mesecons = {effector={
action_off = piston_off,
}}
})
-- pusher
minetest.register_node("mesecons_pistons:piston_up_pusher_normal", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_pusher_front.png",
"mesecons_piston_pusher_back.png",
"mesecons_piston_pusher_left.png^[transformR270",
"mesecons_piston_pusher_right.png^[transformR90",
"mesecons_piston_pusher_bottom.png",
"mesecons_piston_pusher_top.png^[transformR180",
},
paramtype = "light",
paramtype2 = "facedir",
diggable = false,
corresponding_piston = "mesecons_pistons:piston_up_normal_on",
selection_box = piston_up_pusher_box,
node_box = piston_up_pusher_box,
})
-- Sticky
local pistonspec_sticky_up = {
offname = "mesecons_pistons:piston_up_sticky_off",
onname = "mesecons_pistons:piston_up_sticky_on",
dir = {x = 0, y = 1, z = 0},
pusher = "mesecons_pistons:piston_up_pusher_sticky",
sticky = true
}
-- offstate
minetest.register_node("mesecons_pistons:piston_up_sticky_off", {
tiles = {
"mesecons_piston_pusher_front_sticky.png",
"mesecons_piston_back.png",
"mesecons_piston_left.png^[transformR270",
"mesecons_piston_right.png^[transformR90",
"mesecons_piston_bottom.png",
"mesecons_piston_top.png^[transformR180",
"mesecons_piston_tb.png"
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_sticky_off",
mesecons_piston = pistonspec_sticky_up,
mesecons = {effector={
action_on = piston_on,
}}
})
-- onstate
minetest.register_node("mesecons_pistons:piston_up_sticky_on", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_on_front.png",
"mesecons_piston_back.png",
"mesecons_piston_left.png^[transformR270",
"mesecons_piston_right.png^[transformR90",
"mesecons_piston_bottom.png",
"mesecons_piston_top.png^[transformR180",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype = "light",
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_normal_off",
after_dig_node = piston_remove_pusher,
node_box = piston_up_on_box,
selection_box = piston_up_on_box,
mesecons_piston = pistonspec_sticky_up,
mesecons = {effector={
action_off = piston_off,
}}
})
-- pusher
minetest.register_node("mesecons_pistons:piston_up_pusher_sticky", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_pusher_front_sticky.png",
"mesecons_piston_pusher_back.png",
"mesecons_piston_pusher_left.png^[transformR270",
"mesecons_piston_pusher_right.png^[transformR90",
"mesecons_piston_pusher_bottom.png",
"mesecons_piston_pusher_top.png^[transformR180",
},
paramtype = "light",
paramtype2 = "facedir",
diggable = false,
corresponding_piston = "mesecons_pistons:piston_up_sticky_on",
selection_box = piston_up_pusher_box,
node_box = piston_up_pusher_box,
})
--
--
-- DOWN
--
--
local piston_down_pusher_box = {
type = "fixed",
fixed = {
{-2/16, -.5, -2/16, 2/16, .5 + pt, 2/16},
{-.5 , -.5, -.5 , .5 , -.5 + pt, .5},
}
}
local piston_down_on_box = {
type = "fixed",
fixed = {
{-.5, -.5+pt, -.5 , .5, .5, .5}
}
}
-- Normal
local pistonspec_normal_down = {
offname = "mesecons_pistons:piston_down_normal_off",
onname = "mesecons_pistons:piston_down_normal_on",
dir = {x = 0, y = -1, z = 0},
pusher = "mesecons_pistons:piston_down_pusher_normal",
}
-- offstate
minetest.register_node("mesecons_pistons:piston_down_normal_off", {
tiles = {
"mesecons_piston_back.png",
"mesecons_piston_pusher_front.png",
"mesecons_piston_left.png^[transformR90",
"mesecons_piston_right.png^[transformR270",
"mesecons_piston_bottom.png^[transformR180",
"mesecons_piston_top.png",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_normal_off",
mesecons_piston = pistonspec_normal_down,
mesecons = {effector={
action_on = piston_on,
}}
})
-- onstate
minetest.register_node("mesecons_pistons:piston_down_normal_on", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_back.png",
"mesecons_piston_on_front.png",
"mesecons_piston_left.png^[transformR90",
"mesecons_piston_right.png^[transformR270",
"mesecons_piston_bottom.png^[transformR180",
"mesecons_piston_top.png",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype = "light",
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_normal_off",
after_dig_node = piston_remove_pusher,
node_box = piston_down_on_box,
selection_box = piston_down_on_box,
mesecons_piston = pistonspec_normal_down,
mesecons = {effector={
action_off = piston_off,
}}
})
-- pusher
minetest.register_node("mesecons_pistons:piston_down_pusher_normal", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_pusher_back.png",
"mesecons_piston_pusher_front.png",
"mesecons_piston_pusher_left.png^[transformR90",
"mesecons_piston_pusher_right.png^[transformR270",
"mesecons_piston_pusher_bottom.png^[transformR180",
"mesecons_piston_pusher_top.png",
},
paramtype = "light",
paramtype2 = "facedir",
diggable = false,
corresponding_piston = "mesecons_pistons:piston_down_normal_on",
selection_box = piston_down_pusher_box,
node_box = piston_down_pusher_box,
})
-- Sticky
local pistonspec_sticky_down = {
onname = "mesecons_pistons:piston_down_sticky_on",
offname = "mesecons_pistons:piston_down_sticky_off",
dir = {x = 0, y = -1, z = 0},
pusher = "mesecons_pistons:piston_down_pusher_sticky",
sticky = true
}
-- offstate
minetest.register_node("mesecons_pistons:piston_down_sticky_off", {
tiles = {
"mesecons_piston_back.png",
"mesecons_piston_pusher_front_sticky.png",
"mesecons_piston_left.png^[transformR90",
"mesecons_piston_right.png^[transformR270",
"mesecons_piston_bottom.png^[transformR180",
"mesecons_piston_top.png",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_sticky_off",
mesecons_piston = pistonspec_sticky_down,
mesecons = {effector={
action_on = piston_on,
}}
})
-- onstate
minetest.register_node("mesecons_pistons:piston_down_sticky_on", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_back.png",
"mesecons_piston_on_front.png",
"mesecons_piston_left.png^[transformR90",
"mesecons_piston_right.png^[transformR270",
"mesecons_piston_bottom.png^[transformR180",
"mesecons_piston_top.png",
},
inventory_image = "mesecons_piston_top.png",
wield_image = "mesecons_piston_top.png",
groups = {cracky = 3, not_in_creative_inventory = 1},
paramtype = "light",
paramtype2 = "facedir",
drop = "mesecons_pistons:piston_sticky_off",
after_dig_node = piston_remove_pusher,
node_box = piston_down_on_box,
selection_box = piston_down_on_box,
mesecons_piston = pistonspec_sticky_down,
mesecons = {effector={
action_off = piston_off,
}}
})
-- pusher
minetest.register_node("mesecons_pistons:piston_down_pusher_sticky", {
drawtype = "nodebox",
tiles = {
"mesecons_piston_pusher_back.png",
"mesecons_piston_pusher_front_sticky.png",
"mesecons_piston_pusher_left.png^[transformR90",
"mesecons_piston_pusher_right.png^[transformR270",
"mesecons_piston_pusher_bottom.png^[transformR180",
"mesecons_piston_pusher_top.png",
},
paramtype = "light",
paramtype2 = "facedir",
diggable = false,
corresponding_piston = "mesecons_pistons:piston_down_sticky_on",
selection_box = piston_down_pusher_box,
node_box = piston_down_pusher_box,
})
-- Register pushers as stoppers if they would be seperated from the piston -- Register pushers as stoppers if they would be seperated from the piston
local piston_pusher_get_stopper = function (node, dir, stack, stackid) local piston_pusher_get_stopper = function (node, dir, stack, stackid)
if (stack[stackid + 1] if (stack[stackid + 1]
@@ -644,27 +318,9 @@ end
mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_normal", piston_pusher_get_stopper) mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_normal", piston_pusher_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_sticky", piston_pusher_get_stopper) mesecon:register_mvps_stopper("mesecons_pistons:piston_pusher_sticky", piston_pusher_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_normal", piston_pusher_up_down_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_pusher_sticky", piston_pusher_up_down_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_normal", piston_pusher_up_down_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_pusher_sticky", piston_pusher_up_down_get_stopper)
-- Register pistons as stoppers if they would be seperated from the stopper
local piston_up_down_get_stopper = function (node, dir, stack, stackid)
if (stack[stackid + 1]
and stack[stackid + 1].node.name == minetest.registered_nodes[node.name].mesecons_piston.pusher)
or (stack[stackid - 1]
and stack[stackid - 1].node.name == minetest.registered_nodes[node.name].mesecons_piston.pusher) then
return false
end
return true
end
local piston_get_stopper = function (node, dir, stack, stackid) local piston_get_stopper = function (node, dir, stack, stackid)
pistonspec = minetest.registered_nodes[node.name].mesecons_piston pistonspec = minetest.registered_nodes[node.name].mesecons_piston
dir = piston_get_direction(pistonspec.dir, node) dir = piston_facedir_direction(node)
local pusherpos = mesecon:addPosRule(stack[stackid].pos, dir) local pusherpos = mesecon:addPosRule(stack[stackid].pos, dir)
local pushernode = minetest.env:get_node(pusherpos) local pushernode = minetest.env:get_node(pusherpos)
@@ -682,12 +338,6 @@ end
mesecon:register_mvps_stopper("mesecons_pistons:piston_normal_on", piston_get_stopper) mesecon:register_mvps_stopper("mesecons_pistons:piston_normal_on", piston_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_sticky_on", piston_get_stopper) mesecon:register_mvps_stopper("mesecons_pistons:piston_sticky_on", piston_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_normal_on", piston_up_down_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_up_sticky_on", piston_up_down_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_normal_on", piston_up_down_get_stopper)
mesecon:register_mvps_stopper("mesecons_pistons:piston_down_sticky_on", piston_up_down_get_stopper)
--craft recipes --craft recipes
minetest.register_craft({ minetest.register_craft({
output = 'mesecons_pistons:piston_normal_off 2', output = 'mesecons_pistons:piston_normal_off 2',

View File

@@ -15,6 +15,7 @@ minetest.register_node("mesecons_powerplant:power_plant", {
type = "fixed", type = "fixed",
fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1}, fixed = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
}, },
sounds = default.node_sound_leaves_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.on state = mesecon.state.on
}} }}

View File

@@ -17,12 +17,15 @@ pp_on_timer = function (pos, elapsed)
if not ppspec then return end if not ppspec then return end
local objs = minetest.env:get_objects_inside_radius(pos, 1) local objs = minetest.env:get_objects_inside_radius(pos, 1)
local two_below = mesecon:addPosRule(pos, {x = 0, y = -2, z = 0})
if objs[1] == nil and node.name == ppspec.onstate then if objs[1] == nil and node.name == ppspec.onstate then
minetest.env:add_node(pos, {name = ppspec.offstate}) minetest.env:add_node(pos, {name = ppspec.offstate})
mesecon:receptor_off(pos) mesecon:receptor_off(pos)
-- force deactivation of mesecon two blocks below (hacky) -- force deactivation of mesecon two blocks below (hacky)
mesecon:turnoff(mesecon:addPosRule(pos, {x = 0, y = -2, z = 0})) if not mesecon:connected_to_receptor(two_below) then
mesecon:turnoff(two_below)
end
else else
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
local objpos = obj:getpos() local objpos = obj:getpos()
@@ -30,7 +33,7 @@ pp_on_timer = function (pos, elapsed)
minetest.env:add_node(pos, {name=ppspec.onstate}) minetest.env:add_node(pos, {name=ppspec.onstate})
mesecon:receptor_on(pos) mesecon:receptor_on(pos)
-- force activation of mesecon two blocks below (hacky) -- force activation of mesecon two blocks below (hacky)
mesecon:turnon(mesecon:addPosRule(pos, {x = 0, y = -2, z = 0})) mesecon:turnon(two_below)
end end
end end
end end
@@ -82,12 +85,19 @@ function mesecon:register_pressure_plate(offstate, onstate, description, texture
drop = offstate, drop = offstate,
pressureplate = ppspec, pressureplate = ppspec,
on_timer = pp_on_timer, on_timer = pp_on_timer,
sounds = default.node_sound_wood_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.on state = mesecon.state.on
}}, }},
on_construct = function(pos) on_construct = function(pos)
minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL) minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
end, end,
after_dig_node = function(pos)
local two_below = mesecon:addPosRule(pos, {x = 0, y = -2, z = 0})
if not mesecon:connected_to_receptor(two_below) then
mesecon:turnoff(two_below)
end
end
}) })
minetest.register_craft({ minetest.register_craft({

View File

@@ -5,6 +5,7 @@ minetest.register_node("mesecons_random:removestone", {
inventory_image = minetest.inventorycube("jeija_removestone_inv.png"), inventory_image = minetest.inventorycube("jeija_removestone_inv.png"),
groups = {cracky=3}, groups = {cracky=3},
description="Removestone", description="Removestone",
sounds = default.node_sound_stone_defaults(),
mesecons = {effector = { mesecons = {effector = {
action_on = function (pos, node) action_on = function (pos, node)
minetest.env:remove_node(pos) minetest.env:remove_node(pos)

View File

@@ -22,6 +22,7 @@ minetest.register_node("mesecons_solarpanel:solar_panel_on", {
}, },
drop = "mesecons_solarpanel:solar_panel_off", drop = "mesecons_solarpanel:solar_panel_off",
groups = {dig_immediate=3, not_in_creative_inventory = 1}, groups = {dig_immediate=3, not_in_creative_inventory = 1},
sounds = default.node_sound_glass_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.on state = mesecon.state.on
}} }}
@@ -51,6 +52,7 @@ minetest.register_node("mesecons_solarpanel:solar_panel_off", {
}, },
groups = {dig_immediate=3}, groups = {dig_immediate=3},
description="Solar Panel", description="Solar Panel",
sounds = default.node_sound_glass_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.off state = mesecon.state.off
}} }}

View File

@@ -5,12 +5,14 @@ minetest.register_node("mesecons_switch:mesecon_switch_off", {
paramtype2="facedir", paramtype2="facedir",
groups = {dig_immediate=2}, groups = {dig_immediate=2},
description="Switch", description="Switch",
sounds = default.node_sound_stone_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.off state = mesecon.state.off
}}, }},
on_punch = function(pos, node) on_punch = function(pos, node)
mesecon:swap_node(pos, "mesecons_switch:mesecon_switch_on") mesecon:swap_node(pos, "mesecons_switch:mesecon_switch_on")
mesecon:receptor_on(pos) mesecon:receptor_on(pos)
minetest.sound_play("mesecons_switch", {pos=pos})
end end
}) })
@@ -19,12 +21,14 @@ minetest.register_node("mesecons_switch:mesecon_switch_on", {
paramtype2="facedir", paramtype2="facedir",
groups = {dig_immediate=2,not_in_creative_inventory=1}, groups = {dig_immediate=2,not_in_creative_inventory=1},
drop='"mesecons_switch:mesecon_switch_off" 1', drop='"mesecons_switch:mesecon_switch_off" 1',
sounds = default.node_sound_stone_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.on state = mesecon.state.on
}}, }},
on_punch = function(pos, node) on_punch = function(pos, node)
mesecon:swap_node(pos, "mesecons_switch:mesecon_switch_off") mesecon:swap_node(pos, "mesecons_switch:mesecon_switch_off")
mesecon:receptor_off(pos) mesecon:receptor_off(pos)
minetest.sound_play("mesecons_switch", {pos=pos})
end end
}) })

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -34,7 +34,9 @@ minetest.register_node("mesecons_walllever:wall_lever_off", {
on_punch = function (pos, node) on_punch = function (pos, node)
mesecon:swap_node(pos, "mesecons_walllever:wall_lever_on") mesecon:swap_node(pos, "mesecons_walllever:wall_lever_on")
mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node)) mesecon:receptor_on(pos, mesecon.rules.buttonlike_get(node))
minetest.sound_play("mesecons_lever", {pos=pos})
end, end,
sounds = default.node_sound_wood_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
rules = mesecon.rules.buttonlike_get, rules = mesecon.rules.buttonlike_get,
state = mesecon.state.off state = mesecon.state.off
@@ -74,7 +76,9 @@ minetest.register_node("mesecons_walllever:wall_lever_on", {
on_punch = function (pos, node) on_punch = function (pos, node)
mesecon:swap_node(pos, "mesecons_walllever:wall_lever_off") mesecon:swap_node(pos, "mesecons_walllever:wall_lever_off")
mesecon:receptor_off(pos, mesecon.rules.buttonlike_get(node)) mesecon:receptor_off(pos, mesecon.rules.buttonlike_get(node))
minetest.sound_play("mesecons_lever", {pos=pos})
end, end,
sounds = default.node_sound_wood_defaults(),
mesecons = {receptor = { mesecons = {receptor = {
rules = mesecon.rules.buttonlike_get, rules = mesecon.rules.buttonlike_get,
state = mesecon.state.on state = mesecon.state.on

Binary file not shown.