Err too much.
This commit is contained in:
+159
-19
@@ -1,17 +1,34 @@
|
||||
package appeng.tile.qnb;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
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.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cluster.IAECluster;
|
||||
import appeng.me.cluster.IAEMultiBlock;
|
||||
import appeng.me.cluster.implementations.QuantumCalculator;
|
||||
import appeng.me.cluster.implementations.QuantumCluster;
|
||||
import appeng.tile.grid.AENetworkPowerTile;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkInvTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class TileQuantumBridge extends AENetworkPowerTile implements IAEMultiBlock
|
||||
public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
{
|
||||
|
||||
final int sidesRing[] = new int[] {};
|
||||
@@ -19,28 +36,87 @@ public class TileQuantumBridge extends AENetworkPowerTile implements IAEMultiBlo
|
||||
|
||||
AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 );
|
||||
|
||||
final byte start = 8 + 7;
|
||||
public final byte corner = 16;
|
||||
final byte hasSingularity = 32;
|
||||
final byte powered = 64;
|
||||
|
||||
// private QuantumCalculator calc = new QuantumCalculator( this );
|
||||
int oldxdex = -1;
|
||||
private QuantumCalculator calc = new QuantumCalculator( this );
|
||||
byte xdex = -1;
|
||||
|
||||
QuantumCluster clust;
|
||||
public boolean bridgePowered;
|
||||
|
||||
@Override
|
||||
private boolean updateStatus = false;
|
||||
|
||||
class QBridgeHandler extends AETileEventHandler
|
||||
{
|
||||
|
||||
public QBridgeHandler() {
|
||||
super( EnumSet.of( TileEventType.NETWORK, TileEventType.TICK ) );
|
||||
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
gridProxy.setFlags( GridFlags.TIER_2_CAPACITY );
|
||||
gridProxy.setIdlePowerUsage( 22 );
|
||||
inv.setMaxStackSize( 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Tick()
|
||||
{
|
||||
if ( updateStatus )
|
||||
{
|
||||
updateStatus = false;
|
||||
if ( clust != null )
|
||||
clust.updateStatus( true );
|
||||
markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(DataOutputStream data) throws IOException
|
||||
{
|
||||
int out = xdex;
|
||||
|
||||
if ( getStackInSlot( 0 ) != null && xdex != -1 )
|
||||
out = out | hasSingularity;
|
||||
|
||||
if ( gridProxy.isActive() && xdex != -1 )
|
||||
out = out | powered;
|
||||
|
||||
data.writeByte( (byte) out );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(DataInputStream data) throws IOException
|
||||
{
|
||||
int oldValue = xdex;
|
||||
xdex = data.readByte();
|
||||
bridgePowered = (xdex | powered) == powered;
|
||||
return xdex != oldValue;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public TileQuantumBridge() {
|
||||
addNewHandler( new QBridgeHandler() );
|
||||
gridProxy.setFlags( GridFlags.TIER_2_CAPACITY );
|
||||
}
|
||||
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return inv;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void PowerSwitch(MENetworkPowerStatusChange c)
|
||||
{
|
||||
updateStatus = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
{
|
||||
|
||||
if ( clust != null )
|
||||
clust.updateStatus( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,33 +130,51 @@ public class TileQuantumBridge extends AENetworkPowerTile implements IAEMultiBlo
|
||||
@Override
|
||||
public void disconnect()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
if ( clust != null )
|
||||
clust.destroy();
|
||||
clust = null;
|
||||
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAECluster getCluster()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return clust;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return !isInvalid();
|
||||
}
|
||||
|
||||
public void updateStatus(QuantumCluster c, byte fish)
|
||||
public void updateStatus(QuantumCluster c, byte flags)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
clust = c;
|
||||
|
||||
if ( xdex != flags )
|
||||
{
|
||||
xdex = flags;
|
||||
markForUpdate();
|
||||
}
|
||||
|
||||
if ( isCorner() || isCenter() )
|
||||
{
|
||||
gridProxy.setValidSides( getConnections() );
|
||||
}
|
||||
else
|
||||
gridProxy.setValidSides( EnumSet.allOf( ForgeDirection.class ) );
|
||||
}
|
||||
|
||||
public long getQEDest()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
ItemStack is = inv.getStackInSlot( 0 );
|
||||
if ( is != null )
|
||||
{
|
||||
NBTTagCompound c = is.getTagCompound();
|
||||
if ( c != null )
|
||||
return c.getLong( "freq" );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -91,14 +185,22 @@ public class TileQuantumBridge extends AENetworkPowerTile implements IAEMultiBlo
|
||||
|
||||
public boolean isCorner()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return (xdex & corner) == corner && xdex != -1;
|
||||
}
|
||||
|
||||
public boolean isPowered()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return (xdex & powered) == powered;
|
||||
return (xdex & powered) == powered && xdex != -1;
|
||||
|
||||
try
|
||||
{
|
||||
return gridProxy.getEnergy().isNetworkPowered();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -108,4 +210,42 @@ public class TileQuantumBridge extends AENetworkPowerTile implements IAEMultiBlo
|
||||
return xdex != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.DENSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
return new DimensionalCoord( this );
|
||||
}
|
||||
|
||||
public void neighborUpdate()
|
||||
{
|
||||
calc.calculateMultiblock( worldObj, getLocation() );
|
||||
}
|
||||
|
||||
public EnumSet<ForgeDirection> getConnections()
|
||||
{
|
||||
EnumSet<ForgeDirection> set = EnumSet.noneOf( ForgeDirection.class );
|
||||
|
||||
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity te = worldObj.getBlockTileEntity( xCoord + d.offsetX, yCoord + d.offsetY, zCoord + d.offsetZ );
|
||||
if ( te instanceof TileQuantumBridge )
|
||||
set.add( d );
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
public boolean hasQES()
|
||||
{
|
||||
if ( xdex == -1 )
|
||||
return false;
|
||||
return (xdex & hasSingularity) == hasSingularity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user