Why Minecraft is so badly written!
Mads 07 Jan 2013
This is just some code snippets:
Why add a bottleneck for no reason?
public void onUpdate() { this.onEntityUpdate(); }
Why so many bad and random method names??
public int getBlockTextureFromSideAndMetadata(int par1, int par2)
Noo! What is he doing?
public static final Block[] blocksList = new Block[4096];
WHAT THE FLYING FUCK???
/** How much light is subtracted for going through this block */ public static final int[] lightOpacity = new int[4096]; /** Array of booleans that tells if a block can grass */ public static final boolean[] canBlockGrass = new boolean[4096]; /** Amount of light emitted */ public static final int[] lightValue = new int[4096]; public static final boolean[] requiresSelfNotify = new boolean[4096];
And that is only a LITTLE bit of his coding failures...
billysback 07 Jan 2013
billysback 07 Jan 2013
the bottleneck may be so that other classes are able to override/extend upon this method.
also it is considered good practice to hide variables in java, instead using get/set methods in order to get access to these variables, this method (although seemingly pointless at first) may be used to (as I said) more easily modify in order to do things "onUpdate" whilst still keeping onEntityUpdate() the same
onEntityUpdate is also most likely inherited which, once again, helps suggests that this method was created to be overridden.
also what is wrong with "blocksList" and "lightOpacity"
the arrays each tell the game a different thing, instead of keeping everything stored in "Block", presumable so that light updates etc. can be applied more easily, the arrays are being defined per-chunk for every block in each chunk.
Orwell 07 Jan 2013
mad, on 07 January 2013 - 07:51 AM, said:
public void onUpdate() { this.onEntityUpdate(); }
mad, on 07 January 2013 - 07:51 AM, said:
public int getBlockTextureFromSideAndMetadata(int par1, int par2)
mad, on 07 January 2013 - 07:51 AM, said:
public static final Block[] blocksList = new Block[4096];
mad, on 07 January 2013 - 07:51 AM, said:
/** How much light is subtracted for going through this block */ public static final int[] lightOpacity = new int[4096]; /** Array of booleans that tells if a block can grass */ public static final boolean[] canBlockGrass = new boolean[4096]; /** Amount of light emitted */ public static final int[] lightValue = new int[4096]; public static final boolean[] requiresSelfNotify = new boolean[4096];
It's not like I don't agree with the fact that Minecraft isn't efficient. You're just picking the totally wrong examples. These all have minor to none effect at runtime.
Cloudy 07 Jan 2013
Orwell 07 Jan 2013
Cloudy 07 Jan 2013
RunasSudo-AWOLindefinitely 08 Jan 2013
Cloudy 09 Jan 2013
mad, on 07 January 2013 - 07:51 AM, said:
This is just some code snippets:
Why add a bottleneck for no reason?
public void onUpdate() { this.onEntityUpdate(); }
I too, can't see a reason for this - however just because you can't see one, doesn't mean there is none. Could be a throwback from old code, for example.
mad, on 07 January 2013 - 07:51 AM, said:
public int getBlockTextureFromSideAndMetadata(int par1, int par2)
mad, on 07 January 2013 - 07:51 AM, said:
public static final Block[] blocksList = new Block[4096];
He's declaring an array to hold all the blocks in the game. Why is that a bad thing? Sure, there's other methods of holding items - but sometimes you don't need anything more complex than an array. And by "he" I assume you mean Mojang - Notch hasn't been a coder on Minecraft for a long time.
mad, on 07 January 2013 - 07:51 AM, said:
/** How much light is subtracted for going through this block */ public static final int[] lightOpacity = new int[4096]; /** Array of booleans that tells if a block can grass */ public static final boolean[] canBlockGrass = new boolean[4096]; /** Amount of light emitted */ public static final int[] lightValue = new int[4096]; public static final boolean[] requiresSelfNotify = new boolean[4096];
Again, I don't see the problem there. Care to show why you think it is a bad thing?
billysback, on 07 January 2013 - 10:44 AM, said:
his organization is appalling (no packets)
You do realise the obfuscation strips out packages (which I assume is what you meant) right?
billysback, on 07 January 2013 - 10:44 AM, said:
I'm not sure what you mean by this?
billysback, on 07 January 2013 - 10:44 AM, said:
True - but great steps have now been made to make it truly a multiplayer game - even singleplayer is multiplayer!
billysback 09 Jan 2013
Cloudy, on 09 January 2013 - 05:59 AM, said:
oh well, I do now.
Cloudy, on 09 January 2013 - 05:59 AM, said:
Mads 09 Jan 2013
Cloudy, on 09 January 2013 - 05:59 AM, said:
mad, on 07 January 2013 - 07:51 AM, said:
public static final Block[] blocksList = new Block[4096];
He's declaring an array to hold all the blocks in the game. Why is that a bad thing? Sure, there's other methods of holding items - but sometimes you don't need anything more complex than an array. And by "he" I assume you mean Mojang - Notch hasn't been a coder on Minecraft for a long time.
mad, on 07 January 2013 - 07:51 AM, said:
/** How much light is subtracted for going through this block */ public static final int[] lightOpacity = new int[4096]; /** Array of booleans that tells if a block can grass */ public static final boolean[] canBlockGrass = new boolean[4096]; /** Amount of light emitted */ public static final int[] lightValue = new int[4096]; public static final boolean[] requiresSelfNotify = new boolean[4096];
Again, I don't see the problem there. Care to show why you think it is a bad thing?
Block[4096];
There it is: "4096". Why allocate so much memory, if there are 300 blocks in the game, or something like that?
And he is also declaring arrays for single objects, like
int lightValue = new int[4096];
theoriginalbit 09 Jan 2013
mad, on 09 January 2013 - 07:12 AM, said:
And he is also declaring arrays for single objects, like
int lightValue = new int[4096];
the light values are STATIC meaning its not a single object. its the class. that array is for the class not the object.
Orwell 09 Jan 2013
billysback, on 09 January 2013 - 06:42 AM, said:
Cloudy, on 09 January 2013 - 05:59 AM, said:
mad, on 09 January 2013 - 07:12 AM, said:
There it is: "4096". Why allocate so much memory, if there are 300 blocks in the game, or something like that?
And he is also declaring arrays for single objects, like
int lightValue = new int[4096];
billysback 09 Jan 2013
Orwell, on 09 January 2013 - 07:44 AM, said:
billysback, on 09 January 2013 - 06:42 AM, said:
Cloudy, on 09 January 2013 - 05:59 AM, said:
either way, surly deciding what you want to do with each block then looping to generate these decisions is more efficient?
Orwell 09 Jan 2013
billysback, on 09 January 2013 - 07:50 AM, said:
Orwell, on 09 January 2013 - 07:44 AM, said:
either way, surly deciding what you want to do with each block then looping to generate these decisions is more efficient?
I'll try to explain it as simple as possible. In order to do calculations on data, a processor needs to load the data from RAM into its registers first. But loading data from RAM is very slow compared to the processor. In order to avoid this, there's a cache in between the CPU and the RAM. This cache is much smaller, much more expensive and has a faster connection to the CPU which it doesn't need to share with other IO devices. So the cache is much more faster than RAM. When the CPU needs data at a certain address, it will ask the cache. If the cache doesn't has this data, this is called a cache miss, it will load it from RAM into the cache, this takes longer. Data that's used more often will stay in the cache for a longer period. Now, locality of reference means that some data will be accessed more often than others; for example in a loop. Local variables in a small loop block will be accessed a lot more frequently than others, thus it will stay in the cache for most of the time. That way, these regions in memory will be accessed a lot faster than other data.
By having complex loops, you'd push the data out of the cache all the time because you need new data for other calculations in the same loop. So you'd get a lot of cache misses and accessing data would be slower. Having small solid loops will keep most of the needed data in the cache and speed up calculations significantly.
Dlcruz129 09 Jan 2013
RunasSudo-AWOLindefinitely 09 Jan 2013
If you go line-by-line, you have to remember the entire line every time. If you go word-by-word, you only have to remember the current word you're doing.
Same with world generation in Minecraft.
Less to remember = faster = better
(Well, it doesn't work quite like that, but it makes sense, so...)