ME P2P tunnels
This commit is contained in:
@@ -1,25 +1,38 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.core.AELog;
|
||||
import appeng.helpers.TickHandler;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.Connections;
|
||||
import appeng.me.cache.helpers.TunnelConnection;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
|
||||
public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME>
|
||||
public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements IGridTickable
|
||||
{
|
||||
|
||||
AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", true );
|
||||
public Connections connection = new Connections( this );
|
||||
|
||||
public PartP2PTunnelME(ItemStack is) {
|
||||
super( is );
|
||||
proxy.setFlags( GridFlags.TIER_2_CAPACITY, GridFlags.REQURE_CHANNEL, GridFlags.DENSE_CHANNEL, GridFlags.CANNOT_CARRY_DENSE );
|
||||
proxy.setFlags( GridFlags.REQURE_CHANNEL, GridFlags.DENSE_CHANNEL );
|
||||
outerProxy.setFlags( GridFlags.TIER_2_CAPACITY, GridFlags.CANNOT_CARRY_DENSE );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,4 +82,124 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME>
|
||||
return AECableType.DENSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange()
|
||||
{
|
||||
super.onChange();
|
||||
if ( !output )
|
||||
{
|
||||
try
|
||||
{
|
||||
proxy.getTick().wakeDevice( proxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( 5, 20, output, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
// just move on...
|
||||
try
|
||||
{
|
||||
if ( !proxy.getPath().isNetworkBooting() )
|
||||
{
|
||||
if ( !proxy.getEnergy().isNetworkPowered() )
|
||||
{
|
||||
connection.markDestroy();
|
||||
TickHandler.instance.addCallable( connection );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( proxy.isActive() )
|
||||
{
|
||||
connection.markCreate();
|
||||
TickHandler.instance.addCallable( connection );
|
||||
}
|
||||
else
|
||||
{
|
||||
connection.markDestroy();
|
||||
TickHandler.instance.addCallable( connection );
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// meh?
|
||||
}
|
||||
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
public void updateConnections(Connections connections)
|
||||
{
|
||||
if ( connections.destroy )
|
||||
{
|
||||
for (TunnelConnection cw : connection.connections.values())
|
||||
cw.c.destroy();
|
||||
|
||||
connection.connections.clear();
|
||||
}
|
||||
else if ( connections.create )
|
||||
{
|
||||
|
||||
Iterator<TunnelConnection> i = connection.connections.values().iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
TunnelConnection cw = i.next();
|
||||
AELog.info( "Old!" );
|
||||
try
|
||||
{
|
||||
if ( cw.tunnel.proxy.getGrid() != proxy.getGrid() )
|
||||
{
|
||||
cw.c.destroy();
|
||||
i.remove();
|
||||
}
|
||||
else if ( !cw.tunnel.proxy.isActive() )
|
||||
{
|
||||
cw.c.destroy();
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
LinkedList<PartP2PTunnelME> newSides = new LinkedList<PartP2PTunnelME>();
|
||||
try
|
||||
{
|
||||
for (PartP2PTunnelME me : getOutputs())
|
||||
{
|
||||
if ( me.proxy.isActive() && connections.connections.get( me.getGridNode() ) == null )
|
||||
{
|
||||
newSides.add( me );
|
||||
}
|
||||
}
|
||||
|
||||
for (PartP2PTunnelME me : newSides)
|
||||
{
|
||||
connections.connections.put( me.getGridNode(),
|
||||
new TunnelConnection( me, AEApi.instance().createGridConnection( outerProxy.getNode(), me.outerProxy.getNode() ) ) );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user