Skip to content

Commit f2d9b5b

Browse files
rd-132328 (132328)
1 parent aa8383d commit f2d9b5b

File tree

18 files changed

+416
-151
lines changed

18 files changed

+416
-151
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-132211.tar.gz
15+
pip install dist/minecraft-python-132328.tar.gz
1616

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

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
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-132211** (the very first!) as released on _**May 13, 2009**_.
7+
This project is currently recreating the **Preclassic** versions of Minecraft. The latest version is **Preclassic rd-132328** as released on _**May 13, 2009**_.
88

9-
Learn more about this version [here](https://minecraft.fandom.com/wiki/Java_Edition_pre-Classic_rd-132211).
9+
Learn more about this version [here](https://minecraft.fandom.com/wiki/Java_Edition_pre-Classic_rd-132328).
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==132211`.
15+
To easily install this version of *Minecraft: Python Edition*, just run `python -m pip install minecraft-python==132328`.
1616

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

@@ -22,6 +22,10 @@ Run `python -m mc.net.minecraft.Minecraft` to launch the game. *Minecraft: Pytho
2222

2323
Very basic block picking and placing are featured in this version. You can only place stone tiles, except at exact ground level where it is only grass.
2424

25+
Human mobs are featured in this version, but they are all spawned at game start as opposed to on key press.
26+
27+
Press *Esc* to exit the game.
28+
2529
### Additional Notes
2630

2731
The resources directory contains all of the textures that this version uses. However,

mc/Resources.py

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

mc/net/minecraft/Entity.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from mc.net.minecraft.phys.AABB import AABB
2+
3+
import random
4+
import math
5+
6+
class Entity:
7+
xo = 0.0
8+
yo = 0.0
9+
zo = 0.0
10+
xd = 0.0
11+
yd = 0.0
12+
zd = 0.0
13+
yRot = 0.0
14+
xRot = 0.0
15+
yRotO = 0.0
16+
xRotO = 0.0
17+
onGround = False
18+
19+
heightOffset = 0.0
20+
21+
def __init__(self, level):
22+
self.level = level
23+
self.resetPos()
24+
25+
def resetPos(self):
26+
x = random.random() * self.level.width
27+
y = self.level.depth + 10
28+
z = random.random() * self.level.height
29+
self.setPos(x, y, z)
30+
31+
def setPos(self, x, y, z):
32+
self.x = x
33+
self.y = y
34+
self.z = z
35+
w = 0.3
36+
h = 0.9
37+
self.bb = AABB(x - w, y - h, z - w, x + w, y + h, z + w)
38+
39+
def turn(self, xo, yo):
40+
orgXRot = self.xRot
41+
orgYRot = self.yRot
42+
self.yRot = self.yRot + xo * 0.15
43+
self.xRot = self.xRot - yo * 0.15
44+
if self.xRot < -90.0:
45+
self.xRot = -90.0
46+
if self.xRot > 90.0:
47+
self.xRot = 90.0
48+
49+
self.xRotO += self.xRot - orgXRot
50+
self.yRotO += self.yRot - orgYRot
51+
52+
def tick(self):
53+
self.xo = self.x
54+
self.yo = self.y
55+
self.zo = self.z
56+
57+
def move(self, xa, ya, za):
58+
xaOrg = xa
59+
yaOrg = ya
60+
zaOrg = za
61+
62+
aABBs = self.level.getCubes(self.bb.expand(xa, ya, za))
63+
for aABB in aABBs:
64+
ya = aABB.clipYCollide(self.bb, ya)
65+
66+
self.bb.move(0.0, ya, 0.0)
67+
68+
for aABB in aABBs:
69+
xa = aABB.clipXCollide(self.bb, xa)
70+
71+
self.bb.move(xa, 0.0, 0.0)
72+
73+
for aABB in aABBs:
74+
za = aABB.clipZCollide(self.bb, za)
75+
76+
self.bb.move(0.0, 0.0, za)
77+
78+
self.onGround = yaOrg != ya and yaOrg < 0.0
79+
80+
if xaOrg != xa:
81+
self.xd = 0.0
82+
if yaOrg != ya:
83+
self.yd = 0.0
84+
if zaOrg != za:
85+
self.zd = 0.0
86+
self.x = (self.bb.x0 + self.bb.x1) / 2.0
87+
self.y = self.bb.y0 + self.heightOffset
88+
self.z = (self.bb.z0 + self.bb.z1) / 2.0
89+
90+
def moveRelative(self, xa, za, speed):
91+
dist = xa * xa + za * za
92+
if dist < 0.01:
93+
return
94+
95+
dist = speed / math.sqrt(dist)
96+
xa *= dist
97+
za *= dist
98+
99+
sin = math.sin(self.yRot * math.pi / 180.0)
100+
cos = math.cos(self.yRot * math.pi / 180.0)
101+
102+
self.xd += xa * cos - za * sin
103+
self.zd += za * cos + xa * sin

mc/net/minecraft/Minecraft.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from mc.net.minecraft.Timer import Timer
55
from mc.net.minecraft.Player import Player
66
from mc.net.minecraft.HitResult import HitResult
7+
from mc.net.minecraft.character.Vec3 import Vec3
8+
from mc.net.minecraft.character.Cube import Cube
9+
from mc.net.minecraft.character.Zombie import Zombie
710
from mc.net.minecraft.level.Chunk import Chunk
811
from mc.net.minecraft.level.Level import Level
912
from mc.net.minecraft.level.LevelRenderer import LevelRenderer
@@ -12,18 +15,12 @@
1215

1316
import math
1417

15-
class Vec3:
16-
17-
def __init__(self, x, y, z):
18-
self.x = x
19-
self.y = y
20-
self.z = z
21-
2218
class Minecraft(window.Window):
2319
FULLSCREEN_MODE = False
2420
col = 920330
2521
fogColor = ((col >> 16 & 0xFF) / 255.0, (col >> 8 & 0xFF) / 255.0, (col & 0xFF) / 255.0, (col & 0xFF) / 255.0, 1.0)
2622
timer = Timer(60.0)
23+
zombies = set()
2724
hitResult = None
2825
running = True
2926

@@ -49,6 +46,9 @@ def __init__(self, *args, **kwargs):
4946
self.levelRenderer = LevelRenderer(self.level)
5047
self.player = Player(self.level)
5148

49+
for i in range(100):
50+
self.zombies.add(Zombie(self.level, 128.0, 0.0, 128.0))
51+
5252
self.set_exclusive_mouse(True)
5353

5454
def destroy(self):
@@ -75,11 +75,6 @@ def on_mouse_press(self, x, y, button, modifiers):
7575
def on_mouse_motion(self, x, y, dx, dy):
7676
self.player.turn(dx, dy)
7777

78-
def on_activate(self):
79-
# Remove this hack when the window boundary issue is fixed upstream:
80-
if compat_platform == 'win32':
81-
self._update_clipped_cursor()
82-
8378
def on_key_press(self, symbol, modifiers):
8479
if symbol == window.key.R:
8580
self.player.resetPos()
@@ -110,6 +105,11 @@ def on_key_release(self, symbol, modifiers):
110105
elif symbol in (window.key.SPACE, window.key.LWINDOWS, window.key.LMETA):
111106
self.player.spacePressed = False
112107

108+
def on_activate(self):
109+
# Remove this hack when the window boundary issue is fixed upstream:
110+
if compat_platform == 'win32':
111+
self._update_clipped_cursor()
112+
113113
def on_draw(self):
114114
self.clear()
115115
self.timer.advanceTime()
@@ -145,6 +145,9 @@ def run(self):
145145
self.destroy()
146146

147147
def tick(self):
148+
for zombie in self.zombies:
149+
zombie.tick()
150+
148151
self.player.tick()
149152

150153
def moveCameraToPlayer(self, a):
@@ -198,6 +201,10 @@ def render(self, a):
198201

199202
gl.glDisable(gl.GL_FOG)
200203
self.levelRenderer.render(self.player, 0)
204+
205+
for zombie in self.zombies:
206+
zombie.render(a)
207+
201208
gl.glEnable(gl.GL_FOG)
202209
self.levelRenderer.render(self.player, 1)
203210
gl.glDisable(gl.GL_TEXTURE_2D)

mc/net/minecraft/Player.py

Lines changed: 8 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,27 @@
1-
from mc.net.minecraft.phys.AABB import AABB
1+
from mc.net.minecraft.Entity import Entity
22

3-
import random
4-
import math
5-
6-
class Player:
7-
level = None
8-
xo = 0.0
9-
yo = 0.0
10-
zo = 0.0
11-
xd = 0.0
12-
yd = 0.0
13-
zd = 0.0
14-
yRot = 0.0
15-
xRot = 0.0
16-
yRotO = 0.0
17-
xRotO = 0.0
18-
onGround = False
3+
class Player(Entity):
194
upPressed = False
205
downPressed = False
216
leftPressed = False
227
rightPressed = False
238
spacePressed = False
249

2510
def __init__(self, level):
26-
self.level = level
27-
self.resetPos()
28-
29-
def resetPos(self):
30-
x = random.random() * self.level.width
31-
y = self.level.depth + 10
32-
z = random.random() * self.level.height
33-
self.setPos(x, y, z)
34-
35-
def setPos(self, x, y, z):
36-
self.x = x
37-
self.y = y
38-
self.z = z
39-
w = 0.3
40-
h = 0.9
41-
self.bb = AABB(x - w, y - h, z - w, x + w, y + h, z + w)
42-
43-
def turn(self, xo, yo):
44-
orgXRot = self.xRot
45-
orgYRot = self.yRot
46-
self.yRot = self.yRot + xo * 0.15
47-
self.xRot = self.xRot - yo * 0.15
48-
if self.xRot < -90.0:
49-
self.xRot = -90.0
50-
if self.xRot > 90.0:
51-
self.xRot = 90.0
52-
53-
self.xRotO += self.xRot - orgXRot
54-
self.yRotO += self.yRot - orgYRot
11+
super().__init__(level)
12+
self.heightOffset = 1.62
5513

5614
def tick(self):
5715
self.xo = self.x
5816
self.yo = self.y
5917
self.zo = self.z
60-
self.xRotO = self.xRot
61-
self.yRotO = self.yRot
6218
xa = 0.0
6319
ya = 0.0
6420

65-
if self.upPressed:
66-
ya -= 1.0
67-
if self.downPressed:
68-
ya += 1.0
69-
if self.leftPressed:
70-
xa -= 1.0
71-
if self.rightPressed:
72-
xa += 1.0
21+
if self.upPressed: ya -= 1.0
22+
if self.downPressed: ya += 1.0
23+
if self.leftPressed: xa -= 1.0
24+
if self.rightPressed: xa += 1.0
7325
if self.spacePressed:
7426
if self.onGround:
7527
self.yd = 0.12
@@ -85,51 +37,3 @@ def tick(self):
8537
if self.onGround:
8638
self.xd *= 0.8
8739
self.zd *= 0.8
88-
89-
def move(self, xa, ya, za):
90-
xaOrg = xa
91-
yaOrg = ya
92-
zaOrg = za
93-
94-
aABBs = self.level.getCubes(self.bb.expand(xa, ya, za))
95-
for aABB in aABBs:
96-
ya = aABB.clipYCollide(self.bb, ya)
97-
98-
self.bb.move(0.0, ya, 0.0)
99-
100-
for aABB in aABBs:
101-
xa = aABB.clipXCollide(self.bb, xa)
102-
103-
self.bb.move(xa, 0.0, 0.0)
104-
105-
for aABB in aABBs:
106-
za = aABB.clipZCollide(self.bb, za)
107-
108-
self.bb.move(0.0, 0.0, za)
109-
110-
self.onGround = yaOrg != ya and yaOrg < 0.0
111-
112-
if xaOrg != xa:
113-
self.xd = 0.0
114-
if yaOrg != ya:
115-
self.yd = 0.0
116-
if zaOrg != za:
117-
self.zd = 0.0
118-
self.x = (self.bb.x0 + self.bb.x1) / 2.0
119-
self.y = self.bb.y0 + 1.62
120-
self.z = (self.bb.z0 + self.bb.z1) / 2.0
121-
122-
def moveRelative(self, xa, za, speed):
123-
dist = xa * xa + za * za
124-
if dist < 0.01:
125-
return
126-
127-
dist = speed / math.sqrt(dist)
128-
xa *= dist
129-
za *= dist
130-
131-
sin = math.sin(self.yRot * math.pi / 180.0)
132-
cos = math.cos(self.yRot * math.pi / 180.0)
133-
134-
self.xd += xa * cos - za * sin
135-
self.zd += za * cos + xa * sin

mc/net/minecraft/Textures.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ def loadTexture(cls, resourceName, mode):
1111
if resourceName in cls.idMap:
1212
return cls.idMap[resourceName]
1313

14-
ib = BufferUtils.createUintBuffer(1).clear()
15-
14+
ib = BufferUtils.createUintBuffer(1)
15+
ib.clear()
1616
gl.glGenTextures(1, ib)
1717
id_ = ib.get(0)
18+
cls.idMap[resourceName] = id_
19+
print(resourceName + ' -> ' + str(id_))
1820

19-
cls.bind(id_)
21+
gl.glBindTexture(gl.GL_TEXTURE_2D, id_)
2022

2123
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, mode)
2224
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, mode)
@@ -31,9 +33,3 @@ def loadTexture(cls, resourceName, mode):
3133
gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, w, h, 0, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, pixels)
3234

3335
return id_
34-
35-
@classmethod
36-
def bind(cls, id_):
37-
if id_ != cls.lastId:
38-
gl.glBindTexture(gl.GL_TEXTURE_2D, id_)
39-
cls.lastId = id_

0 commit comments

Comments
 (0)