From 2fe7a05a3dfedc77dfdb2ef621695c9241dd8240 Mon Sep 17 00:00:00 2001 From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Fri, 10 Apr 2020 15:16:02 -0400 Subject: [PATCH] Rename switches to levers and fix treecapitator with activated tree node --- mods/main/nodes.lua | 3 ++- mods/redstone/button.lua | 12 +++++------ mods/redstone/craft.lua | 2 +- mods/redstone/functions.lua | 7 ++++++ mods/redstone/init.lua | 10 ++++----- mods/redstone/{switches.lua => lever.lua} | 26 +++++++++++------------ mods/redstone/space_maker.lua | 2 +- 7 files changed, 34 insertions(+), 28 deletions(-) rename mods/redstone/{switches.lua => lever.lua} (83%) diff --git a/mods/main/nodes.lua b/mods/main/nodes.lua index 788c2c4..bec5fcc 100644 --- a/mods/main/nodes.lua +++ b/mods/main/nodes.lua @@ -154,8 +154,9 @@ minetest.register_node("main:tree", { if not meta:contains("placed") then --remove tree for y = -6,6 do + local name = minetest.get_node(vector.new(pos.x,pos.y+y,pos.z)).name --print(y) - if minetest.get_node(vector.new(pos.x,pos.y+y,pos.z)).name == "main:tree" then + if name == "main:tree" or name == "redstone:node_activated_tree" then minetest.node_dig(vector.new(pos.x,pos.y+y,pos.z), node, digger) end end diff --git a/mods/redstone/button.lua b/mods/redstone/button.lua index 14e37f5..63b10bf 100644 --- a/mods/redstone/button.lua +++ b/mods/redstone/button.lua @@ -1,14 +1,12 @@ ---this removes power from node that the switch is powering +--this removes power from node that the button is powering local function on_button_destroy(pos) local param2 = minetest.get_node(pos).param2 - local self = minetest.get_node(pos) - local dir = minetest.wallmounted_to_dir(self.param2) - + local dir = minetest.wallmounted_to_dir(param2) local pos = vector.add(dir,pos) local node = minetest.get_node(pos) local name = node.name - local def = minetest.registered_nodes[name] + if def.drawtype == "normal" and string.match(name, "redstone:node_activated_") then name = "main:"..string.gsub(name, "redstone:node_activated_", "") minetest.set_node(pos, {name=name}) @@ -20,7 +18,7 @@ end minetest.register_node("redstone:button_off", { description = "Crafting Table", tiles = {"stone.png"}, - groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1}, + groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1,dig_immediate=1}, sounds = main.stoneSound(), paramtype = "light", paramtype2 = "wallmounted", @@ -60,7 +58,7 @@ minetest.register_node("redstone:button_off", { minetest.register_node("redstone:button_on", { description = "Crafting Table", tiles = {"stone.png"}, - groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1}, + groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1,dig_immediate=1}, sounds = main.stoneSound(), paramtype = "light", paramtype2 = "wallmounted", diff --git a/mods/redstone/craft.lua b/mods/redstone/craft.lua index a558973..c9bc901 100644 --- a/mods/redstone/craft.lua +++ b/mods/redstone/craft.lua @@ -13,7 +13,7 @@ minetest.register_craft({ } }) minetest.register_craft({ - output = "redstone:switch_off", + output = "redstone:lever_off", recipe = { {"main:stick"}, {"main:stone"}, diff --git a/mods/redstone/functions.lua b/mods/redstone/functions.lua index 3d7847c..638996f 100644 --- a/mods/redstone/functions.lua +++ b/mods/redstone/functions.lua @@ -6,3 +6,10 @@ function vector.abs(v) z = math.abs(v.z) } end + +--add a power signal to the position (i) that doesn't actually exist +redstone.inject_power_signal = function(i) + if not r_index[i.x] then r_index[i.x] = {} end + if not r_index[i.x][i.y] then r_index[i.x][i.y] = {} end + r_index[i.x][i.y][i.z] = {torch = true,power=9} +end diff --git a/mods/redstone/init.lua b/mods/redstone/init.lua index e071b46..d2e0f35 100644 --- a/mods/redstone/init.lua +++ b/mods/redstone/init.lua @@ -1,9 +1,12 @@ ----set a torch source +--define the class +redstone = {} +local r_index = {} + local path = minetest.get_modpath("redstone") dofile(path.."/functions.lua") dofile(path.."/wire.lua") dofile(path.."/torch.lua") -dofile(path.."/switches.lua") +dofile(path.."/lever.lua") dofile(path.."/button.lua") dofile(path.."/repeater.lua") dofile(path.."/light.lua") @@ -16,9 +19,6 @@ dofile(path.."/player_detector.lua") dofile(path.."/space_maker.lua") dofile(path.."/pressure_plate.lua") -redstone = {} - -local r_index = {} get_old_power = function(pos) local meta = minetest.get_meta(pos) diff --git a/mods/redstone/switches.lua b/mods/redstone/lever.lua similarity index 83% rename from mods/redstone/switches.lua rename to mods/redstone/lever.lua index 70c587f..6a4a497 100644 --- a/mods/redstone/switches.lua +++ b/mods/redstone/lever.lua @@ -18,7 +18,7 @@ for name,def in pairs(minetest.registered_nodes) do end ---this removes power from node that the switch is powering +--this removes power from node that the lever is powering local function on_lever_destroy(pos) local param2 = minetest.get_node(pos).param2 local self = minetest.get_node(pos) @@ -31,23 +31,23 @@ local function on_lever_destroy(pos) local def = minetest.registered_nodes[name] if def.drawtype == "normal" and string.match(name, "redstone:node_activated_")then name = "main:"..string.gsub(name, "redstone:node_activated_", "") - minetest.set_node(pos, {name=name}) + minetest.swap_node(pos, {name=name}) redstone.collect_info(pos) end end -minetest.register_node("redstone:switch_off", { - description = "Switch", +minetest.register_node("redstone:lever_off", { + description = "Lever", tiles = {"stone.png"}, - groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1}, + groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1,dig_immediate=1}, sounds = main.stoneSound(), paramtype = "light", paramtype2 = "wallmounted", sunlight_propagates = true, walkable = false, drawtype= "nodebox", - drop="redstone:switch_off", + drop="redstone:lever_off", node_box = { type = "fixed", fixed = { @@ -57,7 +57,7 @@ minetest.register_node("redstone:switch_off", { }, }, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - minetest.set_node(pos, {name="redstone:switch_on",param2=node.param2}) + minetest.set_node(pos, {name="redstone:lever_on",param2=node.param2}) local dir = minetest.wallmounted_to_dir(node.param2) local pos = vector.add(dir,pos) local name = minetest.get_node(pos).name @@ -66,7 +66,7 @@ minetest.register_node("redstone:switch_off", { if def.drawtype == "normal" and string.match(name, "main:") then minetest.sound_play("lever", {pos=pos}) name = "redstone:node_activated_"..string.gsub(name, "main:", "") - minetest.set_node(pos,{name=name}) + minetest.swap_node(pos,{name=name}) redstone.collect_info(pos) else minetest.sound_play("lever", {pos=pos,pitch=0.6}) @@ -74,17 +74,17 @@ minetest.register_node("redstone:switch_off", { end, on_destruct = on_lever_destroy, }) -minetest.register_node("redstone:switch_on", { - description = "Crafting Table", +minetest.register_node("redstone:lever_on", { + description = "Lever On", tiles = {"stone.png"}, - groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1}, + groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1,dig_immediate=1}, sounds = main.stoneSound(), paramtype = "light", paramtype2 = "wallmounted", sunlight_propagates = true, walkable = false, drawtype= "nodebox", - drop="redstone:switch_off", + drop="redstone:lever_off", node_box = { type = "fixed", fixed = { @@ -95,7 +95,7 @@ minetest.register_node("redstone:switch_on", { }, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) minetest.sound_play("lever", {pos=pos,pitch=0.8}) - minetest.set_node(pos, {name="redstone:switch_off",param2=node.param2}) + minetest.set_node(pos, {name="redstone:lever_off",param2=node.param2}) on_lever_destroy(pos) end, on_destruct = on_lever_destroy, diff --git a/mods/redstone/space_maker.lua b/mods/redstone/space_maker.lua index 06a4249..611203a 100644 --- a/mods/redstone/space_maker.lua +++ b/mods/redstone/space_maker.lua @@ -4,7 +4,7 @@ local items = { "redstone:repeater_off_0 50", "redstone:comparator_0 50", "redstone:torch 50", -"redstone:switch_off 50", +"redstone:lever_off 50", "redstone:button_off 50", "redstone:piston_off 50", "redstone:light_off 50",