Add in functioning Redstone

This commit is contained in:
oilboi 2020-02-21 19:29:36 -05:00
parent 75799d05d1
commit f569a2fe58
23 changed files with 511 additions and 13 deletions

View File

@ -4,6 +4,7 @@ local old = settings:get("dedicated_server_step")
settings:set("dedicated_server_step", 0.00001) settings:set("dedicated_server_step", 0.00001)
settings:set("liquid_update", 0.25) settings:set("liquid_update", 0.25)
settings:set("abm_interval", 0.25)
print("Changing server step from "..old.." to 0.00001") print("Changing server step from "..old.." to 0.00001")
print("Changing liquid update to ") print("Changing liquid update to ")

View File

@ -1,16 +1,10 @@
minetest.register_node("minecart:rail",{ minetest.register_node("minecart:rail",{
description = "Rail", description = "Rail",
wield_image = "rail.png", wield_image = "rail.png",
tiles = {
"stone.png", "stone.png",
"stone.png", "stone.png"
},
--[[
tiles = { tiles = {
"rail.png", "railcurve.png", "rail.png", "railcurve.png",
"railt.png", "railcross.png" "railt.png", "railcross.png"
}, },
]]--
drawtype = "raillike", drawtype = "raillike",
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
@ -26,10 +20,10 @@ minetest.register_node("minecart:rail",{
return return
end end
local pos = pointed_thing.above local pos = pointed_thing.above
if minetest.registered_nodes[minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name].walkable then if minetest.registered_nodes[minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name].walkable and minetest.get_node(pointed_thing.above).name == "air" then
minetest.set_node(pointed_thing.above, {name="minecart:rail"}) minetest.set_node(pointed_thing.above, {name="minecart:rail"})
itemstack:take_item(1) itemstack:take_item(1)
print(minetest.get_node(pointed_thing.above).param1) --print(minetest.get_node(pointed_thing.above).param1)
return(itemstack) return(itemstack)
end end
end, end,

View File

@ -0,0 +1 @@
main

136
mods/redstone/init.lua Normal file
View File

@ -0,0 +1,136 @@
--[[
redstone powder is raillike
check if solid block above
--if so, do not conduct above
uses height level to do powerlevel
uses lightlevel
a function for adding and removing redstone level
]]--
---set a torch source
local path = minetest.get_modpath("redstone")
dofile(path.."/wire.lua")
dofile(path.."/torch.lua")
redstone = {}
--3d plane direct neighbor
function redstone.update(pos,oldnode)
local old_max_level = minetest.registered_nodes[minetest.get_node(pos).name].power
--recover old info
if not old_max_level then
print("recovering")
old_max_level = minetest.registered_nodes[oldnode.name].power
end
local max_level = 0
for x = -1,1 do
for y = -1,1 do
for z = -1,1 do
if math.abs(x)+math.abs(y)+math.abs(z) == 1 then
local pos2 = vector.add(pos,vector.new(x,y,z))
local level2 = minetest.registered_nodes[minetest.get_node(pos2).name].power
if level2 and level2 > max_level then
max_level = level2 - 1
end
end
end
end
end
--print(max_level)
if old_max_level and old_max_level > max_level then
max_level = 0
end
--change to dust
if minetest.get_node_group(minetest.get_node(pos).name, "redstone_dust") > 0 then
minetest.set_node(pos, {name="redstone:dust_"..max_level})
end
for x = -1,1 do
for y = -1,1 do
for z = -1,1 do
if math.abs(x)+math.abs(y)+math.abs(z) == 1 then
local pos2 = vector.add(pos,vector.new(x,y,z))
local level2 = minetest.registered_nodes[minetest.get_node(pos2).name].power
if level2 and (level2 < max_level or level2 < old_max_level) then
redstone.update(pos2)
end
end
end
end
end
end
minetest.register_craftitem("redstone:dust", {
description = "Redstone Dust",
inventory_image = "redstone_dust_item.png",
wield_image = "redstone_dust_item.png",
wield_scale = {x = 1, y = 1, z = 1 + 1/16},
liquids_pointable = false,
on_place = function(itemstack, placer, pointed_thing)
if not pointed_thing.type == "node" then
return
end
local pos = pointed_thing.above
if minetest.registered_nodes[minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name].walkable and minetest.get_node(pointed_thing.above).name == "air" then
minetest.add_node(pointed_thing.above, {name="redstone:dust_0"})
itemstack:take_item(1)
--print(minetest.get_node(pointed_thing.above).param1)
minetest.after(0,function(pointed_thing)
minetest.punch_node(pointed_thing.above)
end,pointed_thing)
return(itemstack)
end
end,
})
--8 power levels 8 being the highest
local color = 0
for i = 0,8 do
local coloring = math.floor(color)
minetest.register_node("redstone:dust_"..i,{
description = "Redstone Dust",
wield_image = "redstone_dust_item.png",
tiles = {
"redstone_dust_main.png^[colorize:red:"..coloring, "redstone_turn.png^[colorize:red:"..coloring,
"redstone_t.png^[colorize:red:"..coloring, "redstone_cross.png^[colorize:red:"..coloring
},
power=i,
drawtype = "raillike",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
walkable = false,
node_placement_prediction = "",
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups={instant=1,attached=1,redstone_dust=1,redstone=1},
drop="redstone:dust",
on_punch = function(pos, node, puncher, pointed_thing)
redstone.update(pos)
end,
on_dig = function(pos, node, digger)
minetest.node_dig(pos, node, digger)
redstone.update(pos,node)
end,
})
color= color +31.875
end

View File

@ -0,0 +1,71 @@
minetest.register_node("redstone:wire",{
description = "Redstone Dust",
wield_image = "redstone_dust_item.png",
paramtype = "light",
drawtype = "nodebox",
--paramtype2 = "wallmounted",
walkable = false,
node_box = {
type = "connected",
--{xmin, ymin, zmin, xmax, ymax, zmax}
fixed = {-1/16, -1/2, -1/16, 1/16, -7/16, 1/16},
disconnected_sides = {-1/16, -1/2, -1/16, 1/16, 1/2, 1/16},
connect_top = {-1/16, -1/2, -1/16, 1/16, 1/2, 1/16},
-- connect_bottom =
connect_front = {-1/16, -1/2, -1/2, 1/16, -7/16, 1/16},
connect_left = {-1/2, -1/2, -1/16, 1/16, -7/16, 1/16},
connect_back = {-1/16, -1/2, -1/16, 1/16, -7/16, 1/2},
connect_right = {-1/16, -1/2, -1/16, 1/2, -7/16, 1/16},
},
collision_box = {
type = "connected",
--{xmin, ymin, zmin, xmax, ymax, zmax}
fixed = {-1/16, -1/2, -1/16, 1/16, -7/16, 1/16},
-- connect_top =
-- connect_bottom =
connect_front = {-1/16, -1/2, -1/2, 1/16, -7/16, 1/16},
connect_left = {-1/2, -1/2, -1/16, 1/16, -7/16, 1/16},
connect_back = {-1/16, -1/2, -1/16, 1/16, -7/16, 1/2},
connect_right = {-1/16, -1/2, -1/16, 1/2, -7/16, 1/16},
},
connects_to = {"group:redstone"},
inventory_image = fence_texture,
wield_image = fence_texture,
tiles = {"redstone_dust.png"},
sunlight_propagates = true,
is_ground_content = false,
groups = {redstone =1, instant=1},
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return itemstack
end
local wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above))
local fakestack = itemstack
local retval = false
if wdir < 1 then
return itemstack
elseif wdir == 1 then
retval = fakestack:set_name("redstone:dust")
else
retval = fakestack:set_name("redstone:dust")
end
if not retval then
return itemstack
end
itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
itemstack:set_name("redstone:dust")
if retval then
minetest.sound_play("stone", {pos=pointed_thing.above, gain = 1.0})
end
return itemstack
end,
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

199
mods/redstone/torch.lua Normal file
View File

@ -0,0 +1,199 @@
--get point where particle spawner is added
local function get_offset(wdir)
local z = 0
local x = 0
if wdir == 4 then
z = 0.25
elseif wdir == 2 then
x = 0.25
elseif wdir == 5 then
z = -0.25
elseif wdir == 3 then
x = -0.25
end
return {x = x, y = 0.27, z = z}
end
--remove smoke and fire
local function delete_ps(pos)
local meta = minetest.get_meta(pos)
minetest.delete_particlespawner(meta:get_int("psf"))
minetest.delete_particlespawner(meta:get_int("pss"))
end
--add in smoke and fire
local function create_ps(pos)
local dir = get_offset(minetest.get_node(pos).param2)
local ppos = vector.add(dir,pos)
local meta = minetest.get_meta(pos)
local psf = minetest.add_particlespawner({
amount = 2,
time = 0,
minpos = ppos,
maxpos = ppos,
minvel = vector.new(0,0,0),
maxvel = vector.new(0,0,0),
minacc = {x=0, y=0, z=0},
maxacc = {x=0, y=0, z=0},
minexptime = 1,
maxexptime = 1,
minsize = 3,
maxsize = 3,
collisiondetection = false,
vertical = true,
texture = "redstone_torch_animated.png",
animation = {type = "vertical_frames",
aspect_w = 16,
-- Width of a frame in pixels
aspect_h = 16,
-- Height of a frame in pixels
length = 0.2,
-- Full loop length
},
})
local pss = minetest.add_particlespawner({
amount = 2,
time = 0,
minpos = ppos,
maxpos = ppos,
minvel = vector.new(-0.1,0.1,-0.1),
maxvel = vector.new(0.1,0.3,0.1),
minacc = vector.new(0,0,0),
maxacc = vector.new(0,0,0),
minexptime = 1,
maxexptime = 2,
minsize = 1,
maxsize = 2,
collisiondetection = false,
vertical = false,
texture = "smoke.png",
})
meta:set_int("psf", psf)
meta:set_int("pss", pss)
end
--reload smoke and flame on load
minetest.register_lbm({
name = "redstone:torch",
nodenames = {"redstone:torch_floor","redstone:torch_wall"},
run_at_every_load = true,
action = function(pos, node)
create_ps(pos)
end,
})
-- Item definitions
minetest.register_craftitem("redstone:torch", {
description = "Redstone Torch",
inventory_image = "redstone_torch.png",
wield_image = "redstone_torch.png",
wield_scale = {x = 1, y = 1, z = 1 + 1/16},
liquids_pointable = false,
power = 8,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
return itemstack
end
local wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above))
local fakestack = itemstack
local retval = false
if wdir < 1 then
return itemstack
elseif wdir == 1 then
retval = fakestack:set_name("redstone:torch_floor")
else
retval = fakestack:set_name("redstone:torch_wall")
end
if not retval then
return itemstack
end
itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
itemstack:set_name("redstone:torch")
if retval then
minetest.sound_play("wood", {pos=pointed_thing.above, gain = 1.0})
end
return itemstack
end
})
minetest.register_node("redstone:torch_floor", {
inventory_image = "redstone_torch.png",
wield_image = "redstone_torch.png",
wield_scale = {x = 1, y = 1, z = 1 + 2/16},
drawtype = "mesh",
mesh = "torch_floor.obj",
tiles = {"redstone_torch.png"},
paramtype = "light",
paramtype2 = "none",
power = 8,
sunlight_propagates = true,
drop = "redstone:torch",
walkable = false,
light_source = 13,
groups = {choppy=2, dig_immediate=3, not_in_creative_inventory=1, attached_node=1, torch=1,redstone=1,connect_to_raillike=1},
legacy_wallmounted = true,
selection_box = {
type = "fixed",
fixed = {-1/16, -0.5, -1/16, 1/16, 2/16, 1/16},
},
on_construct = function(pos)
create_ps(pos)
redstone.update(pos)
end,
after_destruct = function(pos, oldnode)
redstone.update(pos,oldnode)
end,
on_destruct = function(pos)
delete_ps(pos)
end,
sounds = main.woodSound(),
})
minetest.register_node("redstone:torch_wall", {
inventory_image = "redstone_torch.png",
wield_image = "redstone_torch.png",
wield_scale = {x = 1, y = 1, z = 1 + 1/16},
drawtype = "mesh",
mesh = "torch_wall.obj",
tiles = {"redstone_torch.png"},
paramtype = "light",
paramtype2 = "wallmounted",
sunlight_propagates = true,
walkable = false,
light_source = 13,
power = 8,
groups = {choppy=2, dig_immediate=3, flammable=1, not_in_creative_inventory=1, attached_node=1, torch=1,redstone=1,redstone_torch=1,connect_to_raillike=1},
drop = "redstone:torch",
selection_box = {
type = "wallmounted",
wall_top = {-0.1, -0.1, -0.1, 0.1, 0.5, 0.1},
wall_bottom = {-0.1, -0.5, -0.1, 0.1, 0.1, 0.1},
wall_side = {-0.5, -0.3, -0.1, -0.2, 0.3, 0.1},
},
on_construct = function(pos)
create_ps(pos)
redstone.update(pos)
end,
after_destruct = function(pos, oldnode)
redstone.update(pos,oldnode)
end,
on_destruct = function(pos)
delete_ps(pos)
end,
sounds = main.woodSound(),
})
minetest.register_craft({
output = "redstone:torch 4",
recipe = {
{"redstone:dust"},
{"main:stick"}
}
})

42
mods/redstone/wire Normal file
View File

@ -0,0 +1,42 @@
minetest.register_node("redstone:wire",{
description = "Redstone Dust",
wield_image = "redstone_dust_item.png",
paramtype = "light",
drawtype = "nodebox",
--paramtype2 = "wallmounted",
walkable = false,
node_box = {
type = "connected",
--{xmin, ymin, zmin, xmax, ymax, zmax}
fixed = {-1/16, -1/2, -1/16, 1/16, -7/16, 1/16},
disconnected_sides = {-1/16, -1/2, -1/16, 1/16, 1/2, 1/16},
connect_top = {-1/16, -1/2, -1/16, 1/16, 1/2, 1/16},
-- connect_bottom =
connect_front = {-1/16, -1/2, -1/2, 1/16, -7/16, 1/16},
connect_left = {-1/2, -1/2, -1/16, 1/16, -7/16, 1/16},
connect_back = {-1/16, -1/2, -1/16, 1/16, -7/16, 1/2},
connect_right = {-1/16, -1/2, -1/16, 1/2, -7/16, 1/16},
},
collision_box = {
type = "connected",
--{xmin, ymin, zmin, xmax, ymax, zmax}
fixed = {-1/16, -1/2, -1/16, 1/16, -7/16, 1/16},
-- connect_top =
-- connect_bottom =
connect_front = {-1/16, -1/2, -1/2, 1/16, -7/16, 1/16},
connect_left = {-1/2, -1/2, -1/16, 1/16, -7/16, 1/16},
connect_back = {-1/16, -1/2, -1/16, 1/16, -7/16, 1/2},
connect_right = {-1/16, -1/2, -1/16, 1/2, -7/16, 1/16},
},
connects_to = {"group:redstone"},
inventory_image = fence_texture,
wield_image = fence_texture,
tiles = {"redstone_dust.png"},
sunlight_propagates = true,
is_ground_content = false,
groups = {redstone =1, instant=1},
})

42
mods/redstone/wire.lua Normal file
View File

@ -0,0 +1,42 @@
minetest.register_node("redstone:wire",{
description = "Redstone Wire",
wield_image = "redstone_dust.png",
paramtype = "light",
drawtype = "nodebox",
--paramtype2 = "wallmounted",
walkable = false,
node_box = {
type = "connected",
--{xmin, ymin, zmin, xmax, ymax, zmax}
fixed = {-1/16, -1/2, -1/16, 1/16, -7/16, 1/16},
disconnected_sides = {-1/16, -1/2, -1/16, 1/16, 1/2, 1/16},
connect_top = {-1/16, -1/2, -1/16, 1/16, 1/2, 1/16},
-- connect_bottom =
connect_front = {-1/16, -1/2, -1/2, 1/16, -7/16, 1/16},
connect_left = {-1/2, -1/2, -1/16, 1/16, -7/16, 1/16},
connect_back = {-1/16, -1/2, -1/16, 1/16, -7/16, 1/2},
connect_right = {-1/16, -1/2, -1/16, 1/2, -7/16, 1/16},
},
collision_box = {
type = "connected",
--{xmin, ymin, zmin, xmax, ymax, zmax}
fixed = {-1/16, -1/2, -1/16, 1/16, -7/16, 1/16},
-- connect_top =
-- connect_bottom =
connect_front = {-1/16, -1/2, -1/2, 1/16, -7/16, 1/16},
connect_left = {-1/2, -1/2, -1/16, 1/16, -7/16, 1/16},
connect_back = {-1/16, -1/2, -1/16, 1/16, -7/16, 1/2},
connect_right = {-1/16, -1/2, -1/16, 1/2, -7/16, 1/16},
},
connects_to = {"group:redstone"},
inventory_image = fence_texture,
wield_image = fence_texture,
tiles = {"redstone_dust.png"},
sunlight_propagates = true,
is_ground_content = false,
groups = {redstone =1, instant=1},
})

View File

@ -92,11 +92,11 @@ minetest.register_craftitem("torch:torch", {
wield_image = "torches_torch.png", wield_image = "torches_torch.png",
wield_scale = {x = 1, y = 1, z = 1 + 1/16}, wield_scale = {x = 1, y = 1, z = 1 + 1/16},
liquids_pointable = false, liquids_pointable = false,
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
return itemstack return itemstack
end end
local wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above)) local wdir = minetest.dir_to_wallmounted(vector.subtract(pointed_thing.under,pointed_thing.above))
local fakestack = itemstack local fakestack = itemstack
@ -113,7 +113,7 @@ minetest.register_craftitem("torch:torch", {
end end
itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir) itemstack, retval = minetest.item_place(fakestack, placer, pointed_thing, wdir)
itemstack:set_name("torch:torch") itemstack:set_name("torch:torch")
if retval then if retval then
minetest.sound_play("wood", {pos=pointed_thing.above, gain = 1.0}) minetest.sound_play("wood", {pos=pointed_thing.above, gain = 1.0})
end end

View File

@ -19,12 +19,22 @@
--water flow faster --water flow faster
--torches with particle --torches with particle
--make a mob --make a mob
--fix tools causing crash on pigs with no fleshy definition --fix tools causing crash on pigs with no fleshy definition
--ladders - only placeable on walls --ladders - only placeable on walls
--eating animation - particles? - entity? --eating animation - particles? - entity?
--boats --boats
make entities push against players --make falling item have fall soundspec
--rebalance sand audio
redstone - make nodes drop multiple items individually redstone - make nodes drop multiple items individually
make entities push against players
rewrite the item collection to magnetize using the possible application below rewrite the item collection to magnetize using the possible application below
crafting bench crafting bench
fishing fishing
@ -40,7 +50,9 @@ if placed last node put another stack into hand
have falling node hurt player? have falling node hurt player?
add a function to set a velocity goal to entities and then implement it with all entities add a function to set a velocity goal to entities and then implement it with all entities
^make a value if below then stop? ^make a value if below then stop?
colored chat messages
check if everyone is in bed before going to next night
also lock player in bed until they get out or daytime
open bugs: open bugs:
fix torches not deleting particles when mounted node dug <- meta glitch? fix torches not deleting particles when mounted node dug <- meta glitch?