Skip to content

Commit

Permalink
Trigger TESR Updates only when vox-ref's change, not just any packet.
Browse files Browse the repository at this point in the history
Trigger TESR Redraws when a C&B BLock next to a TESR is removed or edited.
  • Loading branch information
AlgorithmX2 committed Aug 7, 2016
1 parent c6351e5 commit 0f8656f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public final void writeChisleData(
compound.setByteArray( NBT_VERSIONED_VOXEL, voxelBytes );
}

public final void readChisleData(
public final boolean readChisleData(
final NBTTagCompound compound )
{
sideState = compound.getInteger( NBT_SIDE_FLAGS );
Expand Down Expand Up @@ -174,8 +174,10 @@ public final void readChisleData(

if ( tile != null )
{
tile.updateBlob( this, triggerUpdates );
return tile.updateBlob( this, triggerUpdates );
}

return true;
}

private int getFormat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,24 +279,63 @@ public void onDataPacket(
final NetworkManager net,
final SPacketUpdateTileEntity pkt )
{
readChisleData( pkt.getNbtCompound() );
if ( worldObj != null )
final boolean changed = readChisleData( pkt.getNbtCompound() );

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

/**
* look at near by TESRs and re-render them.
*/
private void triggerDynamicUpdates()
{
if ( worldObj.isRemote )
{
final VoxelNeighborRenderTracker vns = state.getValue( BlockChiseled.UProperty_VoxelNeighborState );

// will it update anyway?
if ( vns != null && vns.isDynamic() )
{
return;
}

for ( final EnumFacing f : EnumFacing.VALUES )
{
final BlockPos p = getPos().offset( f );
if ( worldObj.isBlockLoaded( p ) )
{
final TileEntity te = worldObj.getTileEntity( p );
if ( te instanceof TileEntityBlockChiseledTESR )
{
final TileEntityBlockChiseledTESR tesr = (TileEntityBlockChiseledTESR) te;

if ( tesr.getRenderChunk() != null )
{
tesr.getRenderChunk().rebuild( false );
}
}
}
}
}
}

public void readChisleData(
public boolean readChisleData(
final NBTTagCompound tag )
{
new NBTBlobConverter( false, this ).readChisleData( tag );
final boolean changed = new NBTBlobConverter( false, this ).readChisleData( tag );

final VoxelNeighborRenderTracker vns = state.getValue( BlockChiseled.UProperty_VoxelNeighborState );

if ( vns != null )
{
vns.triggerUpdate();
}

return changed;
}

public void writeChisleData(
Expand Down Expand Up @@ -406,14 +445,16 @@ public void setBlob(
setBlob( vb, true );
}

public void updateBlob(
public boolean updateBlob(
final NBTBlobConverter converter,
final boolean triggerUpdates )
{
final int oldLV = getLightValue();
final boolean oldNC = isNormalCube();
final int oldSides = sideState;

final VoxelBlobStateReference originalRef = getBasicState().getValue( BlockChiseled.UProperty_VoxelBlob );

sideState = converter.getSideState();
final int b = converter.getPrimaryBlockStateID();
lightlevel = converter.getLightValue();
Expand Down Expand Up @@ -449,6 +490,8 @@ public void updateBlob(
worldObj.notifyNeighborsOfStateChange( pos, worldObj.getBlockState( pos ).getBlock() );
}
}

return voxelRef != null ? !voxelRef.equals( originalRef ) : true;
}

public void setBlob(
Expand Down Expand Up @@ -646,6 +689,12 @@ public void completeEditOperation(
setBlob( vb );
final VoxelBlobStateReference after = getBlobStateReference();

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

UndoTracker.getInstance().add( getWorld(), getPos(), before, after );
}

Expand Down Expand Up @@ -716,4 +765,13 @@ public int getLightValue()
return lightlevel;
}

@Override
public void invalidate()
{
if ( worldObj != null )
{
triggerDynamicUpdates();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ private void detatchRenderer()
@Override
public void invalidate()
{
super.invalidate();
detatchRenderer();
}

Expand Down

0 comments on commit 0f8656f

Please sign in to comment.