Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 8d1259f

Browse files
authored
Merge pull request #74 from dave-tucker/clean-cuberite
Cleaner Cuberite integration and world customizations
2 parents c81a14e + 8d6dd76 commit 8d1259f

File tree

261 files changed

+1001
-94177
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+1001
-94177
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ world/players
66
world/whitelist.sqlite
77
world/world/stats/Pixowl.json
88
goproxy/goproxy
9+
dockercraft
File renamed without changes.

Docker/container.lua

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
-- Container object is the representation of a Docker
2+
-- container in the Minecraft world
3+
4+
-- constant variables
5+
CONTAINER_CREATED = 0
6+
CONTAINER_RUNNING = 1
7+
CONTAINER_STOPPED = 2
8+
9+
-- NewContainer returns a Container object,
10+
-- representation of a Docker container in
11+
-- the Minecraft world
12+
function NewContainer()
13+
c = {
14+
displayed = false,
15+
x = 0,
16+
z = 0,
17+
name="",
18+
id="",
19+
imageRepo="",
20+
imageTag="",
21+
running=false,
22+
init=Container.init,
23+
setInfos=Container.setInfos,
24+
destroy=Container.destroy,
25+
display=Container.display,
26+
updateMemSign=Container.updateMemSign,
27+
updateCPUSign=Container.updateCPUSign,
28+
addGround=Container.addGround
29+
}
30+
return c
31+
end
32+
33+
Container = {displayed = false, x = 0, z = 0, name="",id="",imageRepo="",imageTag="",running=false}
34+
35+
-- Container:init sets Container's position
36+
function Container:init(x,z)
37+
self.x = x
38+
self.z = z
39+
self.displayed = false
40+
end
41+
42+
-- Container:setInfos sets Container's id, name, imageRepo,
43+
-- image tag and running state
44+
function Container:setInfos(id,name,imageRepo,imageTag,running)
45+
self.id = id
46+
self.name = name
47+
self.imageRepo = imageRepo
48+
self.imageTag = imageTag
49+
self.running = running
50+
end
51+
52+
-- Container:destroy removes all blocks of the
53+
-- container, it won't be visible on the map anymore
54+
function Container:destroy(running)
55+
local X = self.x+2
56+
local Y = GROUND_LEVEL+2
57+
local Z = self.z+2
58+
LOG("Exploding at X:" .. X .. " Y:" .. Y .. " Z:" .. Z)
59+
local World = cRoot:Get():GetDefaultWorld()
60+
World:BroadcastSoundEffect("random.explode", X, Y, Z, 1, 1)
61+
World:BroadcastParticleEffect("hugeexplosion",X, Y, Z, 0, 0, 0, 1, 1)
62+
63+
-- if a block is removed before it's button/lever/sign, that object will drop
64+
-- and the player can collect it. Remove these first
65+
66+
-- lever
67+
digBlock(UpdateQueue,self.x+1,GROUND_LEVEL+3,self.z+1)
68+
-- signs
69+
digBlock(UpdateQueue,self.x+3,GROUND_LEVEL+2,self.z-1)
70+
digBlock(UpdateQueue,self.x,GROUND_LEVEL+2,self.z-1)
71+
digBlock(UpdateQueue,self.x+1,GROUND_LEVEL+2,self.z-1)
72+
-- torch
73+
digBlock(UpdateQueue,self.x+1,GROUND_LEVEL+3,self.z+1)
74+
--button
75+
digBlock(UpdateQueue,self.x+2,GROUND_LEVEL+3,self.z+2)
76+
77+
-- rest of the blocks
78+
for py = GROUND_LEVEL+1, GROUND_LEVEL+4
79+
do
80+
for px=self.x-1, self.x+4
81+
do
82+
for pz=self.z-1, self.z+5
83+
do
84+
digBlock(UpdateQueue,px,py,pz)
85+
end
86+
end
87+
end
88+
end
89+
90+
-- Container:display displays all Container's blocks
91+
-- Blocks will be blue if the container is running,
92+
-- orange otherwise.
93+
function Container:display(running)
94+
95+
local metaPrimaryColor = E_META_WOOL_LIGHTBLUE
96+
local metaSecondaryColor = E_META_WOOL_BLUE
97+
98+
if running == false
99+
then
100+
metaPrimaryColor = E_META_WOOL_ORANGE
101+
metaSecondaryColor = E_META_WOOL_RED
102+
end
103+
104+
self.displayed = true
105+
106+
for px=self.x, self.x+3
107+
do
108+
for pz=self.z, self.z+4
109+
do
110+
setBlock(UpdateQueue,px,GROUND_LEVEL + 1,pz,E_BLOCK_WOOL,metaPrimaryColor)
111+
end
112+
end
113+
114+
for py = GROUND_LEVEL+2, GROUND_LEVEL+3
115+
do
116+
setBlock(UpdateQueue,self.x+1,py,self.z,E_BLOCK_WOOL,metaPrimaryColor)
117+
118+
-- leave empty space for the door
119+
-- setBlock(UpdateQueue,self.x+2,py,self.z,E_BLOCK_WOOL,metaPrimaryColor)
120+
121+
setBlock(UpdateQueue,self.x,py,self.z,E_BLOCK_WOOL,metaPrimaryColor)
122+
setBlock(UpdateQueue,self.x+3,py,self.z,E_BLOCK_WOOL,metaPrimaryColor)
123+
124+
setBlock(UpdateQueue,self.x,py,self.z+1,E_BLOCK_WOOL,metaSecondaryColor)
125+
setBlock(UpdateQueue,self.x+3,py,self.z+1,E_BLOCK_WOOL,metaSecondaryColor)
126+
127+
setBlock(UpdateQueue,self.x,py,self.z+2,E_BLOCK_WOOL,metaPrimaryColor)
128+
setBlock(UpdateQueue,self.x+3,py,self.z+2,E_BLOCK_WOOL,metaPrimaryColor)
129+
130+
setBlock(UpdateQueue,self.x,py,self.z+3,E_BLOCK_WOOL,metaSecondaryColor)
131+
setBlock(UpdateQueue,self.x+3,py,self.z+3,E_BLOCK_WOOL,metaSecondaryColor)
132+
133+
setBlock(UpdateQueue,self.x,py,self.z+4,E_BLOCK_WOOL,metaPrimaryColor)
134+
setBlock(UpdateQueue,self.x+3,py,self.z+4,E_BLOCK_WOOL,metaPrimaryColor)
135+
136+
setBlock(UpdateQueue,self.x+1,py,self.z+4,E_BLOCK_WOOL,metaPrimaryColor)
137+
setBlock(UpdateQueue,self.x+2,py,self.z+4,E_BLOCK_WOOL,metaPrimaryColor)
138+
end
139+
140+
-- torch
141+
setBlock(UpdateQueue,self.x+1,GROUND_LEVEL+3,self.z+3,E_BLOCK_TORCH,E_META_TORCH_ZP)
142+
143+
-- start / stop lever
144+
setBlock(UpdateQueue,self.x+1,GROUND_LEVEL + 3,self.z + 2,E_BLOCK_WALLSIGN,E_META_CHEST_FACING_XP)
145+
updateSign(UpdateQueue,self.x+1,GROUND_LEVEL + 3,self.z + 2,"","START/STOP","---->","",2)
146+
147+
148+
if running
149+
then
150+
setBlock(UpdateQueue,self.x+1,GROUND_LEVEL+3,self.z+1,E_BLOCK_LEVER,1)
151+
else
152+
setBlock(UpdateQueue,self.x+1,GROUND_LEVEL+3,self.z+1,E_BLOCK_LEVER,9)
153+
end
154+
155+
156+
-- remove button
157+
158+
setBlock(UpdateQueue,self.x+2,GROUND_LEVEL + 3,self.z + 2,E_BLOCK_WALLSIGN,E_META_CHEST_FACING_XM)
159+
updateSign(UpdateQueue,self.x+2,GROUND_LEVEL + 3,self.z + 2,"","REMOVE","---->","",2)
160+
161+
setBlock(UpdateQueue,self.x+2,GROUND_LEVEL+3,self.z+3,E_BLOCK_STONE_BUTTON,E_BLOCK_BUTTON_XM)
162+
163+
164+
-- door
165+
-- Cuberite bug with Minecraft 1.8 apparently, doors are not displayed correctly
166+
-- setBlock(UpdateQueue,self.x+2,GROUND_LEVEL+2,self.z,E_BLOCK_WOODEN_DOOR,E_META_CHEST_FACING_ZM)
167+
168+
169+
for px=self.x, self.x+3
170+
do
171+
for pz=self.z, self.z+4
172+
do
173+
setBlock(UpdateQueue,px,GROUND_LEVEL + 4,pz,E_BLOCK_WOOL,metaPrimaryColor)
174+
end
175+
end
176+
177+
setBlock(UpdateQueue,self.x+3,GROUND_LEVEL + 2,self.z - 1,E_BLOCK_WALLSIGN,E_META_CHEST_FACING_ZM)
178+
updateSign(UpdateQueue,self.x+3,GROUND_LEVEL + 2,self.z - 1,string.sub(self.id,1,8),self.name,self.imageRepo,self.imageTag,2)
179+
180+
-- Mem sign
181+
setBlock(UpdateQueue,self.x,GROUND_LEVEL + 2,self.z - 1,E_BLOCK_WALLSIGN,E_META_CHEST_FACING_ZM)
182+
183+
-- CPU sign
184+
setBlock(UpdateQueue,self.x+1,GROUND_LEVEL + 2,self.z - 1,E_BLOCK_WALLSIGN,E_META_CHEST_FACING_ZM)
185+
end
186+
187+
188+
-- Container:updateMemSign updates the mem usage
189+
-- value displayed on Container's sign
190+
function Container:updateMemSign(s)
191+
updateSign(UpdateQueue,self.x,GROUND_LEVEL + 2,self.z - 1,"Mem usage","",s,"")
192+
end
193+
194+
-- Container:updateCPUSign updates the mem usage
195+
-- value displayed on Container's sign
196+
function Container:updateCPUSign(s)
197+
updateSign(UpdateQueue,self.x+1,GROUND_LEVEL + 2,self.z - 1,"CPU usage","",s,"")
198+
end
199+
200+
-- Container:addGround creates ground blocks
201+
-- necessary to display the container
202+
function Container:addGround()
203+
local y = GROUND_LEVEL
204+
local max_x = GROUND_MAX_X
205+
206+
if GROUND_MIN_X > self.x - 2
207+
then
208+
max_x = GROUND_MIN_X
209+
GROUND_MIN_X = self.x - 2
210+
min_x = GROUND_MIN_X
211+
end
212+
213+
local min_x = GROUND_MIN_X
214+
for x= min_x, max_x
215+
do
216+
for z=GROUND_MIN_Z,GROUND_MAX_Z
217+
do
218+
setBlock(UpdateQueue,x,y,z,E_BLOCK_WOOL,E_META_WOOL_WHITE)
219+
for sky=y+1,y+6
220+
do
221+
setBlock(UpdateQueue,x,sky,z,E_BLOCK_AIR,0)
222+
end
223+
end
224+
end
225+
end

0 commit comments

Comments
 (0)