Commit 526657db authored by Petter Reinholdtsen's avatar Petter Reinholdtsen

New upstream version 0.13

parent 22d045fc
This diff is collapsed.
......@@ -3,3 +3,4 @@ wool
farming?
doors?
flowers?
stained_glass?
\ No newline at end of file
......@@ -110,12 +110,15 @@ minetest.register_globalstep(function(dtime)
minetest.log("action", "RJM websocket client attempting handshake")
end
end
local command_count = 1000
for i = 1, #socket_client_list do
err = false
local line
local finished = false
while not err do
while not err and not finished do
local source = socket_client_list[i]
line,err = source.client:receive(source.read_mode)
if err == "closed" then
......@@ -132,12 +135,19 @@ minetest.register_globalstep(function(dtime)
end
finished = true
err = "handling"
else
command_count = command_count - 1
if command_count < 0 then
finished = true
end
end
end
end
end
if finished then break end
if finished then break end
end
flush_block_buffer()
end)
local old_is_protected = minetest.is_protected
......@@ -252,7 +262,7 @@ function python(name, args, kill_script)
if not script then return true end
if script:find("%.%.") then
minetest.chat_send_all("Sandbox violation in script")
minetest.chat_send_all("Sandbox violation in script name")
return true
end
......@@ -350,20 +360,13 @@ function handle_entity(cmd, id, args)
end
function parse_node(args, start)
local nodenum
local id, meta
if #args < start then
nodenum = 0
return {name="air"}
elseif #args == start then
nodenum = block.Block(tonumber(args[start]),0)
return block.id_meta_to_node(tonumber(args[start]),0)
else
nodenum = block.Block(tonumber(args[start]),tonumber(args[start+1]))
end
local node = block.BLOCK[nodenum]
if node == nil then
node = block.BLOCK[bit.band(nodenum,0xFFF)]
if not node then
node = {name="default:stone"}
end
return block.id_meta_to_node(tonumber(args[start]),tonumber(args[start+1]))
end
return node
end
......@@ -380,69 +383,127 @@ function get_height(x, z)
return -1025
end
local block_buffer = {}
local block_buffer_p1 = {}
local block_buffer_p2 = {}
function flush_block_buffer()
if #block_buffer >= 100 then
local vm = minetest.get_voxel_manip(block_buffer_p1,block_buffer_p2)
for i=1,#block_buffer do
vm:set_node_at(block_buffer[i].pos, block_buffer[i].node)
end
vm:update_liquids()
vm:write_to_map()
vm:update_map()
else
for i=1,#block_buffer do
minetest.set_node(block_buffer[i].pos, block_buffer[i].node)
end
end
block_buffer = {}
block_buffer_p1 = {}
block_buffer_p2 = {}
end
local function buffered_set_node(pos, node)
-- ensure buffer cuboid is no more than about 10000 in size
local new_block_buffer_p1 = {x=block_buffer_p1.x,y=block_buffer_p1.y,z=block_buffer_p1.z}
local new_block_buffer_p2 = {x=block_buffer_p2.x,y=block_buffer_p2.y,z=block_buffer_p2.z}
if not block_buffer_p1.x or pos.x < block_buffer_p1.x then new_block_buffer_p1.x = pos.x end
if not block_buffer_p1.y or pos.y < block_buffer_p1.y then new_block_buffer_p1.y = pos.y end
if not block_buffer_p1.z or pos.z < block_buffer_p1.z then new_block_buffer_p1.z = pos.z end
if not block_buffer_p2.x or pos.x > block_buffer_p2.x then new_block_buffer_p2.x = pos.x end
if not block_buffer_p2.y or pos.y > block_buffer_p2.y then new_block_buffer_p2.y = pos.y end
if not block_buffer_p2.z or pos.z > block_buffer_p2.z then new_block_buffer_p2.z = pos.z end
if #block_buffer > 0 and (new_block_buffer_p2.x - new_block_buffer_p2.x + 1) *
(new_block_buffer_p2.y - new_block_buffer_p2.y + 1) *
(new_block_buffer_p2.z - new_block_buffer_p2.z + 1) > 10000 then
flush_block_buffer()
block_buffer_p1.x = pos.x
block_buffer_p1.y = pos.y
block_buffer_p1.z = pos.z
block_buffer_p2.x = pos.x
block_buffer_p2.y = pos.y
block_buffer_p2.z = pos.z
else
block_buffer_p1 = new_block_buffer_p1
block_buffer_p2 = new_block_buffer_p2
end
table.insert(block_buffer, {pos=pos, node=node})
end
local function set_nodes_with_voxelmanip(x1,y1,z1,x2,y2,z2,node)
local p1 = {x=x1,y=y1,z=z1}
local p2 = {x=x2,y=y2,z=z2}
local vm = minetest.get_voxel_manip()
local emin,emax = vm:read_from_map(p1,p2)
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
local data = vm:get_data()
local param2 = vm:get_param2_data()
local content = minetest.get_content_id(node.name)
for index in area:iterp(p1,p2) do
data[index] = content
param2[index] = node.param2
end
vm:set_data(data)
vm:set_param2_data(param2)
vm:update_liquids()
vm:write_to_map()
vm:update_map()
end
local function setNodes(args, node)
local x1 = math.min(tonumber(args[1]),tonumber(args[4]))
local x2 = math.max(tonumber(args[1]),tonumber(args[4]))
local y1 = math.min(tonumber(args[2]),tonumber(args[5]))
local y2 = math.max(tonumber(args[2]),tonumber(args[5]))
local z1 = math.min(-tonumber(args[3]),-tonumber(args[6]))
local z2 = math.max(-tonumber(args[3]),-tonumber(args[6]))
local volume = (x2+1-x1)*(y2+1-y1)*(z2+1-z1)
if 100 <= volume and volume <= 20000000 then
set_nodes_with_voxelmanip(x1,y1,z1,x2,y2,z2,node)
else
for ycoord = y1,y2 do
for xcoord = x1,x2 do
for zcoord = z1,z2 do
minetest.set_node({x=xcoord,y=ycoord,z=zcoord},node)
end
end
end
end
end
function handle_world(cmd, args)
if cmd == "setBlock" then
local node = parse_node(args, 4)
minetest.set_node({x=tonumber(args[1]),y=tonumber(args[2]),z=-tonumber(args[3])},node)
buffered_set_node({x=tonumber(args[1]),y=tonumber(args[2]),z=-tonumber(args[3])},node)
elseif cmd == "setNode" then
local node = {name=args[4]}
if args[5] then node.param2 = tonumber(args[5]) end
minetest.set_node({x=tonumber(args[1]),y=tonumber(args[2]),z=-tonumber(args[3])},node)
buffered_set_node({x=tonumber(args[1]),y=tonumber(args[2]),z=-tonumber(args[3])},node)
elseif cmd == "setBlocks" then
local node = parse_node(args, 7)
local x1 = math.min(tonumber(args[1]),tonumber(args[4]))
local x2 = math.max(tonumber(args[1]),tonumber(args[4]))
local y1 = math.min(tonumber(args[2]),tonumber(args[5]))
local y2 = math.max(tonumber(args[2]),tonumber(args[5]))
local z1 = math.min(-tonumber(args[3]),-tonumber(args[6]))
local z2 = math.max(-tonumber(args[3]),-tonumber(args[6]))
for ycoord = y1,y2 do
for xcoord = x1,x2 do
for zcoord = z1,z2 do
minetest.set_node({x=xcoord,y=ycoord,z=zcoord},node)
end
end
end
setNodes(args, node)
elseif cmd == "setNodes" then
local node = {name=args[7]}
if args[8] then node.param2 = tonumber(args[8]) end
local x1 = math.min(tonumber(args[1]),tonumber(args[4]))
local x2 = math.max(tonumber(args[1]),tonumber(args[4]))
local y1 = math.min(tonumber(args[2]),tonumber(args[5]))
local y2 = math.max(tonumber(args[2]),tonumber(args[5]))
local z1 = math.min(-tonumber(args[3]),-tonumber(args[6]))
local z2 = math.max(-tonumber(args[3]),-tonumber(args[6]))
for ycoord = y1,y2 do
for xcoord = x1,x2 do
for zcoord = z1,z2 do
minetest.set_node({x=xcoord,y=ycoord,z=zcoord},node)
end
end
end
setNodes(args, node)
elseif cmd == "getNode" then
local node = minetest.get_node({x=tonumber(args[1]),y=tonumber(args[2]),z=-tonumber(args[3])})
return node.name .. node.param2
return node.name .. "," .. node.param2
elseif cmd == "getBlockWithData" or cmd == "getBlock" then
local node = minetest.get_node({x=tonumber(args[1]),y=tonumber(args[2]),z=-tonumber(args[3])})
local id, meta
if node == "ignore" then
id = block.AIR
meta = 0
else
id = block.STONE
meta = 0
for key,value in pairs(block.BLOCK) do
if value.name == node.name then
id = math.floor(bit.band(key,0xFFF))
meta = math.floor(bit.rshift(key,12))
break
end
end
end
local id, meta = block.node_to_id_meta(node)
if cmd == "getBlock" then
return ""..id
return tostring(id)
else
return ""..id..","..meta
return id..","..meta
end
elseif cmd == "getHeight" then
return tonumber(get_height(tonumber(args[1]),-tonumber(args[2])))
......@@ -518,6 +579,11 @@ end
function handle_command(line)
local cmd, argtext = line:match("^([^(]+)%((.*)%)")
if not cmd then return end
if #block_buffer > 0 and cmd ~= "world.setBlock" and cmd ~= "world.setNode" then
flush_block_buffer()
end
local args = {}
for arg in argtext:gmatch("([^,]+)") do
table.insert(args, arg)
......
In socket/core.dll is a win32 Microsoft Visual C build from luasockets as well as a win64
build. Replace with something that fits your operating system if you need to.
\ No newline at end of file
build. Replace with something that fits your operating system if you need to.
......@@ -8,19 +8,24 @@ import datetime
import time
import sys
import fonts
import ast
foreground = SEA_LANTERN # this needs Minecraft 1.8
background = AIR
def parseBlock(s):
try:
return ast.literal_eval(s)
except:
return globals()[s.upper()]
try:
if len(sys.argv) > 1 and not "__" in sys.argv[1]:
foreground = eval(sys.argv[1])
foreground = parseBlock(sys.argv[1])
except:
pass
try:
if len(sys.argv) > 2 and not "__" in sys.argv[2]:
background = eval(sys.argv[2])
background = parseBlock(sys.argv[2])
except:
pass
......
......@@ -2,32 +2,35 @@
# Code under the MIT license by Alexander Pruss
#
import mcpi.minecraft as minecraft
import mcpi.block as block
from mc import *
import math
import sys
from ast import literal_eval
def replace(mcx,mcy,mcz,R,mcblock,mcmeta):
def parseBlock(s):
try:
return literal_eval(s)
except:
return globals()[s.upper()]
def replace(mcx,mcy,mcz,R,mcblock):
for x in range(-R,R):
for y in range(-R,R):
for z in range(-R,R):
if (x**2 + y**2 + z**2 <= R**2 and mc.getBlock(mcx+x,mcy+y,mcz+z) != block.AIR.id):
mc.setBlock(mcx+x,mcy+y,mcz+z,mcblock,mcmeta)
if (x**2 + y**2 + z**2 <= R**2 and mc.getBlock(mcx+x,mcy+y,mcz+z) != AIR.id):
mc.setBlock(mcx+x,mcy+y,mcz+z,mcblock)
mc = minecraft.Minecraft()
mc = Minecraft()
playerPos = mc.player.getPos()
R = 20
b = block.TNT.id
m = 0
b = TNT
if len(sys.argv) >= 2:
R = int(sys.argv[1])
if len(sys.argv) >= 3:
b = int(sys.argv[2])
if len(sys.argv) >= 4:
m = int(sys.argv[3])
b = parseBlock(sys.argv[2])
replace(playerPos.x, playerPos.y, playerPos.z, R, b, m)
replace(playerPos.x, playerPos.y, playerPos.z, R, b)
mc.postToChat("Explosify done")
#
#
# Code under the MIT license by Alexander Pruss
#
......
#The software in this file is copyright 2003,2004 Simon Tatham and copyright 2015 Alexander Pruss
#Based on code from http://www.chiark.greenend.org.uk/~sgtatham/polyhedra/
#Based on code from # http://www.chiark.greenend.org.uk/~sgtatham/polyhedra/
#
#Permission is hereby granted, free of charge, to any person
#obtaining a copy of this software and associated documentation files
......@@ -755,3 +755,4 @@ if __name__ == "__main__":
pos = d.mc.player.getPos()
polyhedron(d,n,faceMode,pos.x, pos.y, pos.z, size,drawing.GLASS,drawing.STONE)
......@@ -851,4 +851,4 @@ if __name__ == "__main__":
mainloop()
else:
go(os.path.dirname(os.path.realpath(sys.argv[0])) + "/" + "models/" + sys.argv[1] + ".txt", sys.argv[2:])
go("models/" + sys.argv[1] + ".txt", sys.argv[2:])
from mcturtle import *
import sys
from ast import literal_eval
def parseBlock(s):
try:
return literal_eval(s)
except:
return globals()[s.upper()]
t = Turtle()
t.pendelay(0)
if len(sys.argv) >= 2:
......@@ -7,7 +15,7 @@ if len(sys.argv) >= 2:
else:
radius = 10
if len(sys.argv) >= 3:
material = eval(sys.argv[2].replace("__","(undefined)"))
material = parseBlock(sys.argv[2])
else:
material = GOLD_BLOCK
t.penwidth(2*radius)
......
......@@ -27,6 +27,7 @@ from mcpi.block import *
from math import *
from sys import maxsize
from copy import copy
from ast import literal_eval
import re
def getSavePath(directory, extension):
......@@ -122,19 +123,21 @@ class Vehicle():
f.write("baseAngle,highWater,baseVehicle="+repr((self.baseAngle,self.highWater,self.baseVehicle))+"\n")
f.close()
@staticmethod
def safeEval(string):
if "__" in string:
raise ValueError
return eval(string)
def load(self,filename):
with open(filename) as f:
data = ''.join(f.readlines())
result = re.search("=\\s*(.*)",data)
if result is None:
raise ValueError
self.baseAngle,self.highWater,self.baseVehicle = Vehicle.safeEval(result.group(1))
# Check to ensure only function called is Block() by getting literal_eval to
# raise an exception when "Block" is removed and the result isn't a literal.
# This SHOULD make the eval call safe, though USE AT YOUR OWN RISK. Ideally,
# one would walk the ast parse tree and use a whitelist.
literal_eval(result.group(1).replace("Block",""))
self.baseAngle,self.highWater,self.baseVehicle = eval(result.group(1))
self.curLocation = None
def safeSetBlockWithData(self,pos,block):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment