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

185 lines
5.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-07-16 03:26:04 +02:00
package appeng.block.misc;
2016-01-01 01:48:15 +01:00
import java.util.Collections;
2014-07-16 03:26:04 +02:00
import java.util.EnumSet;
import java.util.List;
2014-07-16 03:26:04 +02:00
import java.util.Random;
import net.minecraft.block.Block;
2015-06-16 02:44:59 +02:00
import net.minecraft.block.BlockTorch;
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;
import net.minecraft.entity.Entity;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
2014-07-16 03:26:04 +02:00
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
2015-12-24 02:07:03 +01:00
2016-01-01 01:47:22 +01:00
import appeng.api.util.IOrientable;
import appeng.api.util.IOrientableBlock;
import appeng.block.AEBaseTileBlock;
import appeng.core.features.AEFeature;
import appeng.helpers.ICustomCollision;
import appeng.helpers.MetaRotation;
import appeng.tile.misc.TileLightDetector;
2016-01-01 01:48:15 +01:00
2015-12-24 02:03:16 +01:00
public class BlockLightDetector extends AEBaseTileBlock implements IOrientableBlock, ICustomCollision
2014-07-16 03:26:04 +02:00
{
public BlockLightDetector()
{
super( Material.CIRCUITS );
2016-01-01 01:50:28 +01:00
this.setLightOpacity( 0 );
this.setFullSize( false );
this.setOpaque( false );
2016-01-01 01:50:28 +01:00
this.setTileEntity( TileLightDetector.class );
this.setFeature( EnumSet.of( AEFeature.LightDetector ) );
2014-07-16 03:26:04 +02:00
}
@Override
public int getMetaFromState( final IBlockState state )
2015-06-16 02:44:59 +02:00
{
return 0;
}
2015-12-24 02:03:16 +01:00
2015-06-16 02:44:59 +02:00
@Override
public IBlockState getStateFromMeta( final int meta )
2015-06-16 02:44:59 +02:00
{
2016-01-01 01:50:28 +01:00
return this.getDefaultState();
2015-06-16 02:44:59 +02:00
}
2015-12-24 02:03:16 +01:00
2015-06-16 02:44:59 +02:00
@Override
protected IProperty[] getAEStates()
{
//TODO 1.10-R - wtf?
return new IProperty[] { AE_BLOCK_FORWARD, AE_BLOCK_UP, BlockTorch.FACING };
2015-06-16 02:44:59 +02:00
}
@Override
public int getWeakPower( final IBlockState state, final IBlockAccess w, final BlockPos pos, final EnumFacing side )
2014-07-16 03:26:04 +02:00
{
2016-01-01 01:48:15 +01:00
if( w instanceof World && ( (TileLightDetector) this.getTileEntity( w, pos ) ).isReady() )
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
return ( (World) w ).getLightFromNeighbors( pos ) - 6;
2015-04-29 02:30:53 +02:00
}
2014-07-16 03:26:04 +02:00
return 0;
2014-07-16 03:26:04 +02:00
}
@Override
public void onNeighborChange( final IBlockAccess world, final BlockPos pos, final BlockPos neighbor )
2014-07-16 03:26:04 +02:00
{
2015-06-16 02:44:59 +02:00
super.onNeighborChange( world, pos, neighbor );
2014-07-16 03:26:04 +02:00
2015-09-30 14:24:40 +02:00
final TileLightDetector tld = this.getTileEntity( world, pos );
2016-01-01 01:48:15 +01:00
if( tld != null )
2015-04-29 02:30:53 +02:00
{
tld.updateLight();
2015-04-29 02:30:53 +02:00
}
2014-07-16 03:26:04 +02:00
}
@Override
public void randomDisplayTick( final IBlockState state, final World worldIn, final BlockPos pos, final Random rand )
2014-07-16 03:26:04 +02:00
{
// cancel out lightning
}
@Override
public boolean isValidOrientation( final World w, final BlockPos pos, final EnumFacing forward, final EnumFacing up )
{
2016-01-01 01:50:28 +01:00
return this.canPlaceAt( w, pos, up.getOpposite() );
}
private boolean canPlaceAt( final World w, final BlockPos pos, final EnumFacing dir )
{
2015-06-16 02:44:59 +02:00
return w.isSideSolid( pos.offset( dir ), dir.getOpposite(), false );
}
2015-12-24 02:03:16 +01:00
@Override
public Iterable<AxisAlignedBB> getSelectedBoundingBoxesFromPool( final World w, final BlockPos pos, final Entity thePlayer, final boolean b )
2015-09-30 14:24:40 +02:00
{
2016-01-01 01:50:28 +01:00
final EnumFacing up = this.getOrientable( w, pos ).getUp();
2015-09-30 14:24:40 +02:00
final double xOff = -0.3 * up.getFrontOffsetX();
final double yOff = -0.3 * up.getFrontOffsetY();
final double zOff = -0.3 * up.getFrontOffsetZ();
return Collections.singletonList( new AxisAlignedBB( xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7 ) );
}
@Override
public void addCollidingBlockToList( final World w, final BlockPos pos, final AxisAlignedBB bb, final List<AxisAlignedBB> out, final Entity e )
{/*
2016-01-01 01:48:15 +01: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 ) );
*/
}
@Override
public void neighborChanged( IBlockState state, World w, BlockPos pos, Block blockIn )
{
2016-01-01 01:50:28 +01:00
final EnumFacing up = this.getOrientable( w, pos ).getUp();
if( !this.canPlaceAt( (World) w, pos, up.getOpposite() ) )
{
this.dropTorch( (World) w, pos );
}
}
private void dropTorch( final World w, final BlockPos pos )
{
final IBlockState prev = w.getBlockState( pos );
2015-06-16 02:44:59 +02:00
w.destroyBlock( pos, true );
w.notifyBlockUpdate( pos, prev, w.getBlockState( pos ), 3 );
}
2015-12-24 02:03:16 +01:00
@Override
public boolean canPlaceBlockAt( final World w, final BlockPos pos )
{
2016-01-01 01:48:15 +01:00
for( final EnumFacing dir : EnumFacing.VALUES )
{
2016-01-01 01:50:28 +01:00
if( this.canPlaceAt( w, pos, dir ) )
{
return true;
}
}
return false;
}
@Override
public boolean usesMetadata()
{
return true;
}
@Override
public IOrientable getOrientable( final IBlockAccess w, final BlockPos pos )
{
2015-12-24 02:03:16 +01:00
return new MetaRotation( w, pos, true );
}
2014-07-16 03:26:04 +02:00
}