py2hackCraft2 1.0.9__tar.gz → 1.0.11__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.
- {py2hackCraft2-1.0.9 → py2hackCraft2-1.0.11}/PKG-INFO +1 -1
- {py2hackCraft2-1.0.9 → py2hackCraft2-1.0.11}/py2hackCraft/modules.py +86 -112
- {py2hackCraft2-1.0.9 → py2hackCraft2-1.0.11}/py2hackCraft2.egg-info/PKG-INFO +1 -1
- {py2hackCraft2-1.0.9 → py2hackCraft2-1.0.11}/setup.py +1 -1
- {py2hackCraft2-1.0.9 → py2hackCraft2-1.0.11}/README.md +0 -0
- {py2hackCraft2-1.0.9 → py2hackCraft2-1.0.11}/py2hackCraft/__init__.py +0 -0
- {py2hackCraft2-1.0.9 → py2hackCraft2-1.0.11}/py2hackCraft/material.py +0 -0
- {py2hackCraft2-1.0.9 → py2hackCraft2-1.0.11}/py2hackCraft2.egg-info/SOURCES.txt +0 -0
- {py2hackCraft2-1.0.9 → py2hackCraft2-1.0.11}/py2hackCraft2.egg-info/dependency_links.txt +0 -0
- {py2hackCraft2-1.0.9 → py2hackCraft2-1.0.11}/py2hackCraft2.egg-info/requires.txt +0 -0
- {py2hackCraft2-1.0.9 → py2hackCraft2-1.0.11}/py2hackCraft2.egg-info/top_level.txt +0 -0
- {py2hackCraft2-1.0.9 → py2hackCraft2-1.0.11}/setup.cfg +0 -0
|
@@ -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
|
|
@@ -149,11 +168,12 @@ class Location:
|
|
|
149
168
|
@dataclass
|
|
150
169
|
class InteractEvent:
|
|
151
170
|
action: str
|
|
152
|
-
|
|
171
|
+
player: str
|
|
172
|
+
player_uuid: str
|
|
173
|
+
event: str
|
|
153
174
|
name: str
|
|
154
|
-
|
|
175
|
+
type: str
|
|
155
176
|
data: int = 0
|
|
156
|
-
uuid: str = None
|
|
157
177
|
world: str = "world"
|
|
158
178
|
x: int = 0
|
|
159
179
|
y: int = 0
|
|
@@ -266,17 +286,6 @@ class Player:
|
|
|
266
286
|
def logout(self):
|
|
267
287
|
self.client.disconnect()
|
|
268
288
|
|
|
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
289
|
|
|
281
290
|
def getEntity(self, name: str) -> 'Entity':
|
|
282
291
|
"""
|
|
@@ -305,51 +314,6 @@ class Player:
|
|
|
305
314
|
|
|
306
315
|
return Entity(self.client, self.world, result)
|
|
307
316
|
|
|
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
317
|
class Inventory:
|
|
354
318
|
"""
|
|
355
319
|
インベントリを表すクラス。
|
|
@@ -422,32 +386,31 @@ class Entity:
|
|
|
422
386
|
self.uuid = uuid
|
|
423
387
|
self.positions = []
|
|
424
388
|
|
|
425
|
-
def
|
|
389
|
+
def waitForPlayerChat(self):
|
|
426
390
|
"""
|
|
427
|
-
|
|
391
|
+
チャットを受信するまでまつ
|
|
428
392
|
"""
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
chatMessage = ChatMessage(**data)
|
|
433
|
-
callbackFunc(self, chatMessage)
|
|
434
|
-
self.client.setCallback('onPlayerChat', callbackWrapper)
|
|
393
|
+
self.client.waitFor(self.uuid, 'onPlayerChat')
|
|
394
|
+
print('result = ', self.client.result)
|
|
395
|
+
return ChatMessage(** self.client.result)
|
|
435
396
|
|
|
436
|
-
def
|
|
397
|
+
def waitForRedstoneChange(self):
|
|
437
398
|
"""
|
|
438
|
-
|
|
399
|
+
レッドストーン信号が変わるまでまつ。
|
|
439
400
|
"""
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
401
|
+
self.client.waitFor(self.uuid, 'onEntityRedstone')
|
|
402
|
+
return RedstonePower(** self.client.result)
|
|
403
|
+
|
|
404
|
+
def waitForBreakBlock(self):
|
|
405
|
+
"""
|
|
406
|
+
プレイヤーがブロックをこわすまで待つ。
|
|
407
|
+
"""
|
|
408
|
+
self.client.waitFor(self.uuid, 'onPlayerBlockBreak')
|
|
409
|
+
return Block(** self.client.result)
|
|
447
410
|
|
|
448
411
|
def setOnInteractEvent(self, callbackFunc: Callable[['Entity', 'InteractEvent'], Any]):
|
|
449
412
|
"""
|
|
450
|
-
|
|
413
|
+
プレイヤーがイベントアイテムを使った時に呼び出されるコールバック関数を設定する。
|
|
451
414
|
"""
|
|
452
415
|
def callbackWrapper(data):
|
|
453
416
|
logging.debug("onInteractEvent callbackWrapper '%s'" % data)
|
|
@@ -459,7 +422,7 @@ class Entity:
|
|
|
459
422
|
|
|
460
423
|
def setOnMessage(self, callbackFunc: Callable[['Entity', str], Any]):
|
|
461
424
|
"""
|
|
462
|
-
|
|
425
|
+
カスタムイベントメッセージを受信したときに呼び出されるコールバック関数を設定する。
|
|
463
426
|
"""
|
|
464
427
|
def callbackWrapper(data):
|
|
465
428
|
logging.debug("setOnMessage callbackWrapper '%s'" % data)
|
|
@@ -471,7 +434,7 @@ class Entity:
|
|
|
471
434
|
|
|
472
435
|
def sendMessage(self, target: str, message: str):
|
|
473
436
|
"""
|
|
474
|
-
|
|
437
|
+
カスタムイベントメッセージを送信する。
|
|
475
438
|
|
|
476
439
|
Args:
|
|
477
440
|
target (str): 送信先のEntityの名前。
|
|
@@ -487,24 +450,6 @@ class Entity:
|
|
|
487
450
|
command (str): 実行するコマンドの内容。
|
|
488
451
|
"""
|
|
489
452
|
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
453
|
|
|
509
454
|
def openInventory(self, x, y, z) -> Inventory :
|
|
510
455
|
self.client.sendCall(self.uuid, "openInventory", [x, y, z])
|
|
@@ -591,14 +536,16 @@ class Entity:
|
|
|
591
536
|
self.client.sendCall(self.uuid, "sound")
|
|
592
537
|
return str_to_bool(self.client.result)
|
|
593
538
|
|
|
594
|
-
def
|
|
539
|
+
def addForce(self, x: float, y: float, z: float) -> bool :
|
|
595
540
|
"""
|
|
596
541
|
前方へ移動する。
|
|
597
542
|
|
|
598
543
|
Args:
|
|
599
|
-
|
|
544
|
+
x (float): x軸方向の加速
|
|
545
|
+
y (float): y軸方向の加速
|
|
546
|
+
z (float): z軸方向の加速
|
|
600
547
|
"""
|
|
601
|
-
self.client.sendCall(self.uuid, "
|
|
548
|
+
self.client.sendCall(self.uuid, "addForce", [x, y, z])
|
|
602
549
|
return str_to_bool(self.client.result)
|
|
603
550
|
|
|
604
551
|
def turn(self, degrees: int):
|
|
@@ -610,13 +557,6 @@ class Entity:
|
|
|
610
557
|
"""
|
|
611
558
|
self.client.sendCall(self.uuid, "turn", [degrees])
|
|
612
559
|
|
|
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
560
|
def placeHere(self, x, y, z) -> bool :
|
|
621
561
|
"""
|
|
622
562
|
自分を中心に指定した座標にブロックを設置する。
|
|
@@ -828,15 +768,13 @@ class Entity:
|
|
|
828
768
|
location = Location(** json.loads(self.client.result))
|
|
829
769
|
return location
|
|
830
770
|
|
|
831
|
-
def teleport(self,
|
|
771
|
+
def teleport(self, location: Location) :
|
|
832
772
|
"""
|
|
833
773
|
自分を指定されたワールド座標に移動する。
|
|
834
774
|
Args:
|
|
835
|
-
|
|
836
|
-
y (int): Y座標。
|
|
837
|
-
z (int): Z座標。
|
|
775
|
+
location (Location): 座標。
|
|
838
776
|
"""
|
|
839
|
-
self.client.sendCall(self.uuid, "teleport", [x, y, z])
|
|
777
|
+
self.client.sendCall(self.uuid, "teleport", [location.x, location.y, location.z, Coordinates.world])
|
|
840
778
|
|
|
841
779
|
def isBlocked(self) -> bool :
|
|
842
780
|
"""
|
|
@@ -903,3 +841,39 @@ class Entity:
|
|
|
903
841
|
"""
|
|
904
842
|
self.client.sendCall(self.uuid, "getTargetDistance", [uuid])
|
|
905
843
|
return self.client.result
|
|
844
|
+
|
|
845
|
+
def setBlock(self, cord: Coordinates, x: int, y: int, z: int, block: str, data: int = 0):
|
|
846
|
+
"""
|
|
847
|
+
指定された座標にブロックを設置する。
|
|
848
|
+
|
|
849
|
+
Args:
|
|
850
|
+
x (int): 絶対的なX座標。
|
|
851
|
+
y (int): 絶対的なY座標。
|
|
852
|
+
z (int): 絶対的なZ座標。
|
|
853
|
+
block (str): 設置するブロックの種類。
|
|
854
|
+
"""
|
|
855
|
+
self.client.sendCall(self.uuid, "setBlock", [x, y, z, cord, block, data])
|
|
856
|
+
|
|
857
|
+
def getBlock(self, x: int, y: int, z: int) -> Block :
|
|
858
|
+
"""
|
|
859
|
+
指定された座標のブロックを取得する。
|
|
860
|
+
|
|
861
|
+
Args:
|
|
862
|
+
x (int): 絶対的なX座標。
|
|
863
|
+
y (int): 絶対的なY座標。
|
|
864
|
+
z (int): 絶対的なZ座標。
|
|
865
|
+
"""
|
|
866
|
+
self.client.sendCall(self.uuid, "getBlock", [x, y, z])
|
|
867
|
+
block = Block(** json.loads(self.client.result))
|
|
868
|
+
return block
|
|
869
|
+
|
|
870
|
+
def getBlockByColor(self, color: str) -> Block :
|
|
871
|
+
"""
|
|
872
|
+
指定された色に近いブロックを取得する。
|
|
873
|
+
|
|
874
|
+
Args:
|
|
875
|
+
color (str): ブロックの色(HexRGB形式)
|
|
876
|
+
"""
|
|
877
|
+
self.client.sendCall(self.uuid, "blockColor", [color])
|
|
878
|
+
block = Block(** json.loads(self.client.result))
|
|
879
|
+
return block
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|