-
Notifications
You must be signed in to change notification settings - Fork 0
/
EarthQuake.py
171 lines (163 loc) · 5.65 KB
/
EarthQuake.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# https://crazysqueak.wordpress.com/2015/11/29/disasters-minecraft/
import mcpi.minecraft as minc
from mine import *
import mcpi.block as block
from _mp_ds_config import *
mc = Minecraft(Connection(serveradress, serverport), name=playernameonserver)
import random, time, pygame
pygame.mixer.init()
earthSound = pygame.mixer.Sound('earthquake.ogg')
eruptSound = pygame.mixer.Sound('lava.ogg')
meteorSound = pygame.mixer.Sound('meteor.ogg')
def earthquake(x, z):
mc.postToChat('Earthquake!')
y = mc.getHeight(x, z)
endtime = time.time() + 60
nearthtime = time.time()
while endtime > time.time():
if time.time() > nearthtime:
earthSound.play()
nearthtime = time.time() + 5
ppos = mc.player.getPos()
if ppos.x < x+15 and ppos.x > x-15:
if ppos.y < y+15 and ppos.y > -60:
if ppos.z < z+15 and ppos.z > z-15:
mc.player.setPos(ppos.x, ppos.y, ppos.z)
bx = random.randint(x-15, x+15)
by = y
bz = random.randint(z-15, z+15)
if mc.getHeight(bx, bz) > -50:
by = mc.getHeight(bx, bz)
if mc.getBlock(bx, by, bz) in [block.GLASS.id, block.GLASS_PANE.id]:
mc.setBlock(bx, by, bz, block.AIR.id)
continue
mc.setBlock(bx, by, bz, block.GRAVEL.id)
mc.setBlocks(bx, by-1, bz, bx, -60, bz, block.AIR.id)
def sinkhole(x, z):
blks = []
y = mc.getHeight(x, z)
xdist = random.randint(1, 5)
for bx in range(-xdist, xdist+1):
zdist = random.randint(1, 5)
for bz in range(-zdist, zdist+1):
blks.append([x+bx, z+bz])
earthSound.play()
for blk in blks:
mc.setBlocks(blk[0], mc.getHeight(blk[0], blk[1]), blk[1], blk[0], -60, blk[1], block.AIR.id)
mc.setBlocks(blk[0], -55, blk[1], blk[0], -60, blk[1], block.LAVA.id)
for blk in blks:
mc.setBlock(blk[0], y, blk[1], block.GRAVEL.id)
def geyser(x, z):
y = mc.getHeight(x, z)
mc.setBlocks(x-2, y+5, z-2, x+2, -60, z+2, block.WATER.id)
time.sleep(25)
mc.setBlocks(x-2, y+5, z-2, x+2, -60, z+2, block.AIR.id)
def eruption(x, z):
y = mc.getHeight(x, z)
for i in range(3):
eruptSound.play()
mc.setBlocks(x-2, y+9, z-2, x+2, y+9, z+2, block.LAVA.id)
eruptSound.play()
for i in range(15):
time.sleep(1)
eruptSound.play()
eruptSound.play()
mc.setBlocks(x-2, y+10, z-2, x+2, y+10, z+2, block.WATER.id)
eruptSound.play()
for i in range(5):
time.sleep(1)
eruptSound.play()
eruptSound.play()
mc.setBlocks(x-2, y+10, z-2, x+2, y+10, z+2, block.AIR.id)
eruptSound.play()
for i in range(5):
time.sleep(1)
eruptSound.play()
eruptSound.play()
y += 1
eruptSound.play()
def meteor(x, z):
mc.postToChat('Meteor approaching!')
y = 64
h = mc.getHeight(x, z)
x -= (64 - h)
meteorSound.play()
while y > h:
y -= 1
x += 1
mc.setBlocks(x-2, y-2, z-2, x+2, y+2, z+2, block.OBSIDIAN.id)
time.sleep(0.05)
mc.setBlocks(x-2, y-2, z-2, x+2, y+2, z+2, block.AIR.id)
mc.setBlocks(x-2, y-2, z-2, x+2, y+2, z+2, block.LAVA.id)
mc.setBlocks(x-1, y-1, z-1, x+1, y+1, z+1, block.OBSIDIAN.id)
def meteor_shower(x, z):
for i in range(10):
mx = random.randint(x-15, x+15)
mz = random.randint(z-15, z+15)
meteor(mx, mz)
def heatwave(x, z):
y = mc.getHeight(x, z)
endtime = time.time() + random.randint(50, 90)
while time.time() < endtime:
blkid = block.AIR.id
while blkid == block.AIR.id:
bx = random.randint(x-10, x+10)
by = random.randint(y, y+10)
bz = random.randint(z-10, z+10)
blkid = mc.getBlockWithData(bx, by, bz).id
blk = blkid
blkd = mc.getBlockWithData(bx, by, bz).data
if blkid == block.GRASS.id:
blk = block.DIRT.id
blkd = 0
elif blkid in [block.WATER.id, block.WATER_FLOWING.id, block.WATER_STATIONARY.id]:
blk = block.WATER.id
blkd = 1
elif blkid == block.LEAVES.id:
blk = block.COBWEB.id
blkd = 0
elif blkid == block.WOOD.id:
blk = block.LAVA_STATIONARY.id
blkd = 1
mc.setBlock(bx, by, bz, blk, blkd)
def tsunami(x, z):
tend = time.time() + 15
tx = x
while time.time() < tend:
h = mc.getHeight(tx, z)
mc.setBlocks(tx, h-5, z-5, tx, h+5, z+5, block.WATER_STATIONARY.id)
time.sleep(0.1)
mc.setBlocks(tx, h-5, z-5, tx, h+5, z+5, block.AIR.id)
time.sleep(0.1)
tx += 1
hm = 5
while hm > -1:
h = mc.getHeight(tx, z)
mc.setBlocks(tx, h-int(hm), z-5, tx, h+int(hm), z+5, block.WATER_STATIONARY.id)
time.sleep(0.1)
mc.setBlocks(tx, h-int(hm), z-5, tx, h+int(hm), z+5, block.AIR.id)
time.sleep(0.1)
tx += 1
hm -= 0.2
disasters = [tsunami, heatwave, meteor, meteor_shower, geyser, earthquake, sinkhole]
def main(disasters, mc):
baseed = random.randint(1, 10000)
while True:
t = random.randint(15, 180)
t = 15
time.sleep(t)
random.seed(baseed + t)
baseed = random.randint(1, 10000)
random.shuffle(disasters)
disaster = random.choice(disasters)
ppos = mc.player.getTilePos()
#mc.postToChat(str(disaster) + ' in')
#for c in range(3, 0, -1):
# mc.postToChat(str(c))
# time.sleep(0.33)
disaster(ppos.x, ppos.z)
try:
import _thread as thread
except ImportError:
import thread
thread.start_new_thread(main, (disasters, mc))