From 0b25dacc2f7b1ff788e5a1e142ec708d8dbcdeda Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Sat, 23 Mar 2019 17:02:47 +0100 Subject: [PATCH] Prevent the game from lagging if the player decides to walk 600 blocks --- cubyz-common/src/io/cubyz/world/LocalWorld.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cubyz-common/src/io/cubyz/world/LocalWorld.java b/cubyz-common/src/io/cubyz/world/LocalWorld.java index 3230036c..b684189c 100644 --- a/cubyz-common/src/io/cubyz/world/LocalWorld.java +++ b/cubyz-common/src/io/cubyz/world/LocalWorld.java @@ -21,6 +21,7 @@ public class LocalWorld extends World { private String name; private ArrayList chunks; + private int lastChunk = -1; private ArrayList entities = new ArrayList<>(); //private List spatials = new ArrayList<>(); @@ -181,8 +182,12 @@ public class LocalWorld extends World { @Override public Chunk getChunk(int x, int z) { + if(lastChunk >= 0 && chunks.get(lastChunk).getX() == x && chunks.get(lastChunk).getZ() == z) { + return chunks.get(lastChunk); + } for (int i = 0; i < chunks.size(); i++) { if (chunks.get(i).getX() == x && chunks.get(i).getZ() == z) { + lastChunk = i; return chunks.get(i); } } @@ -190,6 +195,7 @@ public class LocalWorld extends World { Chunk c = new Chunk(x, z, this); // not generated chunks.add(c); + lastChunk = chunks.size()-1; return c; }