Applied-Energistics-2-tiler.../src/main/java/appeng/parts/networking/PartCableSmart.java

116 lines
3 KiB
Java
Raw Normal View History

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>.
*/
2014-09-24 02:26:27 +02:00
package appeng.parts.networking;
import com.google.common.collect.ImmutableMap;
2014-09-24 02:26:27 +02:00
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
2014-09-24 02:26:27 +02:00
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.util.AECableType;
2015-06-16 02:44:59 +02:00
import appeng.api.util.AEPartLocation;
import appeng.helpers.Reflected;
2014-09-24 02:26:27 +02:00
import appeng.util.Platform;
2014-09-24 02:26:27 +02:00
public class PartCableSmart extends PartCable
{
@Reflected
2015-09-30 14:24:40 +02:00
public PartCableSmart( final ItemStack is )
{
super( is );
}
2014-09-24 02:26:27 +02:00
@MENetworkEventSubscribe
2015-09-30 14:24:40 +02:00
public void channelUpdated( final MENetworkChannelsChanged c )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.getHost().markForUpdate();
2014-09-24 02:26:27 +02:00
}
@MENetworkEventSubscribe
2015-09-30 14:24:40 +02:00
public void powerRender( final MENetworkPowerStatusChange c )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.getHost().markForUpdate();
2014-09-24 02:26:27 +02:00
}
@Override
public AECableType getCableConnectionType()
{
return AECableType.SMART;
}
@Override
2015-09-30 14:24:40 +02:00
public void getBoxes( final IPartCollisionHelper bch )
2014-09-24 02:26:27 +02:00
{
bch.addBox( 5.0, 5.0, 5.0, 11.0, 11.0, 11.0 );
if( Platform.isServer() )
{
2015-09-30 14:24:40 +02:00
final IGridNode n = this.getGridNode();
if( n != null )
2015-04-29 02:30:53 +02:00
{
this.setConnections( n.getConnectedSides() );
2015-04-29 02:30:53 +02:00
}
else
2015-04-29 02:30:53 +02:00
{
this.getConnections().clear();
2015-04-29 02:30:53 +02:00
}
}
for( final AEPartLocation of : this.getConnections() )
{
switch( of )
{
case DOWN:
bch.addBox( 5.0, 0.0, 5.0, 11.0, 5.0, 11.0 );
break;
case EAST:
bch.addBox( 11.0, 5.0, 5.0, 16.0, 11.0, 11.0 );
break;
case NORTH:
bch.addBox( 5.0, 5.0, 0.0, 11.0, 11.0, 5.0 );
break;
case SOUTH:
bch.addBox( 5.0, 5.0, 11.0, 11.0, 11.0, 16.0 );
break;
case UP:
bch.addBox( 5.0, 11.0, 5.0, 11.0, 16.0, 11.0 );
break;
case WEST:
bch.addBox( 0.0, 5.0, 5.0, 5.0, 11.0, 11.0 );
break;
default:
}
}
2014-09-24 02:26:27 +02:00
}
@Override
protected ImmutableMap.Builder<String, String> propertiesForModel( EnumFacing facing )
{
return facing != null ? super.propertiesForModel( facing ).put( "channels", String.valueOf( getChannelsOnSide( facing.ordinal() ) ) ) : super.propertiesForModel( facing );
}
2014-09-24 02:26:27 +02:00
}