Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Fix concurrent modification in inter-chunk block connections
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Oct 11, 2020
1 parent c34eba0 commit e4a4f01
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void onNeighborChunkLoaded(Direction side) {
while (itr.hasNext()) {
short packed = itr.nextShort();
pos.set(chunk.getPos().getStartX() + unpackLocalX(packed), unpackLocalY(packed), chunk.getPos().getStartZ() + unpackLocalZ(packed));
updateBlock(pos, worldView.getBlockState(pos).getBlock(), false);
connector.fix(worldView, pos, worldView.getBlockState(pos).getBlock());
}
blocksNeedingUpdate.remove(dir);
}
Expand All @@ -100,7 +100,7 @@ public void onNeighborChunkLoaded(Direction side) {
}

public void onBlockChange(BlockPos pos, Block newBlock, boolean updateNeighbors) {
if (updateBlock(pos, newBlock, true) || updateNeighbors) {
if (updateBlock(pos, newBlock) || updateNeighbors) {
for (Direction dir : Direction.values()) {
BlockPos offsetPos = new BlockPos(
chunk.getPos().getStartX() + (pos.getX() & 15) + dir.getOffsetX(),
Expand All @@ -115,15 +115,11 @@ public void onBlockChange(BlockPos pos, Block newBlock, boolean updateNeighbors)
}
}

public boolean updateBlock(BlockPos pos, Block newBlock, boolean checkForUpdateRemoval) {
public boolean updateBlock(BlockPos pos, Block newBlock) {
if (pos.getY() < 0 || pos.getY() > 255) {
return false;
}

if (!checkForUpdateRemoval && !connector.shouldProcess(newBlock)) {
return false;
}

EightWayDirection dir = directionForPos(pos);
if (dir == null) {
return connector.fix(worldView, pos, newBlock);
Expand Down

0 comments on commit e4a4f01

Please sign in to comment.