From 6921028b4918eb01f49b6424bb798110088f4055 Mon Sep 17 00:00:00 2001 From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Thu, 9 Apr 2020 14:21:43 -0400 Subject: [PATCH] Push incomplete version of doubletap running due to possible hardware failure --- init.lua | 226 +++++++++++++++---------------------------- weather_handling.lua | 161 ++++++++++++++++++++++++++++++ 2 files changed, 239 insertions(+), 148 deletions(-) create mode 100644 weather_handling.lua diff --git a/init.lua b/init.lua index 461af94..4d80500 100644 --- a/init.lua +++ b/init.lua @@ -1,165 +1,95 @@ +--first we join the necessary channels so the mod can "listen" to what the server says local weather = minetest.mod_channel_join("weather_nodes") local weather_type = minetest.mod_channel_join("weather_type") -local server = minetest.mod_channel_join("server") +local running_send = minetest.mod_channel_join("running_send") +local running_receive = minetest.mod_channel_join("running_receive") -local all_nodes = {} -local do_effects = false -local snow = false -local rain = false -local weather_update_timer = 0 -local id_table = {} -local spawn_snow = function(player) - local pos = player:get_pos() - local radius = 10 - local particle_table = {} - - local area = vector.new(10,10,10) - - local min = vector.subtract(pos, area) - local max = vector.add(pos, area) - - - local area_index = minetest.find_nodes_in_area_under_air(min, max, all_nodes) - - local spawn_table = {} - --find the highest y value - for _,index in pairs(area_index) do - if not spawn_table[index.x] then spawn_table[index.x] = {} end - if not spawn_table[index.x][index.z] then - spawn_table[index.x][index.z] = index.y - elseif spawn_table[index.x][index.z] < index.y then - spawn_table[index.x][index.z] = index.y - end - end - - for x,x_index in pairs(spawn_table) do - for z,y in pairs(x_index) do - if minetest.get_node_or_nil(vector.new(x,y+1,z)) ~= nil then - --print("got to this spointa") - local pos = vector.new(x,y+1,z) - local lightlevel = 14 - --local lightlevel = minetest.get_node_light(pos, 0.5) - --print("but not here") - if lightlevel >= 14 then - minetest.add_particlespawner({ - amount = 1, - time = 0.5, - minpos = vector.new(x-0.5,y,z-0.5), - maxpos = vector.new(x+0.5,y+20,z+0.5), - minvel = {x=-0.2, y=-0.2, z=-0.2}, - maxvel = {x=0.2, y=-0.5, z=0.2}, - minacc = {x=0, y=0, z=0}, - maxacc = {x=0, y=0, z=0}, - minexptime = 1, - maxexptime = 1, - minsize = 1, - maxsize = 1, - collisiondetection = true, - collision_removal = true, - object_collision = false, - texture = "snowflake_"..math.random(1,2)..".png", - playername = player:get_name(), - }) - end - end - end - end -end +--we load everything seperately because it's easier to work on individual files than have everything jammed into one file +--not into seperate mods because that is unnecessary and cumbersome +local path = minetest.get_modpath("crafter_client") +dofile(path.."/weather_handling.lua") -local spawn_rain = function(player) - local pos = player:get_pos() - local radius = 10 - local particle_table = {} - - local area = vector.new(10,10,10) - - local min = vector.subtract(pos, area) - local max = vector.add(pos, area) - - - local area_index = minetest.find_nodes_in_area_under_air(min, max, all_nodes) - - local spawn_table = {} - --find the highest y value - for _,index in pairs(area_index) do - if not spawn_table[index.x] then spawn_table[index.x] = {} end - if not spawn_table[index.x][index.z] then - spawn_table[index.x][index.z] = index.y - elseif spawn_table[index.x][index.z] < index.y then - spawn_table[index.x][index.z] = index.y - end - end - - for x,x_index in pairs(spawn_table) do - for z,y in pairs(x_index) do - if minetest.get_node_or_nil(vector.new(x,y+1,z)) ~= nil then - --print("got to this spointa") - local pos = vector.new(x,y+1,z) - local lightlevel = 14 - --local lightlevel = minetest.get_node_light(pos, 0.5) - --print("but not here") - if lightlevel >= 14 then - minetest.add_particlespawner({ - amount = 1, - time = 0.5, - minpos = vector.new(x-0.5,y,z-0.5), - maxpos = vector.new(x+0.5,y+20,z+0.5), - minvel = {x=0, y=-9.81, z=0}, - maxvel = {x=0, y=-9.81, z=0}, - minacc = {x=0, y=0, z=0}, - maxacc = {x=0, y=0, z=0}, - minexptime = 1, - maxexptime = 2, - minsize = 1, - maxsize = 1, - collisiondetection = true, - collision_removal = true, - object_collision = false, - vertical = true, - texture = "raindrop.png", - playername = player:get_name(), - }) - end - end +--0 is nothing +--1 is up +--2 is down +--4 is left +--8 is right +--16 is jump +--32 is auxilary +--64 is sneak +--128 is left click +--256 is right click + +--make the data from get_key_pressed usable +--Thanks Thou shalt use my mods! +function minetest.get_control_bits(player) + local input = player:get_key_pressed() + local input_table = {} + --iterate through the table using the highest value first + local keys = {"rightclick","leftclick","sneak","aux","jump","right","left","down","up"} + for index,data in pairs(keys) do + local modifier = math.pow(2, 9-index) + if input >= modifier then + input_table[data] = true + input = input - modifier + else + input_table[data] = false end end + return(input_table) end -minetest.register_globalstep(function(dtime) - if do_effects then - if snow or rain then - weather_update_timer = weather_update_timer + dtime - if weather_update_timer >= 0.5 then - weather_update_timer = 0 - local player = minetest.localplayer - if snow == true then - spawn_snow(minetest.localplayer) - elseif rain == true then - spawn_rain(minetest.localplayer) - end - end - end - end -end) +--double tap running +--set up our initial values +local running = false +local run_discharge_timer = 0 +local old_up = false +--attempt to tell the server to allow us to run +local send_server_run_state = function(state) + running_send:send_all(state) +end +--receive the server states minetest.register_on_modchannel_message(function(channel_name, sender, message) - if channel_name == "weather_nodes" then - all_nodes = minetest.deserialize(message) - do_effects = true + if channel_name == "running_receive" then + running = (message == "true") end - if channel_name == "weather_type" then - if message == "1" then - rain = false - snow = true - elseif message == "2" then - rain = true - snow = false - else - rain = false - snow = false +end) + +--check player's input on the "up" key +minetest.register_globalstep(function(dtime) + local input = minetest.get_control_bits(minetest.localplayer) + + --reset the run flag + if running == true and (input.up == false or input.sneak == true or input.down == true) then + running = false + --print("running toggle off") + send_server_run_state("false") + end + + --half second window to double tap running + if run_discharge_timer > 0 then + run_discharge_timer = run_discharge_timer - dtime + if run_discharge_timer <= 0 then + run_discharge_timer = 0 end + --initialize double tap run + if old_up == false and input.up == true then + run_discharge_timer = 0 + running = true + --print("running toggle on") + send_server_run_state("true") + end + end + --check if new input of walking forwards + if input.up and input.down == false and input.sneak == false and old_up == false and running == false and run_discharge_timer <= 0 then + run_discharge_timer = 0.5 end + --save old value + old_up = input.up end) + + diff --git a/weather_handling.lua b/weather_handling.lua new file mode 100644 index 0000000..e759c0e --- /dev/null +++ b/weather_handling.lua @@ -0,0 +1,161 @@ +local all_nodes = {} +local do_effects = false +local snow = false +local rain = false +local weather_update_timer = 0 +local id_table = {} + +local spawn_snow = function(player) + local pos = player:get_pos() + local radius = 10 + local particle_table = {} + + local area = vector.new(10,10,10) + + local min = vector.subtract(pos, area) + local max = vector.add(pos, area) + + + local area_index = minetest.find_nodes_in_area_under_air(min, max, all_nodes) + + local spawn_table = {} + --find the highest y value + for _,index in pairs(area_index) do + if not spawn_table[index.x] then spawn_table[index.x] = {} end + if not spawn_table[index.x][index.z] then + spawn_table[index.x][index.z] = index.y + elseif spawn_table[index.x][index.z] < index.y then + spawn_table[index.x][index.z] = index.y + end + end + + for x,x_index in pairs(spawn_table) do + for z,y in pairs(x_index) do + if minetest.get_node_or_nil(vector.new(x,y+1,z)) ~= nil then + --print("got to this spointa") + local pos = vector.new(x,y+1,z) + local lightlevel = 14 + --local lightlevel = minetest.get_node_light(pos, 0.5) + --print("but not here") + if lightlevel >= 14 then + minetest.add_particlespawner({ + amount = 1, + time = 0.5, + minpos = vector.new(x-0.5,y,z-0.5), + maxpos = vector.new(x+0.5,y+20,z+0.5), + minvel = {x=-0.2, y=-0.2, z=-0.2}, + maxvel = {x=0.2, y=-0.5, z=0.2}, + minacc = {x=0, y=0, z=0}, + maxacc = {x=0, y=0, z=0}, + minexptime = 1, + maxexptime = 1, + minsize = 1, + maxsize = 1, + collisiondetection = true, + collision_removal = true, + object_collision = false, + texture = "snowflake_"..math.random(1,2)..".png", + playername = player:get_name(), + }) + end + end + end + end +end + +local spawn_rain = function(player) + local pos = player:get_pos() + local radius = 10 + local particle_table = {} + + local area = vector.new(10,10,10) + + local min = vector.subtract(pos, area) + local max = vector.add(pos, area) + + + local area_index = minetest.find_nodes_in_area_under_air(min, max, all_nodes) + + local spawn_table = {} + --find the highest y value + for _,index in pairs(area_index) do + if not spawn_table[index.x] then spawn_table[index.x] = {} end + if not spawn_table[index.x][index.z] then + spawn_table[index.x][index.z] = index.y + elseif spawn_table[index.x][index.z] < index.y then + spawn_table[index.x][index.z] = index.y + end + end + + for x,x_index in pairs(spawn_table) do + for z,y in pairs(x_index) do + if minetest.get_node_or_nil(vector.new(x,y+1,z)) ~= nil then + --print("got to this spointa") + local pos = vector.new(x,y+1,z) + local lightlevel = 14 + --local lightlevel = minetest.get_node_light(pos, 0.5) + --print("but not here") + if lightlevel >= 14 then + minetest.add_particlespawner({ + amount = 1, + time = 0.5, + minpos = vector.new(x-0.5,y,z-0.5), + maxpos = vector.new(x+0.5,y+20,z+0.5), + minvel = {x=0, y=-9.81, z=0}, + maxvel = {x=0, y=-9.81, z=0}, + minacc = {x=0, y=0, z=0}, + maxacc = {x=0, y=0, z=0}, + minexptime = 1, + maxexptime = 2, + minsize = 1, + maxsize = 1, + collisiondetection = true, + collision_removal = true, + object_collision = false, + vertical = true, + texture = "raindrop.png", + playername = player:get_name(), + }) + end + end + end + end +end + +minetest.register_globalstep(function(dtime) + if do_effects then + if snow or rain then + weather_update_timer = weather_update_timer + dtime + if weather_update_timer >= 0.5 then + weather_update_timer = 0 + local player = minetest.localplayer + if snow == true then + spawn_snow(minetest.localplayer) + elseif rain == true then + spawn_rain(minetest.localplayer) + end + end + end + end +end) + + + +minetest.register_on_modchannel_message(function(channel_name, sender, message) + if channel_name == "weather_nodes" then + all_nodes = minetest.deserialize(message) + do_effects = true + end + if channel_name == "weather_type" then + if message == "1" then + rain = false + snow = true + elseif message == "2" then + rain = true + snow = false + else + rain = false + snow = false + end + end +end) -- 2.44.0