mirror of
https://github.com/Minestom/Minestom.git
synced 2024-06-26 06:24:54 +02:00
Fixed chunk
This commit is contained in:
parent
d1967186e5
commit
2afb170ff0
|
@ -16,8 +16,6 @@ public class Entity {
|
||||||
private boolean isActive; // False if entity has only been instanced without being added somewhere
|
private boolean isActive; // False if entity has only been instanced without being added somewhere
|
||||||
private boolean shouldRemove;
|
private boolean shouldRemove;
|
||||||
|
|
||||||
private Object monitor = new Object();
|
|
||||||
|
|
||||||
public Entity() {
|
public Entity() {
|
||||||
this.id = generateId();
|
this.id = generateId();
|
||||||
this.uuid = UUID.randomUUID();
|
this.uuid = UUID.randomUUID();
|
||||||
|
@ -68,7 +66,7 @@ public class Entity {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
Chunk lastChunk = instance.getChunkAt(lastX, lastZ);
|
Chunk lastChunk = instance.getChunkAt(lastX, lastZ);
|
||||||
Chunk newChunk = instance.getChunkAt(x, z);
|
Chunk newChunk = instance.getChunkAt(x, z);
|
||||||
if (newChunk != null && lastChunk != newChunk) {
|
if (lastChunk != null && newChunk != null && lastChunk != newChunk) {
|
||||||
synchronized (lastChunk) {
|
synchronized (lastChunk) {
|
||||||
synchronized (newChunk) {
|
synchronized (newChunk) {
|
||||||
lastChunk.removeEntity(this);
|
lastChunk.removeEntity(this);
|
||||||
|
|
|
@ -17,6 +17,8 @@ public class EntityManager {
|
||||||
public void update() {
|
public void update() {
|
||||||
|
|
||||||
for (Instance instance : instanceManager.getInstances()) {
|
for (Instance instance : instanceManager.getInstances()) {
|
||||||
|
|
||||||
|
synchronized (instance) {
|
||||||
// Creatures
|
// Creatures
|
||||||
for (EntityCreature creature : instance.getCreatures()) {
|
for (EntityCreature creature : instance.getCreatures()) {
|
||||||
creaturesPool.submit(() -> {
|
creaturesPool.submit(() -> {
|
||||||
|
@ -42,4 +44,6 @@ public class EntityManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,11 @@ public class Instance {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO BlockBatch with pool
|
// TODO BlockBatch with pool
|
||||||
public void setBlock(int x, int y, int z, Block block) {
|
public synchronized void setBlock(int x, int y, int z, Block block) {
|
||||||
Chunk chunk = getChunkAt(x, z);
|
int chunkX = Math.floorDiv(x, 16);
|
||||||
|
int chunkZ = Math.floorDiv(z, 16);
|
||||||
|
Chunk chunk = getChunk(chunkX, chunkZ);
|
||||||
if (chunk == null) {
|
if (chunk == null) {
|
||||||
int chunkX = x / 16;
|
|
||||||
int chunkZ = z / 16;
|
|
||||||
chunk = new Chunk(Biome.VOID, chunkX, chunkZ);
|
chunk = new Chunk(Biome.VOID, chunkX, chunkZ);
|
||||||
this.chunksSet.add(chunk);
|
this.chunksSet.add(chunk);
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,8 @@ public class Instance {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chunk getChunkAt(double x, double z) {
|
public Chunk getChunkAt(double x, double z) {
|
||||||
int chunkX = (int) (x / 16);
|
int chunkX = Math.floorDiv((int) x, 16);
|
||||||
int chunkZ = (int) (z / 16);
|
int chunkZ = Math.floorDiv((int) z, 16);
|
||||||
return getChunk(chunkX, chunkZ);
|
return getChunk(chunkX, chunkZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,10 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
||||||
static {
|
static {
|
||||||
instance = Main.getInstanceManager().createInstance();
|
instance = Main.getInstanceManager().createInstance();
|
||||||
for (int x = -64; x < 64; x++)
|
for (int x = -64; x < 64; x++)
|
||||||
for (int z = -64; z < 64; z++)
|
for (int z = -64; z < 64; z++) {
|
||||||
instance.setBlock(x, 4, z, new Block(1));
|
instance.setBlock(x, 4, z, new Block(1));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(PlayerConnection connection, ConnectionManager connectionManager) {
|
public void process(PlayerConnection connection, ConnectionManager connectionManager) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user