Skip to content

Commit

Permalink
Implements blocks with crossed sides (eg. flowers, potatoes…).
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Apr 13, 2013
1 parent be6621c commit ad69c1a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
37 changes: 27 additions & 10 deletions blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def drop_id(self, value):
top_texture = ()
bottom_texture = ()
side_texture = ()
crossed_sides = False
group = None # The texture (group) the block renders from
texture_name = None # A list of block faces, named what Mojang names their blocks/"file".png

Expand Down Expand Up @@ -194,8 +195,11 @@ def __str__(self):
return self.name

def get_texture_data(self):
return list(self.top_texture + self.bottom_texture
+ self.side_texture * 4)
textures = self.top_texture + self.bottom_texture \
+ self.side_texture * 2
if not self.crossed_sides:
textures += (self.side_texture * 2)
return list(textures)

def get_vertices(self, x, y, z):
w = self.width / 2.0
Expand All @@ -208,15 +212,25 @@ def get_vertices(self, x, y, z):
zp = z + w
ret = []
if len(self.top_texture) > 0 or len(self.side_texture) == 0:
ret.extend([xm,yp,zm, xm,yp,zp, xp,yp,zp, xp,yp,zm]) # top
ret.extend([
xm, yp, zm, xm, yp, zp, xp, yp, zp, xp, yp, zm # top
])
if len(self.bottom_texture) > 0 or len(self.side_texture) == 0:
ret.extend([xm,ym,zm, xp,ym,zm, xp,ym,zp, xm,ym,zp]) # bottom
ret.extend([
xm,ym,zm, xm,ym,zp, xm,yp,zp, xm,yp,zm, # left
xp,ym,zp, xp,ym,zm, xp,yp,zm, xp,yp,zp, # right
xm,ym,zp, xp,ym,zp, xp,yp,zp, xm,yp,zp, # front
xp,ym,zm, xm,ym,zm, xm,yp,zm, xp,yp,zm, # back
])
ret.extend([
xm, ym, zm, xp, ym, zm, xp, ym, zp, xm, ym, zp # bottom
])
if self.crossed_sides:
ret.extend([
xm, ym, zm, xp, ym, zp, xp, yp, zp, xm, yp, zm,
xm, ym, zp, xp, ym, zm, xp, yp, zm, xm, yp, zp,
])
else:
ret.extend([
xm, ym, zm, xm, ym, zp, xm, yp, zp, xm, yp, zm, # left
xp, ym, zp, xp, ym, zm, xp, yp, zm, xp, yp, zp, # right
xm, ym, zp, xp, ym, zp, xp, yp, zp, xm, yp, zp, # front
xp, ym, zm, xm, ym, zm, xm, yp, zm, xp, yp, zm, # back
])
return ret

def play_break_sound(self, player=None, position=None):
Expand Down Expand Up @@ -748,6 +762,7 @@ class YFlowersBlock(Block):
top_texture = 6, 6
bottom_texture = -1, -1
side_texture = 6, 5
crossed_sides = True
hardness = 0.0
transparent = True
width = 0.5
Expand Down Expand Up @@ -1097,6 +1112,7 @@ class PotatoBlock(Block):
top_texture = -1, -1
bottom_texture = -1, -1
side_texture = 10, 3
crossed_sides = True
hardness = 0.0
transparent = True
id = 142
Expand All @@ -1109,6 +1125,7 @@ class CarrotBlock(Block):
top_texture = -1, -1
bottom_texture = -1, -1
side_texture = 10, 2
crossed_sides = True
hardness = 0.0
transparent = True
id = 141
Expand Down
4 changes: 1 addition & 3 deletions controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def setup(self):
glEnable(GL_LIGHT0)
glEnable(GL_LIGHT1)
glEnable(GL_LIGHT2)
glEnable(GL_CULL_FACE)
glEnable(GL_ALPHA_TEST)
glAlphaFunc(GL_GREATER, 0.1)
glEnable(GL_BLEND)
glEnable(GL_LINE_SMOOTH)

Expand Down Expand Up @@ -401,9 +401,7 @@ def on_draw(self):
self.set_3d()
glColor3d(1, 1, 1)
self.model.batch.draw()
glDisable(GL_CULL_FACE)
self.model.transparency_batch.draw()
glEnable(GL_CULL_FACE)
self.crack_batch.draw()
self.draw_focused_block()
self.set_2d()
Expand Down

7 comments on commit ad69c1a

@boskee
Copy link
Owner

@boskee boskee commented on ad69c1a Apr 13, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omg, I think I love you ;-)

@BertrandBordage
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehehe! Now, we need to be able to walk on potatoes! Mashed potatoes powaaaaa!

@ronmurphy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow :)

@boskee
Copy link
Owner

@boskee boskee commented on ad69c1a Apr 13, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just getting on the tube home to check your work. Vodka can wait.

@tfaris
Copy link
Collaborator

@tfaris tfaris commented on ad69c1a Apr 13, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh! It works great

@BertrandBordage
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oO
I know you're both from London and Poland, but…

@ronmurphy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind. bad code day, some one else can try to add tall grass that drops random seeds. code just now working for me today.

Please sign in to comment.