Applied-Energistics-2-tiler.../src/main/java/appeng/block/misc/BlockQuartzTorch.java

202 lines
5.4 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.block.misc;
import java.util.Collections;
2014-09-24 02:26:27 +02:00
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
2015-06-16 02:44:59 +02:00
import net.minecraft.block.BlockTorch;
2014-09-24 02:26:27 +02:00
import net.minecraft.block.material.Material;
2015-06-16 02:44:59 +02:00
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.IBlockState;
2014-09-24 02:26:27 +02:00
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
2014-09-24 02:26:27 +02:00
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
2015-06-16 02:44:59 +02:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2014-09-24 02:26:27 +02:00
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.LightningFX;
import appeng.core.AEConfig;
import appeng.core.CommonHelper;
import appeng.core.features.AEFeature;
import appeng.helpers.ICustomCollision;
import appeng.helpers.MetaRotation;
2014-09-24 02:26:27 +02:00
public class BlockQuartzTorch extends AEBaseBlock implements IOrientableBlock, ICustomCollision
{
public BlockQuartzTorch()
{
super( Material.circuits );
2014-09-24 02:26:27 +02:00
this.setFeature( EnumSet.of( AEFeature.DecorativeLights ) );
this.setLightLevel( 0.9375F );
this.setLightOpacity( 0 );
this.isFullSize = false;
this.isOpaque = false;
2014-09-24 02:26:27 +02:00
}
2015-06-16 02:44:59 +02:00
@Override
public int getMetaFromState(
IBlockState state )
{
return 0;
}
@Override
public IBlockState getStateFromMeta(
int meta )
{
return getDefaultState();
}
@Override
protected IProperty[] getAEStates()
{
return new IProperty[]{ BlockTorch.FACING };
}
2014-09-24 02:26:27 +02:00
@Override
protected Class<? extends BaseBlockRender> getRenderer()
2014-09-24 02:26:27 +02:00
{
return RenderQuartzTorch.class;
2014-09-24 02:26:27 +02:00
}
@Override
2015-06-16 02:44:59 +02:00
public boolean isValidOrientation( World w, BlockPos pos, EnumFacing forward, EnumFacing up )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
return this.canPlaceAt( w, pos, up.getOpposite() );
2014-09-24 02:26:27 +02:00
}
2015-06-16 02:44:59 +02:00
private boolean canPlaceAt( World w, BlockPos pos, EnumFacing dir )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
BlockPos test = pos.offset( dir );
return w.isSideSolid( test, dir.getOpposite(), false );
2014-09-24 02:26:27 +02:00
}
@Override
2015-06-16 02:44:59 +02:00
public Iterable<AxisAlignedBB> getSelectedBoundingBoxesFromPool( World w, BlockPos pos, Entity e, boolean isVisual )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
EnumFacing up = this.getOrientable( w, pos ).getUp();
double xOff = -0.3 * up.getFrontOffsetX();
double yOff = -0.3 * up.getFrontOffsetY();
double zOff = -0.3 * up.getFrontOffsetZ();
return Collections.singletonList( AxisAlignedBB.fromBounds( xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7 ) );
2014-09-24 02:26:27 +02:00
}
@Override
2015-06-16 02:44:59 +02:00
public void addCollidingBlockToList( World w, BlockPos pos, AxisAlignedBB bb, List out, Entity e )
2014-09-24 02:26:27 +02:00
{/*
* double xOff = -0.15 * getUp().offsetX; double yOff = -0.15 * getUp().offsetY; double zOff = -0.15 *
* getUp().offsetZ; out.add( AxisAlignedBB.getBoundingBox( xOff + (double) x + 0.15, yOff + (double) y + 0.15, zOff
* + (double) z + 0.15,// ahh xOff + (double) x + 0.85, yOff + (double) y + 0.85, zOff + (double) z + 0.85 ) );
*/
}
2015-06-16 02:44:59 +02:00
2014-09-24 02:26:27 +02:00
@Override
@SideOnly( Side.CLIENT )
2015-06-16 02:44:59 +02:00
public void randomDisplayTick(
World w,
BlockPos pos,
IBlockState state,
Random r )
2014-09-24 02:26:27 +02:00
{
if( !AEConfig.instance.enableEffects )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
return;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
if( r.nextFloat() < 0.98 )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
return;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
EnumFacing up = this.getOrientable( w, pos ).getUp();
double xOff = -0.3 * up.getFrontOffsetX();
double yOff = -0.3 * up.getFrontOffsetY();
double zOff = -0.3 * up.getFrontOffsetZ();
for( int bolts = 0; bolts < 3; bolts++ )
2014-09-24 02:26:27 +02:00
{
if( CommonHelper.proxy.shouldAddParticles( r ) )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
LightningFX fx = new LightningFX( w, xOff + 0.5 + pos.getX(), yOff + 0.5 + pos.getY(), zOff + 0.5 + pos.getZ(), 0.0D, 0.0D, 0.0D );
2014-09-24 02:26:27 +02:00
2014-09-28 20:56:16 +02:00
Minecraft.getMinecraft().effectRenderer.addEffect( fx );
2014-09-24 02:26:27 +02:00
}
}
}
@Override
2015-06-16 02:44:59 +02:00
public void onNeighborBlockChange(
World w,
BlockPos pos,
IBlockState state,
Block neighborBlock )
{
2015-06-16 02:44:59 +02:00
EnumFacing up = this.getOrientable( w, pos ).getUp();
if( !this.canPlaceAt( w, pos, up.getOpposite() ) )
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
this.dropTorch( w, pos );
2015-04-29 02:30:53 +02:00
}
}
2015-06-16 02:44:59 +02:00
private void dropTorch( World w, BlockPos pos )
{
2015-06-16 02:44:59 +02:00
w.destroyBlock( pos, true );
w.markBlockForUpdate( pos );
}
@Override
2015-06-16 02:44:59 +02:00
public boolean canPlaceBlockAt( World w, BlockPos pos )
{
2015-06-16 02:44:59 +02:00
for( EnumFacing dir : EnumFacing.VALUES )
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
if( this.canPlaceAt( w, pos, dir ) )
2015-04-29 02:30:53 +02:00
{
return true;
2015-04-29 02:30:53 +02:00
}
}
return false;
}
2014-09-24 02:26:27 +02:00
@Override
public boolean usesMetadata()
{
return true;
}
@Override
2015-06-16 02:44:59 +02:00
public IOrientable getOrientable( final IBlockAccess w, BlockPos pos )
{
2015-06-16 02:44:59 +02:00
return new MetaRotation( w, pos,true );
}
2014-09-24 02:26:27 +02:00
}