Basic reformat, hit once, hope never again

This commit is contained in:
thatsIch
2015-04-03 08:54:31 +02:00
parent 4ff1631f89
commit d34c988c88
886 changed files with 31400 additions and 30990 deletions
@@ -18,6 +18,7 @@
package appeng.parts.p2p;
import java.util.LinkedList;
import net.minecraft.init.Blocks;
@@ -37,35 +38,32 @@ import appeng.transformer.annotations.Integration.Interface;
import appeng.transformer.annotations.Integration.InterfaceList;
import appeng.util.Platform;
@InterfaceList(value = { @Interface(iface = "ic2.api.energy.tile.IEnergySink", iname = "IC2"),
@Interface(iface = "ic2.api.energy.tile.IEnergySource", iname = "IC2") })
@InterfaceList( value = { @Interface( iface = "ic2.api.energy.tile.IEnergySink", iname = "IC2" ), @Interface( iface = "ic2.api.energy.tile.IEnergySource", iname = "IC2" ) } )
public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements ic2.api.energy.tile.IEnergySink, ic2.api.energy.tile.IEnergySource
{
public PartP2PIC2Power(ItemStack is) {
super( is );
}
// two packet buffering...
double OutputEnergyA;
double OutputEnergyB;
// two packet buffering...
double OutputVoltageA;
double OutputVoltageB;
@Override
public void writeToNBT(NBTTagCompound tag)
public PartP2PIC2Power( ItemStack is )
{
super.writeToNBT( tag );
tag.setDouble( "OutputPacket", this.OutputEnergyA );
tag.setDouble( "OutputPacket2", this.OutputEnergyB );
tag.setDouble( "OutputVoltageA", this.OutputVoltageA );
tag.setDouble( "OutputVoltageB", this.OutputVoltageB );
super( is );
}
@Override
public void readFromNBT(NBTTagCompound tag)
@SideOnly( Side.CLIENT )
public IIcon getTypeTexture()
{
return Blocks.diamond_block.getBlockTextureFromSide( 0 );
}
@Override
public void readFromNBT( NBTTagCompound tag )
{
super.readFromNBT( tag );
this.OutputEnergyA = tag.getDouble( "OutputPacket" );
@@ -75,50 +73,19 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getTypeTexture()
public void writeToNBT( NBTTagCompound tag )
{
return Blocks.diamond_block.getBlockTextureFromSide( 0 );
super.writeToNBT( tag );
tag.setDouble( "OutputPacket", this.OutputEnergyA );
tag.setDouble( "OutputPacket2", this.OutputEnergyB );
tag.setDouble( "OutputVoltageA", this.OutputVoltageA );
tag.setDouble( "OutputVoltageB", this.OutputVoltageB );
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
public void onTunnelConfigChange()
{
if ( !this.output )
return direction == this.side;
return false;
}
@Override
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction)
{
if ( this.output )
return direction == this.side;
return false;
}
@Override
public double getDemandedEnergy()
{
if ( this.output )
return 0;
try
{
for (PartP2PIC2Power t : this.getOutputs())
{
if ( t.OutputEnergyA <= 0.0001 || t.OutputEnergyB <= 0.0001 )
{
return 2048;
}
}
}
catch (GridAccessException e)
{
return 0;
}
return 0;
this.getHost().partChanged();
}
@Override
@@ -128,58 +95,93 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
}
@Override
public void onTunnelConfigChange()
public boolean acceptsEnergyFrom( TileEntity emitter, ForgeDirection direction )
{
this.getHost().partChanged();
}
public float getPowerDrainPerTick()
{
return 0.5f;
if( !this.output )
return direction == this.side;
return false;
}
@Override
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
public boolean emitsEnergyTo( TileEntity receiver, ForgeDirection direction )
{
if( this.output )
return direction == this.side;
return false;
}
@Override
public double getDemandedEnergy()
{
if( this.output )
return 0;
try
{
for( PartP2PIC2Power t : this.getOutputs() )
{
if( t.OutputEnergyA <= 0.0001 || t.OutputEnergyB <= 0.0001 )
{
return 2048;
}
}
}
catch( GridAccessException e )
{
return 0;
}
return 0;
}
@Override
public int getSinkTier()
{
return 4;
}
@Override
public double injectEnergy( ForgeDirection directionFrom, double amount, double voltage )
{
TunnelCollection<PartP2PIC2Power> outs;
try
{
outs = this.getOutputs();
}
catch (GridAccessException e)
catch( GridAccessException e )
{
return amount;
}
if ( outs.isEmpty() )
if( outs.isEmpty() )
return amount;
LinkedList<PartP2PIC2Power> Options = new LinkedList<PartP2PIC2Power>();
for (PartP2PIC2Power o : outs)
for( PartP2PIC2Power o : outs )
{
if ( o.OutputEnergyA <= 0.01 )
if( o.OutputEnergyA <= 0.01 )
Options.add( o );
}
if ( Options.isEmpty() )
if( Options.isEmpty() )
{
for (PartP2PIC2Power o : outs)
if ( o.OutputEnergyB <= 0.01 )
for( PartP2PIC2Power o : outs )
if( o.OutputEnergyB <= 0.01 )
Options.add( o );
}
if ( Options.isEmpty() )
if( Options.isEmpty() )
{
for (PartP2PIC2Power o : outs)
for( PartP2PIC2Power o : outs )
Options.add( o );
}
if ( Options.isEmpty() )
if( Options.isEmpty() )
return amount;
PartP2PIC2Power x = Platform.pickRandom( Options );
if ( x != null && x.OutputEnergyA <= 0.001 )
if( x != null && x.OutputEnergyA <= 0.001 )
{
this.QueueTunnelDrain( PowerUnits.EU, amount );
x.OutputEnergyA = amount;
@@ -187,7 +189,7 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
return 0;
}
if ( x != null && x.OutputEnergyB <= 0.001 )
if( x != null && x.OutputEnergyB <= 0.001 )
{
this.QueueTunnelDrain( PowerUnits.EU, amount );
x.OutputEnergyB = amount;
@@ -198,25 +200,24 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
return amount;
}
@Override
public int getSinkTier()
public float getPowerDrainPerTick()
{
return 4;
return 0.5f;
}
@Override
public double getOfferedEnergy()
{
if ( this.output )
if( this.output )
return this.OutputEnergyA;
return 0;
}
@Override
public void drawEnergy(double amount)
public void drawEnergy( double amount )
{
this.OutputEnergyA -= amount;
if ( this.OutputEnergyA < 0.001 )
if( this.OutputEnergyA < 0.001 )
{
this.OutputEnergyA = this.OutputEnergyB;
this.OutputEnergyB = 0;
@@ -229,14 +230,13 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
@Override
public int getSourceTier()
{
if ( this.output )
if( this.output )
return this.calculateTierFromVoltage( this.OutputVoltageA );
return 4;
}
private int calculateTierFromVoltage(double voltage)
private int calculateTierFromVoltage( double voltage )
{
return ic2.api.energy.EnergyNet.instance.getTierFromPower( voltage );
}
}
+116 -115
View File
@@ -18,6 +18,7 @@
package appeng.parts.p2p;
import java.util.LinkedList;
import java.util.List;
@@ -59,45 +60,89 @@ import appeng.util.inv.WrapperBCPipe;
import appeng.util.inv.WrapperChainedInventory;
import appeng.util.inv.WrapperMCISidedInventory;
@Interface(iface = "buildcraft.api.transport.IPipeConnection", iname = "BC")
@Interface( iface = "buildcraft.api.transport.IPipeConnection", iname = "BC" )
public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeConnection, ISidedInventory, IGridTickable
{
public PartP2PItems(ItemStack is) {
super( is );
}
final LinkedList<IInventory> which = new LinkedList<IInventory>();
int oldSize = 0;
boolean requested;
IInventory cachedInv;
final LinkedList<IInventory> which = new LinkedList<IInventory>();
public PartP2PItems( ItemStack is )
{
super( is );
}
@Override
public void onNeighborChanged()
{
this.cachedInv = null;
PartP2PItems input = this.getInput();
if( input != null && this.output )
input.onTunnelNetworkChange();
}
IInventory getDestination()
{
this.requested = true;
if( this.cachedInv != null )
return this.cachedInv;
List<IInventory> outs = new LinkedList<IInventory>();
TunnelCollection<PartP2PItems> itemTunnels;
try
{
itemTunnels = this.getOutputs();
}
catch( GridAccessException e )
{
return new AppEngNullInventory();
}
for( PartP2PItems t : itemTunnels )
{
IInventory inv = t.getOutputInv();
if( inv != null )
{
if( Platform.getRandomInt() % 2 == 0 )
outs.add( inv );
else
outs.add( 0, inv );
}
}
return this.cachedInv = new WrapperChainedInventory( outs );
}
IInventory getOutputInv()
{
IInventory output = null;
if ( this.proxy.isActive() )
if( this.proxy.isActive() )
{
TileEntity te = this.tile.getWorldObj().getTileEntity( this.tile.xCoord + this.side.offsetX, this.tile.yCoord + this.side.offsetY, this.tile.zCoord + this.side.offsetZ );
if ( this.which.contains( this ) )
if( this.which.contains( this ) )
return null;
this.which.add( this );
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) )
if( AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) )
{
IBC buildcraft = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
if ( buildcraft != null )
if( buildcraft != null )
{
if ( buildcraft.isPipe( te, this.side.getOpposite() ) )
if( buildcraft.isPipe( te, this.side.getOpposite() ) )
{
try
{
output = new WrapperBCPipe( te, this.side.getOpposite() );
}
catch (Throwable ignore)
catch( Throwable ignore )
{
}
}
@@ -110,17 +155,17 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeCo
* WrapperTEPipe( te, side.getOpposite() ); } catch (Throwable ignore) { } } } }
*/
if ( output == null )
if( output == null )
{
if ( te instanceof TileEntityChest )
if( te instanceof TileEntityChest )
{
output = Platform.GetChestInv( te );
}
else if ( te instanceof ISidedInventory )
else if( te instanceof ISidedInventory )
{
output = new WrapperMCISidedInventory( (ISidedInventory) te, this.side.getOpposite() );
}
else if ( te instanceof IInventory )
else if( te instanceof IInventory )
{
output = (IInventory) te;
}
@@ -133,75 +178,32 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeCo
}
@Override
public void onNeighborChanged()
{
this.cachedInv = null;
PartP2PItems input = this.getInput();
if ( input != null && this.output )
input.onTunnelNetworkChange();
}
@Override
public TickingRequest getTickingRequest(IGridNode node)
public TickingRequest getTickingRequest( IGridNode node )
{
return new TickingRequest( TickRates.ItemTunnel.min, TickRates.ItemTunnel.max, false, false );
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
public TickRateModulation tickingRequest( IGridNode node, int TicksSinceLastCall )
{
boolean wasReq = this.requested;
if ( this.requested && this.cachedInv != null )
((WrapperChainedInventory) this.cachedInv).cycleOrder();
if( this.requested && this.cachedInv != null )
( (WrapperChainedInventory) this.cachedInv ).cycleOrder();
this.requested = false;
return wasReq ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
IInventory getDestination()
{
this.requested = true;
if ( this.cachedInv != null )
return this.cachedInv;
List<IInventory> outs = new LinkedList<IInventory>();
TunnelCollection<PartP2PItems> itemTunnels;
try
{
itemTunnels = this.getOutputs();
}
catch (GridAccessException e)
{
return new AppEngNullInventory();
}
for (PartP2PItems t : itemTunnels)
{
IInventory inv = t.getOutputInv();
if ( inv != null )
{
if ( Platform.getRandomInt() % 2 == 0 )
outs.add( inv );
else
outs.add( 0, inv );
}
}
return this.cachedInv = new WrapperChainedInventory( outs );
}
@MENetworkEventSubscribe
public void changeStateA(MENetworkBootingStatusChange bs)
public void changeStateA( MENetworkBootingStatusChange bs )
{
if ( !this.output )
if( !this.output )
{
this.cachedInv = null;
int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSizeInventory();
if ( olderSize != this.oldSize )
if( olderSize != this.oldSize )
{
this.getHost().notifyNeighbors();
}
@@ -209,14 +211,14 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeCo
}
@MENetworkEventSubscribe
public void changeStateB(MENetworkChannelsChanged bs)
public void changeStateB( MENetworkChannelsChanged bs )
{
if ( !this.output )
if( !this.output )
{
this.cachedInv = null;
int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSizeInventory();
if ( olderSize != this.oldSize )
if( olderSize != this.oldSize )
{
this.getHost().notifyNeighbors();
}
@@ -224,29 +226,36 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeCo
}
@MENetworkEventSubscribe
public void changeStateC(MENetworkPowerStatusChange bs)
public void changeStateC( MENetworkPowerStatusChange bs )
{
if ( !this.output )
if( !this.output )
{
this.cachedInv = null;
int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSizeInventory();
if ( olderSize != this.oldSize )
if( olderSize != this.oldSize )
{
this.getHost().notifyNeighbors();
}
}
}
@Override
@SideOnly( Side.CLIENT )
public IIcon getTypeTexture()
{
return Blocks.hopper.getBlockTextureFromSide( 0 );
}
@Override
public void onTunnelNetworkChange()
{
if ( !this.output )
if( !this.output )
{
this.cachedInv = null;
int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSizeInventory();
if ( olderSize != this.oldSize )
if( olderSize != this.oldSize )
{
this.getHost().notifyNeighbors();
}
@@ -254,16 +263,18 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeCo
else
{
PartP2PItems input = this.getInput();
if ( input != null )
if( input != null )
input.getHost().notifyNeighbors();
}
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getTypeTexture()
public int[] getAccessibleSlotsFromSide( int var1 )
{
return Blocks.hopper.getBlockTextureFromSide( 0 );
int[] slots = new int[this.getSizeInventory()];
for( int x = 0; x < this.getSizeInventory(); x++ )
slots[x] = x;
return slots;
}
@Override
@@ -273,25 +284,25 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeCo
}
@Override
public ItemStack getStackInSlot(int i)
public ItemStack getStackInSlot( int i )
{
return this.getDestination().getStackInSlot( i );
}
@Override
public ItemStack decrStackSize(int i, int j)
public ItemStack decrStackSize( int i, int j )
{
return this.getDestination().decrStackSize( i, j );
}
@Override
public ItemStack getStackInSlotOnClosing(int i)
public ItemStack getStackInSlotOnClosing( int i )
{
return null;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
public void setInventorySlotContents( int i, ItemStack itemstack )
{
this.getDestination().setInventorySlotContents( i, itemstack );
}
@@ -314,6 +325,18 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeCo
return this.getDestination().getInventoryStackLimit();
}
@Override
public void markDirty()
{
// eh?
}
@Override
public boolean isUseableByPlayer( EntityPlayer entityplayer )
{
return false;
}
@Override
public void openInventory()
{
@@ -325,18 +348,21 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeCo
}
@Override
public boolean isItemValidForSlot(int i, net.minecraft.item.ItemStack itemstack)
public boolean isItemValidForSlot( int i, net.minecraft.item.ItemStack itemstack )
{
return this.getDestination().isItemValidForSlot( i, itemstack );
}
@Override
public int[] getAccessibleSlotsFromSide(int var1)
public boolean canInsertItem( int i, ItemStack itemstack, int j )
{
int[] slots = new int[this.getSizeInventory()];
for (int x = 0; x < this.getSizeInventory(); x++)
slots[x] = x;
return slots;
return this.getDestination().isItemValidForSlot( i, itemstack );
}
@Override
public boolean canExtractItem( int i, ItemStack itemstack, int j )
{
return false;
}
public float getPowerDrainPerTick()
@@ -345,34 +371,9 @@ public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeCo
}
@Override
public boolean canInsertItem(int i, ItemStack itemstack, int j)
{
return this.getDestination().isItemValidForSlot( i, itemstack );
}
@Override
public boolean canExtractItem(int i, ItemStack itemstack, int j)
{
return false;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return false;
}
@Override
@Method(iname = "BC")
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with)
@Method( iname = "BC" )
public ConnectOverride overridePipeConnection( PipeType type, ForgeDirection with )
{
return this.side == with && type == PipeType.ITEM ? ConnectOverride.CONNECT : ConnectOverride.DEFAULT;
}
@Override
public void markDirty()
{
// eh?
}
}
+102 -99
View File
@@ -18,6 +18,7 @@
package appeng.parts.p2p;
import java.io.IOException;
import io.netty.buffer.ByteBuf;
@@ -41,75 +42,73 @@ import appeng.api.networking.ticking.TickingRequest;
import appeng.core.settings.TickRates;
import appeng.me.GridAccessException;
public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTickable
{
public PartP2PLight(ItemStack is) {
super( is );
}
int lastValue = 0;
float opacity = -1;
public void setLightLevel(int out)
public PartP2PLight( ItemStack is )
{
this.lastValue = out;
this.getHost().markForUpdate();
super( is );
}
@Override
public int getLightLevel()
{
if ( this.output && this.isPowered() )
return this.blockLight( this.lastValue );
return 0;
}
private int blockLight(int emit)
{
if ( this.opacity < 0 )
{
TileEntity te = this.getTile();
this.opacity = 255 - te.getWorldObj().getBlockLightOpacity( te.xCoord + this.side.offsetX, te.yCoord + this.side.offsetY, te.zCoord + this.side.offsetZ );
}
return (int) (emit * (this.opacity / 255.0f));
}
@Override
public void chanRender(MENetworkChannelsChanged c)
public void chanRender( MENetworkChannelsChanged c )
{
this.onTunnelNetworkChange();
super.chanRender( c );
}
@Override
public void powerRender(MENetworkPowerStatusChange c)
public void powerRender( MENetworkPowerStatusChange c )
{
this.onTunnelNetworkChange();
super.powerRender( c );
}
@Override
public void onTunnelNetworkChange()
public void writeToStream( ByteBuf data ) throws IOException
{
if ( this.output )
{
PartP2PLight src = this.getInput();
if ( src != null && src.proxy.isActive() )
this.setLightLevel( src.lastValue );
else
this.getHost().markForUpdate();
}
else
this.doWork();
super.writeToStream( data );
data.writeInt( this.output ? this.lastValue : 0 );
}
@Override
public void onTunnelConfigChange()
public boolean readFromStream( ByteBuf data ) throws IOException
{
this.onTunnelNetworkChange();
super.readFromStream( data );
this.lastValue = data.readInt();
this.output = this.lastValue > 0;
return false;
}
private boolean doWork()
{
if( this.output )
return false;
TileEntity te = this.getTile();
World w = te.getWorldObj();
int newLevel = w.getBlockLightValue( te.xCoord + this.side.offsetX, te.yCoord + this.side.offsetY, te.zCoord + this.side.offsetZ );
if( this.lastValue != newLevel && this.proxy.isActive() )
{
this.lastValue = newLevel;
try
{
for( PartP2PLight out : this.getOutputs() )
out.setLightLevel( this.lastValue );
}
catch( GridAccessException e )
{
// :P
}
return true;
}
return false;
}
@Override
@@ -119,12 +118,54 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
this.doWork();
if ( this.output )
if( this.output )
this.getHost().markForUpdate();
}
@Override
public void writeToNBT(NBTTagCompound tag)
public int getLightLevel()
{
if( this.output && this.isPowered() )
return this.blockLight( this.lastValue );
return 0;
}
public void setLightLevel( int out )
{
this.lastValue = out;
this.getHost().markForUpdate();
}
private int blockLight( int emit )
{
if( this.opacity < 0 )
{
TileEntity te = this.getTile();
this.opacity = 255 - te.getWorldObj().getBlockLightOpacity( te.xCoord + this.side.offsetX, te.yCoord + this.side.offsetY, te.zCoord + this.side.offsetZ );
}
return (int) ( emit * ( this.opacity / 255.0f ) );
}
@Override
@SideOnly( Side.CLIENT )
public IIcon getTypeTexture()
{
return Blocks.quartz_block.getBlockTextureFromSide( 0 );
}
@Override
public void readFromNBT( NBTTagCompound tag )
{
super.readFromNBT( tag );
if( tag.hasKey( "opacity" ) )
this.opacity = tag.getFloat( "opacity" );
this.lastValue = tag.getInteger( "lastValue" );
}
@Override
public void writeToNBT( NBTTagCompound tag )
{
super.writeToNBT( tag );
tag.setFloat( "opacity", this.opacity );
@@ -132,78 +173,40 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
}
@Override
public void readFromNBT(NBTTagCompound tag)
public void onTunnelConfigChange()
{
super.readFromNBT( tag );
if ( tag.hasKey( "opacity" ) )
this.opacity = tag.getFloat( "opacity" );
this.lastValue = tag.getInteger( "lastValue" );
this.onTunnelNetworkChange();
}
@Override
public boolean readFromStream(ByteBuf data) throws IOException
public void onTunnelNetworkChange()
{
super.readFromStream( data );
this.lastValue = data.readInt();
this.output = this.lastValue > 0;
return false;
if( this.output )
{
PartP2PLight src = this.getInput();
if( src != null && src.proxy.isActive() )
this.setLightLevel( src.lastValue );
else
this.getHost().markForUpdate();
}
else
this.doWork();
}
@Override
public void writeToStream(ByteBuf data) throws IOException
{
super.writeToStream( data );
data.writeInt( this.output ? this.lastValue : 0 );
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getTypeTexture()
{
return Blocks.quartz_block.getBlockTextureFromSide( 0 );
}
@Override
public TickingRequest getTickingRequest(IGridNode node)
public TickingRequest getTickingRequest( IGridNode node )
{
return new TickingRequest( TickRates.LightTunnel.min, TickRates.LightTunnel.max, false, false );
}
private boolean doWork()
@Override
public TickRateModulation tickingRequest( IGridNode node, int TicksSinceLastCall )
{
if ( this.output )
return false;
TileEntity te = this.getTile();
World w = te.getWorldObj();
int newLevel = w.getBlockLightValue( te.xCoord + this.side.offsetX, te.yCoord + this.side.offsetY, te.zCoord + this.side.offsetZ );
if ( this.lastValue != newLevel && this.proxy.isActive() )
{
this.lastValue = newLevel;
try
{
for (PartP2PLight out : this.getOutputs())
out.setLightLevel( this.lastValue );
}
catch (GridAccessException e)
{
// :P
}
return true;
}
return false;
return this.doWork() ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
public float getPowerDrainPerTick()
{
return 0.5f;
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
{
return this.doWork() ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
}
+119 -120
View File
@@ -18,6 +18,7 @@
package appeng.parts.p2p;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -38,131 +39,58 @@ import cpw.mods.fml.relauncher.SideOnly;
import appeng.me.GridAccessException;
public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFluidHandler
{
static final ThreadLocal<Stack<PartP2PLiquids>> DEPTH = new ThreadLocal<Stack<PartP2PLiquids>>();
private final static FluidTankInfo[] ACTIVE_TANK = new FluidTankInfo[] { new FluidTankInfo( null, 10000 ) };
private final static FluidTankInfo[] INACTIVE_TANK = new FluidTankInfo[] { new FluidTankInfo( null, 0 ) };
IFluidHandler cachedTank;
private int tmpUsed;
public PartP2PLiquids(ItemStack is) {
public PartP2PLiquids( ItemStack is )
{
super( is );
}
private FluidTankInfo[] getTank()
{
if ( this.output )
{
PartP2PLiquids tun = this.getInput();
if ( tun != null )
return ACTIVE_TANK;
}
else
{
try
{
if ( !this.getOutputs().isEmpty() )
return ACTIVE_TANK;
}
catch (GridAccessException e)
{
// :(
}
}
return INACTIVE_TANK;
}
IFluidHandler cachedTank;
public float getPowerDrainPerTick()
{
return 2.0f;
}
private int tmpUsed;
@Override
@SideOnly(Side.CLIENT)
@SideOnly( Side.CLIENT )
public IIcon getTypeTexture()
{
return Blocks.lapis_block.getBlockTextureFromSide( 0 );
}
List<PartP2PLiquids> getOutputs(Fluid input)
{
List<PartP2PLiquids> outs = new LinkedList<PartP2PLiquids>();
try
{
for (PartP2PLiquids l : this.getOutputs())
{
IFluidHandler handler = l.getTarget();
if ( handler != null )
{
if ( handler.canFill( l.side.getOpposite(), input ) )
outs.add( l );
}
}
}
catch (GridAccessException e)
{
// :P
}
return outs;
}
@Override
public void onNeighborChanged()
{
this.cachedTank = null;
if ( this.output )
{
PartP2PLiquids in = this.getInput();
if ( in != null )
in.onTunnelNetworkChange();
}
}
@Override
public void onTunnelNetworkChange()
{
this.cachedTank = null;
}
IFluidHandler getTarget()
@Override
public void onNeighborChanged()
{
if ( !this.proxy.isActive() )
return null;
if ( this.cachedTank != null )
return this.cachedTank;
TileEntity te = this.tile.getWorldObj().getTileEntity( this.tile.xCoord + this.side.offsetX, this.tile.yCoord + this.side.offsetY, this.tile.zCoord + this.side.offsetZ );
if ( te instanceof IFluidHandler )
return this.cachedTank = (IFluidHandler) te;
return null;
}
static final ThreadLocal<Stack<PartP2PLiquids>> DEPTH = new ThreadLocal<Stack<PartP2PLiquids>>();
private Stack<PartP2PLiquids> getDepth()
{
Stack<PartP2PLiquids> s = DEPTH.get();
if ( s == null )
DEPTH.set( s = new Stack<PartP2PLiquids>() );
return s;
this.cachedTank = null;
if( this.output )
{
PartP2PLiquids in = this.getInput();
if( in != null )
in.onTunnelNetworkChange();
}
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
public int fill( ForgeDirection from, FluidStack resource, boolean doFill )
{
Stack<PartP2PLiquids> stack = this.getDepth();
for (PartP2PLiquids t : stack)
if ( t == this )
for( PartP2PLiquids t : stack )
if( t == this )
return 0;
stack.push( this );
@@ -171,32 +99,32 @@ public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFl
int requestTotal = 0;
Iterator<PartP2PLiquids> i = list.iterator();
while (i.hasNext())
while( i.hasNext() )
{
PartP2PLiquids l = i.next();
IFluidHandler tank = l.getTarget();
if ( tank != null )
if( tank != null )
l.tmpUsed = tank.fill( l.side.getOpposite(), resource.copy(), false );
else
l.tmpUsed = 0;
if ( l.tmpUsed <= 0 )
if( l.tmpUsed <= 0 )
i.remove();
else
requestTotal += l.tmpUsed;
}
if ( requestTotal <= 0 )
if( requestTotal <= 0 )
{
if ( stack.pop() != this )
if( stack.pop() != this )
throw new RuntimeException( "Invalid Recursion detected." );
return 0;
}
if ( !doFill )
if( !doFill )
{
if ( stack.pop() != this )
if( stack.pop() != this )
throw new RuntimeException( "Invalid Recursion detected." );
return Math.min( resource.amount, requestTotal );
@@ -206,17 +134,17 @@ public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFl
int used = 0;
i = list.iterator();
while (i.hasNext())
while( i.hasNext() )
{
PartP2PLiquids l = i.next();
FluidStack insert = resource.copy();
insert.amount = (int) Math.ceil( insert.amount * ((double) l.tmpUsed / (double) requestTotal) );
if ( insert.amount > available )
insert.amount = (int) Math.ceil( insert.amount * ( (double) l.tmpUsed / (double) requestTotal ) );
if( insert.amount > available )
insert.amount = available;
IFluidHandler tank = l.getTarget();
if ( tank != null )
if( tank != null )
l.tmpUsed = tank.fill( l.side.getOpposite(), insert.copy(), true );
else
l.tmpUsed = 0;
@@ -225,42 +153,113 @@ public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFl
used += insert.amount;
}
if ( stack.pop() != this )
if( stack.pop() != this )
throw new RuntimeException( "Invalid Recursion detected." );
return used;
}
private Stack<PartP2PLiquids> getDepth()
{
Stack<PartP2PLiquids> s = DEPTH.get();
if( s == null )
DEPTH.set( s = new Stack<PartP2PLiquids>() );
return s;
}
List<PartP2PLiquids> getOutputs( Fluid input )
{
List<PartP2PLiquids> outs = new LinkedList<PartP2PLiquids>();
try
{
for( PartP2PLiquids l : this.getOutputs() )
{
IFluidHandler handler = l.getTarget();
if( handler != null )
{
if( handler.canFill( l.side.getOpposite(), input ) )
outs.add( l );
}
}
}
catch( GridAccessException e )
{
// :P
}
return outs;
}
IFluidHandler getTarget()
{
if( !this.proxy.isActive() )
return null;
if( this.cachedTank != null )
return this.cachedTank;
TileEntity te = this.tile.getWorldObj().getTileEntity( this.tile.xCoord + this.side.offsetX, this.tile.yCoord + this.side.offsetY, this.tile.zCoord + this.side.offsetZ );
if( te instanceof IFluidHandler )
return this.cachedTank = (IFluidHandler) te;
return null;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
public FluidStack drain( ForgeDirection from, FluidStack resource, boolean doDrain )
{
return null;
}
@Override
public FluidStack drain( ForgeDirection from, int maxDrain, boolean doDrain )
{
return null;
}
@Override
public boolean canFill( ForgeDirection from, Fluid fluid )
{
return !this.output && from == this.side && !this.getOutputs( fluid ).isEmpty();
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{
return null;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
public boolean canDrain( ForgeDirection from, Fluid fluid )
{
return false;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
public FluidTankInfo[] getTankInfo( ForgeDirection from )
{
if ( from == this.side )
if( from == this.side )
return this.getTank();
return new FluidTankInfo[0];
}
private FluidTankInfo[] getTank()
{
if( this.output )
{
PartP2PLiquids tun = this.getInput();
if( tun != null )
return ACTIVE_TANK;
}
else
{
try
{
if( !this.getOutputs().isEmpty() )
return ACTIVE_TANK;
}
catch( GridAccessException e )
{
// :(
}
}
return INACTIVE_TANK;
}
}
@@ -56,12 +56,6 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEn
super( is );
}
@Override
public void onTunnelNetworkChange()
{
this.getHost().notifyNeighbors();
}
@Override
@SideOnly( Side.CLIENT )
public IIcon getTypeTexture()
@@ -69,6 +63,12 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEn
return Blocks.iron_block.getBlockTextureFromSide( 0 );
}
@Override
public void onTunnelNetworkChange()
{
this.getHost().notifyNeighbors();
}
@Override
public void onNeighborChanged()
{
@@ -80,15 +80,15 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEn
@Override
public int receiveEnergy( ForgeDirection from, int maxReceive, boolean simulate )
{
if ( this.output )
if( this.output )
return 0;
if ( this.isActive() )
if( this.isActive() )
{
Stack<PartP2PRFPower> stack = this.getDepth();
for ( PartP2PRFPower t : stack )
if ( t == this )
for( PartP2PRFPower t : stack )
if( t == this )
return 0;
stack.push( this );
@@ -97,39 +97,39 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEn
try
{
for ( PartP2PRFPower t : this.getOutputs() )
for( PartP2PRFPower t : this.getOutputs() )
{
if ( Platform.getRandomInt() % 2 > 0 )
if( Platform.getRandomInt() % 2 > 0 )
{
int receiver = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
maxReceive -= receiver;
total += receiver;
if ( maxReceive <= 0 )
if( maxReceive <= 0 )
break;
}
}
if ( maxReceive > 0 )
if( maxReceive > 0 )
{
for ( PartP2PRFPower t : this.getOutputs() )
for( PartP2PRFPower t : this.getOutputs() )
{
int receiver = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
maxReceive -= receiver;
total += receiver;
if ( maxReceive <= 0 )
if( maxReceive <= 0 )
break;
}
}
this.QueueTunnelDrain( PowerUnits.RF, total );
}
catch ( GridAccessException ignored )
catch( GridAccessException ignored )
{
}
if ( stack.pop() != this )
if( stack.pop() != this )
throw new RuntimeException( "Invalid Recursion detected." );
return total;
@@ -142,7 +142,7 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEn
{
Stack<PartP2PRFPower> s = THREAD_STACK.get();
if ( s == null )
if( s == null )
THREAD_STACK.set( s = new Stack<PartP2PRFPower>() );
return s;
@@ -150,17 +150,17 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEn
private IEnergyReceiver getOutput()
{
if ( this.output )
if( this.output )
{
if ( !this.cachedTarget )
if( !this.cachedTarget )
{
TileEntity self = this.getTile();
TileEntity te = self.getWorldObj().getTileEntity( self.xCoord + this.side.offsetX, self.yCoord + this.side.offsetY, self.zCoord + this.side.offsetZ );
this.outputTarget = te instanceof IEnergyReceiver ? ( IEnergyReceiver ) te : null;
this.outputTarget = te instanceof IEnergyReceiver ? (IEnergyReceiver) te : null;
this.cachedTarget = true;
}
if ( this.outputTarget == null || !this.outputTarget.canConnectEnergy( this.side.getOpposite() ) )
if( this.outputTarget == null || !this.outputTarget.canConnectEnergy( this.side.getOpposite() ) )
return NULL_HANDLER;
return this.outputTarget;
@@ -171,32 +171,32 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEn
@Override
public int getEnergyStored( ForgeDirection from )
{
if ( this.output || !this.isActive() )
if( this.output || !this.isActive() )
return 0;
int total = 0;
Stack<PartP2PRFPower> stack = this.getDepth();
for ( PartP2PRFPower t : stack )
if ( t == this )
for( PartP2PRFPower t : stack )
if( t == this )
return 0;
stack.push( this );
try
{
for ( PartP2PRFPower t : this.getOutputs() )
for( PartP2PRFPower t : this.getOutputs() )
{
total += t.getOutput().getEnergyStored( t.side.getOpposite() );
}
}
catch ( GridAccessException e )
catch( GridAccessException e )
{
return 0;
}
if ( stack.pop() != this )
if( stack.pop() != this )
throw new RuntimeException( "Invalid Recursion detected." );
return total;
@@ -205,32 +205,32 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEn
@Override
public int getMaxEnergyStored( ForgeDirection from )
{
if ( this.output || !this.isActive() )
if( this.output || !this.isActive() )
return 0;
int total = 0;
Stack<PartP2PRFPower> stack = this.getDepth();
for ( PartP2PRFPower t : stack )
if ( t == this )
for( PartP2PRFPower t : stack )
if( t == this )
return 0;
stack.push( this );
try
{
for ( PartP2PRFPower t : this.getOutputs() )
for( PartP2PRFPower t : this.getOutputs() )
{
total += t.getOutput().getMaxEnergyStored( t.side.getOpposite() );
}
}
catch ( GridAccessException e )
catch( GridAccessException e )
{
return 0;
}
if ( stack.pop() != this )
if( stack.pop() != this )
throw new RuntimeException( "Invalid Recursion detected." );
return total;
@@ -18,6 +18,7 @@
package appeng.parts.p2p;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRedstoneWire;
import net.minecraft.init.Blocks;
@@ -36,86 +37,50 @@ import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.me.GridAccessException;
import appeng.util.Platform;
public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone>
{
public PartP2PRedstone(ItemStack is) {
int power;
boolean recursive = false;
public PartP2PRedstone( ItemStack is )
{
super( is );
}
int power;
@Override
public boolean canConnectRedstone()
{
return true;
}
@Override
public int isProvidingStrongPower()
{
return this.output ? this.power : 0;
}
@Override
public int isProvidingWeakPower()
{
return this.output ? this.power : 0;
}
@Override
public void onTunnelNetworkChange()
{
this.setNetworkReady();
}
@MENetworkEventSubscribe
public void changeStateA(MENetworkBootingStatusChange bs)
{
this.setNetworkReady();
}
@MENetworkEventSubscribe
public void changeStateB(MENetworkChannelsChanged bs)
{
this.setNetworkReady();
}
@MENetworkEventSubscribe
public void changeStateC(MENetworkPowerStatusChange bs)
public void changeStateA( MENetworkBootingStatusChange bs )
{
this.setNetworkReady();
}
public void setNetworkReady()
{
if ( this.output )
if( this.output )
{
PartP2PRedstone in = this.getInput();
if ( in != null )
if( in != null )
this.putInput( in.power );
}
}
boolean recursive = false;
protected void putInput(Object o)
protected void putInput( Object o )
{
if ( this.recursive )
if( this.recursive )
return;
this.recursive = true;
if ( this.output && this.proxy.isActive() )
if( this.output && this.proxy.isActive() )
{
int newPower = (Integer) o;
if ( this.power != newPower )
if( this.power != newPower )
{
this.power = newPower;
this.notifyNeighbors();
}
}
this.recursive = false;
}
public void notifyNeighbors()
@@ -137,25 +102,43 @@ public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone>
Platform.notifyBlocksOfNeighbors( worldObj, xCoord + 1, yCoord, zCoord );
}
@Override
public void writeToNBT(NBTTagCompound tag)
@MENetworkEventSubscribe
public void changeStateB( MENetworkChannelsChanged bs )
{
super.writeToNBT( tag );
tag.setInteger( "power", this.power );
this.setNetworkReady();
}
@MENetworkEventSubscribe
public void changeStateC( MENetworkPowerStatusChange bs )
{
this.setNetworkReady();
}
@Override
public void readFromNBT(NBTTagCompound tag)
@SideOnly( Side.CLIENT )
public IIcon getTypeTexture()
{
return Blocks.redstone_block.getBlockTextureFromSide( 0 );
}
@Override
public void readFromNBT( NBTTagCompound tag )
{
super.readFromNBT( tag );
this.power = tag.getInteger( "power" );
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getTypeTexture()
public void writeToNBT( NBTTagCompound tag )
{
return Blocks.redstone_block.getBlockTextureFromSide( 0 );
super.writeToNBT( tag );
tag.setInteger( "power", this.power );
}
@Override
public void onTunnelNetworkChange()
{
this.setNetworkReady();
}
public float getPowerDrainPerTick()
@@ -166,17 +149,17 @@ public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone>
@Override
public void onNeighborChanged()
{
if ( !this.output )
if( !this.output )
{
int x = this.tile.xCoord + this.side.offsetX;
int y = this.tile.yCoord + this.side.offsetY;
int z = this.tile.zCoord + this.side.offsetZ;
Block b = this.tile.getWorldObj().getBlock( x, y, z );
if ( b != null && !this.output )
if( b != null && !this.output )
{
int srcSide = this.side.ordinal();
if ( b instanceof BlockRedstoneWire )
if( b instanceof BlockRedstoneWire )
srcSide = 1;
this.power = b.isProvidingStrongPower( this.tile.getWorldObj(), x, y, z, srcSide );
this.power = Math.max( this.power, b.isProvidingWeakPower( this.tile.getWorldObj(), x, y, z, srcSide ) );
@@ -187,19 +170,36 @@ public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone>
}
}
private void sendToOutput(int power)
@Override
public boolean canConnectRedstone()
{
return true;
}
@Override
public int isProvidingStrongPower()
{
return this.output ? this.power : 0;
}
@Override
public int isProvidingWeakPower()
{
return this.output ? this.power : 0;
}
private void sendToOutput( int power )
{
try
{
for (PartP2PRedstone rs : this.getOutputs())
for( PartP2PRedstone rs : this.getOutputs() )
{
rs.putInput( power );
}
}
catch (GridAccessException e)
catch( GridAccessException e )
{
// :P
}
}
}
@@ -72,7 +72,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
public TunnelCollection<T> getCollection( Collection<PartP2PTunnel> collection, Class<? extends PartP2PTunnel> c )
{
if ( this.type.matches( c ) )
if( this.type.matches( c ) )
{
this.type.setSource( collection );
return this.type;
@@ -83,17 +83,17 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
public T getInput()
{
if ( this.freq == 0 )
if( this.freq == 0 )
return null;
PartP2PTunnel tunnel;
try
{
tunnel = this.proxy.getP2P().getInput( this.freq );
if ( this.getClass().isInstance( tunnel ) )
if( this.getClass().isInstance( tunnel ) )
return (T) tunnel;
}
catch ( GridAccessException e )
catch( GridAccessException e )
{
// :P
}
@@ -102,11 +102,19 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
public TunnelCollection<T> getOutputs() throws GridAccessException
{
if ( this.proxy.isActive() )
if( this.proxy.isActive() )
return (TunnelCollection<T>) this.proxy.getP2P().getOutputs( this.freq, this.getClass() );
return new TunnelCollection( new ArrayList(), this.getClass() );
}
@Override
public void getBoxes( IPartCollisionHelper bch )
{
bch.addBox( 5, 5, 12, 11, 11, 13 );
bch.addBox( 3, 3, 13, 13, 13, 14 );
bch.addBox( 2, 2, 14, 14, 14, 16 );
}
@Override
@SideOnly( Side.CLIENT )
public void renderInventory( IPartRenderHelper rh, RenderBlocks renderer )
@@ -128,7 +136,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
protected IIcon getTypeTexture()
{
final Optional<Block> maybeBlock = AEApi.instance().definitions().blocks().quartz().maybeBlock();
if ( maybeBlock.isPresent() )
if( maybeBlock.isPresent() )
{
return maybeBlock.get().getIcon( 0, 0 );
}
@@ -170,11 +178,11 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
@Override
public ItemStack getItemStack( PartItemStack type )
{
if ( type == PartItemStack.World || type == PartItemStack.Network || type == PartItemStack.Wrench || type == PartItemStack.Pick )
if( type == PartItemStack.World || type == PartItemStack.Network || type == PartItemStack.Wrench || type == PartItemStack.Pick )
return super.getItemStack( type );
final Optional<ItemStack> maybeMEStack = AEApi.instance().definitions().parts().p2PTunnelME().maybeStack( 1 );
if ( maybeMEStack.isPresent() )
if( maybeMEStack.isPresent() )
{
return maybeMEStack.get();
}
@@ -198,14 +206,6 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
data.setLong( "freq", this.freq );
}
@Override
public void getBoxes( IPartCollisionHelper bch )
{
bch.addBox( 5, 5, 12, 11, 11, 13 );
bch.addBox( 3, 3, 13, 13, 13, 14 );
bch.addBox( 2, 2, 14, 14, 14, 16 );
}
@Override
public int cableConnectionRenderTo()
{
@@ -227,7 +227,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
// AELog.info( "ID:" + id.toString() + " : " + is.getItemDamage() );
TunnelType tt = AEApi.instance().registries().p2pTunnel().getTunnelTypeByItem( is );
if ( is != null && is.getItem() instanceof IMemoryCard )
if( is != null && is.getItem() instanceof IMemoryCard )
{
IMemoryCard mc = (IMemoryCard) is.getItem();
NBTTagCompound data = mc.getData( is );
@@ -235,18 +235,18 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
ItemStack newType = ItemStack.loadItemStackFromNBT( data );
long freq = data.getLong( "freq" );
if ( newType != null )
if( newType != null )
{
if ( newType.getItem() instanceof IPartItem )
if( newType.getItem() instanceof IPartItem )
{
IPart testPart = ( (IPartItem) newType.getItem() ).createPartFromItemStack( newType );
if ( testPart instanceof PartP2PTunnel )
if( testPart instanceof PartP2PTunnel )
{
this.getHost().removePart( this.side, true );
ForgeDirection dir = this.getHost().addPart( newType, this.side, player );
IPart newBus = this.getHost().getPart( dir );
if ( newBus instanceof PartP2PTunnel )
if( newBus instanceof PartP2PTunnel )
{
PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
newTunnel.output = true;
@@ -256,7 +256,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
P2PCache p2p = newTunnel.proxy.getP2P();
p2p.updateFreq( newTunnel, freq );
}
catch ( GridAccessException e )
catch( GridAccessException e )
{
// :P
}
@@ -271,58 +271,58 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
}
mc.notifyUser( player, MemoryCardMessages.INVALID_MACHINE );
}
else if ( tt != null ) // attunement
else if( tt != null ) // attunement
{
ItemStack newType = null;
final IParts parts = AEApi.instance().definitions().parts();
switch ( tt )
switch( tt )
{
case LIGHT:
for ( ItemStack stack : parts.p2PTunnelLight().maybeStack( 1 ).asSet() )
for( ItemStack stack : parts.p2PTunnelLight().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
case RF_POWER:
for ( ItemStack stack : parts.p2PTunnelRF().maybeStack( 1 ).asSet() )
for( ItemStack stack : parts.p2PTunnelRF().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
case FLUID:
for ( ItemStack stack : parts.p2PTunnelLiquids().maybeStack( 1 ).asSet() )
for( ItemStack stack : parts.p2PTunnelLiquids().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
case IC2_POWER:
for ( ItemStack stack : parts.p2PTunnelEU().maybeStack( 1 ).asSet() )
for( ItemStack stack : parts.p2PTunnelEU().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
case ITEM:
for ( ItemStack stack : parts.p2PTunnelItems().maybeStack( 1 ).asSet() )
for( ItemStack stack : parts.p2PTunnelItems().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
case ME:
for ( ItemStack stack : parts.p2PTunnelME().maybeStack( 1 ).asSet() )
for( ItemStack stack : parts.p2PTunnelME().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
case REDSTONE:
for ( ItemStack stack : parts.p2PTunnelRedstone().maybeStack( 1 ).asSet() )
for( ItemStack stack : parts.p2PTunnelRedstone().maybeStack( 1 ).asSet() )
{
newType = stack;
}
@@ -332,7 +332,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
break;
}
if ( newType != null && !Platform.isSameItem( newType, this.is ) )
if( newType != null && !Platform.isSameItem( newType, this.is ) )
{
boolean oldOutput = this.output;
long myFreq = this.freq;
@@ -341,7 +341,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
ForgeDirection dir = this.getHost().addPart( newType, this.side, player );
IPart newBus = this.getHost().getPart( dir );
if ( newBus instanceof PartP2PTunnel )
if( newBus instanceof PartP2PTunnel )
{
PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
newTunnel.output = oldOutput;
@@ -352,7 +352,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
P2PCache p2p = newTunnel.proxy.getP2P();
p2p.updateFreq( newTunnel, myFreq );
}
catch ( GridAccessException e )
catch( GridAccessException e )
{
// :P
}
@@ -370,7 +370,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
public boolean onPartShiftActivate( EntityPlayer player, Vec3 pos )
{
ItemStack is = player.inventory.getCurrentItem();
if ( is != null && is.getItem() instanceof IMemoryCard )
if( is != null && is.getItem() instanceof IMemoryCard )
{
IMemoryCard mc = (IMemoryCard) is.getItem();
NBTTagCompound data = new NBTTagCompound();
@@ -379,14 +379,14 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
boolean wasOutput = this.output;
this.output = false;
if ( wasOutput || this.freq == 0 )
if( wasOutput || this.freq == 0 )
newFreq = System.currentTimeMillis();
try
{
this.proxy.getP2P().updateFreq( this, newFreq );
}
catch ( GridAccessException e )
catch( GridAccessException e )
{
// :P
}
@@ -430,7 +430,7 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
{
this.proxy.getEnergy().extractAEPower( ae_to_tax, Actionable.MODULATE, PowerMultiplier.ONE );
}
catch ( GridAccessException e )
catch( GridAccessException e )
{
// :P
}
@@ -50,8 +50,8 @@ import appeng.me.helpers.AENetworkProxy;
public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements IGridTickable
{
final AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", null, true );
public final Connections connection = new Connections( this );
final AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", null, true );
public PartP2PTunnelME( ItemStack is )
{
@@ -60,13 +60,6 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
this.outerProxy.setFlags( GridFlags.DENSE_CAPACITY, GridFlags.CANNOT_CARRY_COMPRESSED );
}
@Override
public void setPartHostInfo( ForgeDirection side, IPartHost host, TileEntity tile )
{
super.setPartHostInfo( side, host, tile );
this.outerProxy.setValidSides( EnumSet.of( side ) );
}
@Override
public void readFromNBT( NBTTagCompound extra )
{
@@ -82,10 +75,26 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
}
@Override
public void addToWorld()
public void onTunnelNetworkChange()
{
super.addToWorld();
this.outerProxy.onReady();
super.onTunnelNetworkChange();
if( !this.output )
{
try
{
this.proxy.getTick().wakeDevice( this.proxy.getNode() );
}
catch( GridAccessException e )
{
// :P
}
}
}
@Override
public AECableType getCableConnectionType( ForgeDirection dir )
{
return AECableType.DENSE;
}
@Override
@@ -95,6 +104,20 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
this.outerProxy.invalidate();
}
@Override
public void addToWorld()
{
super.addToWorld();
this.outerProxy.onReady();
}
@Override
public void setPartHostInfo( ForgeDirection side, IPartHost host, TileEntity tile )
{
super.setPartHostInfo( side, host, tile );
this.outerProxy.setValidSides( EnumSet.of( side ) );
}
@Override
public IGridNode getExternalFacingNode()
{
@@ -102,26 +125,10 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
}
@Override
public AECableType getCableConnectionType( ForgeDirection dir )
public void onPlacement( EntityPlayer player, ItemStack held, ForgeDirection side )
{
return AECableType.DENSE;
}
@Override
public void onTunnelNetworkChange()
{
super.onTunnelNetworkChange();
if ( !this.output )
{
try
{
this.proxy.getTick().wakeDevice( this.proxy.getNode() );
}
catch ( GridAccessException e )
{
// :P
}
}
super.onPlacement( player, held, side );
this.outerProxy.setOwner( player );
}
@Override
@@ -136,16 +143,16 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
// just move on...
try
{
if ( !this.proxy.getPath().isNetworkBooting() )
if( !this.proxy.getPath().isNetworkBooting() )
{
if ( !this.proxy.getEnergy().isNetworkPowered() )
if( !this.proxy.getEnergy().isNetworkPowered() )
{
this.connection.markDestroy();
TickHandler.INSTANCE.addCallable( this.tile.getWorldObj(), this.connection );
}
else
{
if ( this.proxy.isActive() )
if( this.proxy.isActive() )
{
this.connection.markCreate();
TickHandler.INSTANCE.addCallable( this.tile.getWorldObj(), this.connection );
@@ -160,7 +167,7 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
return TickRateModulation.SLEEP;
}
}
catch ( GridAccessException e )
catch( GridAccessException e )
{
// meh?
}
@@ -168,43 +175,36 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
return TickRateModulation.IDLE;
}
@Override
public void onPlacement( EntityPlayer player, ItemStack held, ForgeDirection side )
{
super.onPlacement( player, held, side );
this.outerProxy.setOwner( player );
}
public void updateConnections( Connections connections )
{
if ( connections.destroy )
if( connections.destroy )
{
for ( TunnelConnection cw : this.connection.connections.values() )
for( TunnelConnection cw : this.connection.connections.values() )
cw.c.destroy();
this.connection.connections.clear();
}
else if ( connections.create )
else if( connections.create )
{
Iterator<TunnelConnection> i = this.connection.connections.values().iterator();
while ( i.hasNext() )
while( i.hasNext() )
{
TunnelConnection cw = i.next();
try
{
if ( cw.tunnel.proxy.getGrid() != this.proxy.getGrid() )
if( cw.tunnel.proxy.getGrid() != this.proxy.getGrid() )
{
cw.c.destroy();
i.remove();
}
else if ( !cw.tunnel.proxy.isActive() )
else if( !cw.tunnel.proxy.isActive() )
{
cw.c.destroy();
i.remove();
}
}
catch ( GridAccessException e )
catch( GridAccessException e )
{
// :P
}
@@ -213,22 +213,21 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
LinkedList<PartP2PTunnelME> newSides = new LinkedList<PartP2PTunnelME>();
try
{
for ( PartP2PTunnelME me : this.getOutputs() )
for( PartP2PTunnelME me : this.getOutputs() )
{
if ( me.proxy.isActive() && connections.connections.get( me.getGridNode() ) == null )
if( me.proxy.isActive() && connections.connections.get( me.getGridNode() ) == null )
{
newSides.add( me );
}
}
for ( PartP2PTunnelME me : newSides )
for( PartP2PTunnelME me : newSides )
{
try
{
connections.connections.put( me.getGridNode(),
new TunnelConnection( me, AEApi.instance().createGridConnection( this.outerProxy.getNode(), me.outerProxy.getNode() ) ) );
connections.connections.put( me.getGridNode(), new TunnelConnection( me, AEApi.instance().createGridConnection( this.outerProxy.getNode(), me.outerProxy.getNode() ) ) );
}
catch ( FailedConnection e )
catch( FailedConnection e )
{
final TileEntity start = this.getTile();
final TileEntity end = me.getTile();
@@ -237,7 +236,7 @@ public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements I
}
}
}
catch ( GridAccessException e )
catch( GridAccessException e )
{
AELog.error( e );
}