mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-08-20 13:04:10 +02:00
Use all of VanessaE's textures, bugfixes & improvements
This commit is contained in:
parent
8b41402558
commit
ca4a8cd264
@ -1,10 +1,15 @@
|
||||
EEPROM_SIZE = 255
|
||||
|
||||
minetest.register_node("mesecons_microcontroller:microcontroller", {
|
||||
for a = 0, 1 do
|
||||
for b = 0, 1 do
|
||||
for c = 0, 1 do
|
||||
for d = 0, 1 do
|
||||
local nodename = "mesecons_microcontroller:microcontroller"..tostring(d)..tostring(c)..tostring(b)..tostring(a)
|
||||
minetest.register_node(nodename, {
|
||||
description = "Microcontroller",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"jeija_microcontroller_top_0000.png",
|
||||
"jeija_microcontroller_top_"..tostring(d)..tostring(c)..tostring(b)..tostring(a)..".png",
|
||||
"jeija_microcontroller_sides.png",
|
||||
},
|
||||
inventory_image = "jeija_microcontroller_top_0000.png",
|
||||
@ -13,6 +18,7 @@ minetest.register_node("mesecons_microcontroller:microcontroller", {
|
||||
walkable = true,
|
||||
groups = {dig_immediate=2},
|
||||
material = minetest.digprop_constanttime(1.0),
|
||||
drop = '"mesecons_microcontroller:microcontroller0000" 1',
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -8/16, -8/16, -8/16, 8/16, -4/16, 8/16 },
|
||||
@ -49,9 +55,20 @@ minetest.register_node("mesecons_microcontroller:microcontroller", {
|
||||
end
|
||||
end
|
||||
})
|
||||
local rules={}
|
||||
if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end
|
||||
if (b == 1) then table.insert(rules, {x = 0, y = 0, z = 1}) end
|
||||
if (c == 1) then table.insert(rules, {x = 1, y = 0, z = 0}) end
|
||||
if (d == 1) then table.insert(rules, {x = 0, y = 0, z = -1}) end
|
||||
mesecon:add_rules(nodename, rules)
|
||||
mesecon:add_receptor_node(nodename, rules)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'craft "mesecons_microcontroller:microcontroller" 2',
|
||||
output = 'craft "mesecons_microcontroller:microcontroller0000" 2',
|
||||
recipe = {
|
||||
{'mesecons_materials:silicon', 'mesecons_materials:silicon', 'mesecons:mesecon_off'},
|
||||
{'mesecons_materials:silicon', 'mesecons_materials:silicon', 'mesecons:mesecon_off'},
|
||||
@ -60,10 +77,7 @@ minetest.register_craft({
|
||||
})
|
||||
|
||||
function reset_yc(pos)
|
||||
mesecon:receptor_off(pos, mesecon:get_rules("microcontrollerA"))
|
||||
mesecon:receptor_off(pos, mesecon:get_rules("microcontrollerB"))
|
||||
mesecon:receptor_off(pos, mesecon:get_rules("microcontrollerC"))
|
||||
mesecon:receptor_off(pos, mesecon:get_rules("microcontrollerD"))
|
||||
yc_action(pos, {a=false, b=false, c=false, d=false})
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local r = ""
|
||||
for i=1, EEPROM_SIZE+1 do r=r.."0" end --Generate a string with EEPROM_SIZE*"0"
|
||||
@ -94,7 +108,9 @@ end
|
||||
|
||||
function parse_yccode(code, pos)
|
||||
local endi = 1
|
||||
local L = yc_get_portstates(pos)
|
||||
local Lreal = yc_get_real_portstates(pos)
|
||||
local Lvirtual = yc_get_virtual_portstates(pos)
|
||||
if Lvirtual == nil then return nil end
|
||||
local c
|
||||
local eeprom = minetest.env:get_meta(pos):get_string("eeprom")
|
||||
while true do
|
||||
@ -102,7 +118,7 @@ function parse_yccode(code, pos)
|
||||
if command == nil then return nil end
|
||||
if command == true then break end
|
||||
if command == "if" then
|
||||
r, endi = yc_command_if(code, endi, L, eeprom)
|
||||
r, endi = yc_command_if(code, endi, yc_merge_portstates(Lreal, Lvirtual), eeprom)
|
||||
if r == nil then return nil end
|
||||
if r == true then -- nothing
|
||||
elseif r == false then
|
||||
@ -114,11 +130,11 @@ function parse_yccode(code, pos)
|
||||
if params == nil then return nil end
|
||||
end
|
||||
if command == "on" then
|
||||
L = yc_command_on (params, L)
|
||||
L = yc_command_on (params, Lvirtual)
|
||||
elseif command == "off" then
|
||||
L = yc_command_off(params, L)
|
||||
L = yc_command_off(params, Lvirtual)
|
||||
elseif command == "sbi" then
|
||||
new_eeprom = yc_command_sbi (params, eeprom, L)
|
||||
new_eeprom = yc_command_sbi (params, eeprom, yc_merge_portstates(Lreal, Lvirtual))
|
||||
if new_eeprom == nil then return nil
|
||||
else eeprom = new_eeprom end
|
||||
elseif command == "if" then --nothing
|
||||
@ -129,7 +145,7 @@ function parse_yccode(code, pos)
|
||||
if eeprom == nil then return nil else
|
||||
minetest.env:get_meta(pos):set_string("eeprom", eeprom) end
|
||||
end
|
||||
yc_action(pos, L)
|
||||
yc_action(pos, Lvirtual)
|
||||
return true
|
||||
end
|
||||
|
||||
@ -257,7 +273,7 @@ function yc_command_if_getcondition(code, starti)
|
||||
end
|
||||
|
||||
function yc_command_parsecondition(cond, L, eeprom)
|
||||
cond = string.gsub(cond, "A", tostring(L.a and 1 or 0))
|
||||
cond = string.gsub(cond, "A", tonumber(L.a and 1 or 0))
|
||||
cond = string.gsub(cond, "B", tonumber(L.b and 1 or 0))
|
||||
cond = string.gsub(cond, "C", tonumber(L.c and 1 or 0))
|
||||
cond = string.gsub(cond, "D", tonumber(L.d and 1 or 0))
|
||||
@ -346,36 +362,50 @@ function yc_eeprom_read(number, eeprom)
|
||||
return value, endi
|
||||
end
|
||||
|
||||
function yc_get_port_rules(port)
|
||||
local rules = nil
|
||||
if port == "A" then
|
||||
rules = mesecon:get_rules("microcontrollerA")
|
||||
elseif port == "B" then
|
||||
rules = mesecon:get_rules("microcontrollerB")
|
||||
elseif port == "C" then
|
||||
rules = mesecon:get_rules("microcontrollerC")
|
||||
elseif port == "D" then
|
||||
rules = mesecon:get_rules("microcontrollerD")
|
||||
end
|
||||
return rules
|
||||
function yc_action(pos, L) --L-->Lvirtual
|
||||
yc_action_setports(pos, L)
|
||||
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local code = meta:get_string("code")
|
||||
local eeprom = meta:get_string("eeprom")
|
||||
local infotext = meta:get_string("infotext")
|
||||
local formspec = meta:get_string("formspec")
|
||||
local name = "mesecons_microcontroller:microcontroller"
|
||||
..tonumber(L.d and 1 or 0)
|
||||
..tonumber(L.c and 1 or 0)
|
||||
..tonumber(L.b and 1 or 0)
|
||||
..tonumber(L.a and 1 or 0)
|
||||
minetest.env:add_node(pos, {name=name})
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("code", code)
|
||||
meta:set_string("eeprom", eeprom)
|
||||
meta:set_string("infotext", infotext)
|
||||
meta:set_string("formspec", formspec)
|
||||
end
|
||||
|
||||
function yc_action(pos, L)
|
||||
yc_action_setport("A", L.a, pos)
|
||||
yc_action_setport("B", L.b, pos)
|
||||
yc_action_setport("C", L.c, pos)
|
||||
yc_action_setport("D", L.d, pos)
|
||||
end
|
||||
function yc_action_setports(pos, L)
|
||||
local ps = tonumber(L.d and 1 or 0)
|
||||
..tonumber(L.c and 1 or 0)
|
||||
..tonumber(L.b and 1 or 0)
|
||||
..tonumber(L.a and 1 or 0)
|
||||
|
||||
function yc_action_setport(port, state, pos)
|
||||
local rules = mesecon:get_rules("microcontroller"..port)
|
||||
if state == false then
|
||||
if mesecon:is_power_on({x=pos.x+rules[1].x, y=pos.y+rules[1].y, z=pos.z+rules[1].z}) then
|
||||
mesecon:turnoff(pos, rules[1].x, rules[1].y, rules[1].z, false)
|
||||
end
|
||||
elseif state == true then
|
||||
if mesecon:is_power_off({x=pos.x+rules[1].x, y=pos.y+rules[1].y, z=pos.z+rules[1].z}) then
|
||||
mesecon:turnon(pos, rules[1].x, rules[1].y, rules[1].z, false)
|
||||
local rulesps
|
||||
local rules
|
||||
for i=1, 4 do
|
||||
if i == 1 then rulesps = "1000" end
|
||||
if i == 2 then rulesps = "0100" end
|
||||
if i == 3 then rulesps = "0010" end
|
||||
if i == 4 then rulesps = "0001" end
|
||||
rules = mesecon:get_rules("mesecons_microcontroller:microcontroller"..rulesps)
|
||||
|
||||
if ps:sub(i, i) == "1" then
|
||||
if mesecon:is_power_off({x=pos.x+rules[1].x, y=pos.y+rules[1].y, z=pos.z+rules[1].z}) then
|
||||
mesecon:receptor_on(pos, rules)
|
||||
end
|
||||
else
|
||||
if mesecon:is_power_on({x=pos.x+rules[1].x, y=pos.y+rules[1].y, z=pos.z+rules[1].z}) then
|
||||
mesecon:receptor_off(pos, rules)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -389,11 +419,11 @@ function yc_set_portstate(port, state, L)
|
||||
return L
|
||||
end
|
||||
|
||||
function yc_get_portstates(pos)
|
||||
rulesA = mesecon:get_rules("microcontrollerA")
|
||||
rulesB = mesecon:get_rules("microcontrollerB")
|
||||
rulesC = mesecon:get_rules("microcontrollerC")
|
||||
rulesD = mesecon:get_rules("microcontrollerD")
|
||||
function yc_get_real_portstates(pos)
|
||||
rulesA = mesecon:get_rules("mesecons_microcontroller:microcontroller0001")
|
||||
rulesB = mesecon:get_rules("mesecons_microcontroller:microcontroller0010")
|
||||
rulesC = mesecon:get_rules("mesecons_microcontroller:microcontroller0100")
|
||||
rulesD = mesecon:get_rules("mesecons_microcontroller:microcontroller1000")
|
||||
local L = {
|
||||
a = mesecon:is_power_on({x=pos.x+rulesA[1].x, y=pos.y+rulesA[1].y, z=pos.z+rulesA[1].z}),
|
||||
b = mesecon:is_power_on({x=pos.x+rulesB[1].x, y=pos.y+rulesB[1].y, z=pos.z+rulesB[1].z}),
|
||||
@ -403,6 +433,28 @@ function yc_get_portstates(pos)
|
||||
return L
|
||||
end
|
||||
|
||||
function yc_get_virtual_portstates(pos)
|
||||
name = minetest.env:get_node(pos).name
|
||||
b, a = string.find(name, ":microcontroller")
|
||||
if a == nil then return nil end
|
||||
a = a + 1
|
||||
|
||||
Lvirtual = {false, false, false, false}
|
||||
if name:sub(a , a ) == "1" then Lvirtual.d = true end
|
||||
if name:sub(a+1, a+1) == "1" then Lvirtual.c = true end
|
||||
if name:sub(a+2, a+2) == "1" then Lvirtual.b = true end
|
||||
if name:sub(a+2, a+3) == "1" then Lvirtual.a = true end
|
||||
return Lvirtual
|
||||
end
|
||||
|
||||
function yc_merge_portstates(Lreal, Lvirtual)
|
||||
if Lvirtual.a~=nil then Lreal.a = Lvirtual.a end
|
||||
if Lvirtual.b~=nil then Lreal.b = Lvirtual.b end
|
||||
if Lvirtual.c~=nil then Lreal.c = Lvirtual.c end
|
||||
if Lvirtual.d~=nil then Lreal.d = Lvirtual.d end
|
||||
return Lreal
|
||||
end
|
||||
|
||||
function yc_skip_to_endif(code, starti)
|
||||
local i = starti
|
||||
local s = false
|
||||
@ -417,16 +469,7 @@ function yc_skip_to_endif(code, starti)
|
||||
end
|
||||
|
||||
mesecon:register_on_signal_change(function(pos, node)
|
||||
if node.name == "mesecons_microcontroller:microcontroller" then
|
||||
if string.find(node.name, "mesecons_microcontroller:microcontroller")~=nil then
|
||||
minetest.after(0.5, update_yc, pos)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
mesecon:add_rules("microcontrollerA", {{x = -1, y = 0, z = 0}})
|
||||
mesecon:add_rules("microcontrollerB", {{x = 0, y = 0, z = 1}})
|
||||
mesecon:add_rules("microcontrollerC", {{x = 1, y = 0, z = 0}})
|
||||
mesecon:add_rules("microcontrollerD", {{x = 0, y = 0, z = -1}})
|
||||
mesecon:add_rules("microcontroller_default", {})
|
||||
mesecon:add_receptor_node("mesecons_microcontroller:microcontroller", mesecon:get_rules("microcontroller_default"))
|
||||
mesecon:add_receptor_node("mesecons_microcontroller:microcontroller", mesecon:get_rules("microcontroller_default"))
|
||||
|
Loading…
Reference in New Issue
Block a user