use of net.minecraft.util.EnumFacing in project SpongeCommon by SpongePowered.
the class MixinChunk_Async_Lighting method checkLightAsync.
/**
* Checks light async.
*
* @param neighbors A thread-safe list of surrounding neighbor chunks
*/
private void checkLightAsync(List<Chunk> neighbors) {
this.isTerrainPopulated = true;
this.isLightPopulated = true;
BlockPos blockpos = new BlockPos(this.x << 4, 0, this.z << 4);
if (this.world.provider.hasSkyLight()) {
label44: for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
if (!this.checkLightAsync(i, j, neighbors)) {
this.isLightPopulated = false;
break label44;
}
}
}
if (this.isLightPopulated) {
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) {
int k = enumfacing.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE ? 16 : 1;
final BlockPos pos = blockpos.offset(enumfacing, k);
final Chunk chunk = this.getLightChunk(pos.getX() >> 4, pos.getZ() >> 4, neighbors);
if (chunk == null) {
continue;
}
chunk.checkLightSide(enumfacing.getOpposite());
}
this.setSkylightUpdated();
}
}
}
use of net.minecraft.util.EnumFacing in project SpongeCommon by SpongePowered.
the class MixinChunk_Async_Lighting method relightBlockAsync.
/**
* Relight's a block async.
*
* @param x The x position
* @param y The y position
* @param z The z position
*/
private void relightBlockAsync(int x, int y, int z) {
int i = this.heightMap[z << 4 | x] & 255;
int j = i;
if (y > i) {
j = y;
}
while (j > 0 && this.getBlockLightOpacity(x, j - 1, z) == 0) {
--j;
}
if (j != i) {
this.markBlocksDirtyVerticalAsync(x + this.x * 16, z + this.z * 16, j, i);
this.heightMap[z << 4 | x] = j;
int k = this.x * 16 + x;
int l = this.z * 16 + z;
if (this.world.provider.hasSkyLight()) {
if (j < i) {
for (int j1 = j; j1 < i; ++j1) {
ExtendedBlockStorage extendedblockstorage2 = this.storageArrays[j1 >> 4];
if (extendedblockstorage2 != Chunk.NULL_BLOCK_STORAGE) {
extendedblockstorage2.setSkyLight(x, j1 & 15, z, 15);
this.world.notifyLightSet(new BlockPos((this.x << 4) + x, j1, (this.z << 4) + z));
}
}
} else {
for (int i1 = i; i1 < j; ++i1) {
ExtendedBlockStorage extendedblockstorage = this.storageArrays[i1 >> 4];
if (extendedblockstorage != Chunk.NULL_BLOCK_STORAGE) {
extendedblockstorage.setSkyLight(x, i1 & 15, z, 0);
this.world.notifyLightSet(new BlockPos((this.x << 4) + x, i1, (this.z << 4) + z));
}
}
}
int k1 = 15;
while (j > 0 && k1 > 0) {
--j;
int i2 = this.getBlockLightOpacity(x, j, z);
if (i2 == 0) {
i2 = 1;
}
k1 -= i2;
if (k1 < 0) {
k1 = 0;
}
ExtendedBlockStorage extendedblockstorage1 = this.storageArrays[j >> 4];
if (extendedblockstorage1 != Chunk.NULL_BLOCK_STORAGE) {
extendedblockstorage1.setSkyLight(x, j & 15, z, k1);
}
}
}
int l1 = this.heightMap[z << 4 | x];
int j2 = i;
int k2 = l1;
if (l1 < i) {
j2 = l1;
k2 = i;
}
if (l1 < this.heightMapMinimum) {
this.heightMapMinimum = l1;
}
if (this.world.provider.hasSkyLight()) {
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) {
this.updateSkylightNeighborHeight(k + enumfacing.getFrontOffsetX(), l + enumfacing.getFrontOffsetZ(), j2, k2);
}
this.updateSkylightNeighborHeight(k, l, j2, k2);
}
this.dirty = true;
}
}
use of net.minecraft.util.EnumFacing in project SpongeCommon by SpongePowered.
the class MixinWorldServer_Async_Lighting method checkLightAsync.
@Override
public boolean checkLightAsync(EnumSkyBlock lightType, BlockPos pos, net.minecraft.world.chunk.Chunk currentChunk, List<Chunk> neighbors) {
// Sponge - This check is not needed as neighbors are checked in updateLightAsync
if (false && !this.isAreaLoaded(pos, 17, false)) {
return false;
} else {
final IMixinChunk spongeChunk = (IMixinChunk) currentChunk;
int i = 0;
int j = 0;
// this.theProfiler.startSection("getBrightness"); // Sponge - don't use profiler off of main thread
// Sponge - use thread safe method
int k = this.getLightForAsync(lightType, pos, currentChunk, neighbors);
// Sponge - use thread safe method
int l = this.getRawBlockLightAsync(lightType, pos, currentChunk, neighbors);
int i1 = pos.getX();
int j1 = pos.getY();
int k1 = pos.getZ();
if (l > k) {
this.lightUpdateBlockList[j++] = 133152;
} else if (l < k) {
this.lightUpdateBlockList[j++] = 133152 | k << 18;
while (i < j) {
int l1 = this.lightUpdateBlockList[i++];
int i2 = (l1 & 63) - 32 + i1;
int j2 = (l1 >> 6 & 63) - 32 + j1;
int k2 = (l1 >> 12 & 63) - 32 + k1;
int l2 = l1 >> 18 & 15;
BlockPos blockpos = new BlockPos(i2, j2, k2);
// Sponge - use thread safe method
int i3 = this.getLightForAsync(lightType, blockpos, currentChunk, neighbors);
if (i3 == l2) {
// Sponge - use thread safe method
this.setLightForAsync(lightType, blockpos, 0, currentChunk, neighbors);
if (l2 > 0) {
int j3 = MathHelper.abs(i2 - i1);
int k3 = MathHelper.abs(j2 - j1);
int l3 = MathHelper.abs(k2 - k1);
if (j3 + k3 + l3 < 17) {
BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain();
for (EnumFacing enumfacing : EnumFacing.values()) {
int i4 = i2 + enumfacing.getFrontOffsetX();
int j4 = j2 + enumfacing.getFrontOffsetY();
int k4 = k2 + enumfacing.getFrontOffsetZ();
blockpos$pooledmutableblockpos.setPos(i4, j4, k4);
// Sponge start - get chunk safely
final Chunk pooledChunk = this.getLightChunk(blockpos$pooledmutableblockpos, currentChunk, neighbors);
if (pooledChunk == null) {
continue;
}
int l4 = Math.max(1, pooledChunk.getBlockState(blockpos$pooledmutableblockpos).getLightOpacity());
i3 = this.getLightForAsync(lightType, blockpos$pooledmutableblockpos, currentChunk, neighbors);
if (i3 == l2 - l4 && j < this.lightUpdateBlockList.length) {
this.lightUpdateBlockList[j++] = i4 - i1 + 32 | j4 - j1 + 32 << 6 | k4 - k1 + 32 << 12 | l2 - l4 << 18;
}
}
blockpos$pooledmutableblockpos.release();
}
}
}
}
i = 0;
}
while (i < j) {
int i5 = this.lightUpdateBlockList[i++];
int j5 = (i5 & 63) - 32 + i1;
int k5 = (i5 >> 6 & 63) - 32 + j1;
int l5 = (i5 >> 12 & 63) - 32 + k1;
BlockPos blockpos1 = new BlockPos(j5, k5, l5);
// Sponge - use thread safe method
int i6 = this.getLightForAsync(lightType, blockpos1, currentChunk, neighbors);
// Sponge - use thread safe method
int j6 = this.getRawBlockLightAsync(lightType, blockpos1, currentChunk, neighbors);
if (j6 != i6) {
// Sponge - use thread safe method
this.setLightForAsync(lightType, blockpos1, j6, currentChunk, neighbors);
if (j6 > i6) {
int k6 = Math.abs(j5 - i1);
int l6 = Math.abs(k5 - j1);
int i7 = Math.abs(l5 - k1);
boolean flag = j < this.lightUpdateBlockList.length - 6;
if (k6 + l6 + i7 < 17 && flag) {
// Sponge start - use thread safe method getLightForAsync
if (this.getLightForAsync(lightType, blockpos1.west(), currentChunk, neighbors) < j6) {
this.lightUpdateBlockList[j++] = j5 - 1 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 - k1 + 32 << 12);
}
if (this.getLightForAsync(lightType, blockpos1.east(), currentChunk, neighbors) < j6) {
this.lightUpdateBlockList[j++] = j5 + 1 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 - k1 + 32 << 12);
}
if (this.getLightForAsync(lightType, blockpos1.down(), currentChunk, neighbors) < j6) {
this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 - 1 - j1 + 32 << 6) + (l5 - k1 + 32 << 12);
}
if (this.getLightForAsync(lightType, blockpos1.up(), currentChunk, neighbors) < j6) {
this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 + 1 - j1 + 32 << 6) + (l5 - k1 + 32 << 12);
}
if (this.getLightForAsync(lightType, blockpos1.north(), currentChunk, neighbors) < j6) {
this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 - 1 - k1 + 32 << 12);
}
if (this.getLightForAsync(lightType, blockpos1.south(), currentChunk, neighbors) < j6) {
this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 + 1 - k1 + 32 << 12);
}
// Sponge end
}
}
}
}
// Sponge start - Asynchronous light updates
spongeChunk.getQueuedLightingUpdates(lightType).remove((Short) this.blockPosToShort(pos));
spongeChunk.getPendingLightUpdates().decrementAndGet();
for (net.minecraft.world.chunk.Chunk neighborChunk : neighbors) {
final IMixinChunk neighbor = (IMixinChunk) neighborChunk;
neighbor.getPendingLightUpdates().decrementAndGet();
}
// this.theProfiler.endSection(); // Sponge - don't use profiler off of main thread
return true;
}
}
use of net.minecraft.util.EnumFacing in project SpongeCommon by SpongePowered.
the class MixinWorldServer_Async_Lighting method getRawBlockLightAsync.
private int getRawBlockLightAsync(EnumSkyBlock lightType, BlockPos pos, Chunk currentChunk, List<Chunk> neighbors) {
final Chunk chunk = getLightChunk(pos, currentChunk, neighbors);
if (chunk == null || chunk.unloadQueued) {
return lightType.defaultLightValue;
}
if (lightType == EnumSkyBlock.SKY && chunk.canSeeSky(pos)) {
return 15;
} else {
IBlockState blockState = chunk.getBlockState(pos);
int blockLight = SpongeImplHooks.getChunkPosLight(blockState, (net.minecraft.world.World) (Object) this, pos);
int i = lightType == EnumSkyBlock.SKY ? 0 : blockLight;
int j = SpongeImplHooks.getBlockLightOpacity(blockState, (net.minecraft.world.World) (Object) this, pos);
if (j >= 15 && blockLight > 0) {
j = 1;
}
if (j < 1) {
j = 1;
}
if (j >= 15) {
return 0;
} else if (i >= 14) {
return i;
} else {
for (EnumFacing enumfacing : EnumFacing.values()) {
BlockPos blockpos = pos.offset(enumfacing);
int k = this.getLightForAsync(lightType, blockpos, currentChunk, neighbors) - j;
if (k > i) {
i = k;
}
if (i >= 14) {
return i;
}
}
return i;
}
}
}
use of net.minecraft.util.EnumFacing in project SpongeCommon by SpongePowered.
the class MixinBlockHorizontal method getStateWithValue.
@Override
public <E> Optional<BlockState> getStateWithValue(IBlockState blockState, Key<? extends BaseValue<E>> key, E value) {
if (key.equals(Keys.DIRECTION)) {
final Direction direction = (Direction) value;
final EnumFacing facing = DirectionResolver.getFor(direction);
return Optional.of((BlockState) blockState.withProperty(BlockHorizontal.FACING, facing));
}
return super.getStateWithValue(blockState, key, value);
}
Aggregations