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

414 lines
11 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;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.particle.EntityDiggingFX;
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;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
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;
import appeng.client.texture.ExtraBlockTextures;
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;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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;
}
@SideOnly(Side.CLIENT)
public boolean addHitEffects(World world, MovingObjectPosition target, EffectRenderer effectRenderer)
{
Object pobj = cb( world, target.blockX, target.blockY, target.blockZ );
if ( pobj instanceof IPartHost )
{
IPartHost host = (IPartHost) pobj;
for (ForgeDirection side : ForgeDirection.values())
{
IPart p = host.getPart( side );
IIcon ico = getIcon( p );
if ( ico == null )
continue;
byte b0 = (byte) (Platform.getRandomInt() % 2 == 0 ? 1 : 0);
for (int i1 = 0; i1 < b0; ++i1)
{
for (int j1 = 0; j1 < b0; ++j1)
{
for (int k1 = 0; k1 < b0; ++k1)
{
double d0 = (double) target.blockX + ((double) i1 + 0.5D) / (double) b0;
double d1 = (double) target.blockY + ((double) j1 + 0.5D) / (double) b0;
double d2 = (double) target.blockZ + ((double) k1 + 0.5D) / (double) b0;
double dd0 = target.hitVec.xCoord;
double dd1 = target.hitVec.yCoord;
double dd2 = target.hitVec.zCoord;
EntityDiggingFX fx = (new EntityDiggingFX( world, dd0, dd1, dd2, d0 - (double) target.blockX - 0.5D, d1 - (double) target.blockY
- 0.5D, d2 - (double) target.blockZ - 0.5D, this, 0 )).applyColourMultiplier( target.blockX, target.blockY, target.blockZ );
fx.setParticleIcon( ico );
effectRenderer.addEffect( fx );
}
}
}
}
}
return true;
}
@SideOnly(Side.CLIENT)
public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer)
{
Object pobj = cb( world, x, y, z );
if ( pobj instanceof IPartHost )
{
IPartHost host = (IPartHost) pobj;
for (ForgeDirection side : ForgeDirection.values())
{
IPart p = host.getPart( side );
IIcon ico = getIcon( p );
if ( ico == null )
continue;
byte b0 = 3;
for (int i1 = 0; i1 < b0; ++i1)
{
for (int j1 = 0; j1 < b0; ++j1)
{
for (int k1 = 0; k1 < b0; ++k1)
{
double d0 = (double) x + ((double) i1 + 0.5D) / (double) b0;
double d1 = (double) y + ((double) j1 + 0.5D) / (double) b0;
double d2 = (double) z + ((double) k1 + 0.5D) / (double) b0;
EntityDiggingFX fx = (new EntityDiggingFX( world, d0, d1, d2, d0 - (double) x - 0.5D, d1 - (double) y - 0.5D, d2 - (double) z
- 0.5D, this, meta )).applyColourMultiplier( x, y, z );
fx.setParticleIcon( ico );
effectRenderer.addEffect( fx );
}
}
}
}
}
return true;
}
private IIcon getIcon(IPart p)
{
if ( p == null )
return null;
try
{
IIcon ico = p.getBreakingTexture();
if ( ico != null )
return ico;
}
catch (Throwable t)
{
// nothing.
}
ItemStack is = p.getItemStack( PartItemStack.Network );
if ( is == null || is.getItem() == null )
return null;
return is.getItem().getIcon( is, 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-01-20 17:41:37 +01:00
return cb( world, x, y, z ).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)
{
try
{
2014-03-27 04:27:14 +01:00
return cb( world, x, y, z ).recolourBlock( side, colour, who );
}
catch (Throwable t)
{
}
return false;
}
@Override
public void randomDisplayTick(World world, int x, int y, int z, Random r)
{
2014-01-20 17:41:37 +01:00
cb( world, x, y, z ).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-01-29 04:10:23 +01:00
if ( block != null && block != this )
{
return block.getLightValue( world, x, y, z );
}
if ( block == null )
return 0;
2014-01-20 17:41:37 +01:00
return cb( world, x, y, z ).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)
{
return cb( world, x, y, z ).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-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;
return ExtraBlockTextures.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-02-09 02:34:52 +01:00
public boolean isSideSolid(IBlockAccess w, int x, int y, int z, ForgeDirection side)
{
return cb( w, x, y, z ).isSolidOnSide( side );
}
@Override
2014-02-09 02:34:52 +01:00
public void onNeighborBlockChange(World w, int x, int y, int z, Block meh)
{
cb( w, x, y, z ).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
public boolean onActivated(World w, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
return cb( w, x, y, z ).activate( player, w.getWorldVec3Pool().getVecFromPool( hitX, hitY, hitZ ) );
}
@Override
public void onEntityCollidedWithBlock(World w, int x, int y, int z, Entity e)
{
cb( w, x, y, z ).onEntityCollision( e );
}
@Override
public boolean canConnectRedstone(IBlockAccess w, int x, int y, int z, int side)
{
2014-01-06 07:54:51 +01:00
switch (side)
{
case -1:
case 4:
return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN ) );
case 0:
return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.NORTH ) );
case 1:
return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.EAST ) );
case 2:
return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.SOUTH ) );
case 3:
return cb( w, x, y, z ).canConnectRedstone( EnumSet.of( ForgeDirection.WEST ) );
}
return false;
}
@Override
public int isProvidingWeakPower(IBlockAccess w, int x, int y, int z, int side)
{
2014-01-06 07:54:51 +01:00
return cb( w, x, y, z ).isProvidingWeakPower( ForgeDirection.getOrientation( side ).getOpposite() );
}
@Override
public int isProvidingStrongPower(IBlockAccess w, int x, int y, int z, int side)
{
2014-01-06 07:54:51 +01:00
return cb( w, x, y, z ).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;
}