setBlock, initial
This commit is contained in:
parent
ace30ad496
commit
8cfb87c44d
57
init.lua
57
init.lua
@ -1,7 +1,6 @@
|
||||
local socket = require("socket")
|
||||
local server = socket.bind("*", 4711)
|
||||
server:settimeout(0)
|
||||
|
||||
local clientlist = {}
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
@ -12,14 +11,18 @@ minetest.register_globalstep(function(dtime)
|
||||
print("RJM client connected")
|
||||
end
|
||||
for i = 1, #clientlist do
|
||||
local line,err = clientlist[i]:receive()
|
||||
if err == "closed" then
|
||||
table.remove(clientlist, i)
|
||||
print("RJM client disconnected")
|
||||
break -- The other clients won't be processed on this tick, alas
|
||||
elseif not err then
|
||||
handlecommand(clientlist[i], line)
|
||||
local err = false
|
||||
local line
|
||||
while not err do
|
||||
line,err = clientlist[i]:receive()
|
||||
if err == "closed" then
|
||||
table.remove(clientlist, i)
|
||||
print("RJM client disconnected")
|
||||
elseif not err then
|
||||
handlecommand(clientlist[i], line)
|
||||
end
|
||||
end
|
||||
if err == "closed" then break end
|
||||
end
|
||||
end)
|
||||
|
||||
@ -27,8 +30,12 @@ function getplayer()
|
||||
return minetest.get_connected_players()[1]
|
||||
end
|
||||
|
||||
local BLOCKS = {}
|
||||
BLOCKS[bit.bor(bit.lshift(0,4),0)] = {name="air"}
|
||||
BLOCKS[bit.bor(bit.lshift(1,4),0)] = {name="default:stone"}
|
||||
|
||||
function handlecommand(client, line)
|
||||
--print("Command received: "..line)
|
||||
print("Command received: "..line)
|
||||
local cmd, argtext = string.match(line, "([^(]+)%((.*)%)")
|
||||
if not cmd then return end
|
||||
local args = {}
|
||||
@ -38,21 +45,27 @@ function handlecommand(client, line)
|
||||
if cmd == "chat.post" then
|
||||
minetest.chat_send_all(argtext)
|
||||
elseif cmd == "player.getPos" then
|
||||
local player = getplayer()
|
||||
print(player)
|
||||
print(player:is_player())
|
||||
print(player:get_player_name())
|
||||
local pos = player:getpos()
|
||||
print(pos.x)
|
||||
print(pos.y)
|
||||
print(pos.z)
|
||||
local pos = getplayer():getpos()
|
||||
client:send(""..(pos.x)..","..(pos.y)..","..(pos.z).."\n")
|
||||
elseif cmd == "player.setPos" then
|
||||
local pos = {}
|
||||
pos.x = tonumber(args[1])
|
||||
pos.y = tonumber(args[2])
|
||||
pos.z = tonumber(args[3])
|
||||
getplayer():setpos(pos)
|
||||
getplayer():setpos({x=tonumber(args[1]), y=tonumber(args[2]), z=tonumber(args[3])})
|
||||
elseif cmd == "world.setBlock" then
|
||||
local nodenum
|
||||
if #args == 3 then
|
||||
nodenum = 0
|
||||
elseif #args == 4 then
|
||||
nodenum = bit.lshift(tonumber(args[4]),4)
|
||||
else
|
||||
nodenum = bit.bor(bit.lshift(tonumber(args[4]),4),tonumber(args[5]))
|
||||
end
|
||||
local node = BLOCKS[nodenum]
|
||||
if not node then
|
||||
node = BLOCKS[bit.band(nodenum,0xFFF0)]
|
||||
if not node then
|
||||
node = BLOCKS[bit.lshift(1,4)]
|
||||
end
|
||||
end
|
||||
minetest.set_node({x=tonumber(args[1]),y=tonumber(args[2]),z=tonumber(args[3])},node)
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user