11import mcpi .minecraft as minecraft
22#import mcpi.block as block
33from mcpi .block import *
4+ from mcpi .entity import *
45import time
56from math import *
67import server
@@ -17,9 +18,33 @@ def __init__(self,mc=None):
1718 self .directionIn ()
1819 self .pitch = 0
1920 self .positionIn ()
20- self .follow = True
2121 self .delayTime = 0.05
2222 self .nib = []
23+ self .turtleType = PLAYER
24+ self .playerId = self .mc .getPlayerId ()
25+ self .turtleId = self .playerId
26+
27+ def turtle (self ,turtleType ):
28+ if self .turtleType == turtleType :
29+ return
30+ if self .turtleType and self .turtleType != PLAYER :
31+ self .mc .removeEntity (self .turtleId )
32+ self .turtleType = turtleType
33+ if turtleType == PLAYER :
34+ self .turtleId = self .playerId
35+ elif turtleType :
36+ self .turtleId = self .mc .spawnEntity (turtleType ,
37+ self .position .x ,self .position .y ,self .position .z ,
38+ "{NoAI:1}" )
39+ self .positionOut ()
40+ self .directionOut ()
41+
42+ def follow (self ): # deprecated
43+ self .turtle (PLAYER )
44+
45+ def nofollow (self ): # deprecated
46+ if self .turtleType == PLAYER :
47+ self .turtle (None )
2348
2449 def penwidth (self ,w ):
2550 self .nib = []
@@ -38,6 +63,7 @@ def goto(self,x,y,z):
3863 self .position .y = y
3964 self .position .z = z
4065 self .positionOut ()
66+ self .delay ()
4167
4268 def verticalangle (self ,angle ):
4369 self .pitch = - angle
@@ -47,12 +73,6 @@ def angle(self,angle):
4773 self .rotation = - angle
4874 self .directionOut ()
4975
50- def follow (self ):
51- self .follow = True
52-
53- def nofollow (self ):
54- self .follow = False
55-
5676 def penup (self ):
5777 self .pen = False
5878
@@ -66,8 +86,10 @@ def positionIn(self):
6686 self .position = self .mc .player .getPos ()
6787
6888 def positionOut (self ):
69- if self .follow :
70- self .mc .player .setPos (self .position )
89+ if self .turtleType :
90+ self .mc .entity .setPos (self .turtleId ,self .position )
91+
92+ def delay (self ):
7193 if self .delayTime > 0 :
7294 time .sleep (self .delayTime )
7395
@@ -79,7 +101,7 @@ def directionOut(self):
79101 self .pitch %= 360.
80102 self .rotation %= 360
81103
82- if self .follow :
104+ if self .turtleType :
83105 pitch = self .pitch
84106 rotation = self .rotation
85107
@@ -89,11 +111,8 @@ def directionOut(self):
89111 pitch = 180. - pitch
90112 rotation = (rotation + 180. ) % 360.
91113
92- self .mc .player .setRotation (rotation )
93- self .mc .player .setPitch (pitch )
94-
95- if self .delayTime > 0 :
96- time .sleep (self .delayTime )
114+ self .mc .entity .setRotation (self .turtleId , rotation )
115+ self .mc .entity .setPitch (self .turtleId , pitch )
97116
98117 def pendelay (self , t ):
99118 self .delayTime = t
@@ -104,10 +123,12 @@ def left(self, angle):
104123 def right (self , angle ):
105124 self .rotation += angle
106125 self .directionOut ()
126+ self .delay ()
107127
108128 def up (self , angle ):
109129 self .pitch -= angle
110130 self .directionOut ()
131+ self .delay ()
111132
112133 def down (self , angle ):
113134 self .up (- angle )
@@ -127,6 +148,7 @@ def go(self, distance):
127148 self .position .y = newY
128149 self .position .z = newZ
129150 self .positionOut ()
151+ self .delay ()
130152
131153 def back (self , distance ):
132154 pitch = self .pitch * pi / 180.
@@ -143,6 +165,7 @@ def back(self, distance):
143165 self .position .y = newY
144166 self .position .z = newZ
145167 self .positionOut ()
168+ self .delay ()
146169
147170 def drawPoint (self , x , y , z ):
148171 if self .pen and self .width > 0 :
@@ -158,6 +181,7 @@ def drawPoint(self, x, y, z):
158181 self .position .y = y
159182 self .position .z = z
160183 self .positionOut ()
184+ self .delay ()
161185
162186 def drawLine (self , x1 , y1 , z1 , x2 , y2 , z2 ):
163187 if not self .pen and self .delayTime == 0 :
@@ -229,13 +253,13 @@ def drawLine(self, x1, y1, z1, x2, y2, z2):
229253
230254if __name__ == "__main__" :
231255 t = Turtle ()
232- t .pendelay (0 )
233- t .penwidth (5 )
256+ t .pendelay (0.01 )
257+ t .penwidth (1 )
234258 t .penblock (GLASS )
259+ t .turtle (HORSE )
235260 for i in range (7 ):
236261 print i
237262 t .go (100 )
238263 t .right (180.0 - 180. / 7 )
239264 t .penup ()
240- t .back (10 ) # exit star
241-
265+ t .turtle (None )
0 commit comments