2013-12-27 23:59:59 +01:00
|
|
|
package appeng.block.grindstone;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
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-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.tiles.ICrankable;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.block.AEBaseBlock;
|
|
|
|
import appeng.client.render.BaseBlockRender;
|
|
|
|
import appeng.client.render.blocks.RenderBlockCrank;
|
|
|
|
import appeng.core.features.AEFeature;
|
|
|
|
import appeng.tile.AEBaseTile;
|
|
|
|
import appeng.tile.grindstone.TileCrank;
|
|
|
|
|
|
|
|
public class BlockCrank extends AEBaseBlock
|
|
|
|
{
|
|
|
|
|
|
|
|
public BlockCrank() {
|
|
|
|
super( BlockCrank.class, Material.wood );
|
|
|
|
setfeature( EnumSet.of( AEFeature.GrindStone ) );
|
|
|
|
setTileEntiy( TileCrank.class );
|
|
|
|
setLightOpacity( 0 );
|
|
|
|
isFullSize = isOpaque = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActivated(World w, int x, int y, int z, EntityPlayer p, int side, float hitX, float hitY, float hitZ)
|
|
|
|
{
|
2014-08-07 04:02:08 +02:00
|
|
|
if ( p instanceof FakePlayer )
|
|
|
|
return true;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
AEBaseTile tile = getTileEntity( w, x, y, z );
|
|
|
|
if ( tile instanceof TileCrank )
|
|
|
|
((TileCrank) tile).power();
|
2014-08-07 04:02:08 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends BaseBlockRender> getRenderer()
|
|
|
|
{
|
|
|
|
return RenderBlockCrank.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isCrankable(World w, int x, int y, int z, ForgeDirection offset)
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
TileEntity te = w.getTileEntity( x + offset.offsetX, y + offset.offsetY, z + offset.offsetZ );
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( te instanceof ICrankable )
|
|
|
|
{
|
|
|
|
return ((ICrankable) te).canCrankAttach( offset.getOpposite() );
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private ForgeDirection findCrankable(World w, int x, int y, int z)
|
|
|
|
{
|
|
|
|
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
if ( isCrankable( w, x, y, z, dir ) )
|
|
|
|
return dir;
|
|
|
|
return ForgeDirection.UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canPlaceBlockAt(World w, int x, int y, int z)
|
|
|
|
{
|
|
|
|
return findCrankable( w, x, y, z ) != ForgeDirection.UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isValidOrientation(World w, int x, int y, int z, ForgeDirection forward, ForgeDirection up)
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
TileEntity te = w.getTileEntity( x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
return !(te instanceof TileCrank) || isCrankable( w, x, y, z, up.getOpposite() );
|
|
|
|
}
|
|
|
|
|
|
|
|
private void dropCrank(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 );
|
2013-12-27 23:59:59 +01:00
|
|
|
w.markBlockForUpdate( x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockPlacedBy(World w, int x, int y, int z, EntityLivingBase p, ItemStack is)
|
|
|
|
{
|
|
|
|
AEBaseTile tile = getTileEntity( w, x, y, z );
|
|
|
|
if ( tile != null )
|
|
|
|
{
|
|
|
|
ForgeDirection mnt = findCrankable( w, x, y, z );
|
|
|
|
ForgeDirection forward = ForgeDirection.UP;
|
|
|
|
if ( mnt == ForgeDirection.UP || mnt == ForgeDirection.DOWN )
|
|
|
|
forward = ForgeDirection.SOUTH;
|
|
|
|
tile.setOrientation( forward, mnt.getOpposite() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dropCrank( w, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void onNeighborBlockChange(World w, int x, int y, int z, Block id)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
AEBaseTile tile = getTileEntity( w, x, y, z );
|
|
|
|
if ( tile != null )
|
|
|
|
{
|
|
|
|
if ( !isCrankable( w, x, y, z, tile.getUp().getOpposite() ) )
|
|
|
|
dropCrank( w, x, y, z );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dropCrank( w, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|