Skip to content

Commit

Permalink
Initialize lighting early, and re-check light on packets.
Browse files Browse the repository at this point in the history
Fixes #81 and #286
  • Loading branch information
AlgorithmX2 committed Jul 24, 2017
1 parent 8d74a06 commit 04d258c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Expand Up @@ -997,7 +997,9 @@ public static boolean replaceWithChisled(

if ( blk != null && blk != target )
{
TileEntityBlockChiseled.setLightFromBlock( actingState );
world.setBlockState( pos, blk.getDefaultState(), triggerUpdate ? 3 : 0 );
TileEntityBlockChiseled.setLightFromBlock( null );
final TileEntity te = world.getTileEntity( pos );

TileEntityBlockChiseled tec;
Expand Down
Expand Up @@ -53,7 +53,11 @@ public class TileEntityBlockChiseled extends TileEntity implements IChiseledTile

boolean isNormalCube = false;
int sideState = 0;
int lightlevel = 0;
int lightlevel = -1;

// used to initialize light level before I can properly feed things into the
// tile entity, half 2 of fixing inital lighting issues.
private static ThreadLocal<Integer> localLightLevel = new ThreadLocal<Integer>();

public TileEntityBlockChiseled()
{
Expand Down Expand Up @@ -307,12 +311,19 @@ public void onDataPacket(
final NetworkManager net,
final SPacketUpdateTileEntity pkt )
{
final int oldLight = lightlevel;
final boolean changed = readChisleData( pkt.getNbtCompound() );

if ( worldObj != null && changed )
{
worldObj.markBlockRangeForRenderUpdate( pos, pos );
triggerDynamicUpdates();

// fixes lighting on placement when tile packet arrives.
if ( oldLight != lightlevel )
{
worldObj.checkLight( pos );
}
}
}

Expand Down Expand Up @@ -585,9 +596,11 @@ public boolean updateBlob(
worldObj.checkLight( pos );

// update block state to reflect lighting characteristics
IBlockState state = worldObj.getBlockState( pos );
final IBlockState state = worldObj.getBlockState( pos );
if ( state.isFullCube() != isNormalCube && state.getBlock() instanceof BlockChiseled )
{
worldObj.setBlockState( pos, state.withProperty( BlockChiseled.LProperty_FullBlock, isNormalCube ) );
}
}

if ( oldSides != sideState )
Expand Down Expand Up @@ -692,9 +705,11 @@ else if ( common.mostCommonState != 0 )
worldObj.checkLight( pos );

// update block state to reflect lighting characteristics
IBlockState state = worldObj.getBlockState( pos );
final IBlockState state = worldObj.getBlockState( pos );
if ( state.isFullCube() != isNormalCube && state.getBlock() instanceof BlockChiseled )
{
worldObj.setBlockState( pos, state.withProperty( BlockChiseled.LProperty_FullBlock, isNormalCube ) );
}
}
}

Expand Down Expand Up @@ -875,8 +890,28 @@ public void setNormalCube(
isNormalCube = b;
}

public static void setLightFromBlock(
final IBlockState defaultState )
{
if ( defaultState == null )
{
localLightLevel.remove();
}
else
{
localLightLevel.set( DeprecationHelper.getLightValue( defaultState ) );
}
}

public int getLightValue()
{
// first time requested, pull from local, or default to 0
if ( lightlevel < 0 )
{
final Integer tmp = localLightLevel.get();
lightlevel = tmp == null ? 0 : tmp;
}

return lightlevel;
}

Expand Down

0 comments on commit 04d258c

Please sign in to comment.