-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParaLib.lua
108 lines (98 loc) · 2.81 KB
/
ParaLib.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
--[[
-ParacraftLibary-
Many useful lib:Vector,Blocks,etc.
by Hyt
]]--
ParaLib = {SBlockList = {},Vector = Vector,SBlock = SBlock,SBlockGroup = SBlockGroup};
ParaLib.__index = ParaLib;
function main(entity)
script = blocks.getscript(19200,1,19200);
script.ParaLib = ParaLib;
cmd("/tip -color #0000ff 【ParaLib】 已载入");
end
--VectorLib
Vector = {x = 0, y = 0, z = 0,
__add = function(v1,v2)
local result = NewVector(0,0,0);
result.x = v1.x + v2.x;
result.y = v1.y + v2.y;
result.z = v1.z + v2.z;
return result;
end,
__sub = function(v1,v2)
local result = NewVector(0,0,0);
result.x = v1.x - v2.x;
result.y = v1.y - v2.y;
result.z = v1.z - v2.z;
return result;
end
}
Vector.__index = Vector;
function Vector:Multiply(num)
self.x = self.x * num;
self.y = self.y * num;
self.z = self.z * num;
end
--turn the vector into string
function Vector:ToString()
return self.x.." "..self.y.." "..self.z;
end
--turn the vectot into parm
function Vector:ToParm()
return self.x, self.y, self.z;
end
--Newvector
function ParaLib:NewVector(x,y,z)
local result = {__index = Vector};
--assign the value
result.x = x;
result.y = y;
result.z = z;
return result;
end
--set a group of block
function ParaLib:SetBlocks(pos,range,id,data,flag)
for i = pos.x, pos.x + range.rx do
for j = pos.y, pos.y + range.ry do
for k = pos.z, pos.z + range.rz do
BlockEngine.SetBlock(i,j,k,id,data,flag);
end
end
end
end
SBlock = {Position = {0, 0, 0}, Id = 0, Data = 0};
SBlock.__index = SBlock;
--create a smart block
function ParaLib:CreateSBlock(x,y,z)
local newBlock = {__index = SBlock};
--初始化一堆信息
newBlock.Position = ParaLib:NewVector(x,y,z);
--注册到表里
table.insert(ParaLib.SBlockList,newBlock);
return newBlock;
end
--获取Id
function SBlock:GetId()
return BlockEngine:GetBlockId(self.Position:ToParm());
end
--获取Data
function SBlock:GetData()
return BlockEngine:GetBlockData(self.Position:ToParm());
end
--Move a Block relatively
function SBlock:SimpleMoveRelative(x,y,z,newData)
cmd("/translate ~ ~ ~ to "..ParaLib:NewVector(x,y,z):ToString());
self.Position = self.Position + NewVector(x,y,z);
if not newData then
BlockEngine:SetBlockData(self.Position:ToParm(),newData,0);
end
end
--Move a Block absolately
function SBlock:SimpleMoveAbsolate(x,y,z,newData)
self:SimpleMoveRelative(ParaLib:NewVector( x,y,z) - self.Position,newData);
end
SBlockGroup = {};
SBlockGroup.__index = SBlockGroup;
--Move all SBlock in the group
function SBlockGroup:SimpleMoveGroupRelative(to)
end