Skip to content

Commit 9c5fb11

Browse files
committed
spawn support
1 parent 8685e77 commit 9c5fb11

10 files changed

Lines changed: 232 additions & 43 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ buildscript {
1717

1818
apply plugin: 'forge'
1919

20-
version = "0.10"
20+
version = "0.11"
2121
group= "mobi.omegacentauri.raspberryjammod" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
2222
archivesBaseName = "RaspberryJamMod"
2323

python2-scripts.zip

1.38 KB
Binary file not shown.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
ITEM = "Item"
2+
XPORB = "XPOrb"
3+
LEASHKNOT = "LeashKnot"
4+
PAINTING = "Painting"
5+
ARROW = "Arrow"
6+
SNOWBALL = "Snowball"
7+
FIREBALL = "Fireball"
8+
SMALLFIREBALL = "SmallFireball"
9+
THROWNENDERPEARL = "ThrownEnderpearl"
10+
EYEOFENDERSIGNAL = "EyeOfEnderSignal"
11+
THROWNPOTION = "ThrownPotion"
12+
THROWNEXPBOTTLE = "ThrownExpBottle"
13+
ITEMFRAME = "ItemFrame"
14+
WITHERSKULL = "WitherSkull"
15+
PRIMEDTNT = "PrimedTnt"
16+
FALLINGSAND = "FallingSand"
17+
FIREWORKSROCKETENTITY = "FireworksRocketEntity"
18+
ARMORSTAND = "ArmorStand"
19+
BOAT = "Boat"
20+
MINECARTRIDEABLE = "MinecartRideable"
21+
MINECARTCHEST = "MinecartChest"
22+
MINECARTFURNACE = "MinecartFurnace"
23+
MINECARTTNT = "MinecartTNT"
24+
MINECARTHOPPER = "MinecartHopper"
25+
MINECARTSPAWNER = "MinecartSpawner"
26+
MINECARTCOMMANDBLOCK = "MinecartCommandBlock"
27+
MOB = "Mob"
28+
MONSTER = "Monster"
29+
CREEPER = "Creeper"
30+
SKELETON = "Skeleton"
31+
SPIDER = "Spider"
32+
GIANT = "Giant"
33+
ZOMBIE = "Zombie"
34+
SLIME = "Slime"
35+
GHAST = "Ghast"
36+
PIGZOMBIE = "PigZombie"
37+
ENDERMAN = "Enderman"
38+
CAVESPIDER = "CaveSpider"
39+
SILVERFISH = "Silverfish"
40+
BLAZE = "Blaze"
41+
LAVASLIME = "LavaSlime"
42+
ENDERDRAGON = "EnderDragon"
43+
WITHERBOSS = "WitherBoss"
44+
BAT = "Bat"
45+
WITCH = "Witch"
46+
ENDERMITE = "Endermite"
47+
GUARDIAN = "Guardian"
48+
PIG = "Pig"
49+
SHEEP = "Sheep"
50+
COW = "Cow"
51+
CHICKEN = "Chicken"
52+
SQUID = "Squid"
53+
WOLF = "Wolf"
54+
MUSHROOMCOW = "MushroomCow"
55+
SNOWMAN = "SnowMan"
56+
OZELOT = "Ozelot"
57+
VILLAGERGOLEM = "VillagerGolem"
58+
HORSE = "EntityHorse"
59+
RABBIT = "Rabbit"
60+
VILLAGER = "Villager"
61+
ENDERCRYSTAL = "EnderCrystal"
62+
PLAYER = "(ThePlayer)"

python2-scripts/mcpipy/mcpi/minecraft.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def pollChatPosts(self):
165165

166166
class Minecraft:
167167
"""The main class to interact with a running instance of Minecraft Pi."""
168+
168169
def __init__(self, connection):
169170
self.conn = connection
170171

@@ -173,6 +174,14 @@ def __init__(self, connection):
173174
self.player = CmdPlayer(connection)
174175
self.events = CmdEvents(connection)
175176

177+
def spawnEntity(self, *args):
178+
"""Spawn entity (type,x,y,z,tags) and get its id => id:int"""
179+
return int(self.conn.sendReceive("world.spawnEntity", args))
180+
181+
def removeEntity(self, *args):
182+
"""Remove entity (id)"""
183+
self.conn.send("world.removeEntity", args)
184+
176185
def getBlock(self, *args):
177186
"""Get block (x,y,z) => id:int"""
178187
return int(self.conn.sendReceive("world.getBlock", intFloor(args)))

python2-scripts/mcpipy/turtle.py

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import mcpi.minecraft as minecraft
22
#import mcpi.block as block
33
from mcpi.block import *
4+
from mcpi.entity import *
45
import time
56
from math import *
67
import 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

230254
if __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)

python3-scripts.zip

1.38 KB
Binary file not shown.

python3-scripts/mcpipy/mcpi/minecraft.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def pollChatPosts(self):
165165

166166
class Minecraft:
167167
"""The main class to interact with a running instance of Minecraft Pi."""
168+
168169
def __init__(self, connection):
169170
self.conn = connection
170171

@@ -173,6 +174,14 @@ def __init__(self, connection):
173174
self.player = CmdPlayer(connection)
174175
self.events = CmdEvents(connection)
175176

177+
def spawnEntity(self, *args):
178+
"""Spawn entity (type,x,y,z,tags) and get its id => id:int"""
179+
return int(self.conn.sendReceive("world.spawnEntity", args))
180+
181+
def removeEntity(self, *args):
182+
"""Remove entity (id)"""
183+
self.conn.send("world.removeEntity", args)
184+
176185
def getBlock(self, *args):
177186
"""Get block (x,y,z) => id:int"""
178187
return int(self.conn.sendReceive("world.getBlock", intFloor(args)))

0 commit comments

Comments
 (0)