Applied-Energistics-2-tiler.../block/misc/BlockQuartzTorch.java

141 lines
4.3 KiB
Java
Raw Normal View History

package appeng.block.misc;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
2014-02-09 02:34:52 +01:00
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
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.util.IOrientable;
import appeng.api.util.IOrientableBlock;
import appeng.block.AEBaseBlock;
import appeng.client.render.BaseBlockRender;
import appeng.client.render.blocks.RenderQuartzTorch;
import appeng.client.render.effects.LightningEffect;
2014-02-09 06:08:27 +01:00
import appeng.core.AEConfig;
2014-05-11 18:24:46 +02:00
import appeng.core.CommonHelper;
import appeng.core.features.AEFeature;
import appeng.helpers.ICustomCollision;
import appeng.helpers.MetaRotation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockQuartzTorch extends AEBaseBlock implements IOrientableBlock, ICustomCollision
{
public BlockQuartzTorch() {
super( BlockQuartzTorch.class, Material.circuits );
setfeature( EnumSet.of( AEFeature.DecorativeLights ) );
setLightOpacity( 0 );
2014-02-09 02:34:52 +01:00
setLightLevel( 0.9375F );
isFullSize = isOpaque = false;
}
@Override
protected Class<? extends BaseBlockRender> getRenderer()
{
return RenderQuartzTorch.class;
}
@Override
public IOrientable getOrientable(final IBlockAccess w, final int x, final int y, final int z)
{
return new MetaRotation( w, x, y, z );
}
private void dropTorch(World w, int x, int y, int z)
{
2014-02-09 02:34:52 +01:00
w.func_147480_a( x, y, z, true );
// w.destroyBlock( x, y, z, true );
w.markBlockForUpdate( x, y, z );
}
@Override
public boolean canPlaceBlockAt(World w, int x, int y, int z)
{
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
if ( canPlaceAt( w, x, y, z, dir ) )
return true;
return false;
}
private boolean canPlaceAt(World w, int x, int y, int z, ForgeDirection dir)
{
2014-02-09 02:34:52 +01:00
return w.isSideSolid( x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, dir.getOpposite(), false );
}
@Override
public boolean isValidOrientation(World w, int x, int y, int z, ForgeDirection forward, ForgeDirection up)
{
return canPlaceAt( w, x, y, z, up.getOpposite() );
}
@Override
2014-02-09 02:34:52 +01:00
public void onNeighborBlockChange(World w, int x, int y, int z, Block id)
{
ForgeDirection up = getOrientable( w, x, y, z ).getUp();
if ( !canPlaceAt( w, x, y, z, up.getOpposite() ) )
dropTorch( w, x, y, z );
}
@Override
public Iterable<AxisAlignedBB> getSelectedBoundingBoxsFromPool(World w, int x, int y, int z, Entity e, boolean isVisual)
{
ForgeDirection up = getOrientable( w, x, y, z ).getUp();
double xOff = -0.3 * up.offsetX;
double yOff = -0.3 * up.offsetY;
double zOff = -0.3 * up.offsetZ;
return Arrays.asList( new AxisAlignedBB[] { AxisAlignedBB.getBoundingBox( xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7 ) } );
}
@Override
public void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List out, Entity e)
{/*
2014-02-09 02:34:52 +01:00
* double xOff = -0.15 * getUp().offsetX; double yOff = -0.15 * getUp().offsetY; double zOff = -0.15 *
2014-06-05 05:59:56 +02:00
* getUp().offsetZ; out.add( AxisAlignedBB.getBoundingBox( xOff + (double) x + 0.15, yOff + (double) y +
2014-02-09 02:34:52 +01:00
* 0.15, zOff + (double) z + 0.15,// ahh xOff + (double) x + 0.85, yOff + (double) y + 0.85, zOff + (double) z +
* 0.85 ) );
*/
}
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World w, int x, int y, int z, Random r)
{
2014-02-09 06:08:27 +01:00
if ( !AEConfig.instance.enableEffects )
return;
if ( r.nextFloat() < 0.98 )
return;
ForgeDirection up = getOrientable( w, x, y, z ).getUp();
double xOff = -0.3 * up.offsetX;
double yOff = -0.3 * up.offsetY;
double zOff = -0.3 * up.offsetZ;
for (int bolts = 0; bolts < 3; bolts++)
{
2014-01-30 03:47:55 +01:00
if ( CommonHelper.proxy.shouldAddParticles( r ) )
{
LightningEffect fx = new LightningEffect( w, xOff + 0.5 + x, yOff + 0.5 + y, zOff + 0.5 + z, 0.0D, 0.0D, 0.0D );
2014-01-30 03:47:55 +01:00
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
}
}
}
2014-05-11 18:24:46 +02:00
@Override
public boolean usesMetadata()
{
return true;
}
}