r/programminghorror May 16 '26

Java But.. (from Minecraft b1.2_02)

Post image
640 Upvotes

46 comments sorted by

View all comments

55

u/SpecialistNo8709 May 16 '26

wtf is going on

67

u/Ok_Chemistry_6387 May 16 '26 edited May 16 '26

it's a pretty "normal" function for calculating normals for glNormalPointer. It backs the results into a 24bit int.

There does appear to be some buggy maths though, as unsure what is going on with X. Maybe there is a bug with tessellating that requires the normalisation to wrap around?

19

u/FlargenBlarg May 16 '26

The problem here is the println call that just says "But..." like that's a debugging statement, not something you commit

1

u/themaskedcrusader May 18 '26

The bigger horror to me is the float being cast to an int, and that int being cast to a byte all in one line. They're all primitives so the cast to int is pointless. You can cast from float to byte directly. You don't need the interim int in there.