Skip to content

Commit 5a9ff16

Browse files
rd-161348 (161348)
1 parent d550b20 commit 5a9ff16

File tree

16 files changed

+128
-52
lines changed

16 files changed

+128
-52
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ install:
1212
CYTHONIZE=1 pip install .
1313

1414
install-from-source: dist
15-
pip install dist/minecraft-python-160052.tar.gz
15+
pip install dist/minecraft-python-161348.tar.gz
1616

1717
clean:
1818
$(RM) -r build dist src/*.egg-info

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44

55
_**Minecraft: Python Edition**_ is a project that strives to recreate each and every old Minecraft version in Python using the **Pyglet** multimedia library and **Cython** for performance.
66

7-
This project is currently recreating the **Preclassic** versions of Minecraft. The latest version is **Preclassic rd-160052** as released on _**May 15, 2009**_.
7+
This project is currently recreating the **Preclassic** versions of Minecraft. The latest version is **Preclassic rd-161348** as released on _**May 16, 2009**_.
88

9-
Learn more about this version [here](https://minecraft.fandom.com/wiki/Java_Edition_pre-Classic_rd-160052).
9+
Learn more about this version [here](https://minecraft.fandom.com/wiki/Java_Edition_pre-Classic_rd-161348).
1010

1111
### General Usage
1212

1313
*Pyglet* and *Cython* are required dependencies and can easily be installed with *pip*. Use the versions specified in `requirements.txt`.
1414

15-
To easily install this version of *Minecraft: Python Edition*, just run `python -m pip install minecraft-python==160052`.
15+
To easily install this version of *Minecraft: Python Edition*, just run `python -m pip install minecraft-python==161348`.
1616

1717
Alternatively, for a manual Cython build, run `python setup.py build_ext --inplace`.
1818

1919
Run `python -m mc.net.minecraft.Minecraft` to launch the game. *Minecraft: Python Edition* should be compatible with any modern platform that supports OpenGL and Cython.
2020

2121
### Gameplay
2222

23-
Basic terrain, early block picking and placing, and human mobs are featured in this version. There are four different blocks you can place.
23+
Basic terrain, early block picking and placing, and human mobs are featured in this version. There are five different blocks you can place.
2424

25-
Press *Esc* to exit the game. Press *Return* to save, *R* to reset your position, *G* to spawn a mob, and numbers *1-4* to switch blocks.
25+
Press *Esc* to exit the game. Press *Return* to save, *R* to reset your position, *G* to spawn a mob, and numbers *1-4* (*6* for saplings) to switch blocks.
2626

2727
### Additional Notes
2828

mc/Resources.py

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

mc/net/minecraft/Minecraft.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def __init__(self, *args, **kwargs):
6161
gl.glClearDepth(1.0)
6262
gl.glEnable(gl.GL_DEPTH_TEST)
6363
gl.glDepthFunc(gl.GL_LEQUAL)
64+
gl.glEnable(gl.GL_ALPHA_TEST)
65+
gl.glAlphaFunc(gl.GL_GREATER, 0.0)
6466

6567
gl.glMatrixMode(gl.GL_PROJECTION)
6668
gl.glLoadIdentity()
@@ -89,7 +91,6 @@ def on_mouse_press(self, x, y, button, modifiers):
8991
changed = self.level.setTile(self.hitResult.x, self.hitResult.y, self.hitResult.z, 0)
9092
if oldTile and changed:
9193
oldTile.destroy(self.level, self.hitResult.x, self.hitResult.y, self.hitResult.z, self.particleEngine)
92-
self.level.setTile(self.hitResult.x, self.hitResult.y, self.hitResult.z, 0)
9394
elif button == window.mouse.LEFT:
9495
if self.hitResult:
9596
x = self.hitResult.x
@@ -120,6 +121,8 @@ def on_key_press(self, symbol, modifiers):
120121
self.paintTexture = 4
121122
elif symbol == window.key._4:
122123
self.paintTexture = 5
124+
elif symbol == window.key._6:
125+
self.paintTexture = 6
123126
elif symbol in (window.key.UP, window.key.W):
124127
self.player.upPressed = True
125128
elif symbol in (window.key.DOWN, window.key.S):
@@ -206,14 +209,6 @@ def setupCamera(self, a):
206209
gl.glLoadIdentity()
207210
self.moveCameraToPlayer(a)
208211

209-
def setupOrthoCamera(self):
210-
gl.glMatrixMode(gl.GL_PROJECTION)
211-
gl.glLoadIdentity()
212-
gl.glOrtho(0.0, self.width, self.height, 0.0, 100.0, 300.0)
213-
gl.glMatrixMode(gl.GL_MODELVIEW)
214-
gl.glLoadIdentity()
215-
gl.glTranslatef(0.0, 0.0, -200.0)
216-
217212
def pick(self, a):
218213
xRot = self.player.xRotO + (self.player.xRot - self.player.xRotO) * a
219214
yRot = self.player.yRotO + (self.player.yRot - self.player.yRotO) * a
@@ -261,21 +256,32 @@ def render(self, a):
261256
gl.glDisable(gl.GL_TEXTURE_2D)
262257
gl.glDisable(gl.GL_FOG)
263258
if self.hitResult:
259+
gl.glDisable(gl.GL_ALPHA_TEST)
264260
self.levelRenderer.renderHit(self.hitResult)
261+
gl.glEnable(gl.GL_ALPHA_TEST)
265262

266263
self.drawGui(a)
267264

268265
def drawGui(self, a):
266+
screenWidth = self.width * 240 // self.height
267+
screenHeight = self.height * 240 // self.height
268+
269269
gl.glClear(gl.GL_DEPTH_BUFFER_BIT)
270-
self.setupOrthoCamera()
270+
gl.glMatrixMode(gl.GL_PROJECTION)
271+
gl.glLoadIdentity()
272+
gl.glOrtho(0.0, screenWidth, screenHeight, 0.0, 100.0, 300.0)
273+
gl.glMatrixMode(gl.GL_MODELVIEW)
274+
gl.glLoadIdentity()
275+
gl.glTranslatef(0.0, 0.0, -200.0)
271276

272277
gl.glPushMatrix()
273-
gl.glTranslatef(self.width - 48, 48.0, 0.0)
278+
gl.glTranslatef(screenWidth - 16, 16.0, 0.0)
274279
t = tesselator
275-
gl.glScalef(48.0, 48.0, 48.0)
280+
gl.glScalef(16.0, 16.0, 16.0)
276281
gl.glRotatef(30.0, 1.0, 0.0, 0.0)
277282
gl.glRotatef(45.0, 0.0, 1.0, 0.0)
278-
gl.glTranslatef(1.5, -0.5, -0.5)
283+
gl.glTranslatef(-1.5, 0.5, -0.5)
284+
gl.glScalef(-1.0, -1.0, 1.0)
279285

280286
id_ = Textures.loadTexture('terrain.png', gl.GL_NEAREST)
281287
gl.glBindTexture(gl.GL_TEXTURE_2D, id_)
@@ -286,19 +292,19 @@ def drawGui(self, a):
286292
gl.glDisable(gl.GL_TEXTURE_2D)
287293
gl.glPopMatrix()
288294

289-
wc = self.width // 2
290-
hc = self.height // 2
295+
wc = screenWidth // 2
296+
hc = screenHeight // 2
291297
gl.glColor4f(1.0, 1.0, 1.0, 1.0)
292298
t.init()
293-
t.vertex(wc + 1, hc - 8, 0.0)
294-
t.vertex(wc - 0, hc - 8, 0.0)
295-
t.vertex(wc - 0, hc + 9, 0.0)
296-
t.vertex(wc + 1, hc + 9, 0.0)
297-
298-
t.vertex(wc + 9, hc - 0, 0.0)
299-
t.vertex(wc - 8, hc - 0, 0.0)
300-
t.vertex(wc - 8, hc + 1, 0.0)
301-
t.vertex(wc + 9, hc + 1, 0.0)
299+
t.vertex(wc + 1, hc - 4, 0.0)
300+
t.vertex(wc - 0, hc - 4, 0.0)
301+
t.vertex(wc - 0, hc + 5, 0.0)
302+
t.vertex(wc + 1, hc + 5, 0.0)
303+
304+
t.vertex(wc + 5, hc - 0, 0.0)
305+
t.vertex(wc - 4, hc - 0, 0.0)
306+
t.vertex(wc - 4, hc + 1, 0.0)
307+
t.vertex(wc + 5, hc + 1, 0.0)
302308
t.flush()
303309

304310
def setupFog(self, i):

mc/net/minecraft/character/Zombie.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ def tick(self):
4545
self.yd *= 0.98
4646
self.zd *= 0.91
4747

48-
if self.y > 100.0:
49-
self.resetPos()
50-
5148
if self.onGround:
5249
self.xd *= 0.7
5350
self.zd *= 0.7

mc/net/minecraft/level/Level.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ cdef class Level:
175175
for z in range(z0, z1):
176176
tile = tiles.tiles[self.getTile(x, y, z)]
177177
if tile:
178-
aABBs.add(tile.getAABB(x, y, z))
178+
aabb = tile.getAABB(x, y, z)
179+
if aabb:
180+
aABBs.add(aabb)
179181

180182
return aABBs
181183

mc/net/minecraft/level/Tesselator.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ cdef class Tesselator:
114114
self.p += 1
115115

116116
self.vertices += 1
117-
if self.p >= self.max_floats - self.len:
117+
if self.vertices % 4 == 0 and (self.p >= self.max_floats - self.len * 4):
118118
self.flush()
119119

120120
tesselator = Tesselator()

mc/net/minecraft/level/tile/Bush.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from mc.net.minecraft.level.tile.Tile import Tile
2+
3+
import math
4+
5+
class Bush(Tile):
6+
7+
def __init__(self, tiles, id_):
8+
super().__init__(tiles, id_)
9+
self.tex = 15
10+
11+
def tick(self, level, x, y, z, random):
12+
below = level.getTile(x, y - 1, z)
13+
if not level.isLit(x, y, z) or (below != self.tiles.dirt.id and below != self.tiles.grass.id):
14+
level.setTile(x, y, z, 0)
15+
16+
def render(self, t, level, layer, x, y, z):
17+
if level.isLit(x, y, z) ^ layer != 1:
18+
return
19+
20+
tex = self.getTexture(15)
21+
u0 = tex % 16 / 16.0
22+
u1 = u0 + 0.0624375
23+
v0 = tex // 16 / 16.0
24+
v1 = v0 + 0.0624375
25+
26+
rots = 2
27+
t.color(1.0, 1.0, 1.0)
28+
for r in range(rots):
29+
xa = math.sin(r * math.pi / rots + 0.7854) * 0.5
30+
za = math.cos(r * math.pi / rots + 0.7854) * 0.5
31+
x0 = x + 0.5 - xa
32+
x1 = x + 0.5 + xa
33+
y0 = y + 0.0
34+
y1 = y + 1.0
35+
z0 = z + 0.5 - za
36+
z1 = z + 0.5 + za
37+
38+
t.vertexUV(x0, y1, z0, u1, v0)
39+
t.vertexUV(x1, y1, z1, u0, v0)
40+
t.vertexUV(x1, y0, z1, u0, v1)
41+
t.vertexUV(x0, y0, z0, u1, v1)
42+
43+
t.vertexUV(x1, y1, z1, u0, v0)
44+
t.vertexUV(x0, y1, z0, u1, v0)
45+
t.vertexUV(x0, y0, z0, u1, v1)
46+
t.vertexUV(x1, y0, z1, u0, v1)
47+
48+
def getAABB(self, x, y, z):
49+
return None
50+
51+
def blocksLight(self):
52+
return False
53+
54+
def isSolid(self):
55+
return False

mc/net/minecraft/level/tile/Tile.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ cdef class Tile:
1414
cpdef int getTexture(self, int face)
1515
cpdef renderFace(self, Tesselator t, int x, int y, int z, int face)
1616
cpdef renderFaceNoTexture(self, Tesselator t, int x, int y, int z, int face)
17-
cdef bint blocksLight(self)
17+
cpdef bint blocksLight(self)
1818
cpdef bint isSolid(self)
1919
cpdef void tick(self, level, int x, int y, int z, random) except *

mc/net/minecraft/level/tile/Tile.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,13 @@ cdef class Tile:
134134
t.vertex(x1, y1, z0)
135135
t.vertex(x1, y1, z1)
136136

137+
def getTileAABB(self, int x, int y, int z):
138+
return AABB(x, y, z, x + 1, y + 1, z + 1)
139+
137140
def getAABB(self, int x, int y, int z):
138141
return AABB(x, y, z, x + 1, y + 1, z + 1)
139142

140-
cdef bint blocksLight(self):
143+
cpdef bint blocksLight(self):
141144
return True
142145

143146
cpdef bint isSolid(self):

mc/net/minecraft/level/tile/Tiles.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ cdef class Tiles:
1212
public Tile dirt
1313
public Tile stoneBrick
1414
public Tile wood
15+
public Tile bush

mc/net/minecraft/level/tile/Tiles.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from mc.net.minecraft.level.tile.Tile cimport Tile
44
from mc.net.minecraft.level.tile.GrassTile import GrassTile
55
from mc.net.minecraft.level.tile.DirtTile import DirtTile
6+
from mc.net.minecraft.level.tile.Bush import Bush
67

78
cdef class Tiles:
89

@@ -19,5 +20,7 @@ cdef class Tiles:
1920
self.tiles[4] = self.stoneBrick
2021
self.wood = Tile(self, 5, 4)
2122
self.tiles[5] = self.wood
23+
self.bush = Bush(self, 6)
24+
self.tiles[6] = self.bush
2225

2326
tiles = Tiles()

mc/net/minecraft/particle/Particle.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,28 @@ def __init__(self, level, x, y, z, xa, ya, za, tex):
1818
speed = (random.random() + random.random() + 1.0) * 0.15
1919

2020
dd = math.sqrt(self.xd * self.xd + self.yd * self.yd + self.zd * self.zd)
21-
self.xd = self.xd / dd * speed * 0.7
22-
self.yd = self.yd / dd * speed
23-
self.zd = self.zd / dd * speed * 0.7
21+
self.xd = self.xd / dd * speed * 0.4
22+
self.yd = self.yd / dd * speed * 0.4 + 0.1
23+
self.zd = self.zd / dd * speed * 0.4
2424

2525
self.uo = random.random() * 3.0
2626
self.vo = random.random() * 3.0
2727

28+
self.size = random.random() * 0.5 + 0.5
29+
30+
self.lifetime = 4.0 // (random.random() * 0.9 + 0.1)
31+
self.age = 0
32+
2833
def tick(self):
2934
self.xo = self.x
3035
self.yo = self.y
3136
self.zo = self.z
3237

33-
if random.random() < 0.1:
38+
if self.age >= self.lifetime:
3439
self.remove()
40+
self.age += 1
3541

36-
self.yd -= 0.06
42+
self.yd -= 0.04
3743
self.move(self.xd, self.yd, self.zd)
3844
self.xd *= 0.98
3945
self.yd *= 0.98
@@ -43,17 +49,17 @@ def tick(self):
4349
self.xd *= 0.7
4450
self.zd *= 0.7
4551

46-
def render(self, t, a, xa, ya, za):
52+
def render(self, t, a, xa, ya, za, xa2, za2):
4753
u0 = (self.tex % 16 + self.uo / 4.0) / 16.0
4854
u1 = u0 + 0.01560938
4955
v0 = (self.tex // 16 + self.vo / 4.0) / 16.0
5056
v1 = v0 + 0.01560938
51-
r = 0.1
57+
r = 0.1 * self.size
5258

5359
x = self.xo + (self.x - self.xo) * a
5460
y = self.yo + (self.y - self.yo) * a
5561
z = self.zo + (self.z - self.zo) * a
56-
t.vertexUV(x - xa * r, y - ya * r, z - za * r, u0, v1)
57-
t.vertexUV(x - xa * r, y + ya * r, z - za * r, u0, v0)
58-
t.vertexUV(x + xa * r, y + ya * r, z + za * r, u1, v0)
59-
t.vertexUV(x + xa * r, y - ya * r, z + za * r, u1, v1)
62+
t.vertexUV(x - xa * r - xa2 * r, y - ya * r, z - za * r - za2 * r, u0, v1)
63+
t.vertexUV(x - xa * r + xa2 * r, y + ya * r, z - za * r + za2 * r, u0, v0)
64+
t.vertexUV(x + xa * r + xa2 * r, y + ya * r, z + za * r + za2 * r, u1, v0)
65+
t.vertexUV(x + xa * r - xa2 * r, y - ya * r, z + za * r - za2 * r, u1, v1)

mc/net/minecraft/particle/ParticleEngine.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ def render(self, player, a, layer):
2525
gl.glBindTexture(gl.GL_TEXTURE_2D, id_)
2626
xa = -math.cos(player.yRot * math.pi / 180.0)
2727
za = -math.sin(player.yRot * math.pi / 180.0)
28-
ya = 1.0
28+
29+
xa2 = -za * math.sin(player.xRot * math.pi / 180.0)
30+
za2 = xa * math.sin(player.xRot * math.pi / 180.0)
31+
ya = math.cos(player.xRot * math.pi / 180.0)
2932

3033
t = tesselator
3134
gl.glColor4f(0.8, 0.8, 0.8, 1.0)
3235
t.init()
3336
for p in self.particles:
3437
if p.isLit() ^ layer == 1:
35-
p.render(t, a, xa, ya, za)
38+
p.render(t, a, xa, ya, za, xa2, za2)
3639
t.flush()
3740
gl.glDisable(gl.GL_TEXTURE_2D)

resources/terrain.png

2.93 KB
Loading

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
setup(
2222
name='minecraft-python',
23-
version='160052-1',
23+
version='161348',
2424
author='pythonengineer',
2525
description='A project that seeks to recreate every old Minecraft version in Python using Pyglet and Cython.',
2626
long_description=open('README.md').read(),

0 commit comments

Comments
 (0)