MinicraftPlus / minicraft-plus-revived

Minicraft+, an extension of Notch's original minicraft project, with tons more features.
GNU General Public License v3.0
466 stars 93 forks source link

Fix wrong enemy level in mob generation #596

Closed BenCheung0422 closed 8 months ago

BenCheung0422 commented 8 months ago

As spotted out by @Litorom, there is an exception regarding the enemy level.


Unhandled error: General Application Crash
java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4
    at minicraft.entity.mob.EnemyMob.render(EnemyMob.java:106)
    at minicraft.level.Level.sortAndRender(Level.java:536)
    at minicraft.level.Level.renderSprites(Level.java:499)
    at minicraft.core.Renderer.renderLevel(Renderer.java:209)
    at minicraft.core.Renderer.render(Renderer.java:119)
    at minicraft.core.Initializer.run(Initializer.java:100)
    at minicraft.core.Game.main(Game.java:116)
```occurred in the dungeon level.

This is related to the wrong code getting the level. In the current code, the depth number is mapped to level index ranged from 0 to the number of levels-1, but the enemy level only supports range from 0 to 4. Originally, -1 should be mapped to 1 and etc. Now, it is fixed so that depths with 1 and 0 mapped to 0 and -n mapped to n, where n ∈ {1,2,3,4}.