py2hackCraft2 1.0.8__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.
- {py2hackCraft2-1.0.8 → py2hackCraft2-1.0.10}/PKG-INFO +1 -1
- {py2hackCraft2-1.0.8 → py2hackCraft2-1.0.10}/py2hackCraft/modules.py +117 -100
- {py2hackCraft2-1.0.8 → py2hackCraft2-1.0.10}/py2hackCraft2.egg-info/PKG-INFO +1 -1
- {py2hackCraft2-1.0.8 → py2hackCraft2-1.0.10}/setup.py +1 -1
- {py2hackCraft2-1.0.8 → py2hackCraft2-1.0.10}/README.md +0 -0
- {py2hackCraft2-1.0.8 → py2hackCraft2-1.0.10}/py2hackCraft/__init__.py +0 -0
- {py2hackCraft2-1.0.8 → py2hackCraft2-1.0.10}/py2hackCraft/material.py +0 -0
- {py2hackCraft2-1.0.8 → py2hackCraft2-1.0.10}/py2hackCraft2.egg-info/SOURCES.txt +0 -0
- {py2hackCraft2-1.0.8 → py2hackCraft2-1.0.10}/py2hackCraft2.egg-info/dependency_links.txt +0 -0
- {py2hackCraft2-1.0.8 → py2hackCraft2-1.0.10}/py2hackCraft2.egg-info/requires.txt +0 -0
- {py2hackCraft2-1.0.8 → py2hackCraft2-1.0.10}/py2hackCraft2.egg-info/top_level.txt +0 -0
- {py2hackCraft2-1.0.8 → py2hackCraft2-1.0.10}/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
|
|
@@ -119,6 +123,7 @@ class _WebSocketClient:
|
|
|
119
123
|
logging.debug("send sending'%s'" % message)
|
|
120
124
|
self.wait_for_connection()
|
|
121
125
|
with self.lock:
|
|
126
|
+
self.result = None
|
|
122
127
|
self.response_event.clear() # イベントをクリアして新しいレスポンスの準備をする
|
|
123
128
|
self.ws.send(message)
|
|
124
129
|
self.response_event.wait() # サーバーからのレスポンスを待つ
|
|
@@ -128,6 +133,16 @@ class _WebSocketClient:
|
|
|
128
133
|
self.ws.close()
|
|
129
134
|
self.thread.join()
|
|
130
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
|
+
|
|
131
146
|
def sendCall(self, entity: str, name: str, args=None):
|
|
132
147
|
data = {"entity": entity, "name": name}
|
|
133
148
|
if args is not None:
|
|
@@ -138,6 +153,11 @@ class _WebSocketClient:
|
|
|
138
153
|
}
|
|
139
154
|
self.send(json.dumps(message))
|
|
140
155
|
|
|
156
|
+
class Coordinates:
|
|
157
|
+
world = ""
|
|
158
|
+
relative = "~"
|
|
159
|
+
local = "^"
|
|
160
|
+
|
|
141
161
|
@dataclass
|
|
142
162
|
class Location:
|
|
143
163
|
x: int
|
|
@@ -145,6 +165,19 @@ class Location:
|
|
|
145
165
|
z: int
|
|
146
166
|
world: str = "world"
|
|
147
167
|
|
|
168
|
+
@dataclass
|
|
169
|
+
class InteractEvent:
|
|
170
|
+
action: str
|
|
171
|
+
type: str
|
|
172
|
+
name: str
|
|
173
|
+
block: str = None
|
|
174
|
+
data: int = 0
|
|
175
|
+
uuid: str = None
|
|
176
|
+
world: str = "world"
|
|
177
|
+
x: int = 0
|
|
178
|
+
y: int = 0
|
|
179
|
+
z: int = 0
|
|
180
|
+
|
|
148
181
|
@dataclass
|
|
149
182
|
class EventMessage:
|
|
150
183
|
"""
|
|
@@ -204,11 +237,13 @@ class Block:
|
|
|
204
237
|
isOccluding (bool): 透過しないブロックかどうか。
|
|
205
238
|
isSolid (bool): 壁のあるブロックかどうか。
|
|
206
239
|
isPassable (bool): 通過可能なブロックかどうか。
|
|
240
|
+
world (str): ブロックが存在するワールドの名前(デフォルトは"world")。
|
|
207
241
|
x (int): ブロックのX座標。
|
|
208
242
|
y (int): ブロックのY座標。
|
|
209
243
|
z (int): ブロックのZ座標。
|
|
210
244
|
"""
|
|
211
245
|
name: str
|
|
246
|
+
type: str = "block"
|
|
212
247
|
data: int = 0
|
|
213
248
|
isLiquid: bool = False
|
|
214
249
|
isAir: bool = False
|
|
@@ -220,6 +255,7 @@ class Block:
|
|
|
220
255
|
x: int = 0
|
|
221
256
|
y: int = 0
|
|
222
257
|
z: int = 0
|
|
258
|
+
world: str = "world"
|
|
223
259
|
|
|
224
260
|
@dataclass
|
|
225
261
|
class ItemStack:
|
|
@@ -249,6 +285,7 @@ class Player:
|
|
|
249
285
|
def logout(self):
|
|
250
286
|
self.client.disconnect()
|
|
251
287
|
|
|
288
|
+
|
|
252
289
|
def getEntity(self, name: str) -> 'Entity':
|
|
253
290
|
"""
|
|
254
291
|
指定された名前のエンティティを取得する。
|
|
@@ -270,56 +307,11 @@ class Player:
|
|
|
270
307
|
"data": {"entity": name}
|
|
271
308
|
}
|
|
272
309
|
self.client.send(json.dumps(message))
|
|
273
|
-
|
|
274
|
-
if(
|
|
310
|
+
result = self.client.result
|
|
311
|
+
if(result is None):
|
|
275
312
|
raise ValueError("Entity '%s' not found" % name)
|
|
276
313
|
|
|
277
|
-
return Entity(self.client, self.world,
|
|
278
|
-
|
|
279
|
-
class World:
|
|
280
|
-
"""
|
|
281
|
-
ワールドを表すクラス。
|
|
282
|
-
"""
|
|
283
|
-
def __init__(self, client: _WebSocketClient, world: str, entityUUID: str):
|
|
284
|
-
self.client = client
|
|
285
|
-
self.name = world
|
|
286
|
-
self.entityUUID = entityUUID
|
|
287
|
-
|
|
288
|
-
def setBlock(self, x: int, y: int, z: int, block: str):
|
|
289
|
-
"""
|
|
290
|
-
指定された座標にブロックを設置する。
|
|
291
|
-
|
|
292
|
-
Args:
|
|
293
|
-
x (int): 絶対的なX座標。
|
|
294
|
-
y (int): 絶対的なY座標。
|
|
295
|
-
z (int): 絶対的なZ座標。
|
|
296
|
-
block (str): 設置するブロックの種類。
|
|
297
|
-
"""
|
|
298
|
-
self.client.sendCall(self.entityUUID, "setBlock", [x, y, z, block])
|
|
299
|
-
|
|
300
|
-
def getBlock(self, x: int, y: int, z: int) -> Block :
|
|
301
|
-
"""
|
|
302
|
-
指定された座標のブロックを取得する。
|
|
303
|
-
|
|
304
|
-
Args:
|
|
305
|
-
x (int): 絶対的なX座標。
|
|
306
|
-
y (int): 絶対的なY座標。
|
|
307
|
-
z (int): 絶対的なZ座標。
|
|
308
|
-
"""
|
|
309
|
-
self.client.sendCall(self.entityUUID, "getBlock", [x, y, z])
|
|
310
|
-
block = Block(** json.loads(self.client.result))
|
|
311
|
-
return block
|
|
312
|
-
|
|
313
|
-
def getBlockByColor(self, color: str) -> Block :
|
|
314
|
-
"""
|
|
315
|
-
指定された色に近いブロックを取得する。
|
|
316
|
-
|
|
317
|
-
Args:
|
|
318
|
-
color (str): ブロックの色(HexRGB形式)
|
|
319
|
-
"""
|
|
320
|
-
self.client.sendCall(self.entityUUID, "blockColor", [color])
|
|
321
|
-
block = Block(** json.loads(self.client.result))
|
|
322
|
-
return block
|
|
314
|
+
return Entity(self.client, self.world, result)
|
|
323
315
|
|
|
324
316
|
class Inventory:
|
|
325
317
|
"""
|
|
@@ -393,32 +385,43 @@ class Entity:
|
|
|
393
385
|
self.uuid = uuid
|
|
394
386
|
self.positions = []
|
|
395
387
|
|
|
396
|
-
def
|
|
388
|
+
def waitForPlayerChat(self):
|
|
397
389
|
"""
|
|
398
|
-
|
|
390
|
+
チャットを受信するまでまつ
|
|
399
391
|
"""
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
392
|
+
self.client.waitFor(self.uuid, 'onPlayerChat')
|
|
393
|
+
print('result = ', self.client.result)
|
|
394
|
+
return ChatMessage(** self.client.result)
|
|
395
|
+
|
|
396
|
+
def waitForRedstoneChange(self):
|
|
397
|
+
"""
|
|
398
|
+
レッドストーン信号が変わるまでまつ。
|
|
399
|
+
"""
|
|
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)
|
|
406
409
|
|
|
407
|
-
def
|
|
410
|
+
def setOnInteractEvent(self, callbackFunc: Callable[['Entity', 'InteractEvent'], Any]):
|
|
408
411
|
"""
|
|
409
|
-
|
|
412
|
+
プレイヤーがイベントアイテムを使った時に呼び出されるコールバック関数を設定する。
|
|
410
413
|
"""
|
|
411
414
|
def callbackWrapper(data):
|
|
412
|
-
logging.debug("
|
|
415
|
+
logging.debug("onInteractEvent callbackWrapper '%s'" % data)
|
|
413
416
|
if(data['entityUuid'] == self.uuid):
|
|
414
417
|
logging.debug("callbackWrapper '%s'" % data)
|
|
415
|
-
|
|
416
|
-
callbackFunc(self,
|
|
417
|
-
self.client.setCallback('
|
|
418
|
+
event = InteractEvent(**data["event"])
|
|
419
|
+
callbackFunc(self, event)
|
|
420
|
+
self.client.setCallback('onInteractEvent', callbackWrapper)
|
|
418
421
|
|
|
419
422
|
def setOnMessage(self, callbackFunc: Callable[['Entity', str], Any]):
|
|
420
423
|
"""
|
|
421
|
-
|
|
424
|
+
カスタムイベントメッセージを受信したときに呼び出されるコールバック関数を設定する。
|
|
422
425
|
"""
|
|
423
426
|
def callbackWrapper(data):
|
|
424
427
|
logging.debug("setOnMessage callbackWrapper '%s'" % data)
|
|
@@ -430,7 +433,7 @@ class Entity:
|
|
|
430
433
|
|
|
431
434
|
def sendMessage(self, target: str, message: str):
|
|
432
435
|
"""
|
|
433
|
-
|
|
436
|
+
カスタムイベントメッセージを送信する。
|
|
434
437
|
|
|
435
438
|
Args:
|
|
436
439
|
target (str): 送信先のEntityの名前。
|
|
@@ -438,23 +441,14 @@ class Entity:
|
|
|
438
441
|
"""
|
|
439
442
|
self.client.sendCall(self.uuid, "sendEvent", [target, message])
|
|
440
443
|
|
|
441
|
-
def
|
|
444
|
+
def executeCommand(self, command: str):
|
|
442
445
|
"""
|
|
443
|
-
|
|
446
|
+
コマンドを実行する。
|
|
444
447
|
|
|
445
448
|
Args:
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
Returns:
|
|
449
|
-
World: 取得したワールド。
|
|
450
|
-
|
|
451
|
-
Raises:
|
|
452
|
-
UninitializedClientError: クライアントが初期化されていない場合。
|
|
449
|
+
command (str): 実行するコマンドの内容。
|
|
453
450
|
"""
|
|
454
|
-
|
|
455
|
-
raise UninitializedClientError("Client is not initialized")
|
|
456
|
-
|
|
457
|
-
return World(self.client, self.world, self.uuid)
|
|
451
|
+
self.client.sendCall(self.uuid, "executeCommand", [command])
|
|
458
452
|
|
|
459
453
|
def openInventory(self, x, y, z) -> Inventory :
|
|
460
454
|
self.client.sendCall(self.uuid, "openInventory", [x, y, z])
|
|
@@ -541,20 +535,16 @@ class Entity:
|
|
|
541
535
|
self.client.sendCall(self.uuid, "sound")
|
|
542
536
|
return str_to_bool(self.client.result)
|
|
543
537
|
|
|
544
|
-
def
|
|
538
|
+
def addForce(self, x: float, y: float, z: float) -> bool :
|
|
545
539
|
"""
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
"""
|
|
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
|
-
走る。
|
|
540
|
+
前方へ移動する。
|
|
555
541
|
|
|
542
|
+
Args:
|
|
543
|
+
x (float): x軸方向の加速
|
|
544
|
+
y (float): y軸方向の加速
|
|
545
|
+
z (float): z軸方向の加速
|
|
556
546
|
"""
|
|
557
|
-
self.client.sendCall(self.uuid, "
|
|
547
|
+
self.client.sendCall(self.uuid, "addForce", [x, y, z])
|
|
558
548
|
return str_to_bool(self.client.result)
|
|
559
549
|
|
|
560
550
|
def turn(self, degrees: int):
|
|
@@ -566,13 +556,6 @@ class Entity:
|
|
|
566
556
|
"""
|
|
567
557
|
self.client.sendCall(self.uuid, "turn", [degrees])
|
|
568
558
|
|
|
569
|
-
def jump(self) -> bool :
|
|
570
|
-
"""
|
|
571
|
-
自分をジャンプさせる。
|
|
572
|
-
"""
|
|
573
|
-
self.client.sendCall(self.uuid, "jump")
|
|
574
|
-
return str_to_bool(self.client.result)
|
|
575
|
-
|
|
576
559
|
def placeHere(self, x, y, z) -> bool :
|
|
577
560
|
"""
|
|
578
561
|
自分を中心に指定した座標にブロックを設置する。
|
|
@@ -784,15 +767,13 @@ class Entity:
|
|
|
784
767
|
location = Location(** json.loads(self.client.result))
|
|
785
768
|
return location
|
|
786
769
|
|
|
787
|
-
def teleport(self,
|
|
770
|
+
def teleport(self, location: Location) :
|
|
788
771
|
"""
|
|
789
772
|
自分を指定されたワールド座標に移動する。
|
|
790
773
|
Args:
|
|
791
|
-
|
|
792
|
-
y (int): Y座標。
|
|
793
|
-
z (int): Z座標。
|
|
774
|
+
location (Location): 座標。
|
|
794
775
|
"""
|
|
795
|
-
self.client.sendCall(self.uuid, "teleport", [x, y, z])
|
|
776
|
+
self.client.sendCall(self.uuid, "teleport", [location.x, location.y, location.z, Coordinates.world])
|
|
796
777
|
|
|
797
778
|
def isBlocked(self) -> bool :
|
|
798
779
|
"""
|
|
@@ -859,3 +840,39 @@ class Entity:
|
|
|
859
840
|
"""
|
|
860
841
|
self.client.sendCall(self.uuid, "getTargetDistance", [uuid])
|
|
861
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|