Applied-Energistics-2-tiler.../block/networking/BlockCableBus.java

314 lines
8.6 KiB
Java
Raw Normal View History

package appeng.block.networking;
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
2014-01-29 04:10:23 +01:00
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
2014-02-09 02:34:52 +01:00
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
2013-12-28 21:54:05 +01:00
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
2014-02-09 02:34:52 +01:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
2014-02-09 02:34:52 +01:00
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
2014-02-09 02:34:52 +01:00
import net.minecraftforge.common.util.ForgeDirection;
2014-01-20 17:41:37 +01:00
import appeng.api.parts.PartItemStack;
import appeng.api.parts.SelectedPart;
import appeng.block.AEBaseBlock;
import appeng.client.render.BaseBlockRender;
import appeng.client.render.BusRenderHelper;
import appeng.client.render.blocks.RendererCableBus;
2014-02-09 02:34:52 +01:00
import appeng.client.texture.ExtraTextures;
import appeng.core.AEConfig;
import appeng.core.Api;
import appeng.core.AppEng;
2014-01-20 17:41:37 +01:00
import appeng.core.CommonHelper;
import appeng.core.features.AEFeature;
import appeng.integration.abstraction.IFMP;
2014-01-20 17:41:37 +01:00
import appeng.parts.ICableBusContainer;
import appeng.parts.NullCableBusContainer;
import appeng.tile.AEBaseTile;
import appeng.tile.networking.TileCableBus;
import appeng.tile.networking.TileCableBusTESR;
2014-01-28 20:27:22 +01:00
import appeng.util.Platform;
public class BlockCableBus extends AEBaseBlock
{
2014-01-20 17:41:37 +01:00
static private ICableBusContainer nullCB = new NullCableBusContainer();
static public Class<? extends TileEntity> noTesrTile;
static public Class<? extends TileEntity> tesrTile;
public <T extends TileEntity> T getTileEntity(IBlockAccess w, int x, int y, int z)
{
TileEntity te = w.getTileEntity( x, y, z );
if ( noTesrTile.isInstance( te ) )
return (T) te;
2014-05-24 17:29:45 +02:00
if ( tesrTile != null && tesrTile.isInstance( te ) )
return (T) te;
return null;
}
2014-01-20 17:41:37 +01:00
public BlockCableBus() {
super( BlockCableBus.class, Material.glass );
setfeature( EnumSet.of( AEFeature.Core ) );
setLightOpacity( 0 );
isFullSize = isOpaque = false;
}
@Override
public int getRenderBlockPass()
{
if ( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) )
return 1;
return 0;
}
@Override
public boolean canRenderInPass(int pass)
{
BusRenderHelper.instance.setPass( pass );
if ( AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) )
return true;
return pass == 0;
}
2013-12-28 21:54:05 +01:00
@Override
2014-02-09 02:34:52 +01:00
public boolean isLadder(IBlockAccess world, int x, int y, int z, EntityLivingBase entity)
2013-12-28 21:54:05 +01:00
{
2014-05-29 18:40:42 +02:00
ICableBusContainer cbc = cb( world, x, y, z );
return cbc == null ? false : cbc.isLadder( entity );
2013-12-28 21:54:05 +01:00
}
@Override
public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour)
2014-03-27 04:27:14 +01:00
{
return recolourBlock( world, x, y, z, side, colour, null );
}
public boolean recolourBlock(World world, int x, int y, int z, ForgeDirection side, int colour, EntityPlayer who)
{
2014-05-29 18:40:42 +02:00
ICableBusContainer cbc = cb( world, x, y, z );
return cbc == null ? false : cbc.recolourBlock( side, colour, who );
}
@Override
public void randomDisplayTick(World world, int x, int y, int z, Random r)
{
2014-05-29 18:40:42 +02:00
ICableBusContainer cbc = cb( world, x, y, z );
if( cbc != null )
cbc.randomDisplayTick( world, x, y, z, r );
}
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z)
{
2014-02-09 02:34:52 +01:00
Block block = world.getBlock( x, y, z );
2014-05-29 18:40:42 +02:00
2014-01-29 04:10:23 +01:00
if ( block != null && block != this )
{
return block.getLightValue( world, x, y, z );
}
2014-05-29 18:40:42 +02:00
2014-01-29 04:10:23 +01:00
if ( block == null )
return 0;
2014-05-29 18:40:42 +02:00
ICableBusContainer cbc = cb( world, x, y, z );
return cbc == null ? 0 : cbc.getLightValue();
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
Vec3 v3 = target.hitVec.addVector( -x, -y, -z );
SelectedPart sp = cb( world, x, y, z ).selectPart( v3 );
2014-01-20 17:41:37 +01:00
if ( sp.part != null )
return sp.part.getItemStack( PartItemStack.Pick );
2014-01-20 17:41:37 +01:00
else if ( sp.facade != null )
return sp.facade.getItemStack();
return null;
}
@Override
2014-02-09 02:34:52 +01:00
public boolean isReplaceable(IBlockAccess world, int x, int y, int z)
{
2014-05-29 18:40:42 +02:00
ICableBusContainer cbc = cb( world, x, y, z );
return cbc == null ? false : cbc.isEmpty();
}
@Override
2014-02-09 02:34:52 +01:00
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z)
{
if ( player.capabilities.isCreativeMode )
{
AEBaseTile tile = getTileEntity( world, x, y, z );
if ( tile != null )
tile.dropItems = false;
// maybe ray trace?
}
2014-05-29 18:40:42 +02:00
2014-02-09 02:34:52 +01:00
return super.removedByPlayer( world, player, x, y, z );
}
@Override
2014-02-09 02:34:52 +01:00
public IIcon getIcon(IBlockAccess w, int x, int y, int z, int s)
{
return getIcon( s, 0 );
}
@Override
2014-02-09 02:34:52 +01:00
public IIcon getIcon(int direction, int metadata)
{
2014-02-09 02:34:52 +01:00
IIcon i = super.getIcon( direction, metadata );
if ( i != null )
return i;
2014-02-09 02:34:52 +01:00
return ExtraTextures.BlockQuartzGlassB.getIcon();
}
@Override
protected Class<? extends BaseBlockRender> getRenderer()
{
return RendererCableBus.class;
}
@Override
2014-02-09 02:34:52 +01:00
public void registerBlockIcons(IIconRegister iconRegistry)
{
}
@Override
public boolean canProvidePower()
{
return true;
}
@Override
2014-05-29 18:40:42 +02:00
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side)
{
2014-05-29 18:40:42 +02:00
ICableBusContainer cbc = cb( world, x, y, z );
return cbc == null ? false : cbc.isSolidOnSide( side );
}
@Override
2014-05-29 18:40:42 +02:00
public void onNeighborBlockChange(World world, int x, int y, int z, Block meh)
{
2014-05-29 18:40:42 +02:00
ICableBusContainer cbc = cb( world, x, y, z );
if ( cbc != null )
cbc.onNeighborChanged();
}
2014-01-01 07:30:52 +01:00
@Override
2014-02-09 02:34:52 +01:00
public Item getItemDropped(int i, Random r, int k)
2014-01-01 07:30:52 +01:00
{
2014-02-09 02:34:52 +01:00
return null;
2014-01-01 07:30:52 +01:00
}
@Override
2014-05-29 18:40:42 +02:00
public boolean onActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
2014-05-29 18:40:42 +02:00
ICableBusContainer cbc = cb( world, x, y, z );
return cbc == null ? false : cbc.activate( player, world.getWorldVec3Pool().getVecFromPool( hitX, hitY, hitZ ) );
}
@Override
2014-05-29 18:40:42 +02:00
public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity e)
{
2014-05-29 18:40:42 +02:00
ICableBusContainer cbc = cb( world, x, y, z );
if ( cbc != null )
cbc.onEntityCollision( e );
}
@Override
2014-05-29 18:40:42 +02:00
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side)
{
2014-05-29 18:40:42 +02:00
ICableBusContainer cbc = cb( world, x, y, z );
if ( cbc != null )
2014-01-06 07:54:51 +01:00
{
2014-05-29 18:40:42 +02:00
switch (side)
{
case -1:
case 4:
return cb( world, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN ) );
case 0:
return cb( world, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.NORTH ) );
case 1:
return cb( world, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.EAST ) );
case 2:
return cb( world, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.SOUTH ) );
case 3:
return cb( world, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.WEST ) );
}
2014-01-06 07:54:51 +01:00
}
2014-05-29 18:40:42 +02:00
2014-01-06 07:54:51 +01:00
return false;
}
@Override
2014-05-29 18:40:42 +02:00
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side)
{
2014-05-29 18:40:42 +02:00
ICableBusContainer cbc = cb( world, x, y, z );
return cbc == null ? 0 : cbc.isProvidingWeakPower( ForgeDirection.getOrientation( side ).getOpposite() );
}
@Override
2014-05-29 18:40:42 +02:00
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side)
{
2014-05-29 18:40:42 +02:00
ICableBusContainer cbc = cb( world, x, y, z );
return cbc == null ? 0 : cbc.isProvidingStrongPower( ForgeDirection.getOrientation( side ).getOpposite() );
}
@Override
2014-02-09 02:34:52 +01:00
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
}
public void setupTile()
{
setTileEntiy( noTesrTile = Api.instance.partHelper.getCombinedInstance( TileCableBus.class.getName() ) );
2014-01-28 20:27:22 +01:00
if ( Platform.isClient() )
{
tesrTile = Api.instance.partHelper.getCombinedInstance( TileCableBusTESR.class.getName() );
CommonHelper.proxy.bindTileEntitySpecialRenderer( tesrTile, this );
}
2014-01-20 17:41:37 +01:00
}
private ICableBusContainer cb(IBlockAccess w, int x, int y, int z)
{
2014-02-09 02:34:52 +01:00
TileEntity te = w.getTileEntity( x, y, z );
ICableBusContainer out = null;
2014-01-20 17:41:37 +01:00
if ( te instanceof TileCableBus )
out = ((TileCableBus) te).cb;
2014-01-20 17:41:37 +01:00
else if ( AppEng.instance.isIntegrationEnabled( "FMP" ) )
out = ((IFMP) AppEng.instance.getIntegration( "FMP" )).getCableContainer( te );
2014-01-20 17:41:37 +01:00
return out == null ? nullCB : out;
}
2014-03-22 22:51:37 +01:00
/**
* Immibis MB Support.
*/
boolean ImmibisMicroblocks_TransformableBlockMarker = true;
}