radian-software / TerrariaClone

🔥 An incomprehensible hellscape of spaghetti code.
MIT License
1.8k stars 134 forks source link

I get an array error after one click #20

Open Jark5455 opened 6 years ago

Jark5455 commented 6 years ago

console output after one click in game

Exception in thread java.lang.ArrayIndexOutOfBoundsException: 1203 at TerrariaClone.updateApp(TerrariaClone.java:3283) at TerrariaClone$1$1.actionPerformed(TerrariaClone.java:2119) at javax.swing.Timer.fireActionPerformed(Timer.java:313) at javax.swing.Timer$DoPostEvent.run(Timer.java:245) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

raxod502 commented 6 years ago

It's not a bug, it's a feature; please refer to the README:

Unfortunately, it's only working in the academic sense, since it's so slow that you only get about 0.03 FPS and it crashes when you click the mouse button. But, somewhere in there is a working game. You know, sort of.

voidnull000 commented 6 years ago

I don't think there is a working game in this anywhere, so we must destroy it.

Jark5455 commented 6 years ago

With a little bit of work and debugging, I found the error. On TerrariaCClone line 3929 if (blocks[layer][uy][ux] != 0 && Arrays.asList(BLOCKTOOLS.get(blocks[layer][uy][ux])).contains(inventory.tool())) {

The issue is that on the array the array limit for "uy" is 192 yet you are asking for a number off the array,1202, could you have made a mistake and meant to type 120

Jark5455 commented 6 years ago

fixed, replace 3690-3691 with this if ((layer < blocks.length && uy < blocks[layer].length && ux < blocks[layer][uy].length) && blocks[layer][uy][ux] >= 8 && blocks[layer][uy][ux] <= 14 || blocks[layer][uy][ux] == 17 || blocks[layer][uy][ux] == 23 || blocks[layer][uy][ux] >= 80 && blocks[layer][uy][ux] <= 82) { this breaks the physics of the game but you can atleast right click to be able to use your tools, replace 3363 with this if ((layer < blocks.length && uy < blocks[layer].length && ux < blocks[layer][uy].length) && but you cannot break blocks I still have not found out why the character cannot move