-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdemo.py
68 lines (52 loc) · 1.63 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import sys
from common import Minecraft, IoException, BlockPos
def demo_tpall():
player = mc.player()
if player is None:
return
target = player.position
for e in mc.iter_entities():
try:
e.teleport(target)
print(f"teleported {e.id}")
except IoException as exc:
print(f"failed to tp {e.id}: {exc}")
raise exc
def demo_killall():
player = mc.player()
if player is None:
return
for e in mc.iter_entities(living_filter=True):
if e.id != player.id:
try:
e.kill()
print(f"killed {e.id} ({e.entity_type})")
except Exception as exc:
print(f"failed to kill {e.id}: {exc}")
def demo_blocks():
player = mc.player()
if player is None:
return
pos = player.position.to_block_pos()
pos.y -= 1
sz = 3
for dx in range(-sz, sz):
for dz in range(-sz, sz):
block_pos = BlockPos(pos.x + dx, pos.y, pos.z + dz)
block = mc.block(player.world, block_pos)
block.block_type = "cobblestone"
if __name__ == '__main__':
mc = Minecraft.from_args()
def list_demos():
return [name[len("demo_"):] for name in globals().keys() if name.startswith("demo_")]
try:
what = sys.argv[2]
except IndexError:
print("missing demo name, which can be one of {}".format(list_demos()))
exit(1)
try:
name = "demo_{}".format(what.lower())
globals()[name]()
except KeyError:
print("invalid demo name, must be one of {}".format(list_demos()))
exit(1)