Change rounding method of Instance#getChunkAt to fix negative chunk off-by-one

This commit is contained in:
Matt Worzala 2020-12-28 13:28:10 -05:00
parent ca3667732f
commit c89ffbfc44
No known key found for this signature in database
GPG Key ID: 046D16088BA8F7DD

View File

@ -42,6 +42,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Consumer; import java.util.function.Consumer;
/** /**
@ -752,8 +753,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
*/ */
@Nullable @Nullable
public Chunk getChunkAt(float x, float z) { public Chunk getChunkAt(float x, float z) {
final int chunkX = ChunkUtils.getChunkCoordinate((int) x); final int chunkX = ChunkUtils.getChunkCoordinate((int) Math.floor(x));
final int chunkZ = ChunkUtils.getChunkCoordinate((int) z); final int chunkZ = ChunkUtils.getChunkCoordinate((int) Math.floor(z));
return getChunk(chunkX, chunkZ); return getChunk(chunkX, chunkZ);
} }
@ -930,7 +931,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
Set<Entity> entities = getEntitiesInChunk(chunkIndex); Set<Entity> entities = getEntitiesInChunk(chunkIndex);
entities.add(entity); entities.add(entity);
this.entities.add(entity); boolean added = this.entities.add(entity);
System.out.println(added + " " + chunk.toString());
if (entity instanceof Player) { if (entity instanceof Player) {
this.players.add((Player) entity); this.players.add((Player) entity);
} else if (entity instanceof EntityCreature) { } else if (entity instanceof EntityCreature) {