diff --git a/blocks/component.lua b/blocks/component.lua index c59917f..22378a0 100644 --- a/blocks/component.lua +++ b/blocks/component.lua @@ -29,7 +29,7 @@ function logikraft.registerComponent(name,cmp) ((y==h) and (cables.top and cables.top[x] and "component_port.png" or "component.png") or "component.png"), -- z+ ((y==1) and (cables.bottom and cables.bottom[x] and "component_port.png" or "component.png") or "component.png"), -- z- }, - groups = {circuitry = 1,dig_immediate = 3}, + groups = {circuitry = 1,dig_immediate = 3, not_in_creative_inventory = (x==1 and y==1 and 0) or 1}, paramtype2 = "4dir", inventory_image = (x == 1 and y == 1 and "component_"..name..".png") or nil, drop = "logikraft:component_"..name.."_1_1", diff --git a/blocks/components_register.lua b/blocks/components_register.lua index 14c1305..c29bde7 100644 --- a/blocks/components_register.lua +++ b/blocks/components_register.lua @@ -16,6 +16,81 @@ logikraft.components = { outputs = {"out"}, compute = function(inz) return {out = (inz["in_1"] * inz["in_2"] == 0) and 0 or 1} end }, + ["nand"] = { + width = 2, + height = 3, + ports = { + left = {"in_2",nil,"in_1"}, + right = {nil,"out",nil} + }, + inputs = {"in_1","in_2"}, + outputs = {"out"}, + compute = function(inz) return {out = (inz["in_1"] * inz["in_2"] == 0) and 1 or 0} end + }, + ["or"] = { + width = 2, + height = 3, + ports = { + left = {"in_2",nil,"in_1"}, + right = {nil,"out",nil} + }, + inputs = {"in_1","in_2"}, + outputs = {"out"}, + compute = function(inz) return {out = (inz["in_1"] + inz["in_2"] == 0) and 0 or 1} end + }, + ["nor"] = { + width = 2, + height = 3, + ports = { + left = {"in_2",nil,"in_1"}, + right = {nil,"out",nil} + }, + inputs = {"in_1","in_2"}, + outputs = {"out"}, + compute = function(inz) return {out = (inz["in_1"] + inz["in_2"] == 0) and 1 or 0} end + }, + ["xor"] = { + width = 2, + height = 3, + ports = { + left = {"in_2",nil,"in_1"}, + right = {nil,"out",nil} + }, + inputs = {"in_1","in_2"}, + outputs = {"out"}, + compute = function(inz) return {out = (inz["in_1"] + inz["in_2"] == 1) and 1 or 0} end + }, + ["not"] = { + width = 2, + height = 1, + ports = { + left = {"in"}, + right = {"out"} + }, + inputs = {"in"}, + outputs = {"out"}, + compute = function(inz) return {out = 1 - inz["in"]} end + }, + ["on"] = { + width = 1, + height = 1, + ports = { + right = {"out"} + }, + inputs = {}, + outputs = {"out"}, + compute = function(inz) return {out = 1} end + }, + ["off"] = { + width = 1, + height = 1, + ports = { + right = {"out"} + }, + inputs = {}, + outputs = {"out"}, + compute = function(inz) return {out = 0} end + }, ["switch"] = { width = 2, height = 1, @@ -36,7 +111,17 @@ logikraft.components = { right = {"out_8","out_7","out_6","out_5","out_4","out_3","out_2","out_1"} }, inputs = {"in_1","in_2","in_3"}, - outputs = {"out_8","out_7","out_6","out_5","out_4","out_3","out_2","out_1"} + outputs = {"out_8","out_7","out_6","out_5","out_4","out_3","out_2","out_1"}, + compute = function(inz) return { + out_1 = (inz.in_1 == 0) and (inz.in_2 == 0) and (inz.in_3 == 0) and 1 or 0, + out_2 = (inz.in_1 == 1) and (inz.in_2 == 0) and (inz.in_3 == 0) and 1 or 0, + out_3 = (inz.in_1 == 0) and (inz.in_2 == 1) and (inz.in_3 == 0) and 1 or 0, + out_4 = (inz.in_1 == 1) and (inz.in_2 == 1) and (inz.in_3 == 0) and 1 or 0, + out_5 = (inz.in_1 == 0) and (inz.in_2 == 0) and (inz.in_3 == 1) and 1 or 0, + out_6 = (inz.in_1 == 1) and (inz.in_2 == 0) and (inz.in_3 == 1) and 1 or 0, + out_7 = (inz.in_1 == 0) and (inz.in_2 == 1) and (inz.in_3 == 1) and 1 or 0, + out_8 = (inz.in_1 == 1) and (inz.in_2 == 1) and (inz.in_3 == 1) and 1 or 0, + } end }, ["input"] = { width = 1, diff --git a/circuits.lua b/circuits.lua index 59e365c..4d35103 100644 --- a/circuits.lua +++ b/circuits.lua @@ -257,6 +257,9 @@ local function computeStep(circuit,connvals,computed) if allvalue then local output = logikraft.components[cmp.type].compute(inputs) + print("Component "..cmp.type) + print(dump(inputs)) + print(dump(output)) for name,v in pairs(output) do if cmp.ports[name] and connvals[cmp.ports[name]] diff --git a/textures/component_nand.png b/textures/component_nand.png new file mode 100644 index 0000000..00d6c6a Binary files /dev/null and b/textures/component_nand.png differ diff --git a/textures/component_nor.png b/textures/component_nor.png new file mode 100644 index 0000000..a8f4295 Binary files /dev/null and b/textures/component_nor.png differ diff --git a/textures/component_not.png b/textures/component_not.png new file mode 100644 index 0000000..161c6d0 Binary files /dev/null and b/textures/component_not.png differ diff --git a/textures/component_off.png b/textures/component_off.png new file mode 100644 index 0000000..d59722c Binary files /dev/null and b/textures/component_off.png differ diff --git a/textures/component_on.png b/textures/component_on.png new file mode 100644 index 0000000..e8d142a Binary files /dev/null and b/textures/component_on.png differ diff --git a/textures/component_or.png b/textures/component_or.png new file mode 100644 index 0000000..816bb2a Binary files /dev/null and b/textures/component_or.png differ diff --git a/textures/component_xor.png b/textures/component_xor.png new file mode 100644 index 0000000..025ef55 Binary files /dev/null and b/textures/component_xor.png differ