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

Commit

Permalink
Fixed ship lighting when disassembled to world
Browse files Browse the repository at this point in the history
  • Loading branch information
Tri0de committed Jan 4, 2021
1 parent 287a41e commit 22e5d1e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.valkyrienskies.mod.common.physics.PhysicsCalculations;
import org.valkyrienskies.mod.common.ships.ShipData;
import org.valkyrienskies.mod.common.ships.block_relocation.MoveBlocks;
import org.valkyrienskies.mod.common.ships.block_relocation.SpatialDetector;
import org.valkyrienskies.mod.common.ships.chunk_claims.ClaimedChunkCacheController;
import org.valkyrienskies.mod.common.ships.chunk_claims.SurroundingChunkCacheController;
import org.valkyrienskies.mod.common.ships.interpolation.ITransformInterpolator;
Expand All @@ -37,10 +38,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
Expand Down Expand Up @@ -267,6 +265,25 @@ void destroyShip() {
oldPos.getY() - centerDifference.getY(), oldPos.getZ() - centerDifference.getZ());
MoveBlocks.copyBlockToPos(getWorld(), oldPos, newPos, null);
}

// Then relight the chunks we just copied the blocks to
{
Set<Long> chunksRelit = new HashSet<>();
for (BlockPos changedPos : this.getBlockPositions()) {
int changedChunkX = (changedPos.getX() - centerDifference.getX()) >> 4;
int changedChunkZ = (changedPos.getZ() - centerDifference.getZ()) >> 4;
long changedChunkPos = ChunkPos.asLong(changedChunkX, changedChunkZ);

if (chunksRelit.contains(changedChunkPos)) {
continue;
}
final Chunk chunk = world.getChunk(changedChunkX, changedChunkZ);
chunk.generateSkylightMap();
chunk.checkLight();
chunk.markDirty();
chunksRelit.add(changedChunkPos);
}
}
}

// Just delete the tile entities in ship to prevent any dupe bugs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,29 @@ private void spawnNewShips() {
chunkToSet.markDirty();
}

// Then relight the original chunks
{
Set<Long> chunksRelit = new HashSet<>();
blocksIterator = detector.foundSet.iterator();
while (blocksIterator.hasNext()) {
int hashedPos = blocksIterator.next();
SpatialDetector.setPosWithRespectTo(hashedPos, detector.firstBlock, srcLocationPos);

int changedChunkX = pasteLocationPos.getX() >> 4;
int changedChunkZ = pasteLocationPos.getZ() >> 4;
long changedChunkPos = ChunkPos.asLong(changedChunkX, changedChunkZ);

if (chunksRelit.contains(changedChunkPos)) {
continue;
}
final Chunk chunk = world.getChunk(changedChunkX, changedChunkZ);
chunk.generateSkylightMap();
chunk.checkLight();
chunk.markDirty();
chunksRelit.add(changedChunkPos);
}
}

// Then inject the ship chunks into the world
toSpawn.getChunkClaim().forEach((x, z) -> {
long chunkLong = ChunkPos.asLong(x, z);
Expand Down

0 comments on commit 22e5d1e

Please sign in to comment.