-
Notifications
You must be signed in to change notification settings - Fork 4
/
projectile.py
executable file
·47 lines (33 loc) · 1.49 KB
/
projectile.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
from mcpi.minecraft import Minecraft
from mcpi.minecraft import Vec3
from mcpi.minecraftstuff import MinecraftShape, MinecraftDrawing
from mcpi.minecraftstuff import ShapeBlock
from mcpi import block
from time import sleep
from threading import Thread
class Projectile:
def __init__(self, projectileBlocks):
self.mc = Minecraft.create()
self.projectileBlocks = projectileBlocks
def fire(self,x1,y1,z1,x2,y2,z2,speed,background=False):
#run it in its own thread
fireThread = Thread(None, self._fire, None, (x1, y1, z1, x2, y2, z2, speed))
fireThread.start()
#if backgroud == True, return the thread, otherwise wait for it to finish
if background == False:
fireThread.join()
return fireThread
def _fire(self,x1,y1,z1,x2,y2,z2,speed):
startPos = Vec3(x1,y1,z1)
projectileShape = MinecraftShape(self.mc, startPos, self.projectileBlocks)
mcDraw = MinecraftDrawing(self.mc)
blocksBetween = mcDraw.getLine(x1, y1, z1, x2, y2, z2)
for blockBetween in blocksBetween:
projectileShape.move(blockBetween.x, blockBetween.y, blockBetween.z)
# time to sleep between each block move
sleep(speed)
projectileShape.clear()
class XWingMissile(Projectile):
def __init__(self):
missileBlocks = [ShapeBlock(0,0,0,block.TNT)]
Projectile.__init__(self, missileBlocks)