Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated functions with newer ones #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion depends.txt

This file was deleted.

131 changes: 67 additions & 64 deletions gate_defs.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function swap_gate_node(pos,name,dir)
local node = core.get_node(pos)
local meta = core.get_meta(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local meta0 = meta:to_table()
node.name = name
node.param1=0
Expand All @@ -10,7 +10,7 @@ function swap_gate_node(pos,name,dir)
end

function getDir (player)
local dir=player:get_look_dir()
local dir = player:get_look_dir()
if math.abs(dir.x)>math.abs(dir.z) then
if dir.x>0 then return 0 end
return 1
Expand All @@ -19,26 +19,26 @@ function getDir (player)
return 3
end

function checkNode (pos)
local node=core.get_node(pos)
function checkNode(pos)
local node = minetest.get_node(pos)
if node.name == "air" then return 0 end
return 1
end

function addGateNode (gateNodes,i,pos)
function addGateNode(gateNodes,i,pos)
gateNodes[i].pos.x=pos.x
gateNodes[i].pos.y=pos.y
gateNodes[i].pos.z=pos.z
end

function placeGate (player,pos)
local player_name=player:get_player_name()
local dir=minetest.dir_to_facedir(player:get_look_dir())
local pos1=pos
local gateNodes={}
function placeGate(player,pos)
local player_name = player:get_player_name()
local dir = minetest.dir_to_facedir(player:get_look_dir())
local pos1 = pos
local gateNodes = {}
for i=1,9,1 do
gateNodes[i]={}
gateNodes[i].pos={}
gateNodes[i] = {}
gateNodes[i].pos = {}
end
if dir==1 then
addGateNode(gateNodes,1,pos1)
Expand Down Expand Up @@ -128,58 +128,59 @@ function placeGate (player,pos)
local node=core.get_node(gateNodes[i].pos)
if node.name ~= "air" then return false end
end
core.set_node(gateNodes[1].pos,{name="stargate:gatenode_off", param1=0, param2=dir})
local meta = core.get_meta(gateNodes[1].pos)
meta:set_string("infotext", "Stargate\nOwned by: "..player_name)
meta:set_string("gateNodes",minetest.serialize(gateNodes))

minetest.set_node(gateNodes[1].pos, {name = "stargate:gatenode_off", param1 = 0, param2 = dir})
local meta = minetest.get_meta(gateNodes[1].pos)
meta:set_string("infotext", "Stargate\nOwned by: " .. player_name)
meta:set_string("gateNodes", minetest.serialize(gateNodes))
meta:set_int("gateActive",0)
meta:set_string("owner",player_name)
meta:set_string("dont_destroy","false")
meta:set_string("owner" ,player_name)
meta:set_string("dont_destroy", "false")
stargate.registerGate(player_name,gateNodes[1].pos,dir)
return true
end

function removeGate (pos)
local meta = core.get_meta(pos)
function removeGate(pos)
local meta = minetest.get_meta(pos)
if meta:get_string("dont_destroy") == "true" then return end
local player_name=meta:get_string("owner")
local gateNodes=minetest.deserialize(meta:get_string("gateNodes"))
local player_name = meta:get_string("owner")
local gateNodes = minetest.deserialize(meta:get_string("gateNodes"))
if gateNodes ~= nil then
core.remove_node(gateNodes[1].pos)
stargate.unregisterGate(player_name,gateNodes[1].pos)
minetest.remove_node(gateNodes[1].pos)
stargate.unregisterGate(player_name, gateNodes[1].pos)
end
end

function activateGate (pos)
local node = core.get_node(pos)
local dir=node.param2
local meta = core.get_meta(pos)
local gateNodes=minetest.deserialize(meta:get_string("gateNodes"))
meta:set_int("gateActive",1)
meta:set_string("dont_destroy","true")
minetest.sound_play("gateOpen", {pos = pos, gain = 1.0,loop = false, max_hear_distance = 72,})
swap_gate_node(gateNodes[1].pos,"stargate:gatenode_on",dir)
meta:set_string("dont_destroy","false")
function activateGate(pos)
local node = minetest.get_node(pos)
local dir = node.param2
local meta = minetest.get_meta(pos)
local gateNodes = minetest.deserialize(meta:get_string("gateNodes"))
meta:set_int("gateActive", 1)
meta:set_string("dont_destroy", "true")
minetest.sound_play("gateOpen", {pos = pos, gain = 1.0, loop = false, max_hear_distance = 72})
swap_gate_node(gateNodes[1].pos, "stargate:gatenode_on", dir)
meta:set_string("dont_destroy", "false")
end

function deactivateGate (pos)
local node = core.get_node(pos)
local dir=node.param2
local meta = core.get_meta(pos)
local gateNodes=minetest.deserialize(meta:get_string("gateNodes"))
meta:set_int("gateActive",0)
meta:set_string("dont_destroy","true")
minetest.sound_play("gateClose", {pos = pos, gain = 1.0,loop = false, max_hear_distance = 72,})
swap_gate_node(gateNodes[1].pos,"stargate:gatenode_off",dir)
meta:set_string("dont_destroy","false")
function deactivateGate(pos)
local node = minetest.get_node(pos)
local dir = node.param2
local meta = minetest.get_meta(pos)
local gateNodes = minetest.deserialize(meta:get_string("gateNodes"))
meta:set_int("gateActive", 0)
meta:set_string("dont_destroy", "true")
minetest.sound_play("gateClose", {pos = pos, gain = 1.0, loop = false, max_hear_distance = 72})
swap_gate_node(gateNodes[1].pos, "stargate:gatenode_off", dir)
meta:set_string("dont_destroy", "false")
end

gateCanDig = function(pos,player)
local player_name = player:get_player_name()
local meta = core.get_meta(pos)
local meta = minetest.get_meta(pos)
if meta:get_string("dont_destroy") == "true" then return end
local owner=meta:get_string("owner")
if player_name==owner then return true
local owner = meta:get_string("owner")
if player_name == owner then return true
else return false end
end

Expand Down Expand Up @@ -217,17 +218,18 @@ minetest.register_node("stargate:gatenode_on",{
mesh = "stargate.obj",
visual_scale = 3.0,
groups = sg_groups,
drop="stargate:gatenode_off",
drop = "stargate:gatenode_off",
paramtype2 = "facedir",
paramtype = "light",
light_source = 10,
selection_box = sg_selection_box,
collision_box = sg_collision_box,
can_dig = gateCanDig,
on_destruct = function (pos)
on_destruct = function(pos)
removeGate(pos)
end,
on_rightclick=stargate.gateFormspecHandler,

on_rightclick = stargate.gateFormspecHandler,
})

minetest.register_node("stargate:gatenode_off",{
Expand All @@ -251,7 +253,7 @@ minetest.register_node("stargate:gatenode_off",{
selection_box = sg_selection_box,
collision_box = sg_collision_box,
can_dig = gateCanDig,
on_destruct = function (pos)
on_destruct = function(pos)
removeGate(pos)
end,
on_place = function(itemstack, placer, pointed_thing)
Expand All @@ -263,34 +265,35 @@ minetest.register_node("stargate:gatenode_off",{
return
end
end,
on_rightclick=stargate.gateFormspecHandler,

on_rightclick = stargate.gateFormspecHandler,
})

minetest.register_abm({
nodenames = {"stargate:gatenode_on"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = core.get_meta(pos)
for _,object in ipairs(core.get_objects_inside_radius(pos, 1)) do
local meta = minetest.get_meta(pos)
for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
if object:is_player() then
local player_name = object:get_player_name()
local owner=meta:get_string("owner")
local gate=stargate.findGate (pos)
if gate==nil then print("Gate is not registered!") return end
local owner = meta:get_string("owner")
local gate = stargate.findGate (pos)
if gate == nil then print("Gate is not registered!") return end
local pos1={}
pos1.x=gate["destination"].x
pos1.y=gate["destination"].y
pos1.z=gate["destination"].z
local dest_gate=stargate.findGate (pos1)
if dest_gate==nil then
local dest_gate = stargate.findGate (pos1)
if dest_gate == nil then
gate["destination"]=nil
deactivateGate(pos)
stargate.save_data(owner)
return
end
if player_name~=owner and gate["type"]=="private" then return end
local dir1=gate["destination_dir"]
if player_name ~= owner and gate["type"] == "private" then return end
local dir1 = gate["destination_dir"]
local dest_angle
if dir1 == 0 then
pos1.z = pos1.z-2
Expand All @@ -306,8 +309,8 @@ minetest.register_abm({
dest_angle = -90
end
object:moveto(pos1,false)
object:set_look_yaw(math.rad(dest_angle))
core.sound_play("enterEventHorizon", {pos = pos, gain = 1.0,loop = false, max_hear_distance = 72,})
object:set_look_horizontal(math.rad(dest_angle))
minetest.sound_play("enterEventHorizon", {pos = pos, gain = 1.0, loop = false, max_hear_distance = 72})
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
-- Minetest 0.4.5 : stargate
-- Minetest mod for 5.0.0+: stargate

--data tables definitions
stargate={}
-- Data tables definitions
stargate = {}
stargate_network = {}

modpath=minetest.get_modpath("stargate")
dofile(modpath.."/stargate_gui.lua")
dofile(modpath.."/gate_defs.lua")
modpath = minetest.get_modpath("stargate")
dofile(modpath .. "/stargate_gui.lua")
dofile(modpath .. "/gate_defs.lua")
1 change: 1 addition & 0 deletions mod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name = stargate
Loading