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
Browse files Browse the repository at this point in the history
  • Loading branch information
Tri0de committed Jan 4, 2021
1 parent d292a15 commit 287a41e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/main/java/org/valkyrienskies/mixin/world/MixinClientWorld.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.valkyrienskies.mixin.world;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
Expand Down Expand Up @@ -94,17 +95,32 @@ private void preGetCombinedLight(BlockPos pos, int lightValue,
final int minY = (int) Math.floor(posInLocal.y());
final int minZ = (int) Math.floor(posInLocal.z());

int shipSkyLight = 0;

for (int x = minX; x <= minX + 1; x++) {
for (int y = minY; y <= minY + 1; y++) {
for (int z = minZ; z <= minZ + 1; z++) {
mutableBlockPos.setPos(x, y, z);

final IBlockState blockState = world.getBlockState(mutableBlockPos);

// Ignore the light of full blocks
if (blockState.isFullBlock()) {
continue;
}

final int localBlockLight = world.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, mutableBlockPos);
final int localSkyLight = world.getLightFromNeighborsFor(EnumSkyBlock.SKY, mutableBlockPos);

j = Math.max(j, localBlockLight);
shipSkyLight = Math.max(shipSkyLight, localSkyLight);
}
}
}

if (i > shipSkyLight) {
i = shipSkyLight;
}
}

if (j < lightValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.valkyrienskies.mod.common.config.VSConfig;
Expand Down Expand Up @@ -64,7 +65,13 @@ private void loadAndUnloadShips() {
continue;
}
ShipData shipData = toLoadOptional.get();

PhysicsObject physicsObject = new PhysicsObject(world, shipData);

for (final Chunk chunk : physicsObject.getClaimedChunkCache()) {
chunk.loaded = true;
}

loadedShips.put(toLoadID, physicsObject);
if (VSConfig.showAnnoyingDebugOutput) {
System.out.println("Successfully loaded " + shipData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ private void spawnNewShips() {
}
}

for (final Chunk chunk : copiedChunksMap.values()) {
chunk.generateSkylightMap();
}

// Then delete the copied blocks from the old chunks
blocksIterator = detector.foundSet.iterator();
while (blocksIterator.hasNext()) {
Expand Down Expand Up @@ -322,12 +326,10 @@ private void spawnNewShips() {

private void injectChunkIntoWorldServer(@Nonnull Chunk chunk, int x, int z) {
ChunkProviderServer provider = world.getChunkProvider();
chunk.dirty = true;
chunk.setTerrainPopulated(true);
chunk.setLightPopulated(true);
chunk.onLoad();

provider.loadedChunks.put(ChunkPos.asLong(x, z), chunk);
chunk.onLoad();
chunk.checkLight();
chunk.markDirty();
}

private void loadAndUnloadShips() {
Expand Down

0 comments on commit 287a41e

Please sign in to comment.