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:
@@ -47,7 +47,7 @@ public enum TickRates
|
|||||||
|
|
||||||
ItemTunnel( 5, 60 ),
|
ItemTunnel( 5, 60 ),
|
||||||
|
|
||||||
LightTunnel( 5, 120 ),
|
LightTunnel( 5, 60 ),
|
||||||
|
|
||||||
OpenComputersTunnel( 1, 5 ),
|
OpenComputersTunnel( 1, 5 ),
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int lastValue = 0;
|
private int lastValue = 0;
|
||||||
private float opacity = -1;
|
private int opacity = -1;
|
||||||
|
|
||||||
public PartP2PLight( final ItemStack is )
|
public PartP2PLight( final ItemStack is )
|
||||||
{
|
{
|
||||||
@@ -81,15 +81,21 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
|
|||||||
{
|
{
|
||||||
super.writeToStream( data );
|
super.writeToStream( data );
|
||||||
data.writeInt( this.isOutput() ? this.lastValue : 0 );
|
data.writeInt( this.isOutput() ? this.lastValue : 0 );
|
||||||
|
data.writeInt( this.opacity );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean readFromStream( final ByteBuf data ) throws IOException
|
public boolean readFromStream( final ByteBuf data ) throws IOException
|
||||||
{
|
{
|
||||||
super.readFromStream( data );
|
super.readFromStream( data );
|
||||||
|
final int oldValue = this.lastValue;
|
||||||
|
final int oldOpacity = this.opacity;
|
||||||
|
|
||||||
this.lastValue = data.readInt();
|
this.lastValue = data.readInt();
|
||||||
|
this.opacity = data.readInt();
|
||||||
|
|
||||||
this.setOutput( this.lastValue > 0 );
|
this.setOutput( this.lastValue > 0 );
|
||||||
return false;
|
return lastValue != oldValue || oldOpacity != this.opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean doWork()
|
private boolean doWork()
|
||||||
@@ -126,14 +132,15 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
|
|||||||
@Override
|
@Override
|
||||||
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
||||||
{
|
{
|
||||||
this.opacity = -1;
|
if( this.isOutput() && pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
|
||||||
|
|
||||||
this.doWork();
|
|
||||||
|
|
||||||
if( this.isOutput() )
|
|
||||||
{
|
{
|
||||||
|
this.opacity = -1;
|
||||||
this.getHost().markForUpdate();
|
this.getHost().markForUpdate();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.doWork();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -168,10 +175,6 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
|
|||||||
public void readFromNBT( final NBTTagCompound tag )
|
public void readFromNBT( final NBTTagCompound tag )
|
||||||
{
|
{
|
||||||
super.readFromNBT( tag );
|
super.readFromNBT( tag );
|
||||||
if( tag.hasKey( "opacity" ) )
|
|
||||||
{
|
|
||||||
this.opacity = tag.getFloat( "opacity" );
|
|
||||||
}
|
|
||||||
this.lastValue = tag.getInteger( "lastValue" );
|
this.lastValue = tag.getInteger( "lastValue" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +182,6 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
|
|||||||
public void writeToNBT( final NBTTagCompound tag )
|
public void writeToNBT( final NBTTagCompound tag )
|
||||||
{
|
{
|
||||||
super.writeToNBT( tag );
|
super.writeToNBT( tag );
|
||||||
tag.setFloat( "opacity", this.opacity );
|
|
||||||
tag.setInteger( "lastValue", this.lastValue );
|
tag.setInteger( "lastValue", this.lastValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +221,7 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
|
|||||||
@Override
|
@Override
|
||||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
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()
|
public float getPowerDrainPerTick()
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public abstract class AbstractPartReporting extends AEBasePart implements IPartM
|
|||||||
|
|
||||||
private byte spin = 0; // 0-3
|
private byte spin = 0; // 0-3
|
||||||
private int clientFlags = 0; // sent as byte.
|
private int clientFlags = 0; // sent as byte.
|
||||||
private float opacity = -1;
|
private int opacity = -1;
|
||||||
|
|
||||||
public AbstractPartReporting( final ItemStack is )
|
public AbstractPartReporting( final ItemStack is )
|
||||||
{
|
{
|
||||||
@@ -128,10 +128,6 @@ public abstract class AbstractPartReporting extends AEBasePart implements IPartM
|
|||||||
public void readFromNBT( final NBTTagCompound data )
|
public void readFromNBT( final NBTTagCompound data )
|
||||||
{
|
{
|
||||||
super.readFromNBT( data );
|
super.readFromNBT( data );
|
||||||
if( data.hasKey( "opacity" ) )
|
|
||||||
{
|
|
||||||
this.opacity = data.getFloat( "opacity" );
|
|
||||||
}
|
|
||||||
this.spin = data.getByte( "spin" );
|
this.spin = data.getByte( "spin" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +135,6 @@ public abstract class AbstractPartReporting extends AEBasePart implements IPartM
|
|||||||
public void writeToNBT( final NBTTagCompound data )
|
public void writeToNBT( final NBTTagCompound data )
|
||||||
{
|
{
|
||||||
super.writeToNBT( data );
|
super.writeToNBT( data );
|
||||||
data.setFloat( "opacity", this.opacity );
|
|
||||||
data.setByte( "spin", this.getSpin() );
|
data.setByte( "spin", this.getSpin() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,6 +167,7 @@ public abstract class AbstractPartReporting extends AEBasePart implements IPartM
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.writeByte( (byte) this.getClientFlags() );
|
data.writeByte( (byte) this.getClientFlags() );
|
||||||
|
data.writeInt( this.opacity );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -179,9 +175,13 @@ public abstract class AbstractPartReporting extends AEBasePart implements IPartM
|
|||||||
{
|
{
|
||||||
super.readFromStream( data );
|
super.readFromStream( data );
|
||||||
final int oldFlags = this.getClientFlags();
|
final int oldFlags = this.getClientFlags();
|
||||||
|
final int oldOpacity = this.opacity;
|
||||||
|
|
||||||
this.clientFlags = data.readByte();
|
this.clientFlags = data.readByte();
|
||||||
|
this.opacity = data.readInt();
|
||||||
|
|
||||||
this.spin = (byte) ( this.getClientFlags() & 3 );
|
this.spin = (byte) ( this.getClientFlags() & 3 );
|
||||||
if( this.getClientFlags() == oldFlags )
|
if( this.getClientFlags() == oldFlags && this.opacity == oldOpacity )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,13 +83,14 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl
|
|||||||
protected boolean readFromStream( final ByteBuf data ) throws IOException
|
protected boolean readFromStream( final ByteBuf data ) throws IOException
|
||||||
{
|
{
|
||||||
final boolean c = super.readFromStream( data );
|
final boolean c = super.readFromStream( data );
|
||||||
final boolean ret = this.getCableBus().readFromStream( data );
|
boolean ret = this.getCableBus().readFromStream( data );
|
||||||
|
|
||||||
final int newLV = this.getCableBus().getLightValue();
|
final int newLV = this.getCableBus().getLightValue();
|
||||||
if( newLV != this.oldLV )
|
if( newLV != this.oldLV )
|
||||||
{
|
{
|
||||||
this.oldLV = newLV;
|
this.oldLV = newLV;
|
||||||
this.world.checkLight( this.pos );
|
this.world.checkLight( this.pos );
|
||||||
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateTileSetting();
|
this.updateTileSetting();
|
||||||
@@ -189,7 +190,6 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl
|
|||||||
{
|
{
|
||||||
this.oldLV = newLV;
|
this.oldLV = newLV;
|
||||||
this.world.checkLight( this.pos );
|
this.world.checkLight( this.pos );
|
||||||
// world.updateAllLightTypes( xCoord, yCoord, zCoord );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.markForUpdate();
|
super.markForUpdate();
|
||||||
|
|||||||
Reference in New Issue
Block a user