2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.debug;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.EnumSet;
|
2014-08-21 18:44:55 +02:00
|
|
|
import java.util.HashSet;
|
2015-01-03 02:53:14 +01:00
|
|
|
import java.util.Set;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
import net.minecraft.command.ICommandSender;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.util.ChatComponentText;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.world.World;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.IGridConnection;
|
|
|
|
import appeng.api.networking.IGridHost;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.energy.IAEPowerStorage;
|
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
2014-08-21 18:44:55 +02:00
|
|
|
import appeng.api.networking.pathing.ControllerState;
|
|
|
|
import appeng.api.networking.pathing.IPathingGrid;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.ticking.ITickManager;
|
|
|
|
import appeng.api.parts.IPart;
|
|
|
|
import appeng.api.parts.IPartHost;
|
|
|
|
import appeng.core.features.AEFeature;
|
2014-03-02 09:35:11 +01:00
|
|
|
import appeng.hooks.TickHandler;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.items.AEBaseItem;
|
|
|
|
import appeng.me.Grid;
|
|
|
|
import appeng.me.GridNode;
|
|
|
|
import appeng.me.cache.TickManagerCache;
|
2014-01-22 05:52:48 +01:00
|
|
|
import appeng.parts.p2p.PartP2PTunnel;
|
2014-08-21 18:44:55 +02:00
|
|
|
import appeng.tile.networking.TileController;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public class ToolDebugCard extends AEBaseItem
|
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
public ToolDebugCard()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.setFeature( EnumSet.of( AEFeature.UnsupportedDeveloperTools, AEFeature.Creative ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-01-03 02:53:14 +01:00
|
|
|
public boolean onItemUseFirst( ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isClient() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( player.isSneaking() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
int grids = 0;
|
|
|
|
int totalNodes = 0;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( Grid g : TickHandler.INSTANCE.getGridList() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
grids++;
|
2014-01-23 17:28:12 +01:00
|
|
|
totalNodes += g.getNodes().size();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-01-23 17:28:12 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "Grids: " + grids );
|
|
|
|
this.outputMsg( player, "Total Nodes: " + totalNodes );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
TileEntity te = world.getTileEntity( x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te instanceof IGridHost )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
GridNode node = (GridNode) ( (IGridHost) te ).getGridNode( ForgeDirection.getOrientation( side ) );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( node != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
Grid g = node.getInternalGrid();
|
|
|
|
IGridNode center = g.getPivot();
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "This Node: " + node.toString() );
|
|
|
|
this.outputMsg( player, "Center Node: " + center.toString() );
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2014-08-21 18:44:55 +02:00
|
|
|
IPathingGrid pg = g.getCache( IPathingGrid.class );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pg.getControllerState() == ControllerState.CONTROLLER_ONLINE )
|
2014-08-21 18:44:55 +02:00
|
|
|
{
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
Set<IGridNode> next = new HashSet<IGridNode>();
|
2014-08-21 18:44:55 +02:00
|
|
|
next.add( node );
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2014-08-21 18:44:55 +02:00
|
|
|
int maxLength = 10000;
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2015-09-25 22:52:41 +02:00
|
|
|
int length = 0;
|
2015-01-03 02:53:14 +01:00
|
|
|
outer:
|
2015-04-03 08:54:31 +02:00
|
|
|
while( !next.isEmpty() )
|
2014-08-21 18:44:55 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
Iterable<IGridNode> current = next;
|
2014-09-28 22:20:14 +02:00
|
|
|
next = new HashSet<IGridNode>();
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IGridNode n : current )
|
2014-08-21 18:44:55 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( n.getMachine() instanceof TileController )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-08-21 18:44:55 +02:00
|
|
|
break outer;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IGridConnection c : n.getConnections() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-08-21 18:44:55 +02:00
|
|
|
next.add( c.getOtherSide( n ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-21 18:44:55 +02:00
|
|
|
}
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2014-08-21 18:44:55 +02:00
|
|
|
length++;
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( length > maxLength )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-08-21 18:44:55 +02:00
|
|
|
break;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-21 18:44:55 +02:00
|
|
|
}
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "Cable Distance: " + length );
|
2014-08-21 18:44:55 +02:00
|
|
|
}
|
2015-02-03 12:04:13 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( center.getMachine() instanceof PartP2PTunnel )
|
2014-01-22 05:52:48 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
this.outputMsg( player, "Freq: " + ( (PartP2PTunnel) center.getMachine() ).freq );
|
2014-01-22 05:52:48 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-09-29 09:42:50 +02:00
|
|
|
TickManagerCache tmc = g.getCache( ITickManager.class );
|
2015-04-03 08:54:31 +02:00
|
|
|
for( Class<? extends IGridHost> c : g.getMachineClasses() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
int o = 0;
|
|
|
|
long nanos = 0;
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IGridNode oj : g.getMachines( c ) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
o++;
|
|
|
|
nanos += tmc.getAvgNanoTime( oj );
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( nanos < 0 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, c.getSimpleName() + " - " + o );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, c.getSimpleName() + " - " + o + "; " + this.timeMeasurement( nanos ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "No Node Available." );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "Not Networked Block" );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te instanceof IPartHost )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
IPart center = ( (IPartHost) te ).getPart( ForgeDirection.UNKNOWN );
|
|
|
|
( (IPartHost) te ).markForUpdate();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( center != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
GridNode n = (GridNode) center.getGridNode();
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "Node Channels: " + n.usedChannels() );
|
2015-04-03 08:54:31 +02:00
|
|
|
for( IGridConnection gc : n.getConnections() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
ForgeDirection fd = gc.getDirection( n );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( fd != ForgeDirection.UNKNOWN )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, fd.toString() + ": " + gc.getUsedChannels() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te instanceof IAEPowerStorage )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
IAEPowerStorage ps = (IAEPowerStorage) te;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "Energy: " + ps.getAECurrentPower() + " / " + ps.getAEMaxPower() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te instanceof IGridHost )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
IGridNode node = ( (IGridHost) te ).getGridNode( ForgeDirection.getOrientation( side ) );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( node != null && node.getGrid() != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
IEnergyGrid eg = node.getGrid().getCache( IEnergyGrid.class );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.outputMsg( player, "GridEnergy: " + eg.getStoredPower() + " : " + eg.getEnergyDemand( Double.MAX_VALUE ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
private void outputMsg( ICommandSender player, String string )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
player.addChatMessage( new ChatComponentText( string ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
public String timeMeasurement( long nanos )
|
|
|
|
{
|
|
|
|
long ms = nanos / 100000;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( nanos <= 100000 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-03 02:53:14 +01:00
|
|
|
return nanos + "ns";
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-01-03 02:53:14 +01:00
|
|
|
return ( ms / 10.0f ) + "ms";
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|