py2hackCraft2 1.0.8__tar.gz → 1.0.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2hackCraft2
3
- Version: 1.0.8
3
+ Version: 1.0.9
4
4
  Summary: These are APIs that connect to the hackCraft2 server from Python to manipulate pets.
5
5
  Home-page: https://pypi.org/project/py2hackCraft2/
6
6
  Author: Masafumi Terazono
@@ -119,6 +119,7 @@ class _WebSocketClient:
119
119
  logging.debug("send sending'%s'" % message)
120
120
  self.wait_for_connection()
121
121
  with self.lock:
122
+ self.result = None
122
123
  self.response_event.clear() # イベントをクリアして新しいレスポンスの準備をする
123
124
  self.ws.send(message)
124
125
  self.response_event.wait() # サーバーからのレスポンスを待つ
@@ -145,6 +146,19 @@ class Location:
145
146
  z: int
146
147
  world: str = "world"
147
148
 
149
+ @dataclass
150
+ class InteractEvent:
151
+ action: str
152
+ type: str
153
+ name: str
154
+ block: str = None
155
+ data: int = 0
156
+ uuid: str = None
157
+ world: str = "world"
158
+ x: int = 0
159
+ y: int = 0
160
+ z: int = 0
161
+
148
162
  @dataclass
149
163
  class EventMessage:
150
164
  """
@@ -204,11 +218,13 @@ class Block:
204
218
  isOccluding (bool): 透過しないブロックかどうか。
205
219
  isSolid (bool): 壁のあるブロックかどうか。
206
220
  isPassable (bool): 通過可能なブロックかどうか。
221
+ world (str): ブロックが存在するワールドの名前(デフォルトは"world")。
207
222
  x (int): ブロックのX座標。
208
223
  y (int): ブロックのY座標。
209
224
  z (int): ブロックのZ座標。
210
225
  """
211
226
  name: str
227
+ type: str = "block"
212
228
  data: int = 0
213
229
  isLiquid: bool = False
214
230
  isAir: bool = False
@@ -220,6 +236,7 @@ class Block:
220
236
  x: int = 0
221
237
  y: int = 0
222
238
  z: int = 0
239
+ world: str = "world"
223
240
 
224
241
  @dataclass
225
242
  class ItemStack:
@@ -249,6 +266,18 @@ class Player:
249
266
  def logout(self):
250
267
  self.client.disconnect()
251
268
 
269
+ def setOnBlockBreak(self, callbackFunc: Callable[['Block'], Any]):
270
+ """
271
+ プレイヤーがブロックをこわした時に呼び出されるコールバック関数を設定する。
272
+ """
273
+ def callbackWrapper(data):
274
+ logging.debug("onPlayerBlockBreak callbackWrapper '%s'" % data)
275
+ if(data['playerUuid'] == self.uuid):
276
+ logging.debug("callbackWrapper '%s'" % data)
277
+ block = Block(**data['block'])
278
+ callbackFunc(self, block)
279
+ self.client.setCallback('onPlayerBlockBreak', callbackWrapper)
280
+
252
281
  def getEntity(self, name: str) -> 'Entity':
253
282
  """
254
283
  指定された名前のエンティティを取得する。
@@ -270,11 +299,11 @@ class Player:
270
299
  "data": {"entity": name}
271
300
  }
272
301
  self.client.send(json.dumps(message))
273
- uuid = self.client.result
274
- if(uuid is None):
302
+ result = self.client.result
303
+ if(result is None):
275
304
  raise ValueError("Entity '%s' not found" % name)
276
305
 
277
- return Entity(self.client, self.world, uuid)
306
+ return Entity(self.client, self.world, result)
278
307
 
279
308
  class World:
280
309
  """
@@ -285,7 +314,7 @@ class World:
285
314
  self.name = world
286
315
  self.entityUUID = entityUUID
287
316
 
288
- def setBlock(self, x: int, y: int, z: int, block: str):
317
+ def setBlock(self, x: int, y: int, z: int, block: str, data: int = 0):
289
318
  """
290
319
  指定された座標にブロックを設置する。
291
320
 
@@ -295,7 +324,7 @@ class World:
295
324
  z (int): 絶対的なZ座標。
296
325
  block (str): 設置するブロックの種類。
297
326
  """
298
- self.client.sendCall(self.entityUUID, "setBlock", [x, y, z, block])
327
+ self.client.sendCall(self.entityUUID, "setBlock", [x, y, z, block, data])
299
328
 
300
329
  def getBlock(self, x: int, y: int, z: int) -> Block :
301
330
  """
@@ -416,6 +445,18 @@ class Entity:
416
445
  callbackFunc(self, power)
417
446
  self.client.setCallback('onEntityRedstone', callbackWrapper)
418
447
 
448
+ def setOnInteractEvent(self, callbackFunc: Callable[['Entity', 'InteractEvent'], Any]):
449
+ """
450
+ レッドストーンを受信したときに呼び出されるコールバック関数を設定する。
451
+ """
452
+ def callbackWrapper(data):
453
+ logging.debug("onInteractEvent callbackWrapper '%s'" % data)
454
+ if(data['entityUuid'] == self.uuid):
455
+ logging.debug("callbackWrapper '%s'" % data)
456
+ event = InteractEvent(**data["event"])
457
+ callbackFunc(self, event)
458
+ self.client.setCallback('onInteractEvent', callbackWrapper)
459
+
419
460
  def setOnMessage(self, callbackFunc: Callable[['Entity', str], Any]):
420
461
  """
421
462
  メッセージを受信したときに呼び出されるコールバック関数を設定する。
@@ -438,6 +479,15 @@ class Entity:
438
479
  """
439
480
  self.client.sendCall(self.uuid, "sendEvent", [target, message])
440
481
 
482
+ def executeCommand(self, command: str):
483
+ """
484
+ コマンドを実行する。
485
+
486
+ Args:
487
+ command (str): 実行するコマンドの内容。
488
+ """
489
+ self.client.sendCall(self.uuid, "executeCommand", [command])
490
+
441
491
  def getWorld(self) -> 'World':
442
492
  """
443
493
  指定された名前のワールドを取得する。
@@ -541,20 +591,14 @@ class Entity:
541
591
  self.client.sendCall(self.uuid, "sound")
542
592
  return str_to_bool(self.client.result)
543
593
 
544
- def walk(self) -> bool :
545
- """
546
- 歩く。
547
-
594
+ def move(self, speed: float) -> bool :
548
595
  """
549
- self.client.sendCall(self.uuid, "move", [0.5])
550
- return str_to_bool(self.client.result)
551
-
552
- def sprint(self) -> bool :
553
- """
554
- 走る。
596
+ 前方へ移動する。
555
597
 
598
+ Args:
599
+ speed (float): 移動速度。
556
600
  """
557
- self.client.sendCall(self.uuid, "move", [1.0])
601
+ self.client.sendCall(self.uuid, "move", [speed])
558
602
  return str_to_bool(self.client.result)
559
603
 
560
604
  def turn(self, degrees: int):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2hackCraft2
3
- Version: 1.0.8
3
+ Version: 1.0.9
4
4
  Summary: These are APIs that connect to the hackCraft2 server from Python to manipulate pets.
5
5
  Home-page: https://pypi.org/project/py2hackCraft2/
6
6
  Author: Masafumi Terazono
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="py2hackCraft2",
5
- version="1.0.8",
5
+ version="1.0.9",
6
6
  packages=find_packages(),
7
7
  install_requires=[
8
8
  "websocket-client" # websocketライブラリの追加
File without changes
File without changes