-
Notifications
You must be signed in to change notification settings - Fork 10
/
fence.py
59 lines (45 loc) · 1.76 KB
/
fence.py
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
# Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0
# Author (©): Alvaro del Castillo
import mcpi
from mcpi.vec3 import Vec3
from .thing import Thing
class Fence(Thing):
"""
Build a block plane and empty it to create the fence
"""
fence_space = 5
""" Space between the fence and the thing fenced """
thick = 1
height = None
thing = None
def create(self):
"""
Create a fence around the configured thing
:return:
"""
if self.thing is None:
raise RuntimeError("Thing to be fenced is not defined")
self.add_child(self.thing)
init_x = self.thing.position.x - self.fence_space - self.thick
init_y = self.thing.position.y
init_z = self.thing.position.z - self.fence_space - self.thick
self._position = Vec3(init_x, init_y, init_z)
end_x = self.thing.end_position.x + self.fence_space + self.thick
end_y = self.thing.end_position.y
if self.height:
end_y = self.thing.position.y + (self.height - 1)
end_z = self.thing.end_position.z + self.fence_space + self.thick
self._end_position = Vec3(end_x, end_y, end_z)
self.set_blocks(
Vec3(init_x, init_y, init_z),
Vec3(end_x, end_y, end_z),
self.block.id)
# Fill the prism with air to became a rectangular wall
self.set_blocks(
Vec3(init_x + self.thick, init_y, init_z + self.thick),
Vec3(end_x - self.thick, end_y, end_z - self.thick),
mcpi.block.AIR.id)
# Rebuild the thing because it is destroyed when emptying the fence
# if we are not removing the fence
if self.block.id != mcpi.block.AIR.id:
self.thing.create()