Fix light sync (#3304)

* Sync light opacity changes to client
* While at it, also fix Light P2P
* Use int for opacity, dont store it in NBT
This commit is contained in:
fscan
2018-01-14 13:44:12 +01:00
committed by yueh
parent 8c5842aca9
commit cbfc88c87f
4 changed files with 25 additions and 23 deletions
@@ -55,7 +55,7 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
}
private int lastValue = 0;
private float opacity = -1;
private int opacity = -1;
public PartP2PLight( final ItemStack is )
{
@@ -81,15 +81,21 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
{
super.writeToStream( data );
data.writeInt( this.isOutput() ? this.lastValue : 0 );
data.writeInt( this.opacity );
}
@Override
public boolean readFromStream( final ByteBuf data ) throws IOException
{
super.readFromStream( data );
final int oldValue = this.lastValue;
final int oldOpacity = this.opacity;
this.lastValue = data.readInt();
this.opacity = data.readInt();
this.setOutput( this.lastValue > 0 );
return false;
return lastValue != oldValue || oldOpacity != this.opacity;
}
private boolean doWork()
@@ -126,14 +132,15 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
@Override
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
{
this.opacity = -1;
this.doWork();
if( this.isOutput() )
if( this.isOutput() && pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
{
this.opacity = -1;
this.getHost().markForUpdate();
}
else
{
this.doWork();
}
}
@Override
@@ -168,10 +175,6 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
public void readFromNBT( final NBTTagCompound tag )
{
super.readFromNBT( tag );
if( tag.hasKey( "opacity" ) )
{
this.opacity = tag.getFloat( "opacity" );
}
this.lastValue = tag.getInteger( "lastValue" );
}
@@ -179,7 +182,6 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
public void writeToNBT( final NBTTagCompound tag )
{
super.writeToNBT( tag );
tag.setFloat( "opacity", this.opacity );
tag.setInteger( "lastValue", this.lastValue );
}
@@ -219,7 +221,7 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
@Override
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
{
return this.doWork() ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
return this.doWork() ? TickRateModulation.URGENT : TickRateModulation.SLOWER;
}
public float getPowerDrainPerTick()