py2hackCraft2 1.0.9__tar.gz → 1.0.10__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.9
3
+ Version: 1.0.10
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
@@ -90,6 +90,10 @@ class _WebSocketClient:
90
90
  callback_thread = threading.Thread(target=callback, args=(jsonEvent['data'],))
91
91
  callback_thread.start()
92
92
  # callback(jsonEvent['data'])
93
+ return
94
+ if(jsonEvent['data']):
95
+ self.result = jsonEvent['data']
96
+ self.response_event.set() # イベントをセットして、メッセージの受信を通知
93
97
  return
94
98
  else:
95
99
  self.result = data
@@ -129,6 +133,16 @@ class _WebSocketClient:
129
133
  self.ws.close()
130
134
  self.thread.join()
131
135
 
136
+ def waitFor(self, entity: str, name: str, args=None):
137
+ data = {"entity": entity, "name": name}
138
+ if args is not None:
139
+ data['args'] = args
140
+ message = {
141
+ "type": "hook",
142
+ "data": data
143
+ }
144
+ self.send(json.dumps(message))
145
+
132
146
  def sendCall(self, entity: str, name: str, args=None):
133
147
  data = {"entity": entity, "name": name}
134
148
  if args is not None:
@@ -139,6 +153,11 @@ class _WebSocketClient:
139
153
  }
140
154
  self.send(json.dumps(message))
141
155
 
156
+ class Coordinates:
157
+ world = ""
158
+ relative = "~"
159
+ local = "^"
160
+
142
161
  @dataclass
143
162
  class Location:
144
163
  x: int
@@ -266,17 +285,6 @@ class Player:
266
285
  def logout(self):
267
286
  self.client.disconnect()
268
287
 
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
288
 
281
289
  def getEntity(self, name: str) -> 'Entity':
282
290
  """
@@ -305,51 +313,6 @@ class Player:
305
313
 
306
314
  return Entity(self.client, self.world, result)
307
315
 
308
- class World:
309
- """
310
- ワールドを表すクラス。
311
- """
312
- def __init__(self, client: _WebSocketClient, world: str, entityUUID: str):
313
- self.client = client
314
- self.name = world
315
- self.entityUUID = entityUUID
316
-
317
- def setBlock(self, x: int, y: int, z: int, block: str, data: int = 0):
318
- """
319
- 指定された座標にブロックを設置する。
320
-
321
- Args:
322
- x (int): 絶対的なX座標。
323
- y (int): 絶対的なY座標。
324
- z (int): 絶対的なZ座標。
325
- block (str): 設置するブロックの種類。
326
- """
327
- self.client.sendCall(self.entityUUID, "setBlock", [x, y, z, block, data])
328
-
329
- def getBlock(self, x: int, y: int, z: int) -> Block :
330
- """
331
- 指定された座標のブロックを取得する。
332
-
333
- Args:
334
- x (int): 絶対的なX座標。
335
- y (int): 絶対的なY座標。
336
- z (int): 絶対的なZ座標。
337
- """
338
- self.client.sendCall(self.entityUUID, "getBlock", [x, y, z])
339
- block = Block(** json.loads(self.client.result))
340
- return block
341
-
342
- def getBlockByColor(self, color: str) -> Block :
343
- """
344
- 指定された色に近いブロックを取得する。
345
-
346
- Args:
347
- color (str): ブロックの色(HexRGB形式)
348
- """
349
- self.client.sendCall(self.entityUUID, "blockColor", [color])
350
- block = Block(** json.loads(self.client.result))
351
- return block
352
-
353
316
  class Inventory:
354
317
  """
355
318
  インベントリを表すクラス。
@@ -422,32 +385,31 @@ class Entity:
422
385
  self.uuid = uuid
423
386
  self.positions = []
424
387
 
425
- def setOnPlayerChat(self, callbackFunc: Callable[['Entity', 'ChatMessage'], Any]):
388
+ def waitForPlayerChat(self):
426
389
  """
427
- チャットを受信したときに呼び出されるコールバック関数を設定する。
390
+ チャットを受信するまでまつ
428
391
  """
429
- def callbackWrapper(data):
430
- if(data['entityUuid'] == self.uuid):
431
- logging.debug("callbackWrapper '%s'" % data)
432
- chatMessage = ChatMessage(**data)
433
- callbackFunc(self, chatMessage)
434
- self.client.setCallback('onPlayerChat', callbackWrapper)
392
+ self.client.waitFor(self.uuid, 'onPlayerChat')
393
+ print('result = ', self.client.result)
394
+ return ChatMessage(** self.client.result)
435
395
 
436
- def setOnRedstoneChange(self, callbackFunc: Callable[['Entity', 'RedstonePower'], Any]):
396
+ def waitForRedstoneChange(self):
437
397
  """
438
- レッドストーンを受信したときに呼び出されるコールバック関数を設定する。
398
+ レッドストーン信号が変わるまでまつ。
439
399
  """
440
- def callbackWrapper(data):
441
- logging.debug("setOnRedstoneChange callbackWrapper '%s'" % data)
442
- if(data['entityUuid'] == self.uuid):
443
- logging.debug("callbackWrapper '%s'" % data)
444
- power = RedstonePower(**data)
445
- callbackFunc(self, power)
446
- self.client.setCallback('onEntityRedstone', callbackWrapper)
400
+ self.client.waitFor(self.uuid, 'onEntityRedstone')
401
+ return RedstonePower(** self.client.result)
402
+
403
+ def waitForBreakBlock(self):
404
+ """
405
+ プレイヤーがブロックをこわすまで待つ。
406
+ """
407
+ self.client.waitFor(self.uuid, 'onPlayerBlockBreak')
408
+ return Block(** self.client.result)
447
409
 
448
410
  def setOnInteractEvent(self, callbackFunc: Callable[['Entity', 'InteractEvent'], Any]):
449
411
  """
450
- レッドストーンを受信したときに呼び出されるコールバック関数を設定する。
412
+ プレイヤーがイベントアイテムを使った時に呼び出されるコールバック関数を設定する。
451
413
  """
452
414
  def callbackWrapper(data):
453
415
  logging.debug("onInteractEvent callbackWrapper '%s'" % data)
@@ -459,7 +421,7 @@ class Entity:
459
421
 
460
422
  def setOnMessage(self, callbackFunc: Callable[['Entity', str], Any]):
461
423
  """
462
- メッセージを受信したときに呼び出されるコールバック関数を設定する。
424
+ カスタムイベントメッセージを受信したときに呼び出されるコールバック関数を設定する。
463
425
  """
464
426
  def callbackWrapper(data):
465
427
  logging.debug("setOnMessage callbackWrapper '%s'" % data)
@@ -471,7 +433,7 @@ class Entity:
471
433
 
472
434
  def sendMessage(self, target: str, message: str):
473
435
  """
474
- メッセージを送信する。
436
+ カスタムイベントメッセージを送信する。
475
437
 
476
438
  Args:
477
439
  target (str): 送信先のEntityの名前。
@@ -487,24 +449,6 @@ class Entity:
487
449
  command (str): 実行するコマンドの内容。
488
450
  """
489
451
  self.client.sendCall(self.uuid, "executeCommand", [command])
490
-
491
- def getWorld(self) -> 'World':
492
- """
493
- 指定された名前のワールドを取得する。
494
-
495
- Args:
496
- name (str): ワールドの名前。
497
-
498
- Returns:
499
- World: 取得したワールド。
500
-
501
- Raises:
502
- UninitializedClientError: クライアントが初期化されていない場合。
503
- """
504
- if self.client is None or not self.client.connected: # 接続状態をチェック
505
- raise UninitializedClientError("Client is not initialized")
506
-
507
- return World(self.client, self.world, self.uuid)
508
452
 
509
453
  def openInventory(self, x, y, z) -> Inventory :
510
454
  self.client.sendCall(self.uuid, "openInventory", [x, y, z])
@@ -591,14 +535,16 @@ class Entity:
591
535
  self.client.sendCall(self.uuid, "sound")
592
536
  return str_to_bool(self.client.result)
593
537
 
594
- def move(self, speed: float) -> bool :
538
+ def addForce(self, x: float, y: float, z: float) -> bool :
595
539
  """
596
540
  前方へ移動する。
597
541
 
598
542
  Args:
599
- speed (float): 移動速度。
543
+ x (float): x軸方向の加速
544
+ y (float): y軸方向の加速
545
+ z (float): z軸方向の加速
600
546
  """
601
- self.client.sendCall(self.uuid, "move", [speed])
547
+ self.client.sendCall(self.uuid, "addForce", [x, y, z])
602
548
  return str_to_bool(self.client.result)
603
549
 
604
550
  def turn(self, degrees: int):
@@ -610,13 +556,6 @@ class Entity:
610
556
  """
611
557
  self.client.sendCall(self.uuid, "turn", [degrees])
612
558
 
613
- def jump(self) -> bool :
614
- """
615
- 自分をジャンプさせる。
616
- """
617
- self.client.sendCall(self.uuid, "jump")
618
- return str_to_bool(self.client.result)
619
-
620
559
  def placeHere(self, x, y, z) -> bool :
621
560
  """
622
561
  自分を中心に指定した座標にブロックを設置する。
@@ -828,15 +767,13 @@ class Entity:
828
767
  location = Location(** json.loads(self.client.result))
829
768
  return location
830
769
 
831
- def teleport(self, x: int, y: int, z: int) :
770
+ def teleport(self, location: Location) :
832
771
  """
833
772
  自分を指定されたワールド座標に移動する。
834
773
  Args:
835
- x (int): X座標。
836
- y (int): Y座標。
837
- z (int): Z座標。
774
+ location (Location): 座標。
838
775
  """
839
- self.client.sendCall(self.uuid, "teleport", [x, y, z])
776
+ self.client.sendCall(self.uuid, "teleport", [location.x, location.y, location.z, Coordinates.world])
840
777
 
841
778
  def isBlocked(self) -> bool :
842
779
  """
@@ -903,3 +840,39 @@ class Entity:
903
840
  """
904
841
  self.client.sendCall(self.uuid, "getTargetDistance", [uuid])
905
842
  return self.client.result
843
+
844
+ def setBlock(self, cord: Coordinates, x: int, y: int, z: int, block: str, data: int = 0):
845
+ """
846
+ 指定された座標にブロックを設置する。
847
+
848
+ Args:
849
+ x (int): 絶対的なX座標。
850
+ y (int): 絶対的なY座標。
851
+ z (int): 絶対的なZ座標。
852
+ block (str): 設置するブロックの種類。
853
+ """
854
+ self.client.sendCall(self.uuid, "setBlock", [x, y, z, cord, block, data])
855
+
856
+ def getBlock(self, x: int, y: int, z: int) -> Block :
857
+ """
858
+ 指定された座標のブロックを取得する。
859
+
860
+ Args:
861
+ x (int): 絶対的なX座標。
862
+ y (int): 絶対的なY座標。
863
+ z (int): 絶対的なZ座標。
864
+ """
865
+ self.client.sendCall(self.uuid, "getBlock", [x, y, z])
866
+ block = Block(** json.loads(self.client.result))
867
+ return block
868
+
869
+ def getBlockByColor(self, color: str) -> Block :
870
+ """
871
+ 指定された色に近いブロックを取得する。
872
+
873
+ Args:
874
+ color (str): ブロックの色(HexRGB形式)
875
+ """
876
+ self.client.sendCall(self.uuid, "blockColor", [color])
877
+ block = Block(** json.loads(self.client.result))
878
+ return block
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: py2hackCraft2
3
- Version: 1.0.9
3
+ Version: 1.0.10
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.9",
5
+ version="1.0.10",
6
6
  packages=find_packages(),
7
7
  install_requires=[
8
8
  "websocket-client" # websocketライブラリの追加
File without changes
File without changes