66 lines
2.8 KiB
Java
66 lines
2.8 KiB
Java
package carpet.mixins;
|
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
|
|
import carpet.fakes.ChunkLightProviderInterface;
|
|
import carpet.fakes.LightStorageInterface;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.ChunkSectionPos;
|
|
import net.minecraft.util.math.Direction;
|
|
import net.minecraft.world.LightType;
|
|
import net.minecraft.world.chunk.ChunkNibbleArray;
|
|
import net.minecraft.world.chunk.ChunkProvider;
|
|
import net.minecraft.world.chunk.light.BlockLightStorage;
|
|
import net.minecraft.world.chunk.light.BlockLightStorage.Data;
|
|
import net.minecraft.world.chunk.light.ChunkLightProvider;
|
|
import net.minecraft.world.chunk.light.LightStorage;
|
|
|
|
@Mixin(BlockLightStorage.class)
|
|
public abstract class BlockLightStorage_scarpetChunkCreationMixin extends LightStorage<Data> implements LightStorageInterface
|
|
{
|
|
private BlockLightStorage_scarpetChunkCreationMixin(final LightType lightType, final ChunkProvider chunkProvider, final Data lightData)
|
|
{
|
|
super(lightType, chunkProvider, lightData);
|
|
}
|
|
|
|
@Override
|
|
public void processRelight(final ChunkLightProvider<?, ?> lightProvider, final long cPos)
|
|
{
|
|
final LevelPropagatorInterface levelPropagator = (LevelPropagatorInterface) lightProvider;
|
|
|
|
for (int y = -1; y < 17; ++y)
|
|
{
|
|
final long sectionPos = ChunkSectionPos.asLong(ChunkSectionPos.unpackX(cPos), y, ChunkSectionPos.unpackZ(cPos));
|
|
final long pos = BlockPos.asLong(ChunkSectionPos.getBlockCoord(ChunkSectionPos.unpackX(sectionPos)), ChunkSectionPos.getBlockCoord(y), ChunkSectionPos.getBlockCoord(ChunkSectionPos.unpackZ(sectionPos)));
|
|
|
|
if (!this.hasSection(sectionPos))
|
|
continue;
|
|
|
|
for (final Direction dir : Direction.Type.HORIZONTAL)
|
|
{
|
|
final ChunkNibbleArray neighborLightArray = this.getLightSection(ChunkSectionPos.offset(sectionPos, dir));
|
|
|
|
if (neighborLightArray == null)
|
|
continue;
|
|
|
|
final int ox = 15 * Math.max(dir.getOffsetX(), 0);
|
|
final int oz = 15 * Math.max(dir.getOffsetZ(), 0);
|
|
|
|
final int dx = Math.abs(dir.getOffsetZ());
|
|
final int dz = Math.abs(dir.getOffsetX());
|
|
|
|
for (int t = 0; t < 16; ++t)
|
|
for (int dy = 0; dy < 16; ++dy)
|
|
{
|
|
final long dst = BlockPos.add(pos, ox + t * dx, dy, oz + t * dz);
|
|
final long src = BlockPos.offset(dst, dir);
|
|
|
|
final int srcLevel = ((ChunkLightProviderInterface) lightProvider).callGetCurrentLevelFromSection(neighborLightArray, src);
|
|
|
|
levelPropagator.invokeUpdateLevel(src, dst, levelPropagator.callGetPropagatedLevel(src, dst, srcLevel), true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|