pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.me.cluster.implementations;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -44,267 +43,218 @@ import appeng.me.cluster.IAECluster;
|
||||
import appeng.tile.qnb.TileQuantumBridge;
|
||||
import appeng.util.iterators.ChainedIterator;
|
||||
|
||||
public class QuantumCluster implements ILocatable, IAECluster {
|
||||
|
||||
public class QuantumCluster implements ILocatable, IAECluster
|
||||
{
|
||||
private final WorldCoord min;
|
||||
private final WorldCoord max;
|
||||
private boolean isDestroyed = false;
|
||||
private boolean updateStatus = true;
|
||||
private TileQuantumBridge[] Ring;
|
||||
private boolean registered = false;
|
||||
private ConnectionWrapper connection;
|
||||
private long thisSide;
|
||||
private long otherSide;
|
||||
private TileQuantumBridge center;
|
||||
|
||||
private final WorldCoord min;
|
||||
private final WorldCoord max;
|
||||
private boolean isDestroyed = false;
|
||||
private boolean updateStatus = true;
|
||||
private TileQuantumBridge[] Ring;
|
||||
private boolean registered = false;
|
||||
private ConnectionWrapper connection;
|
||||
private long thisSide;
|
||||
private long otherSide;
|
||||
private TileQuantumBridge center;
|
||||
public QuantumCluster(final WorldCoord min, final WorldCoord max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.setRing(new TileQuantumBridge[8]);
|
||||
}
|
||||
|
||||
public QuantumCluster( final WorldCoord min, final WorldCoord max )
|
||||
{
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.setRing( new TileQuantumBridge[8] );
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void onUnload(final WorldEvent.Unload e) {
|
||||
if (this.center.getWorld() == e.getWorld()) {
|
||||
this.setUpdateStatus(false);
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onUnload( final WorldEvent.Unload e )
|
||||
{
|
||||
if( this.center.getWorld() == e.getWorld() )
|
||||
{
|
||||
this.setUpdateStatus( false );
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void updateStatus(final boolean updateGrid) {
|
||||
|
||||
@Override
|
||||
public void updateStatus( final boolean updateGrid )
|
||||
{
|
||||
final long qe = this.center.getQEFrequency();
|
||||
|
||||
final long qe = this.center.getQEFrequency();
|
||||
if (this.thisSide != qe && this.thisSide != -qe) {
|
||||
if (qe != 0) {
|
||||
if (this.thisSide != 0) {
|
||||
MinecraftForge.EVENT_BUS.post(new LocatableEventAnnounce(this, LocatableEvent.UNREGISTER));
|
||||
}
|
||||
|
||||
if( this.thisSide != qe && this.thisSide != -qe )
|
||||
{
|
||||
if( qe != 0 )
|
||||
{
|
||||
if( this.thisSide != 0 )
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.UNREGISTER ) );
|
||||
}
|
||||
if (this.canUseNode(-qe)) {
|
||||
this.otherSide = qe;
|
||||
this.thisSide = -qe;
|
||||
} else if (this.canUseNode(qe)) {
|
||||
this.thisSide = qe;
|
||||
this.otherSide = -qe;
|
||||
}
|
||||
|
||||
if( this.canUseNode( -qe ) )
|
||||
{
|
||||
this.otherSide = qe;
|
||||
this.thisSide = -qe;
|
||||
}
|
||||
else if( this.canUseNode( qe ) )
|
||||
{
|
||||
this.thisSide = qe;
|
||||
this.otherSide = -qe;
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.post(new LocatableEventAnnounce(this, LocatableEvent.REGISTER));
|
||||
} else {
|
||||
MinecraftForge.EVENT_BUS.post(new LocatableEventAnnounce(this, LocatableEvent.UNREGISTER));
|
||||
|
||||
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.REGISTER ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.UNREGISTER ) );
|
||||
this.otherSide = 0;
|
||||
this.thisSide = 0;
|
||||
}
|
||||
}
|
||||
|
||||
this.otherSide = 0;
|
||||
this.thisSide = 0;
|
||||
}
|
||||
}
|
||||
final ILocatable myOtherSide = this.otherSide == 0 ? null
|
||||
: AEApi.instance().registries().locatable().getLocatableBy(this.otherSide);
|
||||
|
||||
final ILocatable myOtherSide = this.otherSide == 0 ? null : AEApi.instance().registries().locatable().getLocatableBy( this.otherSide );
|
||||
boolean shutdown = false;
|
||||
|
||||
boolean shutdown = false;
|
||||
if (myOtherSide instanceof QuantumCluster) {
|
||||
final QuantumCluster sideA = this;
|
||||
final QuantumCluster sideB = (QuantumCluster) myOtherSide;
|
||||
|
||||
if( myOtherSide instanceof QuantumCluster )
|
||||
{
|
||||
final QuantumCluster sideA = this;
|
||||
final QuantumCluster sideB = (QuantumCluster) myOtherSide;
|
||||
if (sideA.isActive() && sideB.isActive()) {
|
||||
if (this.connection != null && this.connection.getConnection() != null) {
|
||||
final IGridNode a = this.connection.getConnection().a();
|
||||
final IGridNode b = this.connection.getConnection().b();
|
||||
final IGridNode sa = sideA.getNode();
|
||||
final IGridNode sb = sideB.getNode();
|
||||
if ((a == sa || b == sa) && (a == sb || b == sb)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if( sideA.isActive() && sideB.isActive() )
|
||||
{
|
||||
if( this.connection != null && this.connection.getConnection() != null )
|
||||
{
|
||||
final IGridNode a = this.connection.getConnection().a();
|
||||
final IGridNode b = this.connection.getConnection().b();
|
||||
final IGridNode sa = sideA.getNode();
|
||||
final IGridNode sb = sideB.getNode();
|
||||
if( ( a == sa || b == sa ) && ( a == sb || b == sb ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (sideA.connection != null) {
|
||||
if (sideA.connection.getConnection() != null) {
|
||||
sideA.connection.getConnection().destroy();
|
||||
sideA.connection = new ConnectionWrapper(null);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( sideA.connection != null )
|
||||
{
|
||||
if( sideA.connection.getConnection() != null )
|
||||
{
|
||||
sideA.connection.getConnection().destroy();
|
||||
sideA.connection = new ConnectionWrapper( null );
|
||||
}
|
||||
}
|
||||
if (sideB.connection != null) {
|
||||
if (sideB.connection.getConnection() != null) {
|
||||
sideB.connection.getConnection().destroy();
|
||||
sideB.connection = new ConnectionWrapper(null);
|
||||
}
|
||||
}
|
||||
|
||||
if( sideB.connection != null )
|
||||
{
|
||||
if( sideB.connection.getConnection() != null )
|
||||
{
|
||||
sideB.connection.getConnection().destroy();
|
||||
sideB.connection = new ConnectionWrapper( null );
|
||||
}
|
||||
}
|
||||
sideA.connection = sideB.connection = new ConnectionWrapper(
|
||||
AEApi.instance().grid().createGridConnection(sideA.getNode(), sideB.getNode()));
|
||||
} catch (final FailedConnectionException e) {
|
||||
// :(
|
||||
AELog.debug(e);
|
||||
}
|
||||
} else {
|
||||
shutdown = true;
|
||||
}
|
||||
} else {
|
||||
shutdown = true;
|
||||
}
|
||||
|
||||
sideA.connection = sideB.connection = new ConnectionWrapper( AEApi.instance().grid().createGridConnection( sideA.getNode(), sideB.getNode() ) );
|
||||
}
|
||||
catch( final FailedConnectionException e )
|
||||
{
|
||||
// :(
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
shutdown = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
shutdown = true;
|
||||
}
|
||||
if (shutdown && this.connection != null) {
|
||||
if (this.connection.getConnection() != null) {
|
||||
this.connection.getConnection().destroy();
|
||||
this.connection.setConnection(null);
|
||||
this.connection = new ConnectionWrapper(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( shutdown && this.connection != null )
|
||||
{
|
||||
if( this.connection.getConnection() != null )
|
||||
{
|
||||
this.connection.getConnection().destroy();
|
||||
this.connection.setConnection( null );
|
||||
this.connection = new ConnectionWrapper( null );
|
||||
}
|
||||
}
|
||||
}
|
||||
private boolean canUseNode(final long qe) {
|
||||
final QuantumCluster qc = (QuantumCluster) AEApi.instance().registries().locatable().getLocatableBy(qe);
|
||||
if (qc != null) {
|
||||
final World theWorld = qc.center.getWorld();
|
||||
if (!qc.isDestroyed) {
|
||||
ChunkPos cPos = new ChunkPos(qc.center.getPos());
|
||||
if (theWorld.getChunkProvider().isChunkLoaded(cPos)) {
|
||||
final DimensionType id = theWorld.dimension.getType();
|
||||
final World cur = theWorld.getServer().getWorld(id);
|
||||
|
||||
private boolean canUseNode( final long qe )
|
||||
{
|
||||
final QuantumCluster qc = (QuantumCluster) AEApi.instance().registries().locatable().getLocatableBy( qe );
|
||||
if( qc != null )
|
||||
{
|
||||
final World theWorld = qc.center.getWorld();
|
||||
if( !qc.isDestroyed )
|
||||
{
|
||||
ChunkPos cPos = new ChunkPos( qc.center.getPos() );
|
||||
if( theWorld.getChunkProvider().isChunkLoaded( cPos ) )
|
||||
{
|
||||
final DimensionType id = theWorld.dimension.getType();
|
||||
final World cur = theWorld.getServer().getWorld( id );
|
||||
final TileEntity te = theWorld.getTileEntity(qc.center.getPos());
|
||||
return te != qc.center || theWorld != cur;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
final TileEntity te = theWorld.getTileEntity( qc.center.getPos() );
|
||||
return te != qc.center || theWorld != cur;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private boolean isActive() {
|
||||
if (this.isDestroyed || !this.registered) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isActive()
|
||||
{
|
||||
if( this.isDestroyed || !this.registered )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.center.isPowered() && this.hasQES();
|
||||
}
|
||||
|
||||
return this.center.isPowered() && this.hasQES();
|
||||
}
|
||||
private IGridNode getNode() {
|
||||
return this.center.getGridNode(AEPartLocation.INTERNAL);
|
||||
}
|
||||
|
||||
private IGridNode getNode()
|
||||
{
|
||||
return this.center.getGridNode( AEPartLocation.INTERNAL );
|
||||
}
|
||||
private boolean hasQES() {
|
||||
return this.thisSide != 0;
|
||||
}
|
||||
|
||||
private boolean hasQES()
|
||||
{
|
||||
return this.thisSide != 0;
|
||||
}
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (this.isDestroyed) {
|
||||
return;
|
||||
}
|
||||
this.isDestroyed = true;
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
if( this.isDestroyed )
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.isDestroyed = true;
|
||||
if (this.registered) {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
this.registered = false;
|
||||
}
|
||||
|
||||
if( this.registered )
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.unregister( this );
|
||||
this.registered = false;
|
||||
}
|
||||
if (this.thisSide != 0) {
|
||||
this.updateStatus(true);
|
||||
MinecraftForge.EVENT_BUS.post(new LocatableEventAnnounce(this, LocatableEvent.UNREGISTER));
|
||||
}
|
||||
|
||||
if( this.thisSide != 0 )
|
||||
{
|
||||
this.updateStatus( true );
|
||||
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.UNREGISTER ) );
|
||||
}
|
||||
this.center.updateStatus(null, (byte) -1, this.isUpdateStatus());
|
||||
|
||||
this.center.updateStatus( null, (byte) -1, this.isUpdateStatus() );
|
||||
for (final TileQuantumBridge r : this.getRing()) {
|
||||
r.updateStatus(null, (byte) -1, this.isUpdateStatus());
|
||||
}
|
||||
|
||||
for( final TileQuantumBridge r : this.getRing() )
|
||||
{
|
||||
r.updateStatus( null, (byte) -1, this.isUpdateStatus() );
|
||||
}
|
||||
this.center = null;
|
||||
this.setRing(new TileQuantumBridge[8]);
|
||||
}
|
||||
|
||||
this.center = null;
|
||||
this.setRing( new TileQuantumBridge[8] );
|
||||
}
|
||||
@Override
|
||||
public Iterator<IGridHost> getTiles() {
|
||||
return new ChainedIterator<>(this.getRing()[0], this.getRing()[1], this.getRing()[2], this.getRing()[3],
|
||||
this.getRing()[4], this.getRing()[5], this.getRing()[6], this.getRing()[7], this.center);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IGridHost> getTiles()
|
||||
{
|
||||
return new ChainedIterator<>( this.getRing()[0], this.getRing()[1], this.getRing()[2], this.getRing()[3], this.getRing()[4], this.getRing()[5], this.getRing()[6], this.getRing()[7], this.center );
|
||||
}
|
||||
public boolean isCorner(final TileQuantumBridge tileQuantumBridge) {
|
||||
return this.getRing()[0] == tileQuantumBridge || this.getRing()[2] == tileQuantumBridge
|
||||
|| this.getRing()[4] == tileQuantumBridge || this.getRing()[6] == tileQuantumBridge;
|
||||
}
|
||||
|
||||
public boolean isCorner( final TileQuantumBridge tileQuantumBridge )
|
||||
{
|
||||
return this.getRing()[0] == tileQuantumBridge || this.getRing()[2] == tileQuantumBridge || this.getRing()[4] == tileQuantumBridge || this.getRing()[6] == tileQuantumBridge;
|
||||
}
|
||||
@Override
|
||||
public long getLocatableSerial() {
|
||||
return this.thisSide;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLocatableSerial()
|
||||
{
|
||||
return this.thisSide;
|
||||
}
|
||||
public TileQuantumBridge getCenter() {
|
||||
return this.center;
|
||||
}
|
||||
|
||||
public TileQuantumBridge getCenter()
|
||||
{
|
||||
return this.center;
|
||||
}
|
||||
void setCenter(final TileQuantumBridge c) {
|
||||
this.registered = true;
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
this.center = c;
|
||||
}
|
||||
|
||||
void setCenter( final TileQuantumBridge c )
|
||||
{
|
||||
this.registered = true;
|
||||
MinecraftForge.EVENT_BUS.register( this );
|
||||
this.center = c;
|
||||
}
|
||||
private boolean isUpdateStatus() {
|
||||
return this.updateStatus;
|
||||
}
|
||||
|
||||
private boolean isUpdateStatus()
|
||||
{
|
||||
return this.updateStatus;
|
||||
}
|
||||
public void setUpdateStatus(final boolean updateStatus) {
|
||||
this.updateStatus = updateStatus;
|
||||
}
|
||||
|
||||
public void setUpdateStatus( final boolean updateStatus )
|
||||
{
|
||||
this.updateStatus = updateStatus;
|
||||
}
|
||||
TileQuantumBridge[] getRing() {
|
||||
return this.Ring;
|
||||
}
|
||||
|
||||
TileQuantumBridge[] getRing()
|
||||
{
|
||||
return this.Ring;
|
||||
}
|
||||
|
||||
private void setRing( final TileQuantumBridge[] ring )
|
||||
{
|
||||
this.Ring = ring;
|
||||
}
|
||||
private void setRing(final TileQuantumBridge[] ring) {
|
||||
this.Ring = ring;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user