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>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.block.grindstone;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2017-04-12 16:10:13 +02:00
|
|
|
import appeng.api.implementations.tiles.ICrankable;
|
|
|
|
import appeng.block.AEBaseTileBlock;
|
|
|
|
import appeng.client.render.blocks.RenderBlockCrank;
|
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.core.stats.Stats;
|
|
|
|
import appeng.tile.AEBaseTile;
|
|
|
|
import appeng.tile.grindstone.TileCrank;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.block.Block;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.world.World;
|
2014-08-07 04:02:08 +02:00
|
|
|
import net.minecraftforge.common.util.FakePlayer;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2017-04-12 16:10:13 +02:00
|
|
|
import java.util.EnumSet;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-05-09 12:18:43 +02:00
|
|
|
public class BlockCrank extends AEBaseTileBlock
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public BlockCrank()
|
|
|
|
{
|
2015-04-04 00:42:19 +02:00
|
|
|
super( Material.wood );
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setTileEntity( TileCrank.class );
|
|
|
|
this.setLightOpacity( 0 );
|
2015-01-17 15:07:01 +01:00
|
|
|
this.setHarvestLevel( "axe", 0 );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.isFullSize = this.isOpaque = false;
|
2015-04-04 01:26:35 +02:00
|
|
|
this.setFeature( EnumSet.of( AEFeature.GrindStone ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-16 18:03:07 +02:00
|
|
|
@SideOnly( Side.CLIENT )
|
|
|
|
public RenderBlockCrank getRenderer()
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-09-16 18:03:07 +02:00
|
|
|
return new RenderBlockCrank();
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean onActivated( final World w, final int x, final int y, final int z, final EntityPlayer player, final int side, final float hitX, final float hitY, final float hitZ )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( player instanceof FakePlayer || player == null )
|
2014-11-29 12:34:33 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.dropCrank( w, x, y, z );
|
2014-08-07 04:02:08 +02:00
|
|
|
return true;
|
2014-11-29 12:34:33 +01:00
|
|
|
}
|
2014-08-07 04:02:08 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final AEBaseTile tile = this.getTileEntity( w, x, y, z );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tile instanceof TileCrank )
|
2014-08-31 10:06:06 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ( (TileCrank) tile ).power() )
|
2014-08-31 10:06:06 +02:00
|
|
|
{
|
2014-11-29 12:34:33 +01:00
|
|
|
Stats.TurnedCranks.addToPlayer( player, 1 );
|
2014-08-31 10:06:06 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-07 04:02:08 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
private void dropCrank( final World world, final int x, final int y, final int z )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-11-29 12:34:33 +01:00
|
|
|
world.func_147480_a( x, y, z, true ); // w.destroyBlock( x, y, z, true );
|
|
|
|
world.markBlockForUpdate( x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void onBlockPlacedBy( final World world, final int x, final int y, final int z, final EntityLivingBase placer, final ItemStack itemStack )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final AEBaseTile tile = this.getTileEntity( world, x, y, z );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tile != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ForgeDirection mnt = this.findCrankable( world, x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
ForgeDirection forward = ForgeDirection.UP;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( mnt == ForgeDirection.UP || mnt == ForgeDirection.DOWN )
|
2014-11-29 12:34:33 +01:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
forward = ForgeDirection.SOUTH;
|
2014-11-29 12:34:33 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
tile.setOrientation( forward, mnt.getOpposite() );
|
|
|
|
}
|
|
|
|
else
|
2014-11-29 12:34:33 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.dropCrank( world, x, y, z );
|
2014-11-29 12:34:33 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean isValidOrientation( final World world, final int x, final int y, final int z, final ForgeDirection forward, final ForgeDirection up )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final TileEntity te = world.getTileEntity( x, y, z );
|
2015-04-03 08:54:31 +02:00
|
|
|
return !( te instanceof TileCrank ) || this.isCrankable( world, x, y, z, up.getOpposite() );
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
private ForgeDirection findCrankable( final World world, final int x, final int y, final int z )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isCrankable( world, x, y, z, dir ) )
|
|
|
|
{
|
|
|
|
return dir;
|
|
|
|
}
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return ForgeDirection.UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
private boolean isCrankable( final World world, final int x, final int y, final int z, final ForgeDirection offset )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final TileEntity te = world.getTileEntity( x + offset.offsetX, y + offset.offsetY, z + offset.offsetZ );
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
return te instanceof ICrankable && ( (ICrankable) te ).canCrankAttach( offset.getOpposite() );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public void onNeighborBlockChange( final World world, final int x, final int y, final int z, final Block block )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final AEBaseTile tile = this.getTileEntity( world, x, y, z );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tile != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.isCrankable( world, x, y, z, tile.getUp().getOpposite() ) )
|
2014-11-29 12:34:33 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.dropCrank( world, x, y, z );
|
2014-11-29 12:34:33 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
else
|
2014-11-29 12:34:33 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.dropCrank( world, x, y, z );
|
2014-11-29 12:34:33 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean canPlaceBlockAt( final World world, final int x, final int y, final int z )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
return this.findCrankable( world, x, y, z ) != ForgeDirection.UNKNOWN;
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|